Merge "Enforce autospec in common tests"

This commit is contained in:
Zuul 2020-08-25 08:00:10 +00:00 committed by Gerrit Code Review
commit d46550178e
6 changed files with 36 additions and 32 deletions

View File

@ -78,8 +78,9 @@ class KeystoneTestCase(base.TestCase):
self.assertEqual('admin', adapter.interface)
self.assertEqual(session, adapter.session)
@mock.patch('keystoneauth1.service_token.ServiceTokenAuthWrapper')
@mock.patch('keystoneauth1.token_endpoint.Token')
@mock.patch('keystoneauth1.service_token.ServiceTokenAuthWrapper',
autospec=True)
@mock.patch('keystoneauth1.token_endpoint.Token', autospec=True)
def test_get_service_auth(self, token_mock, service_auth_mock):
ctxt = context.RequestContext(auth_token='spam')
mock_auth = mock.Mock()

View File

@ -183,7 +183,7 @@ class TestRemoveVifsTestCase(db_base.DbTestCase):
network_interface='flat',
provision_state=states.DELETING)
@mock.patch.object(neutron_common, 'unbind_neutron_port')
@mock.patch.object(neutron_common, 'unbind_neutron_port', autospec=True)
def test_remove_vifs_from_node_failure(self, mock_unbind):
db_utils.create_test_port(
node_id=self.node.id, address='aa:bb:cc:dd:ee:ff',

View File

@ -967,8 +967,8 @@ class TestNeutronNetworkActions(db_base.DbTestCase):
port = self.ports[0]
self.assertFalse(neutron.is_smartnic_port(port))
@mock.patch.object(neutron, '_validate_agent')
@mock.patch.object(time, 'sleep')
@mock.patch.object(neutron, '_validate_agent', autospec=True)
@mock.patch.object(time, 'sleep', autospec=True)
def test_wait_for_host_agent_up_target_state_up(
self, sleep_mock, validate_agent_mock):
validate_agent_mock.return_value = True
@ -976,8 +976,8 @@ class TestNeutronNetworkActions(db_base.DbTestCase):
self.client_mock, 'hostname'))
sleep_mock.assert_not_called()
@mock.patch.object(neutron, '_validate_agent')
@mock.patch.object(time, 'sleep')
@mock.patch.object(neutron, '_validate_agent', autospec=True)
@mock.patch.object(time, 'sleep', autospec=True)
def test_wait_for_host_agent_down_target_state_up(
self, sleep_mock, validate_agent_mock):
validate_agent_mock.return_value = False
@ -985,8 +985,8 @@ class TestNeutronNetworkActions(db_base.DbTestCase):
neutron.wait_for_host_agent,
self.client_mock, 'hostname')
@mock.patch.object(neutron, '_validate_agent')
@mock.patch.object(time, 'sleep')
@mock.patch.object(neutron, '_validate_agent', autospec=True)
@mock.patch.object(time, 'sleep', autospec=True)
def test_wait_for_host_agent_up_target_state_down(
self, sleep_mock, validate_agent_mock):
validate_agent_mock.return_value = True
@ -994,8 +994,8 @@ class TestNeutronNetworkActions(db_base.DbTestCase):
neutron.wait_for_host_agent,
self.client_mock, 'hostname', target_state='down')
@mock.patch.object(neutron, '_validate_agent')
@mock.patch.object(time, 'sleep')
@mock.patch.object(neutron, '_validate_agent', autospec=True)
@mock.patch.object(time, 'sleep', autospec=True)
def test_wait_for_host_agent_down_target_state_down(
self, sleep_mock, validate_agent_mock):
validate_agent_mock.return_value = False
@ -1004,22 +1004,22 @@ class TestNeutronNetworkActions(db_base.DbTestCase):
target_state='down'))
sleep_mock.assert_not_called()
@mock.patch.object(neutron, '_get_port_by_uuid')
@mock.patch.object(time, 'sleep')
@mock.patch.object(neutron, '_get_port_by_uuid', autospec=True)
@mock.patch.object(time, 'sleep', autospec=True)
def test_wait_for_port_status_up(self, sleep_mock, get_port_mock):
get_port_mock.return_value = {'status': 'ACTIVE'}
neutron.wait_for_port_status(self.client_mock, 'port_id', 'ACTIVE')
sleep_mock.assert_not_called()
@mock.patch.object(neutron, '_get_port_by_uuid')
@mock.patch.object(time, 'sleep')
@mock.patch.object(neutron, '_get_port_by_uuid', autospec=True)
@mock.patch.object(time, 'sleep', autospec=True)
def test_wait_for_port_status_down(self, sleep_mock, get_port_mock):
get_port_mock.side_effect = [{'status': 'DOWN'}, {'status': 'ACTIVE'}]
neutron.wait_for_port_status(self.client_mock, 'port_id', 'ACTIVE')
sleep_mock.assert_called_once()
@mock.patch.object(neutron, '_get_port_by_uuid')
@mock.patch.object(time, 'sleep')
@mock.patch.object(neutron, '_get_port_by_uuid', autospec=True)
@mock.patch.object(time, 'sleep', autospec=True)
def test_wait_for_port_status_active_max_retry(self, sleep_mock,
get_port_mock):
get_port_mock.return_value = {'status': 'DOWN'}
@ -1027,8 +1027,8 @@ class TestNeutronNetworkActions(db_base.DbTestCase):
neutron.wait_for_port_status,
self.client_mock, 'port_id', 'ACTIVE')
@mock.patch.object(neutron, '_get_port_by_uuid')
@mock.patch.object(time, 'sleep')
@mock.patch.object(neutron, '_get_port_by_uuid', autospec=True)
@mock.patch.object(time, 'sleep', autospec=True)
def test_wait_for_port_status_down_max_retry(self, sleep_mock,
get_port_mock):
get_port_mock.return_value = {'status': 'ACTIVE'}

View File

@ -68,12 +68,13 @@ class NovaApiTestCase(base.TestCase):
[{'events': [{'code': 400}]}, 207, False],
# This (response 207, event code 200) will never happen IRL
[{'events': [{'code': 200}]}, 207, True])
@mock.patch.object(nova, '_get_nova_adapter')
@mock.patch.object(nova, '_get_nova_adapter', autospec=True)
def test_power_update(self, nova_result, resp_status, exp_ret,
mock_adapter, mock_log):
server_ids = ['server-id-1', 'server-id-2']
nova_adapter = mock.Mock()
with mock.patch.object(nova_adapter, 'post') as mock_post_event:
with mock.patch.object(nova_adapter, 'post',
autospec=True) as mock_post_event:
post_resp_mock = requests.Response()
def json_func():
@ -112,10 +113,11 @@ class NovaApiTestCase(base.TestCase):
expected = ("Nova event response: %s.", nova_result['events'][0])
mock_log.debug.assert_called_with(*expected)
@mock.patch.object(nova, '_get_nova_adapter')
@mock.patch.object(nova, '_get_nova_adapter', autospec=True)
def test_invalid_power_update(self, mock_adapter, mock_log):
nova_adapter = mock.Mock()
with mock.patch.object(nova_adapter, 'post') as mock_post_event:
with mock.patch.object(nova_adapter, 'post',
autospec=True) as mock_post_event:
result = self.api.power_update(self.ctx, 'server', None)
self.assertFalse(result)
expected = ('Invalid Power State %s.', None)
@ -130,7 +132,8 @@ class NovaApiTestCase(base.TestCase):
'server_uuid': 'server-id-1',
'tag': 'POWER_OFF'}]
nova_result = requests.Response()
with mock.patch.object(nova_adapter, 'post') as mock_post_event:
with mock.patch.object(nova_adapter, 'post',
autospec=True) as mock_post_event:
for stat_code in (500, 404, 400):
mock_log.reset_mock()
nova_result.status_code = stat_code
@ -155,11 +158,12 @@ class NovaApiTestCase(base.TestCase):
{'events': []},
{'events': None},
{})
@mock.patch.object(nova, '_get_nova_adapter')
@mock.patch.object(nova, '_get_nova_adapter', autospec=True)
def test_power_update_invalid_reponse_format(self, nova_result,
mock_adapter, mock_log):
nova_adapter = mock.Mock()
with mock.patch.object(nova_adapter, 'post') as mock_post_event:
with mock.patch.object(nova_adapter, 'post',
autospec=True) as mock_post_event:
post_resp_mock = requests.Response()
def json_func():
@ -192,7 +196,7 @@ class NovaApiTestCase(base.TestCase):
self.assertFalse(result)
mock_adapter.assert_not_called()
@mock.patch.object(nova, '_get_nova_adapter')
@mock.patch.object(nova, '_get_nova_adapter', autospec=True)
def test_power_update_failed_no_nova_auth_url(self, mock_adapter,
mock_log):
server = 'server-id-1'

View File

@ -1047,7 +1047,7 @@ class PXEInterfacesTestCase(db_base.DbTestCase):
self._test_get_instance_image_info()
@mock.patch('ironic.drivers.modules.deploy_utils.get_boot_option',
return_value='local')
return_value='local', autospec=True)
def test_get_instance_image_info_localboot(self, boot_opt_mock):
self.node.driver_internal_info['is_whole_disk_image'] = False
self.node.save()
@ -1068,7 +1068,7 @@ class PXEInterfacesTestCase(db_base.DbTestCase):
self.assertEqual({}, image_info)
@mock.patch('ironic.drivers.modules.deploy_utils.get_boot_option',
return_value='ramdisk')
return_value='ramdisk', autospec=True)
def test_get_instance_image_info_boot_iso(self, boot_opt_mock):
self.node.instance_info = {'boot_iso': 'http://localhost/boot.iso'}
self.node.save()
@ -1822,7 +1822,7 @@ class CleanUpPxeEnvTestCase(db_base.DbTestCase):
class TFTPImageCacheTestCase(db_base.DbTestCase):
@mock.patch.object(fileutils, 'ensure_tree')
@mock.patch.object(fileutils, 'ensure_tree', autospec=True)
def test_with_master_path(self, mock_ensure_tree):
self.config(tftp_master_path='/fake/path', group='pxe')
self.config(image_cache_size=500, group='pxe')
@ -1834,7 +1834,7 @@ class TFTPImageCacheTestCase(db_base.DbTestCase):
self.assertEqual(500 * 1024 * 1024, cache._cache_size)
self.assertEqual(30 * 60, cache._cache_ttl)
@mock.patch.object(fileutils, 'ensure_tree')
@mock.patch.object(fileutils, 'ensure_tree', autospec=True)
def test_without_master_path(self, mock_ensure_tree):
self.config(tftp_master_path='', group='pxe')
self.config(image_cache_size=500, group='pxe')

View File

@ -131,7 +131,6 @@ per-file-ignores =
ironic/cmd/__init__.py:E402
ironic/tests/base.py:E402
ironic/tests/unit/api/controllers/*:H210
ironic/tests/unit/common/*:H210
ironic/tests/unit/drivers/modules/test_console_utils.py:H210
ironic/tests/unit/drivers/modules/ilo/*:H210