From 8484a234a8047019627184efbc2656f6ce2cb06d Mon Sep 17 00:00:00 2001 From: Sonia Ghanekar Date: Mon, 2 Nov 2015 13:58:42 -0800 Subject: [PATCH] Using extra-specs in cloned vols for Nimble driver This patch uses the set extra-specs while cloning a volume. All existing extra-specs: 'nimble:encryption', 'nimble:perfpol-name' and 'nimble:multi-initiator' are being reflected in the cloned volume. In the existing code, the extra-specs were not being considered while cloning volumes; the parent volume attributes were used directly in the cloned volume. This patch uses the extra-spec values if they are set or if not then uses the default values for the same. Change-Id: I7610377e557720038f77ebd318422456e658e2ce Closes-Bug: #1507821 --- cinder/tests/unit/test_nimble.py | 22 ++++++++++++++++++--- cinder/volume/drivers/nimble.py | 34 ++++++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/cinder/tests/unit/test_nimble.py b/cinder/tests/unit/test_nimble.py index 8a21c31a6..3b8551eff 100644 --- a/cinder/tests/unit/test_nimble.py +++ b/cinder/tests/unit/test_nimble.py @@ -516,6 +516,11 @@ class NimbleDriverVolumeTestCase(NimbleDriverBaseTestCase): @mock.patch(NIMBLE_CLIENT) @mock.patch.object(obj_volume.VolumeList, 'get_all', mock.Mock(return_value=[])) + @mock.patch.object(volume_types, 'get_volume_type_extra_specs', + mock.Mock(type_id=FAKE_TYPE_ID, return_value={ + 'nimble:perfpol-name': 'default', + 'nimble:encryption': 'yes', + 'nimble:multi-initiator': 'false'})) @NimbleDriverBaseTestCase.client_mock_decorator(create_configuration( 'nimble', 'nimble_pass', '10.18.108.55', 'default', '*', False)) @mock.patch(NIMBLE_RANDOM) @@ -533,7 +538,8 @@ class NimbleDriverVolumeTestCase(NimbleDriverBaseTestCase): 'provider_location': '172.18.108.21:3260 iqn.test 0', 'provider_auth': None}, self.driver.create_cloned_volume({'name': 'volume', - 'size': 5}, + 'size': 5, + 'volume_type_id': FAKE_TYPE_ID}, {'name': 'testvolume', 'size': 5})) expected_calls = [mock.call.service.snapVol( @@ -551,6 +557,8 @@ class NimbleDriverVolumeTestCase(NimbleDriverBaseTestCase): 'reserve': 5368709120, 'online': True, 'warn-level': 4294967296, + 'encryptionAttr': {'cipher': 2}, + 'multi-initiator': 'false', 'perfpol-name': 'default', 'agent-type': 5}, 'name': 'testvolume', @@ -718,7 +726,7 @@ class NimbleDriverVolumeTestCase(NimbleDriverBaseTestCase): def test_get_volume_stats(self): self.mock_client_service.service.getGroupConfig.return_value = \ FAKE_POSITIVE_GROUP_CONFIG_RESPONSE - expected_res = {'driver_version': '2.0.0', + expected_res = {'driver_version': '2.0.2', 'vendor_name': 'Nimble', 'volume_backend_name': 'NIMBLE', 'storage_protocol': 'iSCSI', @@ -787,6 +795,11 @@ class NimbleDriverSnapshotTestCase(NimbleDriverBaseTestCase): @mock.patch(NIMBLE_CLIENT) @mock.patch.object(obj_volume.VolumeList, 'get_all', mock.Mock(return_value=[])) + @mock.patch.object(volume_types, 'get_volume_type_extra_specs', + mock.Mock(type_id=FAKE_TYPE_ID, return_value={ + 'nimble:perfpol-name': 'default', + 'nimble:encryption': 'yes', + 'nimble:multi-initiator': 'false'})) @NimbleDriverBaseTestCase.client_mock_decorator(create_configuration( 'nimble', 'nimble_pass', '10.18.108.55', 'default', '*')) def test_create_volume_from_snapshot(self): @@ -801,7 +814,8 @@ class NimbleDriverSnapshotTestCase(NimbleDriverBaseTestCase): 'provider_auth': None}, self.driver.create_volume_from_snapshot( {'name': 'clone-testvolume', - 'size': 2}, + 'size': 2, + 'volume_type_id': FAKE_TYPE_ID}, {'volume_name': 'testvolume', 'name': 'testvolume-snap1', 'volume_size': 1})) @@ -815,6 +829,8 @@ class NimbleDriverSnapshotTestCase(NimbleDriverBaseTestCase): 'reserve': 0, 'warn-level': 858993459, 'perfpol-name': 'default', + 'encryptionAttr': {'cipher': 2}, + 'multi-initiator': 'false', 'agent-type': 5}, 'name': 'testvolume', 'sid': 'a9b9aba7'}), diff --git a/cinder/volume/drivers/nimble.py b/cinder/volume/drivers/nimble.py index 883a471ad..190ccbc0f 100644 --- a/cinder/volume/drivers/nimble.py +++ b/cinder/volume/drivers/nimble.py @@ -38,7 +38,7 @@ from cinder.volume.drivers.san import san from cinder.volume import volume_types -DRIVER_VERSION = '2.0.0' +DRIVER_VERSION = '2.0.2' AES_256_XTS_CIPHER = 2 DEFAULT_CIPHER = 3 EXTRA_SPEC_ENCRYPTION = 'nimble:encryption' @@ -95,6 +95,8 @@ class NimbleISCSIDriver(san.SanISCSIDriver): 2.0.0 - Added Extra Spec Capability Correct capacity reporting Added Manage/Unmanage volume support + 2.0.1 - Added multi-initiator support through extra-specs + 2.0.2 - Fixed supporting extra specs while cloning vols """ VERSION = DRIVER_VERSION @@ -827,27 +829,47 @@ class NimbleAPIExecutor(object): clone_name = volume['name'] snap_size = snapshot['volume_size'] reserve_size = snap_size * units.Gi if reserve else 0 + + specs = self._get_volumetype_extraspecs(volume) + extra_specs_map = self._get_extra_spec_values(specs) + perf_policy_name = extra_specs_map.get(EXTRA_SPEC_PERF_POLICY) + encrypt = extra_specs_map.get(EXTRA_SPEC_ENCRYPTION) + multi_initiator = extra_specs_map.get(EXTRA_SPEC_MULTI_INITIATOR) + # default value of cipher for encryption + cipher = DEFAULT_CIPHER + if encrypt.lower() == 'yes': + cipher = AES_256_XTS_CIPHER + LOG.info(_LI('Cloning volume from snapshot volume=%(vol)s ' - 'snapshot=%(snap)s clone=%(clone)s snap_size=%(size)s' - 'reserve=%(reserve)s' 'agent-type=%(agent-type)s'), + 'snapshot=%(snap)s clone=%(clone)s snap_size=%(size)s ' + 'reserve=%(reserve)s' 'agent-type=%(agent-type)s ' + 'perfpol-name=%(perfpol-name)s ' + 'encryption=%(encryption)s cipher=%(cipher)s ' + 'multi-initiator=%(multi-initiator)s'), {'vol': volume_name, 'snap': snap_name, 'clone': clone_name, 'size': snap_size, 'reserve': reserve, - 'agent-type': AGENT_TYPE_OPENSTACK}) + 'agent-type': AGENT_TYPE_OPENSTACK, + 'perfpol-name': perf_policy_name, + 'encryption': encrypt, + 'cipher': cipher, + 'multi-initiator': multi_initiator}) clone_size = snap_size * units.Gi return self.client.service.cloneVol( request={'sid': self.sid, 'name': volume_name, 'attr': {'name': clone_name, - 'perfpol-name': 'default', 'reserve': reserve_size, 'warn-level': int(clone_size * WARN_LEVEL), 'quota': clone_size, 'snap-quota': DEFAULT_SNAP_QUOTA, 'online': True, - 'agent-type': AGENT_TYPE_OPENSTACK}, + 'agent-type': AGENT_TYPE_OPENSTACK, + 'perfpol-name': perf_policy_name, + 'encryptionAttr': {'cipher': cipher}, + 'multi-initiator': multi_initiator}, 'snap-name': snap_name}) @_connection_checker -- 2.45.2