Huawei driver supports specifying copy speed

Currently, while creating volume from snapshot or cloning volume,
Huawei driver always specifies the copy speed as medium.

This patch lets users specify the copy speed they want, via
the metadata optional argument.

Change-Id: Ic70f2fee06866932b1c105d657a864553307c835
Closes-bug: #1646019
This commit is contained in:
zengyingzhe 2016-09-12 09:40:44 +08:00 committed by huyang
parent ed20152b78
commit 045b1647c0
5 changed files with 79 additions and 5 deletions

View File

@ -2139,6 +2139,7 @@ class FakeFCStorage(huawei_driver.HuaweiFCDriver):
self.configuration)
@ddt.ddt
class HuaweiTestBase(test.TestCase):
"""Base class for Huawei test cases.
@ -2200,6 +2201,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):
@ -2209,7 +2259,6 @@ class HuaweiISCSIDriverTestCase(HuaweiTestBase):
self.configuration = mock.Mock(spec=conf.Configuration)
self.configuration.hypermetro_devices = hypermetro_devices
self.flags(rpc_backend='oslo_messaging._drivers.impl_fake')
self.stubs.Set(time, 'sleep', Fake_sleep)
self.driver = FakeISCSIStorage(configuration=self.configuration)
self.driver.do_setup()
self.portgroup = 'portgroup-test'
@ -3724,7 +3773,6 @@ class HuaweiFCDriverTestCase(HuaweiTestBase):
self.flags(rpc_backend='oslo_messaging._drivers.impl_fake')
self.huawei_conf = FakeHuaweiConf(self.configuration, 'FC')
self.configuration.hypermetro_devices = hypermetro_devices
self.stubs.Set(time, 'sleep', Fake_sleep)
driver = FakeFCStorage(configuration=self.configuration)
self.driver = driver
self.driver.do_setup()

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

@ -1176,9 +1176,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

@ -360,13 +360,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.