From 7eefc6ea2eb69d545b2af9310e87cd959556f202 Mon Sep 17 00:00:00 2001 From: Jason Ni Date: Wed, 27 Aug 2014 05:52:51 +0300 Subject: [PATCH] Add retype method to xiv/ds8k driver interface. Change-Id: I1389a3391a17c80e47aad1ed3e7209ec47333e41 --- cinder/tests/test_ibm_xiv_ds8k.py | 83 +++++++++++++++++++++++++++ cinder/volume/drivers/ibm/xiv_ds8k.py | 5 ++ 2 files changed, 88 insertions(+) diff --git a/cinder/tests/test_ibm_xiv_ds8k.py b/cinder/tests/test_ibm_xiv_ds8k.py index ef4baf65f..4a4caa9fa 100644 --- a/cinder/tests/test_ibm_xiv_ds8k.py +++ b/cinder/tests/test_ibm_xiv_ds8k.py @@ -24,11 +24,13 @@ import copy import mox from oslo.config import cfg +from cinder import context from cinder import exception from cinder.i18n import _ from cinder import test from cinder.volume import configuration as conf from cinder.volume.drivers.ibm import xiv_ds8k +from cinder.volume import volume_types FAKE = "fake" @@ -166,6 +168,10 @@ class XIVDS8KFakeProxyDriver(object): reason="Target and source volumes have different size.") return + def retype(self, ctxt, volume, new_type, diff, host): + volume['easytier'] = new_type['extra_specs']['easytier'] + return True, volume + class XIVDS8KVolumeDriverTest(test.TestCase): """Test IBM XIV and DS8K volume driver.""" @@ -480,3 +486,80 @@ class XIVDS8KVolumeDriverTest(test.TestCase): tgt_volume, src_volume ) + + def test_retype(self): + """Test that retype returns successfully.""" + + self.driver.do_setup(None) + + # prepare parameters + ctxt = context.get_admin_context() + + host = { + 'host': 'foo', + 'capabilities': { + 'location_info': 'xiv_ds8k_fake_1', + 'extent_size': '1024' + } + } + + key_specs_old = {'easytier': False, 'warning': 2, 'autoexpand': True} + key_specs_new = {'easytier': True, 'warning': 5, 'autoexpand': False} + old_type_ref = volume_types.create(ctxt, 'old', key_specs_old) + new_type_ref = volume_types.create(ctxt, 'new', key_specs_new) + + diff, equal = volume_types.volume_types_diff( + ctxt, + old_type_ref['id'], + new_type_ref['id'], + ) + + volume = copy.deepcopy(VOLUME) + old_type = volume_types.get_volume_type(ctxt, old_type_ref['id']) + volume['volume_type'] = old_type + volume['host'] = host + new_type = volume_types.get_volume_type(ctxt, new_type_ref['id']) + + self.driver.create_volume(volume) + ret = self.driver.retype(ctxt, volume, new_type, diff, host) + self.assertTrue(ret) + self.assertTrue(volume['easytier']) + + def test_retype_fail_on_exception(self): + """Test that retype fails on exception.""" + + self.driver.do_setup(None) + + # prepare parameters + ctxt = context.get_admin_context() + + host = { + 'host': 'foo', + 'capabilities': { + 'location_info': 'xiv_ds8k_fake_1', + 'extent_size': '1024' + } + } + + key_specs_old = {'easytier': False, 'warning': 2, 'autoexpand': True} + old_type_ref = volume_types.create(ctxt, 'old', key_specs_old) + new_type_ref = volume_types.create(ctxt, 'new') + + diff, equal = volume_types.volume_types_diff( + ctxt, + old_type_ref['id'], + new_type_ref['id'], + ) + + volume = copy.deepcopy(VOLUME) + old_type = volume_types.get_volume_type(ctxt, old_type_ref['id']) + volume['volume_type'] = old_type + volume['host'] = host + new_type = volume_types.get_volume_type(ctxt, new_type_ref['id']) + + self.driver.create_volume(volume) + self.assertRaises( + KeyError, + self.driver.retype, + ctxt, volume, new_type, diff, host + ) diff --git a/cinder/volume/drivers/ibm/xiv_ds8k.py b/cinder/volume/drivers/ibm/xiv_ds8k.py index 3ec94b500..0dbfdf039 100644 --- a/cinder/volume/drivers/ibm/xiv_ds8k.py +++ b/cinder/volume/drivers/ibm/xiv_ds8k.py @@ -221,3 +221,8 @@ class XIVDS8KDriver(san.SanDriver): """Creates a test replica clone of the specified replicated volume.""" return self.xiv_ds8k_proxy.create_replica_test_volume(volume, src_vref) + + def retype(self, ctxt, volume, new_type, diff, host): + """Convert the volume to be of the new type.""" + + return self.xiv_ds8k_proxy.retype(ctxt, volume, new_type, diff, host) -- 2.45.2