]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add retype method to xiv/ds8k driver interface.
authorJason Ni <jason.ni.py@gmail.com>
Wed, 27 Aug 2014 02:52:51 +0000 (05:52 +0300)
committerJason Ni <jason.ni.py@gmail.com>
Wed, 27 Aug 2014 02:52:51 +0000 (05:52 +0300)
Change-Id: I1389a3391a17c80e47aad1ed3e7209ec47333e41

cinder/tests/test_ibm_xiv_ds8k.py
cinder/volume/drivers/ibm/xiv_ds8k.py

index ef4baf65fe1db1fb4c8539537f1090d3c140775c..4a4caa9fa309b22fd32f45dad567ed7de5e1d143 100644 (file)
@@ -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
+        )
index 3ec94b500b91d904d824a89ea8af66142c599ec4..0dbfdf0394df24b848c1c4a5ac09a99bb1162c2a 100644 (file)
@@ -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)