Fixes unit tests to work with latest version of oslo.config

In version 4.0.0 of oslo.config the type of the values given in the
config file is verified to see if it corresponds with the type declared.
Some unit tests used values with different types for the config
parameters.

Change-Id: I013d0689d8adf832f97cbfb008463711df928cae
This commit is contained in:
Paula Madalina Crismaru 2017-04-27 14:05:19 +03:00
parent 834f19058c
commit f8db0d5333
6 changed files with 16 additions and 19 deletions

View File

@ -46,7 +46,7 @@ class LocalScriptsPluginTests(unittest.TestCase):
@mock.patch('cloudbaseinit.plugins.common.execcmd'
'.get_plugin_return_value')
@testutils.ConfPatcher('local_scripts_path',
mock.sentinel.mock_local_scripts_path)
'fake_local_scripts_path')
@mock.patch('cloudbaseinit.plugins.common.localscripts'
'.LocalScriptsPlugin._get_files_in_dir')
@mock.patch('cloudbaseinit.plugins.common.fileexecutils.exec_file')
@ -65,7 +65,7 @@ class LocalScriptsPluginTests(unittest.TestCase):
response = self._localscripts.execute(mock_service, shared_data=None)
mock_get_files_in_dir.assert_called_once_with(
mock.sentinel.mock_local_scripts_path)
'fake_local_scripts_path')
mock_exec_file.assert_called_with(fake_path)
mock_get_plugin_return_value.assert_any_call(1001)
mock_get_plugin_return_value.assert_any_call(1002)

View File

@ -33,7 +33,7 @@ class NTPClientPluginTests(unittest.TestCase):
self._ntpclient = ntpclient.NTPClientPlugin()
self.snatcher = testutils.LogSnatcher(MODULE_PATH)
@testutils.ConfPatcher("real_time_clock_utc", "fake time")
@testutils.ConfPatcher("real_time_clock_utc", True)
@mock.patch('cloudbaseinit.osutils.factory.get_os_utils')
@mock.patch('cloudbaseinit.utils.dhcp.get_dhcp_options')
@mock.patch(MODULE_PATH + '.NTPClientPlugin.verify_time_service')
@ -59,15 +59,9 @@ class NTPClientPluginTests(unittest.TestCase):
mock_options_data.get.return_value = ntp_data
expected_logging = []
reboot_required = False
reboot_required = not is_real_time
if is_real_time:
mock_time = "fake time"
else:
mock_time = "fake value"
reboot_required = True
mock_osutils.is_real_time_clock_utc.return_value = mock_time
mock_osutils.is_real_time_clock_utc.return_value = is_real_time
with self.snatcher:
with testutils.ConfPatcher('ntp_enable_service', enable_service):
@ -81,8 +75,8 @@ class NTPClientPluginTests(unittest.TestCase):
mock_osutils.is_real_time_clock_utc.assert_called_once_with()
if not is_real_time:
mock_osutils.set_real_time_clock_utc.assert_called_once_with(
"fake time")
expected_logging.append('RTC set to UTC: %s' % mock_time)
True)
expected_logging.append('RTC set to UTC: %s' % is_real_time)
if enable_service:
mock_verify_time_service.assert_called_once_with(mock_osutils)
expected_logging.append('NTP client service enabled')

View File

@ -34,7 +34,7 @@ class SetUserSSHPublicKeysPluginTests(unittest.TestCase):
self.fake_data = fake_json_response.get_fake_metadata_json(
'2013-04-04')
@testutils.ConfPatcher('username', mock.sentinel.username)
@testutils.ConfPatcher('username', 'fake_username')
@mock.patch('cloudbaseinit.osutils.factory.get_os_utils')
@mock.patch('os.path')
@mock.patch('os.makedirs')
@ -60,7 +60,7 @@ class SetUserSSHPublicKeysPluginTests(unittest.TestCase):
fake_shared_data)
mock_service.get_public_keys.assert_called_with()
mock_osutils.get_user_home.assert_called_with(
mock.sentinel.username)
'fake_username')
self.assertEqual(2, mock_os_path.join.call_count)
mock_os_makedirs.assert_called_once_with(mock_os_path.join())

View File

@ -21,6 +21,7 @@ except ImportError:
import mock
from cloudbaseinit import conf as cloudbaseinit_conf
from cloudbaseinit import constant
from cloudbaseinit.plugins.common import base
from cloudbaseinit.tests import testutils
@ -51,7 +52,8 @@ class BootConfigPluginTest(unittest.TestCase):
self.bcd_config = bootconfig.BCDConfigPlugin()
self.snatcher = testutils.LogSnatcher(MODPATH)
@testutils.ConfPatcher("bcd_boot_status_policy", True)
@testutils.ConfPatcher("bcd_boot_status_policy",
constant.POLICY_IGNORE_ALL_FAILURES)
@mock.patch("cloudbaseinit.utils.windows.bootconfig."
"set_boot_status_policy")
def _test_execute_policy_plugin(self, mock_set_boot_status_policy,

View File

@ -98,7 +98,7 @@ class PageFilesPluginTest(unittest.TestCase):
self._test_get_page_file_volumes_by_label(drives=mock_drives)
def test_get_page_file_volumes_by_label_drive_found(self):
fake_label = mock.Mock()
fake_label = "fake_label"
mock_drives = [mock.sentinel.fake_drive]
mock_labels = fake_label
mock_conf_labels = [fake_label]

View File

@ -245,8 +245,9 @@ class ConfigWinRMListenerPluginTests(unittest.TestCase):
"certificate_thumbprint": certificate_thumbprint
}
mock_get_winrm_listeners.return_value = [listener_config]
winrm_enable_basic_auth = mock.Mock(spec=bool)
with testutils.ConfPatcher('winrm_enable_basic_auth',
str(mock.sentinel.winrm_enable_basic_auth)):
winrm_enable_basic_auth):
result = self._winrmlistener.execute(
mock.sentinel.service, mock.sentinel.shared_data)
@ -260,7 +261,7 @@ class ConfigWinRMListenerPluginTests(unittest.TestCase):
mock_check_restrictions.assert_called_once_with(mock_osutils)
mock_WinRMConfig.assert_called_once_with()
mock_winrm_config.set_auth_config.assert_called_once_with(
basic=str(mock.sentinel.winrm_enable_basic_auth))
basic=winrm_enable_basic_auth)
winrmconfig = importlib.import_module('cloudbaseinit.utils.'
'windows.winrmconfig')
if (protocol == winrmconfig.LISTENER_PROTOCOL_HTTPS and