Remove backward compatibility with pre-grizzly releases

Method get_instance_path libvirt/utils.py contained code that
keeps compatibility with pre-grizzly releases, where instance-path
was instance.name. This patch removes extra param from that method,
and code, that was used for pre-grizzly.

Change-Id: I50f3003f82f50a4b8d61b2c558093ec849ba86e1
This commit is contained in:
Timofey Durakov 2016-07-28 15:28:56 +03:00
parent 7cf8ab7354
commit 5ce0dbd197
6 changed files with 20 additions and 62 deletions

View File

@ -151,9 +151,8 @@ def fetch_raw_image(context, target, image_id, max_size=0):
pass
def get_instance_path(instance, forceold=False, relative=False):
return libvirt_utils.get_instance_path(instance, forceold=forceold,
relative=relative)
def get_instance_path(instance, relative=False):
return libvirt_utils.get_instance_path(instance, relative=relative)
def get_instance_path_at_destination(instance, migrate_data=None):

View File

@ -16076,7 +16076,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
mock_get_path.return_value = '/fake/inst'
drvr._cleanup_resize(ins_ref, _fake_network_info(self, 1))
mock_get_path.assert_called_once_with(ins_ref, forceold=True)
mock_get_path.assert_called_once_with(ins_ref)
mock_exec.assert_called_once_with('rm', '-rf', '/fake/inst_resize',
delay_on_retry=True, attempts=5)
@ -16103,7 +16103,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
mock_get_path.return_value = '/fake/inst'
drvr._cleanup_resize(ins_ref, fake_net)
mock_get_path.assert_called_once_with(ins_ref, forceold=True)
mock_get_path.assert_called_once_with(ins_ref)
mock_exec.assert_called_once_with('rm', '-rf', '/fake/inst_resize',
delay_on_retry=True, attempts=5)
mock_undef.assert_called_once_with(ins_ref)
@ -16127,7 +16127,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
mock_get_path.return_value = '/fake/inst'
drvr._cleanup_resize(ins_ref, _fake_network_info(self, 1))
mock_get_path.assert_called_once_with(ins_ref, forceold=True)
mock_get_path.assert_called_once_with(ins_ref)
mock_exec.assert_called_once_with('rm', '-rf', '/fake/inst_resize',
delay_on_retry=True, attempts=5)
mock_remove.assert_called_once_with(
@ -16151,7 +16151,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
mock_get_path.return_value = '/fake/inst'
drvr._cleanup_resize(ins_ref, _fake_network_info(self, 1))
mock_get_path.assert_called_once_with(ins_ref, forceold=True)
mock_get_path.assert_called_once_with(ins_ref)
mock_exec.assert_called_once_with('rm', '-rf', '/fake/inst_resize',
delay_on_retry=True, attempts=5)
self.assertFalse(mock_remove.called)

View File

@ -77,8 +77,6 @@ class _ImageTestCase(object):
self.TEMPLATE = 'template'
self.CONTEXT = context.get_admin_context()
self.OLD_STYLE_INSTANCE_PATH = \
fake_libvirt_utils.get_instance_path(self.INSTANCE, forceold=True)
self.PATH = os.path.join(
fake_libvirt_utils.get_instance_path(self.INSTANCE), self.NAME)
@ -215,8 +213,6 @@ class FlatTestCase(_ImageTestCase, test.NoDBTestCase):
def test_cache(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(False)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
@ -234,8 +230,6 @@ class FlatTestCase(_ImageTestCase, test.NoDBTestCase):
def test_cache_image_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
os.path.exists(self.PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_PATH).AndReturn(True)
@ -248,8 +242,6 @@ class FlatTestCase(_ImageTestCase, test.NoDBTestCase):
def test_cache_base_dir_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
@ -266,8 +258,6 @@ class FlatTestCase(_ImageTestCase, test.NoDBTestCase):
def test_cache_template_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(True)
@ -371,8 +361,6 @@ class Qcow2TestCase(_ImageTestCase, test.NoDBTestCase):
def test_cache(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(CONF.instances_path).AndReturn(True)
os.path.exists(self.TEMPLATE_DIR).AndReturn(False)
@ -391,8 +379,6 @@ class Qcow2TestCase(_ImageTestCase, test.NoDBTestCase):
def test_cache_image_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(self.INSTANCES_PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
@ -407,8 +393,6 @@ class Qcow2TestCase(_ImageTestCase, test.NoDBTestCase):
def test_cache_base_dir_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(self.INSTANCES_PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
@ -426,8 +410,6 @@ class Qcow2TestCase(_ImageTestCase, test.NoDBTestCase):
def test_cache_template_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(self.INSTANCES_PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
@ -459,8 +441,6 @@ class Qcow2TestCase(_ImageTestCase, test.NoDBTestCase):
self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(imagebackend.Image,
'verify_base_size')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(self.INSTANCES_PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
@ -482,8 +462,6 @@ class Qcow2TestCase(_ImageTestCase, test.NoDBTestCase):
fn = self.prepare_mocks()
self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(imagebackend.Qcow2, 'get_disk_size')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(self.INSTANCES_PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_PATH).AndReturn(True)
@ -504,8 +482,6 @@ class Qcow2TestCase(_ImageTestCase, test.NoDBTestCase):
'get_disk_backing_file')
self.mox.StubOutWithMock(imagebackend.Image,
'verify_base_size')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(CONF.instances_path).AndReturn(True)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
@ -537,8 +513,6 @@ class Qcow2TestCase(_ImageTestCase, test.NoDBTestCase):
'get_disk_backing_file')
self.mox.StubOutWithMock(imagebackend.Image,
'verify_base_size')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(self.INSTANCES_PATH).AndReturn(True)
@ -581,7 +555,6 @@ class LvmTestCase(_ImageTestCase, test.NoDBTestCase):
self.flags(enabled=False, group='ephemeral_storage_encryption')
self.INSTANCE['ephemeral_key_uuid'] = None
self.LV = '%s_%s' % (self.INSTANCE['uuid'], self.NAME)
self.OLD_STYLE_INSTANCE_PATH = None
self.PATH = os.path.join('/dev', self.VG, self.LV)
self.disk = imagebackend.disk
self.utils = imagebackend.utils
@ -647,8 +620,6 @@ class LvmTestCase(_ImageTestCase, test.NoDBTestCase):
def test_cache(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(False)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
@ -667,8 +638,6 @@ class LvmTestCase(_ImageTestCase, test.NoDBTestCase):
def test_cache_image_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
os.path.exists(self.PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_PATH).AndReturn(True)
@ -681,8 +650,6 @@ class LvmTestCase(_ImageTestCase, test.NoDBTestCase):
def test_cache_base_dir_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
@ -793,7 +760,6 @@ class EncryptedLvmTestCase(_ImageTestCase, test.NoDBTestCase):
group='key_manager')
self.flags(images_volume_group=self.VG, group='libvirt')
self.LV = '%s_%s' % (self.INSTANCE['uuid'], self.NAME)
self.OLD_STYLE_INSTANCE_PATH = None
self.LV_PATH = os.path.join('/dev', self.VG, self.LV)
self.PATH = os.path.join('/dev/mapper',
imagebackend.dmcrypt.volume_name(self.LV))
@ -1592,8 +1558,6 @@ class PloopTestCase(_ImageTestCase, test.NoDBTestCase):
def test_cache(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(False)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)

View File

@ -1114,13 +1114,6 @@ class LibvirtDriver(driver.ComputeDriver):
host=CONF.host)
def _cleanup_resize(self, instance, network_info):
# NOTE(wangpan): we get the pre-grizzly instance path firstly,
# so the backup dir of pre-grizzly instance can
# be deleted correctly with grizzly or later nova.
pre_grizzly_name = libvirt_utils.get_instance_path(instance,
forceold=True)
target = pre_grizzly_name + '_resize'
if not os.path.exists(target):
target = libvirt_utils.get_instance_path(instance) + '_resize'
if os.path.exists(target):

View File

@ -429,25 +429,16 @@ def fetch_raw_image(context, target, image_id):
images.fetch(context, image_id, target)
def get_instance_path(instance, forceold=False, relative=False):
def get_instance_path(instance, relative=False):
"""Determine the correct path for instance storage.
This method determines the directory name for instance storage, while
handling the fact that we changed the naming style to something more
unique in the grizzly release.
This method determines the directory name for instance storage.
:param instance: the instance we want a path for
:param forceold: force the use of the pre-grizzly format
:param relative: if True, just the relative path is returned
:returns: a path to store information about that instance
"""
pre_grizzly_name = os.path.join(CONF.instances_path, instance.name)
if forceold or os.path.exists(pre_grizzly_name):
if relative:
return instance.name
return pre_grizzly_name
if relative:
return instance.uuid
return os.path.join(CONF.instances_path, instance.uuid)

View File

@ -0,0 +1,11 @@
---
upgrade:
- Prior to Grizzly release default instance directory names were based on
instance.id field, for example directory for instance could be named
``instance-00000008``. In Grizzly this mechanism was changed,
instance.uuid is used as an instance directory name, e.g. path to instance:
``/opt/stack/data/nova/instances/34198248-5541-4d52-a0b4-a6635a7802dd/``.
In Newton backward compatibility is dropped. For instances that haven't
been restarted since Folsom and earlier maintanance should be scheduled
before upgrade(stop, rename directory to instance.uuid, then start) so Nova
will start using new paths for instances.