mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add grains unit test for Ubuntu systems
This commit is contained in:
parent
3904e4b81c
commit
4dc45f2509
1 changed files with 73 additions and 0 deletions
|
@ -376,6 +376,79 @@ PATCHLEVEL = 3
|
|||
self._run_suse_os_grains_tests(_os_release_map)
|
||||
|
||||
|
||||
@skipIf(not salt.utils.is_linux(), 'System is not Linux')
|
||||
def test_suse_os_grains_ubuntu(self):
|
||||
'''
|
||||
Test if OS grains are parsed correctly in Ubuntu Xenial Xerus
|
||||
'''
|
||||
_os_release_map = {
|
||||
'os_release_file': {
|
||||
'NAME': 'Ubuntu',
|
||||
'VERSION': '16.04.1 LTS (Xenial Xerus)',
|
||||
'VERSION_ID': '16.04',
|
||||
'PRETTY_NAME': '',
|
||||
'ID': 'ubuntu',
|
||||
},
|
||||
'oscodename': 'xenial',
|
||||
'osfullname': 'Ubuntu',
|
||||
'osrelease': '16.04',
|
||||
'osrelease_info': [16, 4],
|
||||
'osmajorrelease': '16',
|
||||
'osfinger': 'Ubuntu-16.04',
|
||||
}
|
||||
self._run_ubuntu_os_grains_tests(_os_release_map)
|
||||
|
||||
|
||||
def _run_ubuntu_os_grains_tests(self, os_release_map):
|
||||
path_isfile_mock = MagicMock(side_effect=lambda x: x in ['/etc/os-release'])
|
||||
empty_mock = MagicMock(return_value={})
|
||||
osarch_mock = MagicMock(return_value="amd64")
|
||||
os_release_mock = MagicMock(return_value=os_release_map.get('os_release_file'))
|
||||
|
||||
orig_import = __import__
|
||||
|
||||
def _import_mock(name, *args):
|
||||
if name == 'lsb_release':
|
||||
raise ImportError('No module named lsb_release')
|
||||
return orig_import(name, *args)
|
||||
|
||||
# Skip the first if statement
|
||||
with patch.object(salt.utils, 'is_proxy',
|
||||
MagicMock(return_value=False)):
|
||||
# Skip the selinux/systemd stuff (not pertinent)
|
||||
with patch.object(core, '_linux_bin_exists',
|
||||
MagicMock(return_value=False)):
|
||||
# Skip the init grain compilation (not pertinent)
|
||||
with patch.object(os.path, 'exists', path_isfile_mock):
|
||||
# Ensure that lsb_release fails to import
|
||||
with patch('__builtin__.__import__',
|
||||
side_effect=_import_mock):
|
||||
# Skip all the /etc/*-release stuff (not pertinent)
|
||||
with patch.object(os.path, 'isfile', path_isfile_mock):
|
||||
with patch.object(core, '_parse_os_release', os_release_mock):
|
||||
# Mock platform.linux_distribution to give us the
|
||||
# OS name that we want.
|
||||
distro_mock = MagicMock(return_value=('Ubuntu', '16.04', 'xenial'))
|
||||
with patch("salt.utils.fopen", mock_open()) as suse_release_file:
|
||||
suse_release_file.return_value.__iter__.return_value = os_release_map.get(
|
||||
'suse_release_file', '').splitlines()
|
||||
with patch.object(platform, 'linux_distribution', distro_mock):
|
||||
with patch.object(core, '_linux_gpu_data', empty_mock):
|
||||
with patch.object(core, '_linux_cpudata', empty_mock):
|
||||
with patch.object(core, '_virtual', empty_mock):
|
||||
# Mock the osarch
|
||||
with patch.dict(core.__salt__, {'cmd.run': osarch_mock}):
|
||||
os_grains = core.os_data()
|
||||
|
||||
self.assertEqual(os_grains.get('os'), 'Ubuntu')
|
||||
self.assertEqual(os_grains.get('os_family'), 'Debian')
|
||||
self.assertEqual(os_grains.get('osfullname'), os_release_map['osfullname'])
|
||||
self.assertEqual(os_grains.get('oscodename'), os_release_map['oscodename'])
|
||||
self.assertEqual(os_grains.get('osrelease'), os_release_map['osrelease'])
|
||||
self.assertListEqual(list(os_grains.get('osrelease_info')), os_release_map['osrelease_info'])
|
||||
self.assertEqual(os_grains.get('osmajorrelease'), os_release_map['osmajorrelease'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(CoreGrainsTestCase, needs_daemon=False)
|
||||
|
|
Loading…
Add table
Reference in a new issue