From cc3b912d768970d218a8b3f7758ccdeffb68e667 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Fri, 1 Jun 2012 01:44:02 +0000 Subject: [PATCH] Refactor libvirt create calls * minimizes duplicated code for create * makes wait_for_destroy happen on shutdown instead of undefine * allows for destruction of an instance while leaving the domain * uses reset for hard reboot instead of create/destroy * makes resume_host_state use new methods instead of hard_reboot * makes rescue/unrescue not use hard reboot to recreate domain Change-Id: I2072f93ad6c889d534b04009671147af653048e7 --- nova/tests/fakelibvirt.py | 5 +++++ nova/tests/test_libvirt.py | 26 ++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/nova/tests/fakelibvirt.py b/nova/tests/fakelibvirt.py index 69333040..563677cc 100644 --- a/nova/tests/fakelibvirt.py +++ b/nova/tests/fakelibvirt.py @@ -288,6 +288,11 @@ class Domain(object): self._state = VIR_DOMAIN_SHUTDOWN self._connection._mark_not_running(self) + def reset(self, flags): + # FIXME: Not handling flags at the moment + self._state = VIR_DOMAIN_RUNNING + self._connection._mark_running(self) + def info(self): return [self._state, long(self._def['memory']), diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 958a0087..65855c1e 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -2496,7 +2496,7 @@ class LibvirtDriverTestCase(test.TestCase): def fake_get_instance_disk_info(instance): return '[]' - def fake_destroy(instance, network_info, cleanup=True): + def fake_destroy(instance): pass def fake_get_host_ip_addr(): @@ -2541,7 +2541,7 @@ class LibvirtDriverTestCase(test.TestCase): def fake_get_instance_disk_info(instance): return disk_info_text - def fake_destroy(instance, network_info, cleanup=True): + def fake_destroy(instance): pass def fake_get_host_ip_addr(): @@ -2623,9 +2623,12 @@ class LibvirtDriverTestCase(test.TestCase): block_device_info=None): pass - def fake_create_new_domain(xml): + def fake_create_domain(xml): return None + def fake_enable_hairpin(instance): + pass + def fake_execute(*args, **kwargs): pass @@ -2635,8 +2638,10 @@ class LibvirtDriverTestCase(test.TestCase): self.stubs.Set(self.libvirtconnection, 'plug_vifs', fake_plug_vifs) self.stubs.Set(self.libvirtconnection, '_create_image', fake_create_image) - self.stubs.Set(self.libvirtconnection, '_create_new_domain', - fake_create_new_domain) + self.stubs.Set(self.libvirtconnection, '_create_domain', + fake_create_domain) + self.stubs.Set(self.libvirtconnection, '_enable_hairpin', + fake_enable_hairpin) self.stubs.Set(utils, 'execute', fake_execute) fw = base_firewall.NoopFirewallDriver() self.stubs.Set(self.libvirtconnection, 'firewall_driver', fw) @@ -2658,15 +2663,20 @@ class LibvirtDriverTestCase(test.TestCase): def fake_plug_vifs(instance, network_info): pass - def fake_create_new_domain(xml): + def fake_create_domain(xml): return None + def fake_enable_hairpin(instance): + pass + self.stubs.Set(self.libvirtconnection, 'plug_vifs', fake_plug_vifs) self.stubs.Set(utils, 'execute', fake_execute) fw = base_firewall.NoopFirewallDriver() self.stubs.Set(self.libvirtconnection, 'firewall_driver', fw) - self.stubs.Set(self.libvirtconnection, '_create_new_domain', - fake_create_new_domain) + self.stubs.Set(self.libvirtconnection, '_create_domain', + fake_create_domain) + self.stubs.Set(self.libvirtconnection, '_enable_hairpin', + fake_enable_hairpin) with utils.tempdir() as tmpdir: self.flags(instances_path=tmpdir)