stabilize unit test asserting log
The test_get_guest_cpu_config_host_passthrough_with_extra_flags asserts that no WARNING log is emited during the unit test case, but the LibvirtDriver itself could emit an unrelated WARNING log sometimes during the test making the test fail. This patch moves the mocking and the assert closer together to avoid the race in the log. Change-Id: I91667a95afd2a1c1ad53afaf4755224f831b52f6
This commit is contained in:
parent
5dbfbe692f
commit
c501e23cb7
|
@ -8447,9 +8447,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
|||
# assert that no warning is thrown
|
||||
mock_warn.assert_not_called()
|
||||
|
||||
@mock.patch.object(libvirt_driver.LOG, 'warning')
|
||||
def test_get_guest_cpu_config_host_passthrough_with_extra_flags(self,
|
||||
mock_warn):
|
||||
def test_get_guest_cpu_config_host_passthrough_with_extra_flags(self):
|
||||
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
instance_ref = objects.Instance(**self.test_instance)
|
||||
image_meta = objects.ImageMeta.from_dict(self.test_image_meta)
|
||||
|
@ -8460,9 +8458,14 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
|||
disk_info = blockinfo.get_disk_info(CONF.libvirt.virt_type,
|
||||
instance_ref,
|
||||
image_meta)
|
||||
conf = drvr._get_guest_config(instance_ref,
|
||||
_fake_network_info(self),
|
||||
image_meta, disk_info)
|
||||
with mock.patch.object(libvirt_driver.LOG, 'warning') as mock_warn:
|
||||
conf = drvr._get_guest_config(instance_ref,
|
||||
_fake_network_info(self),
|
||||
image_meta, disk_info)
|
||||
# We have lifted the restriction for 'host-passthrough' as well;
|
||||
# so here too, assert that no warning is thrown
|
||||
mock_warn.assert_not_called()
|
||||
|
||||
features = [feature.name for feature in conf.cpu.features]
|
||||
self.assertIsInstance(conf.cpu,
|
||||
vconfig.LibvirtConfigGuestCPU)
|
||||
|
@ -8471,9 +8474,6 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
|||
self.assertEqual(conf.cpu.sockets, instance_ref.flavor.vcpus)
|
||||
self.assertEqual(conf.cpu.cores, 1)
|
||||
self.assertEqual(conf.cpu.threads, 1)
|
||||
# We have lifted the restriction for 'host-passthrough' as well;
|
||||
# so here too, assert that no warning is thrown
|
||||
mock_warn.assert_not_called()
|
||||
|
||||
def test_get_guest_cpu_topology(self):
|
||||
instance_ref = objects.Instance(**self.test_instance)
|
||||
|
|
Loading…
Reference in New Issue