Remove double mocking... again
I thought we fixed all the double mocking issues with I3998d0d49583806ac1c3ae64f1b1fe343cefd20d but I was wrong. While we used both mock and unittest.mock the fixtures.MockPatch used the mock lib instead of the unittest.mock lib. The path Ibf4f36136f2c65adad64f75d665c00cf2de4b400 (Remove the PowerVM driver) removed the last user of mock lib from nova. So it is also removed the mock from test-requirements. This triggered that fixtures.MockPatch athat started using unittest.mock too. Before Ibf4f36136f2c65adad64f75d665c00cf2de4b400 a function can be mocked twice once with unittest.mock and once with fixtures.MockPatch (still using mock). However after that patch both path of such double mocking goes through unittest.mock and the second one fails. So this patch fixes double mocking so far hidden behind fixtures.MockPatch. Also this patch makes the py310 and functional-py310 jobs voting at least in the check queue to prevent future changes adding double mocks. Change-Id: Ic1352ec31996577a5d0ad18a057339df3e49de25
This commit is contained in:
parent
adeea3d5e7
commit
bf654e3a4a
.zuul.yaml
nova/tests
fixtures
functional
unit
api/openstack/compute
test_create_backup.pytest_migrate_server.pytest_quotas.pytest_server_group_quotas.pytest_servers.pytest_volumes.py
compute
policies
virt
@ -665,7 +665,9 @@
|
||||
- nova-tox-functional-py38
|
||||
- nova-tox-functional-py39
|
||||
- nova-tox-functional-py310:
|
||||
voting: false
|
||||
voting: true
|
||||
- openstack-tox-py310:
|
||||
voting: true
|
||||
- tempest-integrated-compute:
|
||||
# NOTE(gmann): Policies changes do not need to run all the
|
||||
# integration test jobs. Running only tempest and grenade
|
||||
|
27
nova/tests/fixtures/libvirt.py
vendored
27
nova/tests/fixtures/libvirt.py
vendored
@ -2220,8 +2220,8 @@ class LibvirtFixture(fixtures.Fixture):
|
||||
|
||||
self.useFixture(
|
||||
fixtures.MockPatch('nova.virt.libvirt.utils.get_fs_info'))
|
||||
self.useFixture(
|
||||
fixtures.MockPatch('nova.compute.utils.get_machine_ips'))
|
||||
self.mock_get_machine_ips = self.useFixture(
|
||||
fixtures.MockPatch('nova.compute.utils.get_machine_ips')).mock
|
||||
|
||||
# libvirt driver needs to call out to the filesystem to get the
|
||||
# parent_ifname for the SRIOV VFs.
|
||||
@ -2231,20 +2231,25 @@ class LibvirtFixture(fixtures.Fixture):
|
||||
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'nova.pci.utils.get_mac_by_pci_address',
|
||||
new=self.fake_get_mac_by_pci_address))
|
||||
side_effect=self.fake_get_mac_by_pci_address))
|
||||
|
||||
# libvirt calls out to sysfs to get the vfs ID during macvtap plug
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'nova.pci.utils.get_vf_num_by_pci_address', return_value=1))
|
||||
self.mock_get_vf_num_by_pci_address = self.useFixture(
|
||||
fixtures.MockPatch(
|
||||
'nova.pci.utils.get_vf_num_by_pci_address', return_value=1
|
||||
)
|
||||
).mock
|
||||
|
||||
# libvirt calls out to privsep to set the mac and vlan of a macvtap
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'nova.privsep.linux_net.set_device_macaddr_and_vlan'))
|
||||
self.mock_set_device_macaddr_and_vlan = self.useFixture(
|
||||
fixtures.MockPatch(
|
||||
'nova.privsep.linux_net.set_device_macaddr_and_vlan')).mock
|
||||
|
||||
# libvirt calls out to privsep to set the port state during macvtap
|
||||
# plug
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'nova.privsep.linux_net.set_device_macaddr'))
|
||||
self.mock_set_device_macaddr = self.useFixture(
|
||||
fixtures.MockPatch(
|
||||
'nova.privsep.linux_net.set_device_macaddr')).mock
|
||||
|
||||
# Don't assume that the system running tests has a valid machine-id
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
@ -2259,8 +2264,8 @@ class LibvirtFixture(fixtures.Fixture):
|
||||
# Ensure tests perform the same on all host architectures
|
||||
fake_uname = os_uname(
|
||||
'Linux', '', '5.4.0-0-generic', '', obj_fields.Architecture.X86_64)
|
||||
self.useFixture(
|
||||
fixtures.MockPatch('os.uname', return_value=fake_uname))
|
||||
self.mock_uname = self.useFixture(
|
||||
fixtures.MockPatch('os.uname', return_value=fake_uname)).mock
|
||||
|
||||
# ...and on all machine types
|
||||
fake_loaders = [
|
||||
|
10
nova/tests/fixtures/nova.py
vendored
10
nova/tests/fixtures/nova.py
vendored
@ -1002,9 +1002,15 @@ class OSAPIFixture(fixtures.Fixture):
|
||||
self.api = client.TestOpenStackClient(
|
||||
'fake', base_url, project_id=self.project_id,
|
||||
roles=['reader', 'member'])
|
||||
self.alternative_api = client.TestOpenStackClient(
|
||||
'fake', base_url, project_id=self.project_id,
|
||||
roles=['reader', 'member'])
|
||||
self.admin_api = client.TestOpenStackClient(
|
||||
'admin', base_url, project_id=self.project_id,
|
||||
roles=['reader', 'member', 'admin'])
|
||||
self.alternative_admin_api = client.TestOpenStackClient(
|
||||
'admin', base_url, project_id=self.project_id,
|
||||
roles=['reader', 'member', 'admin'])
|
||||
self.reader_api = client.TestOpenStackClient(
|
||||
'reader', base_url, project_id=self.project_id,
|
||||
roles=['reader'])
|
||||
@ -1100,9 +1106,9 @@ class PoisonFunctions(fixtures.Fixture):
|
||||
# Don't poison the function if it's already mocked
|
||||
import nova.virt.libvirt.host
|
||||
if not isinstance(nova.virt.libvirt.host.Host._init_events, mock.Mock):
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'nova.virt.libvirt.host.Host._init_events',
|
||||
side_effect=evloop))
|
||||
evloop))
|
||||
|
||||
|
||||
class IndirectionAPIFixture(fixtures.Fixture):
|
||||
|
@ -29,7 +29,6 @@ from nova import conf
|
||||
from nova import context
|
||||
from nova import objects
|
||||
from nova import test
|
||||
from nova.tests import fixtures as nova_fixtures
|
||||
from nova.tests.functional import fixtures as func_fixtures
|
||||
from nova.tests.functional import integrated_helpers
|
||||
from nova.virt import driver as virt_driver
|
||||
@ -694,15 +693,6 @@ class TestProviderConfig(integrated_helpers.ProviderUsageBaseTestCase):
|
||||
feature a vm cannot be spawning using a custom trait and then start a
|
||||
compute service that provides that trait.
|
||||
"""
|
||||
|
||||
self.useFixture(nova_fixtures.NeutronFixture(self))
|
||||
self.useFixture(nova_fixtures.GlanceFixture(self))
|
||||
|
||||
# Start nova services.
|
||||
self.api = self.useFixture(nova_fixtures.OSAPIFixture(
|
||||
api_version='v2.1')).admin_api
|
||||
self.api.microversion = 'latest'
|
||||
self.start_service('conductor')
|
||||
# start nova-compute that will not have the additional trait.
|
||||
self._start_compute("fake-host-1")
|
||||
|
||||
|
@ -51,12 +51,12 @@ class ServersTestBase(integrated_helpers._IntegratedTestBase):
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'nova.virt.libvirt.LibvirtDriver._get_local_gb_info',
|
||||
return_value={'total': 128, 'used': 44, 'free': 84}))
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
self.mock_is_valid_hostname = self.useFixture(fixtures.MockPatch(
|
||||
'nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname',
|
||||
return_value=True))
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
return_value=True)).mock
|
||||
self.mock_file_open = self.useFixture(fixtures.MockPatch(
|
||||
'nova.virt.libvirt.driver.libvirt_utils.file_open',
|
||||
side_effect=lambda *a, **k: io.BytesIO(b'')))
|
||||
side_effect=lambda *a, **k: io.BytesIO(b''))).mock
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'nova.privsep.utils.supports_direct_io',
|
||||
return_value=True))
|
||||
|
@ -30,17 +30,7 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
class VGPUReshapeTests(base.ServersTestBase):
|
||||
|
||||
@mock.patch('nova.virt.libvirt.LibvirtDriver._get_local_gb_info',
|
||||
return_value={'total': 128,
|
||||
'used': 44,
|
||||
'free': 84})
|
||||
@mock.patch('nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname',
|
||||
return_value=True)
|
||||
@mock.patch('nova.virt.libvirt.driver.libvirt_utils.file_open',
|
||||
side_effect=[io.BytesIO(b''), io.BytesIO(b''),
|
||||
io.BytesIO(b'')])
|
||||
def test_create_servers_with_vgpu(
|
||||
self, mock_file_open, mock_valid_hostname, mock_get_fs_info):
|
||||
def test_create_servers_with_vgpu(self):
|
||||
"""Verify that vgpu reshape works with libvirt driver
|
||||
|
||||
1) create two servers with an old tree where the VGPU resource is on
|
||||
@ -49,7 +39,8 @@ class VGPUReshapeTests(base.ServersTestBase):
|
||||
3) check that the allocations of the servers are still valid
|
||||
4) create another server now against the new tree
|
||||
"""
|
||||
|
||||
self.mock_file_open.side_effect = [
|
||||
io.BytesIO(b''), io.BytesIO(b''), io.BytesIO(b'')]
|
||||
# NOTE(gibi): We cannot simply ask the virt driver to create an old
|
||||
# RP tree with vgpu on the root RP as that code path does not exist
|
||||
# any more. So we have to hack a "bit". We will create a compute
|
||||
|
@ -49,11 +49,11 @@ class VGPUTestBase(base.ServersTestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(VGPUTestBase, self).setUp()
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'nova.virt.libvirt.LibvirtDriver._get_local_gb_info',
|
||||
return_value={'total': 128,
|
||||
'used': 44,
|
||||
'free': 84}))
|
||||
libvirt_driver.LibvirtDriver._get_local_gb_info.return_value = {
|
||||
'total': 128,
|
||||
'used': 44,
|
||||
'free': 84,
|
||||
}
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'nova.privsep.libvirt.create_mdev',
|
||||
side_effect=self._create_mdev))
|
||||
|
@ -51,14 +51,6 @@ class TestEvacuateResourceTrackerRace(
|
||||
self.api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(
|
||||
api_version='v2.1'))
|
||||
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'nova.pci.utils.get_mac_by_pci_address',
|
||||
return_value='52:54:00:1e:59:c6'))
|
||||
|
||||
self.useFixture(fixtures.MockPatch(
|
||||
'nova.pci.utils.get_vf_num_by_pci_address',
|
||||
return_value=1))
|
||||
|
||||
self.admin_api = self.api_fixture.admin_api
|
||||
self.admin_api.microversion = 'latest'
|
||||
self.api = self.admin_api
|
||||
|
@ -935,11 +935,11 @@ class TestAggregateMultiTenancyIsolationFilter(
|
||||
|
||||
# Start nova services.
|
||||
self.start_service('conductor')
|
||||
self.admin_api = self.useFixture(
|
||||
nova_fixtures.OSAPIFixture(api_version='v2.1')).admin_api
|
||||
self.api = self.useFixture(
|
||||
nova_fixtures.OSAPIFixture(api_version='v2.1',
|
||||
project_id=uuids.non_admin)).api
|
||||
api_fixture = self.useFixture(
|
||||
nova_fixtures.OSAPIFixture(api_version='v2.1'))
|
||||
self.admin_api = api_fixture.admin_api
|
||||
self.api = api_fixture.api
|
||||
self.api.project_id = uuids.non_admin
|
||||
# Add the AggregateMultiTenancyIsolation to the list of enabled
|
||||
# filters since it is not enabled by default.
|
||||
enabled_filters = CONF.filter_scheduler.enabled_filters
|
||||
@ -1037,15 +1037,15 @@ class AggregateMultiTenancyIsolationColdMigrateTest(
|
||||
self.glance = self.useFixture(nova_fixtures.GlanceFixture(self))
|
||||
self.useFixture(nova_fixtures.NeutronFixture(self))
|
||||
self.useFixture(func_fixtures.PlacementFixture())
|
||||
# Intentionally keep these separate since we want to create the
|
||||
# server with the non-admin user in a different project.
|
||||
admin_api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(
|
||||
# Intentionally define different project id for the two client since
|
||||
# we want to create the server with the non-admin user in a different
|
||||
# project.
|
||||
api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(
|
||||
api_version='v2.1', project_id=uuids.admin_project))
|
||||
self.admin_api = admin_api_fixture.admin_api
|
||||
self.admin_api = api_fixture.admin_api
|
||||
self.admin_api.microversion = 'latest'
|
||||
user_api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(
|
||||
api_version='v2.1', project_id=uuids.user_project))
|
||||
self.api = user_api_fixture.api
|
||||
self.api = api_fixture.api
|
||||
self.api.project_id = uuids.user_project
|
||||
self.api.microversion = 'latest'
|
||||
|
||||
self.start_service('conductor')
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
from oslo_utils.fixture import uuidsentinel as uuids
|
||||
|
||||
from nova.tests import fixtures as nova_fixtures
|
||||
from nova.tests.functional.api import client
|
||||
from nova.tests.functional import integrated_helpers
|
||||
|
||||
@ -70,10 +69,9 @@ class ImagesTest(integrated_helpers._IntegratedTestBase):
|
||||
server = self.api.post_server({"server": server})
|
||||
server = self._wait_for_state_change(server, 'ACTIVE')
|
||||
|
||||
# Create an admin API fixture with a unique project ID.
|
||||
admin_api = self.useFixture(
|
||||
nova_fixtures.OSAPIFixture(
|
||||
project_id=uuids.admin_project)).admin_api
|
||||
# use an admin API with a unique project ID.
|
||||
admin_api = self.api_fixture.alternative_admin_api
|
||||
admin_api.project_id = uuids.admin_project
|
||||
|
||||
# Create a snapshot of the server using the admin project.
|
||||
name = 'admin-created-snapshot'
|
||||
|
@ -65,12 +65,12 @@ class ServerGroupTestBase(test.TestCase,
|
||||
self.useFixture(nova_fixtures.NeutronFixture(self))
|
||||
|
||||
self.useFixture(func_fixtures.PlacementFixture())
|
||||
api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(
|
||||
self.api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(
|
||||
api_version='v2.1'))
|
||||
|
||||
self.api = api_fixture.api
|
||||
self.api = self.api_fixture.api
|
||||
self.api.microversion = self.microversion
|
||||
self.admin_api = api_fixture.admin_api
|
||||
self.admin_api = self.api_fixture.admin_api
|
||||
self.admin_api.microversion = self.microversion
|
||||
|
||||
self.start_service('conductor')
|
||||
@ -175,13 +175,8 @@ class ServerGroupTestV21(ServerGroupTestBase):
|
||||
|
||||
# Create an API using project 'openstack1'.
|
||||
# This is a non-admin API.
|
||||
#
|
||||
# NOTE(sdague): this is actually very much *not* how this
|
||||
# fixture should be used. This actually spawns a whole
|
||||
# additional API server. Should be addressed in the future.
|
||||
api_openstack1 = self.useFixture(nova_fixtures.OSAPIFixture(
|
||||
api_version=self.api_major_version,
|
||||
project_id=PROJECT_ID_ALT)).api
|
||||
api_openstack1 = self.api_fixture.alternative_api
|
||||
api_openstack1.project_id = PROJECT_ID_ALT
|
||||
api_openstack1.microversion = self.microversion
|
||||
|
||||
# Create a server group in project 'openstack'
|
||||
|
@ -1253,9 +1253,7 @@ class ServerTestV269(integrated_helpers._IntegratedTestBase):
|
||||
def test_get_servers_detail_filters(self):
|
||||
# We get the results only from the up cells, this ignoring the down
|
||||
# cells if list_records_by_skipping_down_cells config option is True.
|
||||
api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(
|
||||
api_version='v2.1'))
|
||||
self.admin_api = api_fixture.admin_api
|
||||
self.admin_api = self.api_fixture.admin_api
|
||||
self.admin_api.microversion = '2.69'
|
||||
servers = self.admin_api.get_servers(
|
||||
search_opts={'hostname': "cell3-inst0"})
|
||||
@ -1263,9 +1261,7 @@ class ServerTestV269(integrated_helpers._IntegratedTestBase):
|
||||
self.assertEqual(self.up_cell_insts[2], servers[0]['id'])
|
||||
|
||||
def test_get_servers_detail_all_tenants_with_down_cells(self):
|
||||
api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(
|
||||
api_version='v2.1'))
|
||||
self.admin_api = api_fixture.admin_api
|
||||
self.admin_api = self.api_fixture.admin_api
|
||||
self.admin_api.microversion = '2.69'
|
||||
servers = self.admin_api.get_servers(search_opts={'all_tenants': True})
|
||||
# 4 servers from the up cells and 4 servers from the down cells
|
||||
@ -1523,10 +1519,8 @@ class ServersTestV280(integrated_helpers._IntegratedTestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(ServersTestV280, self).setUp()
|
||||
api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(
|
||||
api_version='v2.1'))
|
||||
self.api = api_fixture.api
|
||||
self.admin_api = api_fixture.admin_api
|
||||
self.api = self.api_fixture.api
|
||||
self.admin_api = self.api_fixture.admin_api
|
||||
|
||||
self.api.microversion = '2.80'
|
||||
self.admin_api.microversion = '2.80'
|
||||
@ -1585,9 +1579,8 @@ class ServersTestV280(integrated_helpers._IntegratedTestBase):
|
||||
|
||||
project_id_1 = '4906260553374bf0a5d566543b320516'
|
||||
project_id_2 = 'c850298c1b6b4796a8f197ac310b2469'
|
||||
new_api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(
|
||||
api_version=self.api_major_version, project_id=project_id_1))
|
||||
new_admin_api = new_api_fixture.admin_api
|
||||
new_admin_api = self.api_fixture.alternative_admin_api
|
||||
new_admin_api.project_id = project_id_1
|
||||
new_admin_api.microversion = '2.80'
|
||||
|
||||
post = {
|
||||
|
@ -41,10 +41,6 @@ class CreateBackupTestsV21(admin_only_action_common.CommonMixin,
|
||||
self.controller = getattr(self.create_backup, self.controller_name)()
|
||||
self.compute_api = self.controller.compute_api
|
||||
|
||||
patch_get = mock.patch.object(self.compute_api, 'get')
|
||||
self.mock_get = patch_get.start()
|
||||
self.addCleanup(patch_get.stop)
|
||||
|
||||
@mock.patch.object(common, 'check_img_metadata_properties_quota')
|
||||
@mock.patch.object(api.API, 'backup')
|
||||
def test_create_backup_with_metadata(self, mock_backup, mock_check_image):
|
||||
|
@ -531,9 +531,8 @@ class MigrateServerTestsV256(MigrateServerTestsV234):
|
||||
self.req, fakes.FAKE_UUID, body=body)
|
||||
|
||||
def _test_migrate_exception(self, exc_info, expected_result):
|
||||
@mock.patch.object(self.compute_api, 'get')
|
||||
@mock.patch.object(self.compute_api, 'resize', side_effect=exc_info)
|
||||
def _test(mock_resize, mock_get):
|
||||
def _test(mock_resize):
|
||||
instance = objects.Instance(uuid=uuids.instance)
|
||||
self.assertRaises(expected_result,
|
||||
self.controller._migrate,
|
||||
|
@ -883,7 +883,8 @@ class UnifiedLimitsQuotaSetsTest(NoopQuotaSetsTest):
|
||||
local_limit.KEY_PAIRS: 100,
|
||||
local_limit.SERVER_GROUPS: 12,
|
||||
local_limit.SERVER_GROUP_MEMBERS: 10}
|
||||
self.useFixture(limit_fixture.LimitFixture(reglimits, {}))
|
||||
self.limit_fixture = self.useFixture(
|
||||
limit_fixture.LimitFixture(reglimits, {}))
|
||||
|
||||
@mock.patch.object(placement_limit, "get_legacy_project_limits")
|
||||
def test_show_v21(self, mock_proj):
|
||||
@ -1099,7 +1100,7 @@ class UnifiedLimitsQuotaSetsTest(NoopQuotaSetsTest):
|
||||
local_limit.KEY_PAIRS: 1,
|
||||
local_limit.SERVER_GROUPS: 3,
|
||||
local_limit.SERVER_GROUP_MEMBERS: 2}
|
||||
self.useFixture(limit_fixture.LimitFixture(reglimits, {}))
|
||||
self.limit_fixture.reglimits = reglimits
|
||||
|
||||
req = fakes.HTTPRequest.blank("")
|
||||
response = self.controller.defaults(req, uuids.project_id)
|
||||
|
@ -210,7 +210,8 @@ class ServerGroupQuotasUnifiedLimitsTestV21(ServerGroupQuotasTestV21):
|
||||
self.flags(driver='nova.quota.UnifiedLimitsDriver', group='quota')
|
||||
self.req = fakes.HTTPRequest.blank('')
|
||||
self.controller = sg_v21.ServerGroupController()
|
||||
self.useFixture(limit_fixture.LimitFixture({'server_groups': 10}, {}))
|
||||
self.limit_fixture = self.useFixture(
|
||||
limit_fixture.LimitFixture({'server_groups': 10}, {}))
|
||||
|
||||
@mock.patch('nova.limit.local.enforce_db_limit')
|
||||
def test_create_server_group_during_recheck(self, mock_enforce):
|
||||
@ -237,7 +238,7 @@ class ServerGroupQuotasUnifiedLimitsTestV21(ServerGroupQuotasTestV21):
|
||||
delta=1)
|
||||
|
||||
def test_create_group_fails_with_zero_quota(self):
|
||||
self.useFixture(limit_fixture.LimitFixture({'server_groups': 0}, {}))
|
||||
self.limit_fixture.reglimits = {'server_groups': 0}
|
||||
sgroup = {'name': 'test', 'policies': ['anti-affinity']}
|
||||
exc = self.assertRaises(webob.exc.HTTPForbidden,
|
||||
self.controller.create,
|
||||
@ -246,7 +247,7 @@ class ServerGroupQuotasUnifiedLimitsTestV21(ServerGroupQuotasTestV21):
|
||||
self.assertIn(msg, str(exc))
|
||||
|
||||
def test_create_only_one_group_when_limit_is_one(self):
|
||||
self.useFixture(limit_fixture.LimitFixture({'server_groups': 1}, {}))
|
||||
self.limit_fixture.reglimits = {'server_groups': 1}
|
||||
policies = ['anti-affinity']
|
||||
sgroup = {'name': 'test', 'policies': policies}
|
||||
res_dict = self.controller.create(
|
||||
|
@ -2088,10 +2088,10 @@ class ServersControllerTestV216(_ServersControllerTest):
|
||||
|
||||
return server_dict
|
||||
|
||||
@mock.patch('nova.compute.api.API.get_instance_host_status')
|
||||
def _verify_host_status_policy_behavior(self, func, mock_get_host_status):
|
||||
def _verify_host_status_policy_behavior(self, func):
|
||||
# Set policy to disallow both host_status cases and verify we don't
|
||||
# call the get_instance_host_status compute RPC API.
|
||||
self.mock_get_instance_host_status.reset_mock()
|
||||
rules = {
|
||||
'os_compute_api:servers:show:host_status': '!',
|
||||
'os_compute_api:servers:show:host_status:unknown-only': '!',
|
||||
@ -2099,7 +2099,7 @@ class ServersControllerTestV216(_ServersControllerTest):
|
||||
orig_rules = policy.get_rules()
|
||||
policy.set_rules(oslo_policy.Rules.from_dict(rules), overwrite=False)
|
||||
func()
|
||||
mock_get_host_status.assert_not_called()
|
||||
self.mock_get_instance_host_status.assert_not_called()
|
||||
# Restore the original rules.
|
||||
policy.set_rules(orig_rules)
|
||||
|
||||
@ -2639,15 +2639,13 @@ class ServersControllerTestV275(ControllerTest):
|
||||
|
||||
microversion = '2.75'
|
||||
|
||||
@mock.patch('nova.compute.api.API.get_all')
|
||||
def test_get_servers_additional_query_param_old_version(self, mock_get):
|
||||
def test_get_servers_additional_query_param_old_version(self):
|
||||
req = fakes.HTTPRequest.blank(self.path_with_query % 'unknown=1',
|
||||
use_admin_context=True,
|
||||
version='2.74')
|
||||
self.controller.index(req)
|
||||
|
||||
@mock.patch('nova.compute.api.API.get_all')
|
||||
def test_get_servers_ignore_sort_key_old_version(self, mock_get):
|
||||
def test_get_servers_ignore_sort_key_old_version(self):
|
||||
req = fakes.HTTPRequest.blank(
|
||||
self.path_with_query % 'sort_key=deleted',
|
||||
use_admin_context=True, version='2.74')
|
||||
@ -3585,13 +3583,13 @@ class ServersControllerRebuildTestV263(ControllerTest):
|
||||
},
|
||||
}
|
||||
|
||||
@mock.patch('nova.compute.api.API.get')
|
||||
def _rebuild_server(self, mock_get, certs=None,
|
||||
conf_enabled=True, conf_certs=None):
|
||||
def _rebuild_server(self, certs=None, conf_enabled=True, conf_certs=None):
|
||||
ctx = self.req.environ['nova.context']
|
||||
mock_get.return_value = fakes.stub_instance_obj(ctx,
|
||||
vm_state=vm_states.ACTIVE, trusted_certs=certs,
|
||||
project_id=self.req_project_id, user_id=self.req_user_id)
|
||||
self.mock_get.side_effect = None
|
||||
self.mock_get.return_value = fakes.stub_instance_obj(
|
||||
ctx, vm_state=vm_states.ACTIVE, trusted_certs=certs,
|
||||
project_id=self.req_project_id, user_id=self.req_user_id
|
||||
)
|
||||
|
||||
self.flags(default_trusted_certificate_ids=conf_certs, group='glance')
|
||||
|
||||
@ -3744,10 +3742,10 @@ class ServersControllerRebuildTestV271(ControllerTest):
|
||||
}
|
||||
}
|
||||
|
||||
@mock.patch('nova.compute.api.API.get')
|
||||
def _rebuild_server(self, mock_get):
|
||||
def _rebuild_server(self):
|
||||
ctx = self.req.environ['nova.context']
|
||||
mock_get.return_value = fakes.stub_instance_obj(ctx,
|
||||
self.mock_get.side_effect = None
|
||||
self.mock_get.return_value = fakes.stub_instance_obj(ctx,
|
||||
vm_state=vm_states.ACTIVE, project_id=self.req_project_id,
|
||||
user_id=self.req_user_id)
|
||||
server = self.controller._action_rebuild(
|
||||
|
@ -1889,8 +1889,7 @@ class AssistedSnapshotDeleteTestCaseV21(test.NoDBTestCase):
|
||||
req, '5')
|
||||
|
||||
def _test_assisted_delete_instance_conflict(self, api_error):
|
||||
# unset the stub on volume_snapshot_delete from setUp
|
||||
self.mock_volume_snapshot_delete.stop()
|
||||
self.mock_volume_snapshot_delete.side_effect = api_error
|
||||
params = {
|
||||
'delete_info': jsonutils.dumps({'volume_id': '1'}),
|
||||
}
|
||||
@ -1899,10 +1898,9 @@ class AssistedSnapshotDeleteTestCaseV21(test.NoDBTestCase):
|
||||
urllib.parse.urlencode(params),
|
||||
version=self.microversion)
|
||||
req.method = 'DELETE'
|
||||
with mock.patch.object(compute_api.API, 'volume_snapshot_delete',
|
||||
side_effect=api_error):
|
||||
self.assertRaises(
|
||||
webob.exc.HTTPBadRequest, self.controller.delete, req, '5')
|
||||
|
||||
self.assertRaises(
|
||||
webob.exc.HTTPBadRequest, self.controller.delete, req, '5')
|
||||
|
||||
def test_assisted_delete_instance_invalid_state(self):
|
||||
api_error = exception.InstanceInvalidState(
|
||||
|
@ -967,6 +967,31 @@ class _ComputeAPIUnitTestMixIn(object):
|
||||
|
||||
return snapshot_id
|
||||
|
||||
def _test_delete(self, delete_type, **attrs):
|
||||
delete_time = datetime.datetime(
|
||||
1955, 11, 5, 9, 30, tzinfo=iso8601.UTC)
|
||||
timeutils.set_time_override(delete_time)
|
||||
self.addCleanup(timeutils.clear_time_override)
|
||||
|
||||
with test.nested(
|
||||
mock.patch.object(
|
||||
self.compute_api.compute_rpcapi, 'confirm_resize'),
|
||||
mock.patch.object(
|
||||
self.compute_api.compute_rpcapi, 'terminate_instance'),
|
||||
mock.patch.object(
|
||||
self.compute_api.compute_rpcapi, 'soft_delete_instance'),
|
||||
) as (
|
||||
mock_confirm, mock_terminate, mock_soft_delete
|
||||
):
|
||||
self._do_delete(
|
||||
delete_type,
|
||||
mock_confirm,
|
||||
mock_terminate,
|
||||
mock_soft_delete,
|
||||
delete_time,
|
||||
**attrs
|
||||
)
|
||||
|
||||
@mock.patch.object(compute_utils,
|
||||
'notify_about_instance_action')
|
||||
@mock.patch.object(objects.Migration, 'get_by_instance_and_status')
|
||||
@ -986,12 +1011,13 @@ class _ComputeAPIUnitTestMixIn(object):
|
||||
@mock.patch.object(objects.BlockDeviceMappingList,
|
||||
'get_by_instance_uuid', return_value=[])
|
||||
@mock.patch.object(objects.Instance, 'save')
|
||||
def _test_delete(self, delete_type, mock_save, mock_bdm_get, mock_elevated,
|
||||
mock_get_cn, mock_up, mock_record, mock_inst_update,
|
||||
mock_deallocate, mock_inst_meta, mock_inst_destroy,
|
||||
mock_notify_legacy, mock_get_inst,
|
||||
mock_save_im, mock_image_delete, mock_mig_get,
|
||||
mock_notify, **attrs):
|
||||
def _do_delete(
|
||||
self, delete_type, mock_confirm, mock_terminate, mock_soft_delete,
|
||||
delete_time, mock_save, mock_bdm_get, mock_elevated, mock_get_cn,
|
||||
mock_up, mock_record, mock_inst_update, mock_deallocate,
|
||||
mock_inst_meta, mock_inst_destroy, mock_notify_legacy, mock_get_inst,
|
||||
mock_save_im, mock_image_delete, mock_mig_get, mock_notify, **attrs
|
||||
):
|
||||
expected_save_calls = [mock.call()]
|
||||
expected_record_calls = []
|
||||
expected_elevated_calls = []
|
||||
@ -1001,17 +1027,11 @@ class _ComputeAPIUnitTestMixIn(object):
|
||||
deltas = {'instances': -1,
|
||||
'cores': -inst.flavor.vcpus,
|
||||
'ram': -inst.flavor.memory_mb}
|
||||
delete_time = datetime.datetime(1955, 11, 5, 9, 30,
|
||||
tzinfo=iso8601.UTC)
|
||||
self.useFixture(utils_fixture.TimeFixture(delete_time))
|
||||
task_state = (delete_type == 'soft_delete' and
|
||||
task_states.SOFT_DELETING or task_states.DELETING)
|
||||
updates = {'progress': 0, 'task_state': task_state}
|
||||
if delete_type == 'soft_delete':
|
||||
updates['deleted_at'] = delete_time
|
||||
rpcapi = self.compute_api.compute_rpcapi
|
||||
mock_confirm = self.useFixture(
|
||||
fixtures.MockPatchObject(rpcapi, 'confirm_resize')).mock
|
||||
|
||||
def _reset_task_state(context, instance, migration, src_host,
|
||||
cast=False):
|
||||
@ -1026,11 +1046,6 @@ class _ComputeAPIUnitTestMixIn(object):
|
||||
snapshot_id = self._set_delete_shelved_part(inst,
|
||||
mock_image_delete)
|
||||
|
||||
mock_terminate = self.useFixture(
|
||||
fixtures.MockPatchObject(rpcapi, 'terminate_instance')).mock
|
||||
mock_soft_delete = self.useFixture(
|
||||
fixtures.MockPatchObject(rpcapi, 'soft_delete_instance')).mock
|
||||
|
||||
if inst.task_state == task_states.RESIZE_FINISH:
|
||||
self._test_delete_resizing_part(inst, deltas)
|
||||
|
||||
@ -2637,9 +2652,6 @@ class _ComputeAPIUnitTestMixIn(object):
|
||||
|
||||
rpcapi = self.compute_api.compute_rpcapi
|
||||
|
||||
mock_pause = self.useFixture(
|
||||
fixtures.MockPatchObject(rpcapi, 'pause_instance')).mock
|
||||
|
||||
with mock.patch.object(rpcapi, 'pause_instance') as mock_pause:
|
||||
self.compute_api.pause(self.context, instance)
|
||||
|
||||
|
@ -1229,10 +1229,9 @@ class ServersPolicyTest(base.BasePolicyTest):
|
||||
@mock.patch('nova.compute.api.API._allow_resize_to_same_host')
|
||||
@mock.patch('nova.objects.RequestSpec.get_by_instance_uuid')
|
||||
@mock.patch('nova.objects.Instance.save')
|
||||
@mock.patch('nova.api.openstack.common.get_instance')
|
||||
@mock.patch('nova.conductor.ComputeTaskAPI.resize_instance')
|
||||
def test_cross_cell_resize_server_policy(
|
||||
self, mock_resize, mock_get, mock_save, mock_rs, mock_allow, m_net
|
||||
self, mock_resize, mock_save, mock_rs, mock_allow, m_net
|
||||
):
|
||||
|
||||
# 'migrate' policy is checked before 'resize:cross_cell' so
|
||||
@ -1262,7 +1261,7 @@ class ServersPolicyTest(base.BasePolicyTest):
|
||||
)
|
||||
return inst
|
||||
|
||||
mock_get.side_effect = fake_get
|
||||
self.mock_get.side_effect = fake_get
|
||||
|
||||
def fake_validate(context, instance,
|
||||
host_name, allow_cross_cell_resize):
|
||||
|
@ -2598,9 +2598,6 @@ class IronicDriverSyncTestCase(IronicDriverTestCase):
|
||||
# that the thread completes.
|
||||
self.useFixture(nova_fixtures.SpawnIsSynchronousFixture())
|
||||
|
||||
self.mock_conn = self.useFixture(
|
||||
fixtures.MockPatchObject(self.driver, '_ironic_connection')).mock
|
||||
|
||||
@mock.patch.object(loopingcall, 'FixedIntervalLoopingCall')
|
||||
@mock.patch.object(FAKE_CLIENT.node, 'set_provision_state')
|
||||
def test_rescue(self, mock_sps, mock_looping):
|
||||
|
@ -740,16 +740,14 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||
'resolve_driver_format',
|
||||
imagebackend.Image._get_driver_format)
|
||||
|
||||
self.useFixture(nova_fixtures.LibvirtFixture())
|
||||
self.libvirt = self.useFixture(nova_fixtures.LibvirtFixture())
|
||||
|
||||
# ensure tests perform the same on all host architectures; this is
|
||||
# already done by the fakelibvirt fixture but we want to change the
|
||||
# architecture in some tests
|
||||
_p = mock.patch('os.uname')
|
||||
self.mock_uname = _p.start()
|
||||
self.mock_uname = self.libvirt.mock_uname
|
||||
self.mock_uname.return_value = fakelibvirt.os_uname(
|
||||
'Linux', '', '5.4.0-0-generic', '', fields.Architecture.X86_64)
|
||||
self.addCleanup(_p.stop)
|
||||
|
||||
self.test_instance = _create_test_instance()
|
||||
network_info = objects.InstanceInfoCache(
|
||||
@ -2260,6 +2258,8 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||
instance_ref.info_cache = objects.InstanceInfoCache(
|
||||
network_info=network_info)
|
||||
|
||||
pci_utils.get_mac_by_pci_address.side_effect = None
|
||||
pci_utils.get_mac_by_pci_address.return_value = 'da:d1:f2:91:95:c1'
|
||||
with test.nested(
|
||||
mock.patch('nova.objects.VirtualInterfaceList'
|
||||
'.get_by_instance_uuid', return_value=vifs),
|
||||
@ -2269,8 +2269,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||
return_value=guest),
|
||||
mock.patch.object(nova.virt.libvirt.guest.Guest, 'get_xml_desc',
|
||||
return_value=xml),
|
||||
mock.patch.object(pci_utils, 'get_mac_by_pci_address',
|
||||
return_value='da:d1:f2:91:95:c1')):
|
||||
):
|
||||
metadata_obj = drvr._build_device_metadata(self.context,
|
||||
instance_ref)
|
||||
metadata = metadata_obj.devices
|
||||
@ -16075,9 +16074,10 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||
self.assertEqual(ip, CONF.my_ip)
|
||||
|
||||
@mock.patch.object(libvirt_driver.LOG, 'warning')
|
||||
@mock.patch('nova.compute.utils.get_machine_ips')
|
||||
def test_check_my_ip(self, mock_ips, mock_log):
|
||||
mock_ips.return_value = ['8.8.8.8', '75.75.75.75']
|
||||
def test_check_my_ip(self, mock_log):
|
||||
|
||||
self.libvirt.mock_get_machine_ips.return_value = [
|
||||
'8.8.8.8', '75.75.75.75']
|
||||
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
drvr._check_my_ip()
|
||||
mock_log.assert_called_once_with(u'my_ip address (%(my_ip)s) was '
|
||||
@ -16099,6 +16099,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
service_mock = mock.MagicMock()
|
||||
service_mock.disabled.return_value = False
|
||||
drvr._host._init_events.return_value = None
|
||||
with test.nested(
|
||||
mock.patch.object(drvr._host, "_connect",
|
||||
side_effect=fakelibvirt.make_libvirtError(
|
||||
@ -16106,8 +16107,6 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||
"Failed to connect to host",
|
||||
error_code=
|
||||
fakelibvirt.VIR_ERR_INTERNAL_ERROR)),
|
||||
mock.patch.object(drvr._host, "_init_events",
|
||||
return_value=None),
|
||||
mock.patch.object(objects.Service, "get_by_compute_host",
|
||||
return_value=service_mock)):
|
||||
|
||||
@ -16122,6 +16121,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
service_mock = mock.MagicMock()
|
||||
service_mock.disabled.return_value = False
|
||||
drvr._host._init_events.return_value = None
|
||||
with test.nested(
|
||||
mock.patch.object(drvr._host, "_connect",
|
||||
side_effect=fakelibvirt.make_libvirtError(
|
||||
@ -16129,8 +16129,6 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||
"Failed to connect to host",
|
||||
error_code=
|
||||
fakelibvirt.VIR_ERR_INTERNAL_ERROR)),
|
||||
mock.patch.object(drvr._host, "_init_events",
|
||||
return_value=None),
|
||||
mock.patch.object(host.Host, "has_min_version",
|
||||
return_value=True),
|
||||
mock.patch.object(drvr, "_do_quality_warnings",
|
||||
@ -16150,11 +16148,10 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
service_mock = mock.MagicMock()
|
||||
service_mock.disabled.return_value = True
|
||||
drvr._host._init_events.return_value = None
|
||||
with test.nested(
|
||||
mock.patch.object(drvr._host, "_connect",
|
||||
return_value=mock.MagicMock()),
|
||||
mock.patch.object(drvr._host, "_init_events",
|
||||
return_value=None),
|
||||
mock.patch.object(host.Host, "has_min_version",
|
||||
return_value=True),
|
||||
mock.patch.object(drvr, "_do_quality_warnings",
|
||||
@ -17642,12 +17639,11 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||
got = drvr._get_cpu_info()
|
||||
self.assertEqual(want, got)
|
||||
|
||||
@mock.patch.object(pci_utils, 'get_ifname_by_pci_address',
|
||||
return_value='ens1')
|
||||
@mock.patch.object(host.Host, 'list_pci_devices',
|
||||
return_value=['pci_0000_04_00_3', 'pci_0000_04_10_7',
|
||||
'pci_0000_04_11_7'])
|
||||
def test_get_pci_passthrough_devices(self, mock_list, mock_get_ifname):
|
||||
def test_get_pci_passthrough_devices(self, mock_list):
|
||||
pci_utils.get_ifname_by_pci_address.return_value = 'ens1'
|
||||
|
||||
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
@ -17720,7 +17716,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||
|
||||
# The first call for every VF is to determine parent_ifname and
|
||||
# the second call to determine the MAC address.
|
||||
mock_get_ifname.assert_has_calls([
|
||||
pci_utils.get_ifname_by_pci_address.assert_has_calls([
|
||||
mock.call('0000:04:10.7', pf_interface=True),
|
||||
mock.call('0000:04:11.7', pf_interface=True),
|
||||
])
|
||||
|
@ -72,11 +72,10 @@ class HostTestCase(test.NoDBTestCase):
|
||||
self.useFixture(nova_fixtures.LibvirtFixture())
|
||||
self.host = host.Host("qemu:///system")
|
||||
|
||||
@mock.patch("nova.virt.libvirt.host.Host._init_events")
|
||||
def test_repeat_initialization(self, mock_init_events):
|
||||
def test_repeat_initialization(self):
|
||||
for i in range(3):
|
||||
self.host.initialize()
|
||||
mock_init_events.assert_called_once_with()
|
||||
self.host._init_events.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(fakelibvirt.virConnect, "registerCloseCallback")
|
||||
def test_close_callback(self, mock_close):
|
||||
@ -1156,12 +1155,9 @@ Active: 8381604 kB
|
||||
expect_vf = ["rx", "tx", "sg", "tso", "gso", "gro", "rxvlan", "txvlan"]
|
||||
self.assertEqual(expect_vf, actualvf)
|
||||
|
||||
@mock.patch.object(pci_utils, 'get_mac_by_pci_address',
|
||||
new=mock.MagicMock(
|
||||
side_effect=exception.PciDeviceNotFoundById(
|
||||
'0000:04:00.3')))
|
||||
@mock.patch.object(pci_utils, 'get_ifname_by_pci_address')
|
||||
def test_get_pcidev_info_non_nic(self, mock_get_ifname):
|
||||
def test_get_pcidev_info_non_nic(self):
|
||||
pci_utils.get_mac_by_pci_address.side_effect = (
|
||||
exception.PciDeviceNotFoundById('0000:04:00.3'))
|
||||
dev_name = "pci_0000_04_11_7"
|
||||
pci_dev = fakelibvirt.NodeDevice(
|
||||
self.host._get_connection(),
|
||||
@ -1175,11 +1171,10 @@ Active: 8381604 kB
|
||||
'parent_addr': '0000:04:00.3',
|
||||
}
|
||||
self.assertEqual(expect_vf, actual_vf)
|
||||
mock_get_ifname.assert_not_called()
|
||||
pci_utils.get_ifname_by_pci_address.assert_not_called()
|
||||
|
||||
@mock.patch.object(pci_utils, 'get_ifname_by_pci_address',
|
||||
return_value='ens1')
|
||||
def test_get_pcidev_info(self, mock_get_ifname):
|
||||
def test_get_pcidev_info(self):
|
||||
pci_utils.get_ifname_by_pci_address.return_value = 'ens1'
|
||||
devs = {
|
||||
"pci_0000_04_00_3", "pci_0000_04_10_7", "pci_0000_04_11_7",
|
||||
"pci_0000_04_00_1", "pci_0000_03_00_0", "pci_0000_03_00_1",
|
||||
|
@ -518,18 +518,17 @@ class LibvirtVifTestCase(test.NoDBTestCase):
|
||||
def setUp(self):
|
||||
super(LibvirtVifTestCase, self).setUp()
|
||||
|
||||
self.useFixture(nova_fixtures.LibvirtFixture(stub_os_vif=False))
|
||||
self.libvirt = self.useFixture(
|
||||
nova_fixtures.LibvirtFixture(stub_os_vif=False))
|
||||
|
||||
# os_vif.initialize is typically done in nova-compute startup
|
||||
os_vif.initialize()
|
||||
self.setup_os_vif_objects()
|
||||
|
||||
# multiqueue configuration is host OS specific
|
||||
_a = mock.patch('os.uname')
|
||||
self.mock_uname = _a.start()
|
||||
self.mock_uname = self.libvirt.mock_uname
|
||||
self.mock_uname.return_value = fakelibvirt.os_uname(
|
||||
'Linux', '', '5.10.13-200-generic', '', 'x86_64')
|
||||
self.addCleanup(_a.stop)
|
||||
|
||||
def _get_node(self, xml):
|
||||
doc = etree.fromstring(xml)
|
||||
@ -984,14 +983,9 @@ class LibvirtVifTestCase(test.NoDBTestCase):
|
||||
self.vif_bridge,
|
||||
self.vif_bridge['network']['bridge'])
|
||||
|
||||
@mock.patch.object(pci_utils, 'get_ifname_by_pci_address')
|
||||
@mock.patch.object(pci_utils, 'get_vf_num_by_pci_address', return_value=1)
|
||||
@mock.patch('nova.privsep.linux_net.set_device_macaddr')
|
||||
@mock.patch('nova.privsep.linux_net.set_device_macaddr_and_vlan')
|
||||
def _test_hw_veb_op(self, op, vlan, mock_set_macaddr_and_vlan,
|
||||
mock_set_macaddr, mock_get_vf_num,
|
||||
mock_get_ifname):
|
||||
mock_get_ifname.side_effect = ['eth1', 'eth13']
|
||||
def _test_hw_veb_op(self, op, vlan):
|
||||
self.libvirt.mock_get_vf_num_by_pci_address.return_value = 1
|
||||
pci_utils.get_ifname_by_pci_address.side_effect = ['eth1', 'eth13']
|
||||
vlan_id = int(vlan)
|
||||
port_state = 'up' if vlan_id > 0 else 'down'
|
||||
mac = ('00:00:00:00:00:00' if op.__name__ == 'unplug'
|
||||
@ -1006,10 +1000,13 @@ class LibvirtVifTestCase(test.NoDBTestCase):
|
||||
'set_macaddr': [mock.call('eth13', mac, port_state=port_state)]
|
||||
}
|
||||
op(self.instance, self.vif_hw_veb_macvtap)
|
||||
mock_get_ifname.assert_has_calls(calls['get_ifname'])
|
||||
mock_get_vf_num.assert_has_calls(calls['get_vf_num'])
|
||||
mock_set_macaddr.assert_has_calls(calls['set_macaddr'])
|
||||
mock_set_macaddr_and_vlan.assert_called_once_with(
|
||||
pci_utils.get_ifname_by_pci_address.assert_has_calls(
|
||||
calls['get_ifname'])
|
||||
self.libvirt.mock_get_vf_num_by_pci_address.assert_has_calls(
|
||||
calls['get_vf_num'])
|
||||
self.libvirt.mock_set_device_macaddr.assert_has_calls(
|
||||
calls['set_macaddr'])
|
||||
self.libvirt.mock_set_device_macaddr_and_vlan.assert_called_once_with(
|
||||
'eth1', 1, mock.ANY, vlan_id)
|
||||
|
||||
def test_plug_hw_veb(self):
|
||||
@ -1219,9 +1216,8 @@ class LibvirtVifTestCase(test.NoDBTestCase):
|
||||
self.assertEqual(1, len(node))
|
||||
self._assertPciEqual(node, self.vif_hostdev_physical)
|
||||
|
||||
@mock.patch.object(pci_utils, 'get_ifname_by_pci_address',
|
||||
return_value='eth1')
|
||||
def test_hw_veb_driver_macvtap(self, mock_get_ifname):
|
||||
def test_hw_veb_driver_macvtap(self):
|
||||
pci_utils.get_ifname_by_pci_address.return_value = 'eth1'
|
||||
d = vif.LibvirtGenericVIFDriver()
|
||||
xml = self._get_instance_xml(d, self.vif_hw_veb_macvtap)
|
||||
node = self._get_node(xml)
|
||||
|
Loading…
Reference in New Issue
Block a user