Skip to content

Instantly share code, notes, and snippets.

@DirectXMan12
Last active August 29, 2015 13:56
Show Gist options
  • Save DirectXMan12/9217699 to your computer and use it in GitHub Desktop.
Save DirectXMan12/9217699 to your computer and use it in GitHub Desktop.
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 9aa21a1..07cfdc8 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -3185,9 +3185,11 @@ class ComputeManager(manager.Manager):
block_device_info = self._get_instance_volume_block_device_info(
context, instance)
+ shared_storage = self._is_instance_storage_shared(context, instance)
+
disk_info = self.driver.migrate_disk_and_power_off(
context, instance, migration.dest_host,
- instance_type, network_info,
+ instance_type, network_info, shared_storage,
block_device_info)
self._terminate_volume_connections(context, instance)
diff --git a/nova/tests/virt/libvirt/test_libvirt.py b/nova/tests/virt/libvirt/test_libvirt.py
index fcd7098..8f47c24 100644
--- a/nova/tests/virt/libvirt/test_libvirt.py
+++ b/nova/tests/virt/libvirt/test_libvirt.py
@@ -6014,38 +6014,6 @@ class LibvirtConnTestCase(test.TestCase):
conn.set_cache_mode(fake_conf)
self.assertEqual(fake_conf.driver_cache, 'fake')
- def _test_shared_storage_detection(self, is_same):
- conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
- self.mox.StubOutWithMock(conn, 'get_host_ip_addr')
- self.mox.StubOutWithMock(utils, 'execute')
- self.mox.StubOutWithMock(os.path, 'exists')
- self.mox.StubOutWithMock(os, 'unlink')
- conn.get_host_ip_addr().AndReturn('bar')
- utils.execute('ssh', 'foo', 'touch', mox.IgnoreArg())
- os.path.exists(mox.IgnoreArg()).AndReturn(is_same)
- if is_same:
- os.unlink(mox.IgnoreArg())
- else:
- utils.execute('ssh', 'foo', 'rm', mox.IgnoreArg())
- self.mox.ReplayAll()
- return conn._is_storage_shared_with('foo', '/path')
-
- def test_shared_storage_detection_same_host(self):
- self.assertTrue(self._test_shared_storage_detection(True))
-
- def test_shared_storage_detection_different_host(self):
- self.assertFalse(self._test_shared_storage_detection(False))
-
- def test_shared_storage_detection_easy(self):
- conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
- self.mox.StubOutWithMock(conn, 'get_host_ip_addr')
- self.mox.StubOutWithMock(utils, 'execute')
- self.mox.StubOutWithMock(os.path, 'exists')
- self.mox.StubOutWithMock(os, 'unlink')
- conn.get_host_ip_addr().AndReturn('foo')
- self.mox.ReplayAll()
- self.assertTrue(conn._is_storage_shared_with('foo', '/path'))
-
def test_create_domain_define_xml_fails(self):
"""
Tests that the xml is logged when defining the domain fails.
@@ -7538,7 +7506,6 @@ class LibvirtDriverTestCase(test.TestCase):
"""
self.counter = 0
- self.checked_shared_storage = False
def fake_get_instance_disk_info(instance, xml=None,
block_device_info=None):
@@ -7558,17 +7525,11 @@ class LibvirtDriverTestCase(test.TestCase):
def fake_os_path_exists(path):
return True
- def fake_is_storage_shared(dest, inst_base):
- self.checked_shared_storage = True
- return False
-
self.stubs.Set(self.libvirtconnection, 'get_instance_disk_info',
fake_get_instance_disk_info)
self.stubs.Set(self.libvirtconnection, '_destroy', fake_destroy)
self.stubs.Set(self.libvirtconnection, 'get_host_ip_addr',
fake_get_host_ip_addr)
- self.stubs.Set(self.libvirtconnection, '_is_storage_shared_with',
- fake_is_storage_shared)
self.stubs.Set(utils, 'execute', fake_execute)
self.stubs.Set(os.path, 'exists', fake_os_path_exists)
@@ -7576,7 +7537,7 @@ class LibvirtDriverTestCase(test.TestCase):
self.assertRaises(AssertionError,
self.libvirtconnection.migrate_disk_and_power_off,
- None, ins_ref, '10.0.0.2', None, None)
+ None, ins_ref, '10.0.0.2', None, None, False)
def test_migrate_disk_and_power_off(self):
"""Test for nova.virt.libvirt.libvirt_driver.LivirtConnection
@@ -7616,12 +7577,12 @@ class LibvirtDriverTestCase(test.TestCase):
ins_ref = self._create_instance()
# dest is different host case
out = self.libvirtconnection.migrate_disk_and_power_off(
- None, ins_ref, '10.0.0.2', None, None)
+ None, ins_ref, '10.0.0.2', None, None, False)
self.assertEqual(out, disk_info_text)
# dest is same host case
out = self.libvirtconnection.migrate_disk_and_power_off(
- None, ins_ref, '10.0.0.1', None, None)
+ None, ins_ref, '10.0.0.1', None, None, True)
self.assertEqual(out, disk_info_text)
def test_wait_for_running(self):
diff --git a/nova/virt/driver.py b/nova/virt/driver.py
index ea76909..bb2b188 100644
--- a/nova/virt/driver.py
+++ b/nova/virt/driver.py
@@ -422,6 +422,7 @@ class ComputeDriver(object):
def migrate_disk_and_power_off(self, context, instance, dest,
flavor, network_info,
+ shared_storage=None,
block_device_info=None):
"""
Transfers the disk of a running instance in multiple phases, turning
diff --git a/nova/virt/fake.py b/nova/virt/fake.py
index 9e62c6c..6490d54 100644
--- a/nova/virt/fake.py
+++ b/nova/virt/fake.py
@@ -164,7 +164,7 @@ class FakeDriver(driver.ComputeDriver):
pass
def migrate_disk_and_power_off(self, context, instance, dest,
- flavor, network_info,
+ flavor, network_info, shared_storage=None,
block_device_info=None):
pass
diff --git a/nova/virt/hyperv/driver.py b/nova/virt/hyperv/driver.py
index 30be02e..df52b98 100644
--- a/nova/virt/hyperv/driver.py
+++ b/nova/virt/hyperv/driver.py
@@ -178,7 +178,7 @@ class HyperVDriver(driver.ComputeDriver):
LOG.debug(_("unfilter_instance called"), instance=instance)
def migrate_disk_and_power_off(self, context, instance, dest,
- flavor, network_info,
+ flavor, network_info, shared_storage=None,
block_device_info=None):
return self._migrationops.migrate_disk_and_power_off(context,
instance, dest,
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index 12d221c..84242ae 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -4697,29 +4697,8 @@ class LibvirtDriver(driver.ComputeDriver):
except Exception:
pass
- def _is_storage_shared_with(self, dest, inst_base):
- # NOTE (rmk): There are two methods of determining whether we are
- # on the same filesystem: the source and dest IP are the
- # same, or we create a file on the dest system via SSH
- # and check whether the source system can also see it.
- shared_storage = (dest == self.get_host_ip_addr())
- if not shared_storage:
- tmp_file = uuid.uuid4().hex + '.tmp'
- tmp_path = os.path.join(inst_base, tmp_file)
-
- try:
- utils.execute('ssh', dest, 'touch', tmp_path)
- if os.path.exists(tmp_path):
- shared_storage = True
- os.unlink(tmp_path)
- else:
- utils.execute('ssh', dest, 'rm', tmp_path)
- except Exception:
- pass
- return shared_storage
-
def migrate_disk_and_power_off(self, context, instance, dest,
- flavor, network_info,
+ flavor, network_info, shared_storage,
block_device_info=None):
LOG.debug(_("Starting migrate_disk_and_power_off"),
instance=instance)
@@ -4732,7 +4711,6 @@ class LibvirtDriver(driver.ComputeDriver):
# shared storage for instance dir (eg. NFS).
inst_base = libvirt_utils.get_instance_path(instance)
inst_base_resize = inst_base + "_resize"
- shared_storage = self._is_storage_shared_with(dest, inst_base)
# try to create the directory on the remote compute node
# if this fails we pass the exception up the stack so we can catch
diff --git a/nova/virt/vmwareapi/driver.py b/nova/virt/vmwareapi/driver.py
index 36f4d82..84d3b17 100644
--- a/nova/virt/vmwareapi/driver.py
+++ b/nova/virt/vmwareapi/driver.py
@@ -390,7 +390,7 @@ class VMwareVCDriver(VMwareESXDriver):
self._vc_state = self._resources.get(first_cluster).get('vcstate')
def migrate_disk_and_power_off(self, context, instance, dest,
- flavor, network_info,
+ flavor, network_info, shared_storage=None,
block_device_info=None):
"""
Transfers the disk of a running instance in multiple phases, turning
diff --git a/nova/virt/xenapi/driver.py b/nova/virt/xenapi/driver.py
index 61d0bbf..a8b13ec 100644
--- a/nova/virt/xenapi/driver.py
+++ b/nova/virt/xenapi/driver.py
@@ -300,7 +300,7 @@ class XenAPIDriver(driver.ComputeDriver):
self._vmops.unpause(instance)
def migrate_disk_and_power_off(self, context, instance, dest,
- flavor, network_info,
+ flavor, network_info, shared_storage=None,
block_device_info=None):
"""Transfers the VHD of a running instance to another host, then shuts
off the instance copies over the COW disk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment