Use autospec=True in mocks
This is a follow up to comments on https://review.opendev.org/720010. Adding autospect=True requires an update to ironic_inspector.test.\ base.BaseTest.assertCalledWithPatch. Also add autospec=True in several mocks where it was not used. Change-Id: Ia340d7a8ecde1c8cf191555de87b11b19b30f06c
This commit is contained in:
parent
43de977994
commit
079b458db0
@ -80,7 +80,7 @@ class BaseTest(test_base.BaseTestCase):
|
||||
return call[0][1]
|
||||
except IndexError:
|
||||
pass
|
||||
return call[0][0]
|
||||
return call[0][2]
|
||||
|
||||
actual = sum(map(_get_patch_param, mock_call.call_args_list), [])
|
||||
self.assertPatchEqual(actual, expected)
|
||||
|
@ -54,8 +54,8 @@ class TestBasePortPhysnetHook(test_base.NodeTest):
|
||||
self.node_info = node_cache.NodeInfo(uuid=self.uuid, started_at=0,
|
||||
node=self.node, ports=ports)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(FakePortPhysnetHook, 'get_physnet')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
@mock.patch.object(FakePortPhysnetHook, 'get_physnet', autospec=True)
|
||||
def test_expected_data(self, mock_get, mock_patch):
|
||||
patches = [
|
||||
{'path': '/physical_network',
|
||||
@ -64,29 +64,29 @@ class TestBasePortPhysnetHook(test_base.NodeTest):
|
||||
mock_get.return_value = 'physnet2'
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
port = list(self.node_info.ports().values())[0]
|
||||
mock_get.assert_called_once_with(port, 'em1', self.data)
|
||||
mock_get.assert_called_once_with(self.hook, port, 'em1', self.data)
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(FakePortPhysnetHook, 'get_physnet')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
@mock.patch.object(FakePortPhysnetHook, 'get_physnet', autospec=True)
|
||||
def test_noop(self, mock_get, mock_patch):
|
||||
mock_get.return_value = 'physnet1'
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertFalse(mock_patch.called)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_no_mapping(self, mock_patch):
|
||||
self.hook.physnet = None
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertFalse(mock_patch.called)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_interface_not_in_all_interfaces(self, mock_patch):
|
||||
self.data['all_interfaces'] = {}
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertFalse(mock_patch.called)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_interface_not_in_ironic(self, mock_patch):
|
||||
self.node_info._ports = {}
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
@ -97,7 +97,7 @@ class TestBasePortPhysnetHook(test_base.NodeTest):
|
||||
self.assertRaises(utils.Error, self.hook.before_update,
|
||||
self.data, self.node_info)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_no_overwrite(self, mock_patch):
|
||||
cfg.CONF.set_override('overwrite_existing', False, group='processing')
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
|
@ -22,7 +22,7 @@ from ironic_inspector import utils
|
||||
|
||||
|
||||
@mock.patch.object(extra_hardware.swift, 'SwiftAPI', autospec=True)
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
class TestExtraHardware(test_base.NodeTest):
|
||||
hook = extra_hardware.ExtraHardwareHook()
|
||||
|
||||
@ -39,6 +39,7 @@ class TestExtraHardware(test_base.NodeTest):
|
||||
name = 'extra_hardware-%s' % self.uuid
|
||||
swift_conn.create_object.assert_called_once_with(name, data)
|
||||
patch_mock.assert_called_once_with(
|
||||
self.node_info,
|
||||
[{'op': 'add', 'path': '/extra/hardware_swift_object',
|
||||
'value': name}])
|
||||
|
||||
@ -73,6 +74,7 @@ class TestExtraHardware(test_base.NodeTest):
|
||||
name = 'extra_hardware-%s' % self.uuid
|
||||
swift_conn.create_object.assert_called_once_with(name, data)
|
||||
patch_mock.assert_called_once_with(
|
||||
self.node_info,
|
||||
[{'op': 'add', 'path': '/extra/hardware_swift_object',
|
||||
'value': name}])
|
||||
|
||||
|
@ -57,7 +57,7 @@ class TestGenericLocalLinkConnectionHook(test_base.NodeTest):
|
||||
self.node_info = node_cache.NodeInfo(uuid=self.uuid, started_at=0,
|
||||
node=self.node, ports=ports)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_expected_data(self, mock_patch):
|
||||
patches = [
|
||||
{'path': '/local_link_connection/port_id',
|
||||
@ -68,7 +68,7 @@ class TestGenericLocalLinkConnectionHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_invalid_chassis_id_subtype(self, mock_patch):
|
||||
# First byte of TLV value is processed to calculate the subtype for the
|
||||
# chassis ID, Subtype 5 ('05...') isn't a subtype supported by this
|
||||
@ -82,7 +82,7 @@ class TestGenericLocalLinkConnectionHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_invalid_port_id_subtype(self, mock_patch):
|
||||
# First byte of TLV value is processed to calculate the subtype for the
|
||||
# port ID, Subtype 6 ('06...') isn't a subtype supported by this
|
||||
@ -96,7 +96,7 @@ class TestGenericLocalLinkConnectionHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_port_id_subtype_mac(self, mock_patch):
|
||||
self.data['inventory']['interfaces'][0]['lldp'][2] = (
|
||||
2, '03885a92ec5458')
|
||||
@ -109,21 +109,21 @@ class TestGenericLocalLinkConnectionHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_lldp_none(self, mock_patch):
|
||||
self.data['inventory']['interfaces'][0]['lldp'] = None
|
||||
patches = []
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_interface_not_in_all_interfaces(self, mock_patch):
|
||||
self.data['all_interfaces'] = {}
|
||||
patches = []
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_interface_not_in_ironic(self, mock_patch):
|
||||
self.node_info._ports = {}
|
||||
patches = []
|
||||
@ -135,7 +135,7 @@ class TestGenericLocalLinkConnectionHook(test_base.NodeTest):
|
||||
self.assertRaises(utils.Error, self.hook.before_update,
|
||||
self.data, self.node_info)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_no_overwrite(self, mock_patch):
|
||||
cfg.CONF.set_override('overwrite_existing', False, group='processing')
|
||||
patches = [
|
||||
@ -145,7 +145,7 @@ class TestGenericLocalLinkConnectionHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_processed_data_available(self, mock_patch):
|
||||
self.data['all_interfaces'] = {
|
||||
'em1': {"ip": self.ips[0], "mac": self.macs[0],
|
||||
@ -164,7 +164,7 @@ class TestGenericLocalLinkConnectionHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_processed_data_chassis_only(self, mock_patch):
|
||||
self.data['all_interfaces'] = {
|
||||
'em1': {"ip": self.ips[0], "mac": self.macs[0],
|
||||
@ -180,7 +180,7 @@ class TestGenericLocalLinkConnectionHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_processed_data_port_only(self, mock_patch):
|
||||
self.data['all_interfaces'] = {
|
||||
'em1': {"ip": self.ips[0], "mac": self.macs[0],
|
||||
@ -196,7 +196,7 @@ class TestGenericLocalLinkConnectionHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_processed_chassis_id_not_mac(self, mock_patch):
|
||||
self.data['all_interfaces'] = {
|
||||
'em1': {"ip": self.ips[0], "mac": self.macs[0],
|
||||
@ -215,7 +215,7 @@ class TestGenericLocalLinkConnectionHook(test_base.NodeTest):
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch('ironic_inspector.plugins.local_link_connection.LOG')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_patch_port_exception(self, mock_patch, mock_log):
|
||||
self.data['all_interfaces'] = {
|
||||
'em1': {"ip": self.ips[0], "mac": self.macs[0],
|
||||
|
@ -47,7 +47,7 @@ class TestPhysnetCidrMapHook(test_base.NodeTest):
|
||||
self.node_info = node_cache.NodeInfo(uuid=self.uuid, started_at=0,
|
||||
node=self.node, ports=ports)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_expected_data(self, mock_patch):
|
||||
cfg.CONF.set_override('cidr_map', '1.1.1.0/24:physnet_a',
|
||||
group='port_physnet')
|
||||
@ -57,14 +57,14 @@ class TestPhysnetCidrMapHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_no_matching_mapping_config(self, mock_patch):
|
||||
cfg.CONF.set_override('cidr_map', '2.2.2.0/24:physnet_b',
|
||||
group='port_physnet')
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertFalse(mock_patch.called)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_expected_data_ipv6_lowercase(self, mock_patch):
|
||||
self.data['inventory']['interfaces'][0].pop('ipv4_address')
|
||||
self.data['inventory']['interfaces'][0]['ipv6_address'] = '2001:db8::1'
|
||||
@ -76,7 +76,7 @@ class TestPhysnetCidrMapHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_expected_data_ipv6_uppercase(self, mock_patch):
|
||||
self.data['inventory']['interfaces'][0].pop('ipv4_address')
|
||||
self.data['inventory']['interfaces'][0]['ipv6_address'] = '2001:db8::1'
|
||||
@ -88,7 +88,7 @@ class TestPhysnetCidrMapHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patches, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_no_mapping_in_config(self, mock_patch):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertFalse(mock_patch.called)
|
||||
@ -101,7 +101,7 @@ class TestPhysnetCidrMapHook(test_base.NodeTest):
|
||||
self.data, self.node_info)
|
||||
|
||||
@mock.patch('ironic_inspector.plugins.base_physnet.LOG')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_interface_not_in_ironic(self, mock_patch, mock_log):
|
||||
cfg.CONF.set_override('cidr_map', '1.1.1.0/24:physnet_a',
|
||||
group='port_physnet')
|
||||
@ -109,7 +109,7 @@ class TestPhysnetCidrMapHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertTrue(mock_log.debug.called)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_no_overwrite(self, mock_patch):
|
||||
ports = [mock.Mock(spec=['address', 'uuid', 'physical_network'],
|
||||
address=a, physical_network='foo')
|
||||
@ -123,7 +123,7 @@ class TestPhysnetCidrMapHook(test_base.NodeTest):
|
||||
self.assertFalse(mock_patch.called)
|
||||
|
||||
@mock.patch('ironic_inspector.plugins.base_physnet.LOG')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_patch_port_exception(self, mock_patch, mock_log):
|
||||
cfg.CONF.set_override('cidr_map', '1.1.1.0/24:physnet_a',
|
||||
group='port_physnet')
|
||||
@ -133,7 +133,7 @@ class TestPhysnetCidrMapHook(test_base.NodeTest):
|
||||
mock_log.warning.assert_called_with(log_msg, mock.ANY,
|
||||
node_info=mock.ANY)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch_port', autospec=True)
|
||||
def test_no_ip_address_on_interface(self, mock_patch):
|
||||
cfg.CONF.set_override('cidr_map', '1.1.1.0/24:physnet_a',
|
||||
group='port_physnet')
|
||||
|
@ -43,7 +43,7 @@ class TestRaidDeviceDetection(test_base.NodeTest):
|
||||
class TestRaidDeviceDetectionUpdate(test_base.NodeTest):
|
||||
hook = raid_device.RaidDeviceDetection()
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def _check(self, data, patch, mock_patch):
|
||||
self.hook.before_processing(data)
|
||||
self.hook.before_update(data, self.node_info)
|
||||
|
@ -162,32 +162,32 @@ class TestSetAttributeAction(test_base.NodeTest):
|
||||
self.params['value'] = None
|
||||
self.act.validate(self.params)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def test_apply(self, mock_patch):
|
||||
self.act.apply(self.node_info, self.params)
|
||||
mock_patch.assert_called_once_with([{'op': 'add',
|
||||
'path': '/extra/value',
|
||||
'value': 42}])
|
||||
mock_patch.assert_called_once_with(
|
||||
self.node_info,
|
||||
[{'op': 'add', 'path': '/extra/value', 'value': 42}])
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def test_apply_driver(self, mock_patch):
|
||||
params = {'path': '/driver', 'value': 'ipmi'}
|
||||
self.act.apply(self.node_info, params)
|
||||
mock_patch.assert_called_once_with([{'op': 'add',
|
||||
'path': '/driver',
|
||||
'value': 'ipmi'}],
|
||||
reset_interfaces=True)
|
||||
mock_patch.assert_called_once_with(
|
||||
self.node_info,
|
||||
[{'op': 'add', 'path': '/driver', 'value': 'ipmi'}],
|
||||
reset_interfaces=True)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def test_apply_driver_no_reset_interfaces(self, mock_patch):
|
||||
params = {'path': '/driver', 'value': 'ipmi',
|
||||
'reset_interfaces': False}
|
||||
self.act.apply(self.node_info, params)
|
||||
mock_patch.assert_called_once_with([{'op': 'add',
|
||||
'path': '/driver',
|
||||
'value': 'ipmi'}])
|
||||
mock_patch.assert_called_once_with(
|
||||
self.node_info,
|
||||
[{'op': 'add', 'path': '/driver', 'value': 'ipmi'}])
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def test_apply_driver_not_supported(self, mock_patch):
|
||||
for exc in (TypeError, os_exc.SDKException):
|
||||
mock_patch.reset_mock()
|
||||
@ -195,9 +195,11 @@ class TestSetAttributeAction(test_base.NodeTest):
|
||||
params = {'path': '/driver', 'value': 'ipmi'}
|
||||
self.act.apply(self.node_info, params)
|
||||
mock_patch.assert_has_calls([
|
||||
mock.call([{'op': 'add', 'path': '/driver', 'value': 'ipmi'}],
|
||||
mock.call(self.node_info,
|
||||
[{'op': 'add', 'path': '/driver', 'value': 'ipmi'}],
|
||||
reset_interfaces=True),
|
||||
mock.call([{'op': 'add', 'path': '/driver', 'value': 'ipmi'}])
|
||||
mock.call(self.node_info,
|
||||
[{'op': 'add', 'path': '/driver', 'value': 'ipmi'}])
|
||||
])
|
||||
|
||||
|
||||
@ -210,19 +212,20 @@ class TestSetCapabilityAction(test_base.NodeTest):
|
||||
self.act.validate(self.params)
|
||||
self.assertRaises(ValueError, self.act.validate, {'value': 42})
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def test_apply(self, mock_patch):
|
||||
self.act.apply(self.node_info, self.params)
|
||||
mock_patch.assert_called_once_with(
|
||||
self.node_info,
|
||||
[{'op': 'add', 'path': '/properties/capabilities',
|
||||
'value': 'cap1:val'}], mock.ANY)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def test_apply_with_existing(self, mock_patch):
|
||||
self.node.properties['capabilities'] = 'x:y,cap1:old_val,answer:42'
|
||||
self.act.apply(self.node_info, self.params)
|
||||
|
||||
patch = mock_patch.call_args[0][0]
|
||||
patch = mock_patch.call_args[0][1]
|
||||
new_caps = ir_utils.capabilities_to_dict(patch[0]['value'])
|
||||
self.assertEqual({'cap1': 'val', 'x': 'y', 'answer': '42'}, new_caps)
|
||||
|
||||
@ -236,22 +239,24 @@ class TestExtendAttributeAction(test_base.NodeTest):
|
||||
self.act.validate(self.params)
|
||||
self.assertRaises(ValueError, self.act.validate, {'value': 42})
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def test_apply(self, mock_patch):
|
||||
self.act.apply(self.node_info, self.params)
|
||||
mock_patch.assert_called_once_with(
|
||||
self.node_info,
|
||||
[{'op': 'add', 'path': '/extra/value', 'value': [42]}], mock.ANY)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def test_apply_non_empty(self, mock_patch):
|
||||
self.node.extra['value'] = [0]
|
||||
self.act.apply(self.node_info, self.params)
|
||||
|
||||
mock_patch.assert_called_once_with(
|
||||
self.node_info,
|
||||
[{'op': 'replace', 'path': '/extra/value', 'value': [0, 42]}],
|
||||
mock.ANY)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def test_apply_unique_with_existing(self, mock_patch):
|
||||
params = dict(unique=True, **self.params)
|
||||
self.node.extra['value'] = [42]
|
||||
|
@ -39,7 +39,7 @@ class TestSchedulerHook(test_base.NodeTest):
|
||||
ext = base.processing_hooks_manager()['scheduler']
|
||||
self.assertIsInstance(ext.obj, std_plugins.SchedulerHook)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def test_ok(self, mock_patch):
|
||||
patch = [
|
||||
{'path': '/properties/cpus', 'value': '4', 'op': 'add'},
|
||||
@ -50,7 +50,7 @@ class TestSchedulerHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patch, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def test_no_overwrite(self, mock_patch):
|
||||
CONF.set_override('overwrite_existing', False, 'processing')
|
||||
self.node.properties = {
|
||||
@ -64,7 +64,7 @@ class TestSchedulerHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patch, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def test_missing_cpu(self, mock_patch):
|
||||
self.data['inventory']['cpu'] = {'count': 'none'}
|
||||
patch = [
|
||||
@ -74,7 +74,7 @@ class TestSchedulerHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patch, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def test_missing_memory(self, mock_patch):
|
||||
# We require physical_mb, not total
|
||||
self.data['inventory']['memory'] = {'total': 42}
|
||||
@ -86,7 +86,7 @@ class TestSchedulerHook(test_base.NodeTest):
|
||||
self.hook.before_update(self.data, self.node_info)
|
||||
self.assertCalledWithPatch(patch, mock_patch)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True)
|
||||
def test_no_data(self, mock_patch):
|
||||
self.data['inventory']['cpu'] = {}
|
||||
self.data['inventory']['memory'] = {}
|
||||
|
@ -452,7 +452,8 @@ class TestProcessNode(BaseTest):
|
||||
ret_val = process._process_node(self.node_info, self.node, self.data)
|
||||
self.assertEqual(self.uuid, ret_val.get('uuid'))
|
||||
|
||||
@mock.patch.object(example_plugin.ExampleProcessingHook, 'before_update')
|
||||
@mock.patch.object(example_plugin.ExampleProcessingHook, 'before_update',
|
||||
autospec=True)
|
||||
def test_wrong_provision_state(self, post_hook_mock):
|
||||
self.node.provision_state = 'active'
|
||||
|
||||
@ -460,7 +461,8 @@ class TestProcessNode(BaseTest):
|
||||
self.node_info, self.node, self.data)
|
||||
self.assertFalse(post_hook_mock.called)
|
||||
|
||||
@mock.patch.object(example_plugin.ExampleProcessingHook, 'before_update')
|
||||
@mock.patch.object(example_plugin.ExampleProcessingHook, 'before_update',
|
||||
autospec=True)
|
||||
@mock.patch.object(node_cache.NodeInfo, 'finished', autospec=True)
|
||||
def test_ok(self, finished_mock, post_hook_mock):
|
||||
process._process_node(self.node_info, self.node, self.data)
|
||||
@ -477,7 +479,8 @@ class TestProcessNode(BaseTest):
|
||||
'power off')
|
||||
self.assertFalse(self.cli.validate_node.called)
|
||||
|
||||
post_hook_mock.assert_called_once_with(self.data, self.node_info)
|
||||
post_hook_mock.assert_called_once_with(mock.ANY, self.data,
|
||||
self.node_info)
|
||||
finished_mock.assert_called_once_with(mock.ANY, istate.Events.finish)
|
||||
|
||||
@mock.patch.object(example_plugin.ExampleProcessingHook, 'before_update',
|
||||
@ -531,7 +534,8 @@ class TestProcessNode(BaseTest):
|
||||
'management configuration: boom' % self.uuid
|
||||
)
|
||||
|
||||
@mock.patch.object(example_plugin.ExampleProcessingHook, 'before_update')
|
||||
@mock.patch.object(example_plugin.ExampleProcessingHook, 'before_update',
|
||||
autospec=True)
|
||||
@mock.patch.object(node_cache.NodeInfo, 'finished', autospec=True)
|
||||
def test_power_off_enroll_state(self, finished_mock, post_hook_mock):
|
||||
self.node.provision_state = 'enroll'
|
||||
@ -665,7 +669,8 @@ class TestReapply(BaseTest):
|
||||
introspection_data=self.data)
|
||||
|
||||
|
||||
@mock.patch.object(example_plugin.ExampleProcessingHook, 'before_update')
|
||||
@mock.patch.object(example_plugin.ExampleProcessingHook, 'before_update',
|
||||
autospec=True)
|
||||
@mock.patch.object(process.rules, 'apply', autospec=True)
|
||||
@mock.patch.object(swift, 'SwiftAPI', autospec=True)
|
||||
@mock.patch.object(node_cache.NodeInfo, 'finished', autospec=True)
|
||||
@ -717,7 +722,8 @@ class TestReapplyNode(BaseTest):
|
||||
|
||||
self.commit_fixture.mock.assert_called_once_with(self.node_info)
|
||||
|
||||
post_hook_mock.assert_called_once_with(mock.ANY, self.node_info)
|
||||
post_hook_mock.assert_called_once_with(mock.ANY, mock.ANY,
|
||||
self.node_info)
|
||||
|
||||
self.node_info.invalidate_cache.assert_called_once_with()
|
||||
apply_mock.assert_called_once_with(self.node_info, self.data)
|
||||
|
@ -30,7 +30,7 @@ class TestCheckAuth(base.BaseTest):
|
||||
super(TestCheckAuth, self).setUp()
|
||||
self.cfg.config(auth_strategy='keystone')
|
||||
|
||||
@mock.patch.object(auth_token, 'AuthProtocol')
|
||||
@mock.patch.object(auth_token, 'AuthProtocol', autospec=True)
|
||||
def test_middleware(self, mock_auth):
|
||||
self.cfg.config(group='keystone_authtoken',
|
||||
admin_user='admin',
|
||||
|
Loading…
Reference in New Issue
Block a user