From 64b63f44b054dc60346b67ef3875dd67a358e542 Mon Sep 17 00:00:00 2001 From: Kurt Martin Date: Wed, 9 Mar 2016 14:33:55 -0800 Subject: [PATCH] LeftHand: Create cloned volume didn't honor size If the volume being created was larger than the cloned volume the new volume was not being extended. Change-Id: I65cbf76ca6c4b11b82cc992f731b868c511e653e Closes-Bug: 1554746 --- cinder/tests/unit/test_hpelefthand.py | 51 ++++++++++++++++++- .../volume/drivers/hpe/hpe_lefthand_iscsi.py | 8 ++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/cinder/tests/unit/test_hpelefthand.py b/cinder/tests/unit/test_hpelefthand.py index ad4942a9d..489957ef6 100644 --- a/cinder/tests/unit/test_hpelefthand.py +++ b/cinder/tests/unit/test_hpelefthand.py @@ -116,7 +116,10 @@ class HPELeftHandBaseDriver(object): 'volume': volume} cloned_volume_name = "clone_volume" - cloned_volume = {'name': cloned_volume_name} + cloned_volume = {'name': cloned_volume_name, + 'size': 1} + cloned_volume_extend = {'name': cloned_volume_name, + 'size': 5} cloned_snapshot_name = "clonedshapshot" cloned_snapshot_id = 5 @@ -805,6 +808,52 @@ class TestHPELeftHandISCSIDriver(HPELeftHandBaseDriver, test.TestCase): # validate call chain mock_client.assert_has_calls(expected) + def test_create_cloned_volume_extend(self): + + # setup drive with default configuration + # and return the mock HTTP LeftHand client + mock_client = self.setup_driver() + + mock_client.getVolumeByName.return_value = {'id': self.volume_id} + mock_client.cloneVolume.return_value = { + 'iscsiIqn': self.connector['initiator']} + mock_client.getVolumes.return_value = {'total': 1, 'members': []} + + with mock.patch.object(hpe_lefthand_iscsi.HPELeftHandISCSIDriver, + '_create_client') as mock_do_setup: + mock_do_setup.return_value = mock_client + + # execute create_cloned_volume with extend + model_update = self.driver.create_cloned_volume( + self.cloned_volume_extend, self.volume) + + expected_iqn = 'iqn.1993-08.org.debian:01:222 0' + expected_location = "10.0.1.6:3260,1 %s" % expected_iqn + self.assertEqual(expected_location, + model_update['provider_location']) + + expected = self.driver_startup_call_stack + [ + mock.call.getVolumeByName('fakevolume'), + mock.call.cloneVolume('clone_volume', 1), + mock.call.login('foo1', 'bar2'), + mock.call.getClusterByName('CloudCluster1'), + mock.call.setSSHOptions( + HPELEFTHAND_SSH_IP, + HPELEFTHAND_USERNAME, + HPELEFTHAND_PASSWORD, + missing_key_policy='AutoAddPolicy', + privatekey=HPELEFTHAND_SAN_SSH_PRIVATE, + known_hosts_file=mock.ANY, + port=HPELEFTHAND_SSH_PORT, + conn_timeout=HPELEFTHAND_SAN_SSH_CON_TIMEOUT), + mock.call.getVolumeByName('clone_volume'), + mock.call.modifyVolume(self.volume_id, {'size': 5 * units.Gi}), + mock.call.logout(), + mock.call.logout()] + + # validate call chain + mock_client.assert_has_calls(expected) + @mock.patch.object(volume_types, 'get_volume_type') def test_extra_spec_mapping(self, _mock_get_volume_type): diff --git a/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py b/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py index 733948e98..36264f2ed 100644 --- a/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py +++ b/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py @@ -150,9 +150,10 @@ class HPELeftHandISCSIDriver(driver.ISCSIDriver): 2.0.4 - Add manage/unmanage snapshot support 2.0.5 - Changed minimum client version to be 2.1.0 2.0.6 - Update replication to version 2.1 + 2.0.7 - Fixed bug #1554746, Create clone volume with new size. """ - VERSION = "2.0.6" + VERSION = "2.0.7" device_stats = {} @@ -774,6 +775,11 @@ class HPELeftHandISCSIDriver(driver.ISCSIDriver): volume_info = client.getVolumeByName(src_vref['name']) clone_info = client.cloneVolume(volume['name'], volume_info['id']) + # Extend volume + if volume['size'] > src_vref['size']: + LOG.debug("Resize the new volume to %s.", volume['size']) + self.extend_volume(volume, volume['size']) + model_update = self._update_provider(clone_info) # v2 replication check -- 2.45.2