Fix database poison warnings, part 8

The following warning appears in the unit test logs a number of times.
This patch fixes the warnings in virt.libvirt.test_driver that come from
driver._get_connection() calls, but there are still a bunch more
warnings in that file.

    "UserWarning: This test uses methods that set internal oslo_db
state, but it does not claim to use the database. This will conflict
with the setup of tests that do use the database and cause failures
later."

Note that this warning is only emitted once per unit test worker, so new
offenders will show up in the logs each time you fix a test until they
are all gone.

Change-Id: Icacce09f8a83cb4c73d5b6caf5cd31b55032c847
Related-Bug: #1568414
This commit is contained in:
Diana Clarke 2016-05-02 17:42:50 -04:00
parent 82098d06db
commit cf9713f3a4
1 changed files with 18 additions and 7 deletions

View File

@ -1362,8 +1362,9 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.assertRaises(exception.PciDevicePrepareFailed,
drvr._prepare_pci_devices_for_use, pci_devices)
@mock.patch.object(host.Host, 'get_connection')
@mock.patch.object(nova.virt.libvirt.guest.Guest, 'get_xml_desc')
def test_detach_pci_devices(self, mocked_get_xml_desc):
def test_detach_pci_devices(self, mocked_get_xml_desc, mock_conn):
fake_domXML1_with_pci = (
"""<domain> <devices>
@ -1406,8 +1407,9 @@ class LibvirtConnTestCase(test.NoDBTestCase):
guest = libvirt_guest.Guest(dom)
drvr._detach_pci_devices(guest, pci_devices)
@mock.patch.object(host.Host, 'get_connection')
@mock.patch.object(nova.virt.libvirt.guest.Guest, 'get_xml_desc')
def test_detach_pci_devices_timeout(self, mocked_get_xml_desc):
def test_detach_pci_devices_timeout(self, mocked_get_xml_desc, mock_conn):
fake_domXML1_with_pci = (
"""<domain> <devices>
@ -7466,9 +7468,11 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.assertFalse(mock_exist.called)
self.assertFalse(mock_shutil.called)
@mock.patch.object(host.Host, "get_connection")
@mock.patch.object(host.Host, "has_min_version", return_value=False)
@mock.patch.object(fakelibvirt.Domain, "XMLDesc")
def test_live_migration_copy_disk_paths(self, mock_xml, mock_version):
def test_live_migration_copy_disk_paths(self, mock_xml, mock_version,
mock_conn):
xml = """
<domain>
<name>dummy</name>
@ -7509,13 +7513,14 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.assertEqual((["/var/lib/nova/instance/123/disk.root",
"/dev/mapper/somevol"], ['vda', 'vdd']), paths)
@mock.patch.object(host.Host, "get_connection")
@mock.patch.object(host.Host, "has_min_version", return_value=True)
@mock.patch('nova.virt.driver.get_block_device_info')
@mock.patch('nova.objects.BlockDeviceMappingList.get_by_instance_uuid')
@mock.patch.object(fakelibvirt.Domain, "XMLDesc")
def test_live_migration_copy_disk_paths_selective_block_migration(
self, mock_xml, mock_get_instance,
mock_block_device_info, mock_version):
mock_block_device_info, mock_version, mock_conn):
xml = """
<domain>
<name>dummy</name>
@ -7647,6 +7652,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
@mock.patch.object(time, "time")
@mock.patch.object(time, "sleep",
side_effect=lambda x: eventlet.sleep(0))
@mock.patch.object(host.Host, "get_connection")
@mock.patch.object(host.DomainJobInfo, "for_domain")
@mock.patch.object(objects.Instance, "save")
@mock.patch.object(objects.Migration, "save")
@ -7661,6 +7667,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
mock_save,
mock_mig_save,
mock_job_info,
mock_conn,
mock_sleep,
mock_time,
expected_mig_status=None):
@ -7979,6 +7986,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
(900, 400),
], list(steps))
@mock.patch.object(host.Host, "get_connection")
@mock.patch.object(utils, "spawn")
@mock.patch.object(libvirt_driver.LibvirtDriver, "_live_migration_monitor")
@mock.patch.object(host.Host, "get_guest")
@ -7986,7 +7994,8 @@ class LibvirtConnTestCase(test.NoDBTestCase):
@mock.patch.object(libvirt_driver.LibvirtDriver,
"_live_migration_copy_disk_paths")
def test_live_migration_main(self, mock_copy_disk_path, mock_running,
mock_guest, mock_monitor, mock_thread):
mock_guest, mock_monitor, mock_thread,
mock_conn):
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
instance = objects.Instance(**self.test_instance)
dom = fakelibvirt.Domain(drvr._get_connection(),
@ -13435,8 +13444,9 @@ class LibvirtConnTestCase(test.NoDBTestCase):
drvr.live_migration_force_complete(self.test_instance)
pause.assert_called_once_with(self.test_instance)
@mock.patch.object(host.Host, "get_connection")
@mock.patch.object(fakelibvirt.virDomain, "abortJob")
def test_live_migration_abort(self, mock_abort):
def test_live_migration_abort(self, mock_abort, mock_conn):
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
dom = fakelibvirt.Domain(drvr._get_connection(), "<domain/>", False)
guest = libvirt_guest.Guest(dom)
@ -15742,7 +15752,8 @@ class LibvirtNonblockingTestCase(test.NoDBTestCase):
drvr.set_host_enabled = mock.Mock()
jsonutils.to_primitive(drvr._conn, convert_instances=True)
def test_tpool_execute_calls_libvirt(self):
@mock.patch.object(objects.Service, 'get_by_compute_host')
def test_tpool_execute_calls_libvirt(self, mock_svc):
conn = fakelibvirt.virConnect()
conn.is_expected = True