From 804ebf9db3c44cf9964e297e03c18309c817a9fd Mon Sep 17 00:00:00 2001 From: "ChangBo Guo(gcb)" Date: Wed, 24 Sep 2014 16:26:55 +0800 Subject: [PATCH] libvirt: add _get_launch_flags helper method in unit test In libvirt driver , we have some logic to generate launch_flags in method _create_domain_and_network, but in unit test we hard code launch_flags with '0'. This may lead unit test failure in actual test. We can't extract the logic to a method in libvirt/driver.py, so add a helper method with same logic for unit test. Change-Id: I39ce0162b856daf18488e006b0e424c11811e0c0 --- nova/tests/virt/libvirt/test_driver.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/nova/tests/virt/libvirt/test_driver.py b/nova/tests/virt/libvirt/test_driver.py index a37628cc4c..ed658f686d 100644 --- a/nova/tests/virt/libvirt/test_driver.py +++ b/nova/tests/virt/libvirt/test_driver.py @@ -576,6 +576,21 @@ class LibvirtConnTestCase(test.TestCase): return db.service_get_by_compute_host(context.get_admin_context(), host)['disabled'] + def _get_launch_flags(self, conn, network_info, power_on=True, + vifs_already_plugged=False): + timeout = CONF.vif_plugging_timeout + + events = [] + if (conn._conn_supports_start_paused and + utils.is_neutron() and + not vifs_already_plugged and + power_on and timeout): + events = conn._get_neutron_events(network_info) + + launch_flags = events and libvirt.VIR_DOMAIN_START_PAUSED or 0 + + return launch_flags + def test_public_api_signatures(self): baseinst = driver.ComputeDriver(None) inst = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) @@ -9692,9 +9707,8 @@ Active: 8381604 kB instance, vifs, power_on=power_on) plug_vifs.assert_called_with(instance, vifs) - event = (utils.is_neutron() and CONF.vif_plugging_timeout and - power_on) - flag = event and libvirt.VIR_DOMAIN_START_PAUSED or 0 + + flag = self._get_launch_flags(conn, vifs, power_on=power_on) self.assertEqual(flag, create.call_args_list[0][1]['launch_flags']) if flag: @@ -9841,8 +9855,9 @@ Active: 8381604 kB network_info) prepare_instance_filter.assert_called_once_with(instance, network_info) + flags = self._get_launch_flags(conn, network_info) create_domain.assert_called_once_with(fake_xml, instance=instance, - launch_flags=0, + launch_flags=flags, power_on=True) self.assertEqual(mock_dom, domain)