diff options
author | Ćukasz 'sil2100' Zemczak <lukasz.zemczak@ubuntu.com> | 2017-05-18 19:58:02 +0200 |
---|---|---|
committer | usd-importer <ubuntu-server@lists.ubuntu.com> | 2017-05-31 09:53:12 +0000 |
commit | 4fb0b5a09b26135ade285844da5d7dfe582a8d4c (patch) | |
tree | 09b1e5867d6e7501118cdd0af0012b51fc216530 /tests/common/osutil/test_default.py | |
parent | 473ad6fbfe0b9c3b362b530492928303f2b4c7f3 (diff) | |
download | vyos-walinuxagent-4fb0b5a09b26135ade285844da5d7dfe582a8d4c.tar.gz vyos-walinuxagent-4fb0b5a09b26135ade285844da5d7dfe582a8d4c.zip |
Import patches-unapplied version 2.2.12-0ubuntu1 to ubuntu/artful-proposed
Imported using git-ubuntu import.
Changelog parent: 473ad6fbfe0b9c3b362b530492928303f2b4c7f3
New changelog entries:
* New upstream release (LP: #1690854).
- Refreshed debian/patches/disable_import_test.patch.
Diffstat (limited to 'tests/common/osutil/test_default.py')
-rw-r--r-- | tests/common/osutil/test_default.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/common/osutil/test_default.py b/tests/common/osutil/test_default.py index 933787b..87acc60 100644 --- a/tests/common/osutil/test_default.py +++ b/tests/common/osutil/test_default.py @@ -18,8 +18,11 @@ import socket import glob import mock + import azurelinuxagent.common.osutil.default as osutil import azurelinuxagent.common.utils.shellutil as shellutil +from azurelinuxagent.common.exception import OSUtilError +from azurelinuxagent.common.future import ustr from azurelinuxagent.common.osutil import get_osutil from azurelinuxagent.common.utils import fileutil from tests.tools import * @@ -40,6 +43,50 @@ class TestOSUtil(AgentTestCase): self.assertEqual(run_patch.call_count, retries) self.assertEqual(run_patch.call_args_list[0][0][0], 'ifdown {0} && ifup {0}'.format(ifname)) + def test_get_dvd_device_success(self): + with patch.object(os, 'listdir', return_value=['cpu', 'cdrom0']): + osutil.DefaultOSUtil().get_dvd_device() + + def test_get_dvd_device_failure(self): + with patch.object(os, 'listdir', return_value=['cpu', 'notmatching']): + try: + osutil.DefaultOSUtil().get_dvd_device() + self.fail('OSUtilError was not raised') + except OSUtilError as ose: + self.assertTrue('notmatching' in ustr(ose)) + + @patch('time.sleep') + def test_mount_dvd_success(self, _): + msg = 'message' + with patch.object(osutil.DefaultOSUtil, + 'get_dvd_device', + return_value='/dev/cdrom'): + with patch.object(shellutil, + 'run_get_output', + return_value=(0, msg)) as patch_run: + with patch.object(os, 'makedirs'): + try: + osutil.DefaultOSUtil().mount_dvd() + except OSUtilError: + self.fail("mounting failed") + + @patch('time.sleep') + def test_mount_dvd_failure(self, _): + msg = 'message' + with patch.object(osutil.DefaultOSUtil, + 'get_dvd_device', + return_value='/dev/cdrom'): + with patch.object(shellutil, + 'run_get_output', + return_value=(1, msg)) as patch_run: + with patch.object(os, 'makedirs'): + try: + osutil.DefaultOSUtil().mount_dvd() + self.fail('OSUtilError was not raised') + except OSUtilError as ose: + self.assertTrue(msg in ustr(ose)) + self.assertTrue(patch_run.call_count == 6) + def test_get_first_if(self): ifname, ipaddr = osutil.DefaultOSUtil().get_first_if() self.assertTrue(ifname.startswith('eth')) @@ -315,5 +362,37 @@ Match host 192.168.1.2\n\ conf.get_sshd_conf_file_path(), expected_output) + @patch('os.path.isfile', return_value=True) + @patch('azurelinuxagent.common.utils.fileutil.read_file', + return_value="B9F3C233-9913-9F42-8EB3-BA656DF32502") + def test_get_instance_id_from_file(self, mock_read, mock_isfile): + util = osutil.DefaultOSUtil() + self.assertEqual( + "B9F3C233-9913-9F42-8EB3-BA656DF32502", + util.get_instance_id()) + + @patch('os.path.isfile', return_value=False) + @patch('azurelinuxagent.common.utils.shellutil.run_get_output', + return_value=[0, 'B9F3C233-9913-9F42-8EB3-BA656DF32502']) + def test_get_instance_id_from_dmidecode(self, mock_shell, mock_isfile): + util = osutil.DefaultOSUtil() + self.assertEqual( + "B9F3C233-9913-9F42-8EB3-BA656DF32502", + util.get_instance_id()) + + @patch('os.path.isfile', return_value=False) + @patch('azurelinuxagent.common.utils.shellutil.run_get_output', + return_value=[1, 'Error Value']) + def test_get_instance_id_missing(self, mock_shell, mock_isfile): + util = osutil.DefaultOSUtil() + self.assertEqual("", util.get_instance_id()) + + @patch('os.path.isfile', return_value=False) + @patch('azurelinuxagent.common.utils.shellutil.run_get_output', + return_value=[0, 'Unexpected Value']) + def test_get_instance_id_unexpected(self, mock_shell, mock_isfile): + util = osutil.DefaultOSUtil() + self.assertEqual("", util.get_instance_id()) + if __name__ == '__main__': unittest.main() |