Merge "Huawei driver supports specifying copy speed"

This commit is contained in:
Jenkins 2017-03-02 05:54:06 +00:00 committed by Gerrit Code Review
commit 47346facdd
5 changed files with 79 additions and 3 deletions

View File

@ -2203,6 +2203,7 @@ class FakeFCStorage(huawei_driver.HuaweiFCDriver):
self.configuration)
@ddt.ddt
class HuaweiTestBase(test.TestCase):
"""Base class for Huawei test cases.
@ -2264,6 +2265,55 @@ class HuaweiTestBase(test.TestCase):
lun_info = self.driver.create_snapshot(self.snapshot)
self.assertEqual(11, lun_info['provider_location'])
@ddt.data('1', '', '0')
def test_copy_volume(self, input_speed):
self.driver.configuration.lun_copy_wait_interval = 0
self.volume.metadata = {'copyspeed': input_speed}
mocker = self.mock_object(
self.driver.client, 'create_luncopy',
mock.Mock(wraps=self.driver.client.create_luncopy))
self.driver._copy_volume(self.volume,
'fake_copy_name',
'fake_src_lun',
'fake_tgt_lun')
mocker.assert_called_once_with('fake_copy_name',
'fake_src_lun',
'fake_tgt_lun',
input_speed)
@ddt.data({'input_speed': '1',
'actual_speed': '1'},
{'input_speed': '',
'actual_speed': '2'},
{'input_speed': None,
'actual_speed': '2'},
{'input_speed': '5',
'actual_speed': '2'})
@ddt.unpack
def test_client_create_luncopy(self, input_speed, actual_speed):
mocker = self.mock_object(
self.driver.client, 'call',
mock.Mock(wraps=self.driver.client.call))
self.driver.client.create_luncopy('fake_copy_name',
'fake_src_lun',
'fake_tgt_lun',
input_speed)
mocker.assert_called_once_with(
mock.ANY,
{"TYPE": 219,
"NAME": 'fake_copy_name',
"DESCRIPTION": 'fake_copy_name',
"COPYSPEED": actual_speed,
"LUNCOPYTYPE": "1",
"SOURCELUN": "INVALID;fake_src_lun;INVALID;INVALID;INVALID",
"TARGETLUN": "INVALID;fake_tgt_lun;INVALID;INVALID;INVALID"}
)
@ddt.ddt
class HuaweiISCSIDriverTestCase(HuaweiTestBase):

View File

@ -114,3 +114,10 @@ REPLICA_DATA_STATUS_INCOMPLETE = '3'
VOLUME_NOT_EXISTS_WARN = 'warning'
VOLUME_NOT_EXISTS_RAISE = 'raise'
LUN_COPY_SPEED_TYPES = (
LUN_COPY_SPEED_LOW,
LUN_COPY_SPEED_MEDIUM,
LUN_COPY_SPEED_HIGH,
LUN_COPY_SPEED_HIGHEST
) = ('1', '2', '3', '4')

View File

@ -1263,9 +1263,12 @@ class HuaweiBaseDriver(driver.VolumeDriver):
return self.configuration.safe_get("backup_use_temp_snapshot")
def _copy_volume(self, volume, copy_name, src_lun, tgt_lun):
metadata = huawei_utils.get_volume_metadata(volume)
copyspeed = metadata.get('copyspeed')
luncopy_id = self.client.create_luncopy(copy_name,
src_lun,
tgt_lun)
tgt_lun,
copyspeed)
wait_interval = self.configuration.lun_copy_wait_interval
try:

View File

@ -370,13 +370,20 @@ class RestClient(object):
return self._get_id_from_result(result, name, 'NAME')
def create_luncopy(self, luncopyname, srclunid, tgtlunid):
def create_luncopy(self, luncopyname, srclunid, tgtlunid, copyspeed):
"""Create a luncopy."""
url = "/luncopy"
if copyspeed not in constants.LUN_COPY_SPEED_TYPES:
LOG.warning(_LW('The copy speed %(copyspeed)s is not valid, '
'using default value %(default)s instead.'),
{'copyspeed': copyspeed,
'default': constants.LUN_COPY_SPEED_MEDIUM})
copyspeed = constants.LUN_COPY_SPEED_MEDIUM
data = {"TYPE": 219,
"NAME": luncopyname,
"DESCRIPTION": luncopyname,
"COPYSPEED": 2,
"COPYSPEED": copyspeed,
"LUNCOPYTYPE": "1",
"SOURCELUN": ("INVALID;%s;INVALID;INVALID;INVALID"
% srclunid),

View File

@ -0,0 +1,9 @@
---
features:
- Allow users to specify the copy speed while using Huawei
driver to create volume from snapshot or clone volume, by
the new added metadata 'copyspeed'.
For example, user can add --metadata copyspeed=1 when
creating volume from source volume/snapshot.
The valid optional range of copyspeed is [1, 2, 3, 4],
respectively representing LOW, MEDIUM, HIGH and HIGHEST.