diff options
Diffstat (limited to 'cinder/tests/unit/volume/drivers/hitachi/test_hitachi_hbsd_rest_iscsi.py')
-rw-r--r-- | cinder/tests/unit/volume/drivers/hitachi/test_hitachi_hbsd_rest_iscsi.py | 174 |
1 files changed, 152 insertions, 22 deletions
diff --git a/cinder/tests/unit/volume/drivers/hitachi/test_hitachi_hbsd_rest_iscsi.py b/cinder/tests/unit/volume/drivers/hitachi/test_hitachi_hbsd_rest_iscsi.py index 65c6b1650..9d79a1031 100644 --- a/cinder/tests/unit/volume/drivers/hitachi/test_hitachi_hbsd_rest_iscsi.py +++ b/cinder/tests/unit/volume/drivers/hitachi/test_hitachi_hbsd_rest_iscsi.py @@ -33,6 +33,7 @@ from cinder.volume import configuration as conf from cinder.volume import driver from cinder.volume.drivers.hitachi import hbsd_common from cinder.volume.drivers.hitachi import hbsd_iscsi +from cinder.volume.drivers.hitachi import hbsd_replication from cinder.volume.drivers.hitachi import hbsd_rest from cinder.volume.drivers.hitachi import hbsd_rest_api from cinder.volume import volume_types @@ -191,6 +192,8 @@ GET_LDEV_RESULT = { "attributes": ["CVS", "HDP"], "status": "NML", "poolId": 30, + "dataReductionStatus": "DISABLED", + "dataReductionMode": "disabled", } GET_LDEV_RESULT_MAPPED = { @@ -252,6 +255,16 @@ GET_SNAPSHOTS_RESULT_PAIR = { ], } +GET_HOST_GROUPS_RESULT_PAIR = { + "data": [ + { + "hostGroupNumber": 1, + "portId": CONFIG_MAP['port_id'], + "hostGroupName": "HBSD-pair00", + }, + ], +} + GET_LDEVS_RESULT = { "data": [ { @@ -331,7 +344,7 @@ class HBSDRESTISCSIDriverTest(test.TestCase): self.configuration.driver_ssl_cert_verify = False self.configuration.hitachi_storage_id = CONFIG_MAP['serial'] - self.configuration.hitachi_pool = ['30'] + self.configuration.hitachi_pools = ['30'] self.configuration.hitachi_snap_pool = None self.configuration.hitachi_ldev_range = "0-1" self.configuration.hitachi_target_ports = [CONFIG_MAP['port_id']] @@ -343,6 +356,7 @@ class HBSDRESTISCSIDriverTest(test.TestCase): self.configuration.hitachi_copy_check_interval = 3 self.configuration.hitachi_async_copy_check_interval = 10 self.configuration.hitachi_port_scheduler = False + self.configuration.hitachi_group_name_format = None self.configuration.san_login = CONFIG_MAP['user_id'] self.configuration.san_password = CONFIG_MAP['user_pass'] @@ -353,7 +367,6 @@ class HBSDRESTISCSIDriverTest(test.TestCase): self.configuration.hitachi_rest_disable_io_wait = True self.configuration.hitachi_rest_tcp_keepalive = True self.configuration.hitachi_discard_zero_page = True - self.configuration.hitachi_rest_number = "0" self.configuration.hitachi_lun_timeout = hbsd_rest._LUN_TIMEOUT self.configuration.hitachi_lun_retry_interval = ( hbsd_rest._LUN_RETRY_INTERVAL) @@ -399,6 +412,21 @@ class HBSDRESTISCSIDriverTest(test.TestCase): self.configuration.ssh_min_pool_conn = '1' self.configuration.ssh_max_pool_conn = '5' + self.configuration.hitachi_replication_number = 0 + self.configuration.hitachi_pair_target_number = 0 + self.configuration.hitachi_rest_pair_target_ports = [] + self.configuration.hitachi_quorum_disk_id = '' + self.configuration.hitachi_mirror_copy_speed = '' + self.configuration.hitachi_mirror_storage_id = '' + self.configuration.hitachi_mirror_pool = '' + self.configuration.hitachi_mirror_ldev_range = '' + self.configuration.hitachi_mirror_target_ports = '' + self.configuration.hitachi_mirror_rest_user = '' + self.configuration.hitachi_mirror_rest_password = '' + self.configuration.hitachi_mirror_rest_api_ip = '' + self.configuration.hitachi_set_mirror_reserve_attribute = '' + self.configuration.hitachi_path_group_id = '' + self.configuration.safe_get = self._fake_safe_get CONF = cfg.CONF @@ -425,7 +453,8 @@ class HBSDRESTISCSIDriverTest(test.TestCase): FakeResponse(200, GET_PORTS_RESULT), FakeResponse(200, GET_PORT_RESULT), FakeResponse(200, GET_HOST_ISCSIS_RESULT), - FakeResponse(200, GET_HOST_GROUP_RESULT)] + FakeResponse(200, GET_HOST_GROUP_RESULT), + FakeResponse(200, GET_HOST_GROUPS_RESULT_PAIR)] self.driver.do_setup(None) self.driver.check_for_setup_error() self.driver.local_path(None) @@ -454,7 +483,8 @@ class HBSDRESTISCSIDriverTest(test.TestCase): FakeResponse(200, GET_PORTS_RESULT), FakeResponse(200, GET_PORT_RESULT), FakeResponse(200, GET_HOST_ISCSIS_RESULT), - FakeResponse(200, GET_HOST_GROUP_RESULT)] + FakeResponse(200, GET_HOST_GROUP_RESULT), + FakeResponse(200, GET_HOST_GROUPS_RESULT_PAIR)] drv.do_setup(None) self.assertEqual( {CONFIG_MAP['port_id']: @@ -463,7 +493,7 @@ class HBSDRESTISCSIDriverTest(test.TestCase): 'port': CONFIG_MAP['tcpPort']}}, drv.common.storage_info['portals']) self.assertEqual(1, brick_get_connector_properties.call_count) - self.assertEqual(5, request.call_count) + self.assertEqual(6, request.call_count) # stop the Loopingcall within the do_setup treatment self.driver.common.client.keep_session_loop.stop() self.driver.common.client.keep_session_loop.wait() @@ -484,7 +514,8 @@ class HBSDRESTISCSIDriverTest(test.TestCase): FakeResponse(200, NOTFOUND_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), - FakeResponse(202, COMPLETED_SUCCEEDED_RESULT)] + FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), + FakeResponse(200, GET_HOST_GROUPS_RESULT_PAIR)] drv.do_setup(None) self.assertEqual( {CONFIG_MAP['port_id']: @@ -493,12 +524,63 @@ class HBSDRESTISCSIDriverTest(test.TestCase): 'port': CONFIG_MAP['tcpPort']}}, drv.common.storage_info['portals']) self.assertEqual(1, brick_get_connector_properties.call_count) - self.assertEqual(8, request.call_count) + self.assertEqual(9, request.call_count) # stop the Loopingcall within the do_setup treatment self.driver.common.client.keep_session_loop.stop() self.driver.common.client.keep_session_loop.wait() @mock.patch.object(requests.Session, "request") + @mock.patch.object( + volume_utils, 'brick_get_connector_properties', + side_effect=_brick_get_connector_properties) + def test_do_setup_create_hg_format( + self, brick_get_connector_properties, request): + drv = hbsd_iscsi.HBSDISCSIDriver(configuration=self.configuration) + self._setup_config() + self.configuration.hitachi_group_name_format = 'HBSD-{ip}@{host}-_:.' + request.side_effect = [FakeResponse(200, POST_SESSIONS_RESULT), + FakeResponse(200, GET_PORTS_RESULT), + FakeResponse(200, GET_PORT_RESULT), + FakeResponse(200, NOTFOUND_RESULT), + FakeResponse(200, NOTFOUND_RESULT), + FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), + FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), + FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), + FakeResponse(200, GET_HOST_GROUPS_RESULT_PAIR)] + drv.do_setup(None) + self.assertEqual( + {CONFIG_MAP['port_id']: + '%(ip)s:%(port)s' % { + 'ip': CONFIG_MAP['ipv4Address'], + 'port': CONFIG_MAP['tcpPort']}}, + drv.common.storage_info['portals']) + self.assertEqual(1, brick_get_connector_properties.call_count) + self.assertEqual(9, request.call_count) + # stop the Loopingcall within the do_setup treatment + self.driver.common.client.keep_session_loop.stop() + self.driver.common.client.keep_session_loop.wait() + + @mock.patch.object(requests.Session, "request") + @mock.patch.object( + volume_utils, 'brick_get_connector_properties', + side_effect=_brick_get_connector_properties) + def test_do_setup_create_hg_format_error( + self, brick_get_connector_properties, request): + drv = hbsd_iscsi.HBSDISCSIDriver(configuration=self.configuration) + self._setup_config() + self.configuration.hitachi_group_name_format = ( + 'HBSD-{ip}@{host}ZZZZZZZZZZZ') + request.side_effect = [FakeResponse(200, POST_SESSIONS_RESULT), + FakeResponse(200, GET_PORTS_RESULT), + FakeResponse(200, GET_PORT_RESULT), + FakeResponse(200, NOTFOUND_RESULT), + FakeResponse(200, NOTFOUND_RESULT), + FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), + FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), + FakeResponse(202, COMPLETED_SUCCEEDED_RESULT)] + self.assertRaises(exception.VolumeDriverException, drv.do_setup, None) + + @mock.patch.object(requests.Session, "request") def test_extend_volume(self, request): request.side_effect = [FakeResponse(200, GET_LDEV_RESULT), FakeResponse(200, GET_LDEV_RESULT), @@ -541,8 +623,11 @@ class HBSDRESTISCSIDriverTest(test.TestCase): self.assertEqual(4, request.call_count) @mock.patch.object(requests.Session, "request") + @mock.patch.object(volume_types, 'get_volume_type_extra_specs') @mock.patch.object(sqlalchemy_api, 'volume_get', side_effect=_volume_get) - def test_create_snapshot(self, volume_get, request): + def test_create_snapshot( + self, volume_get, get_volume_type_extra_specs, request): + get_volume_type_extra_specs.return_value = {} request.side_effect = [FakeResponse(200, GET_LDEV_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), @@ -552,6 +637,7 @@ class HBSDRESTISCSIDriverTest(test.TestCase): {'location_info': {'pool_id': 30}}] ret = self.driver.create_snapshot(TEST_SNAPSHOT[0]) self.assertEqual('1', ret['provider_location']) + self.assertEqual(1, get_volume_type_extra_specs.call_count) self.assertEqual(4, request.call_count) @mock.patch.object(requests.Session, "request") @@ -564,32 +650,40 @@ class HBSDRESTISCSIDriverTest(test.TestCase): self.assertEqual(4, request.call_count) @mock.patch.object(requests.Session, "request") - def test_create_cloned_volume(self, request): + @mock.patch.object(volume_types, 'get_volume_type_extra_specs') + def test_create_cloned_volume( + self, get_volume_type_extra_specs, request): request.side_effect = [FakeResponse(200, GET_LDEV_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), FakeResponse(200, GET_SNAPSHOTS_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT)] + get_volume_type_extra_specs.return_value = {} self.driver.common._stats = {} self.driver.common._stats['pools'] = [ {'location_info': {'pool_id': 30}}] vol = self.driver.create_cloned_volume(TEST_VOLUME[0], TEST_VOLUME[1]) self.assertEqual('1', vol['provider_location']) + self.assertEqual(1, get_volume_type_extra_specs.call_count) self.assertEqual(5, request.call_count) @mock.patch.object(requests.Session, "request") - def test_create_volume_from_snapshot(self, request): + @mock.patch.object(volume_types, 'get_volume_type_extra_specs') + def test_create_volume_from_snapshot( + self, get_volume_type_extra_specs, request): request.side_effect = [FakeResponse(200, GET_LDEV_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), FakeResponse(200, GET_SNAPSHOTS_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT)] + get_volume_type_extra_specs.return_value = {} self.driver.common._stats = {} self.driver.common._stats['pools'] = [ {'location_info': {'pool_id': 30}}] vol = self.driver.create_volume_from_snapshot( TEST_VOLUME[0], TEST_SNAPSHOT[0]) self.assertEqual('1', vol['provider_location']) + self.assertEqual(1, get_volume_type_extra_specs.call_count) self.assertEqual(5, request.call_count) @mock.patch.object(requests.Session, "request") @@ -786,10 +880,9 @@ class HBSDRESTISCSIDriverTest(test.TestCase): @mock.patch.object(requests.Session, "request") def test_retype(self, request): - request.return_value = FakeResponse(200, GET_LDEV_RESULT) - new_specs = {'hbsd:test': 'test'} - new_type_ref = volume_types.create(self.ctxt, 'new', new_specs) - diff = {} + request.side_effect = [FakeResponse(200, GET_LDEV_RESULT), + FakeResponse(200, GET_LDEV_RESULT), + FakeResponse(202, COMPLETED_SUCCEEDED_RESULT)] host = { 'capabilities': { 'location_info': { @@ -797,9 +890,17 @@ class HBSDRESTISCSIDriverTest(test.TestCase): }, }, } + new_type = {'extra_specs': { + 'hbsd:capacity_saving': 'deduplication_compression'}} + old_specs = {'hbsd:capacity_saving': 'disable'} + new_specs = {'hbsd:capacity_saving': 'deduplication_compression'} + old_type_ref = volume_types.create(self.ctxt, 'old', old_specs) + new_type_ref = volume_types.create(self.ctxt, 'new', new_specs) + diff = volume_types.volume_types_diff(self.ctxt, old_type_ref['id'], + new_type_ref['id'])[0] ret = self.driver.retype( - self.ctxt, TEST_VOLUME[0], new_type_ref, diff, host) - self.assertEqual(1, request.call_count) + self.ctxt, TEST_VOLUME[0], new_type, diff, host) + self.assertEqual(3, request.call_count) self.assertTrue(ret) @mock.patch.object(requests.Session, "request") @@ -852,7 +953,10 @@ class HBSDRESTISCSIDriverTest(test.TestCase): self.assertTupleEqual(actual, ret) @mock.patch.object(requests.Session, "request") - def test_create_group_from_src_volume(self, request): + @mock.patch.object(volume_types, 'get_volume_type_extra_specs') + def test_create_group_from_src_volume( + self, get_volume_type_extra_specs, request): + get_volume_type_extra_specs.return_value = {} request.side_effect = [FakeResponse(200, GET_LDEV_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), @@ -865,13 +969,17 @@ class HBSDRESTISCSIDriverTest(test.TestCase): self.ctxt, TEST_GROUP[1], [TEST_VOLUME[1]], source_group=TEST_GROUP[0], source_vols=[TEST_VOLUME[0]] ) + self.assertEqual(1, get_volume_type_extra_specs.call_count) self.assertEqual(5, request.call_count) actual = ( None, [{'id': TEST_VOLUME[1]['id'], 'provider_location': '1'}]) self.assertTupleEqual(actual, ret) @mock.patch.object(requests.Session, "request") - def test_create_group_from_src_snapshot(self, request): + @mock.patch.object(volume_types, 'get_volume_type_extra_specs') + def test_create_group_from_src_snapshot( + self, get_volume_type_extra_specs, request): + get_volume_type_extra_specs.return_value = {} request.side_effect = [FakeResponse(200, GET_LDEV_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), @@ -884,6 +992,7 @@ class HBSDRESTISCSIDriverTest(test.TestCase): self.ctxt, TEST_GROUP[0], [TEST_VOLUME[0]], group_snapshot=TEST_GROUP_SNAP[0], snapshots=[TEST_SNAPSHOT[0]] ) + self.assertEqual(1, get_volume_type_extra_specs.call_count) self.assertEqual(5, request.call_count) actual = ( None, [{'id': TEST_VOLUME[0]['id'], 'provider_location': '1'}]) @@ -914,10 +1023,13 @@ class HBSDRESTISCSIDriverTest(test.TestCase): @mock.patch.object(requests.Session, "request") @mock.patch.object(sqlalchemy_api, 'volume_get', side_effect=_volume_get) + @mock.patch.object(volume_types, 'get_volume_type_extra_specs') @mock.patch.object(volume_utils, 'is_group_a_cg_snapshot_type') def test_create_group_snapshot_non_cg( - self, is_group_a_cg_snapshot_type, volume_get, request): + self, is_group_a_cg_snapshot_type, get_volume_type_extra_specs, + volume_get, request): is_group_a_cg_snapshot_type.return_value = False + get_volume_type_extra_specs.return_value = {} request.side_effect = [FakeResponse(200, GET_LDEV_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), @@ -928,6 +1040,7 @@ class HBSDRESTISCSIDriverTest(test.TestCase): ret = self.driver.create_group_snapshot( self.ctxt, TEST_GROUP_SNAP[0], [TEST_SNAPSHOT[0]] ) + self.assertEqual(1, get_volume_type_extra_specs.call_count) self.assertEqual(4, request.call_count) actual = ( {'status': 'available'}, @@ -939,10 +1052,13 @@ class HBSDRESTISCSIDriverTest(test.TestCase): @mock.patch.object(requests.Session, "request") @mock.patch.object(sqlalchemy_api, 'volume_get', side_effect=_volume_get) + @mock.patch.object(volume_types, 'get_volume_type_extra_specs') @mock.patch.object(volume_utils, 'is_group_a_cg_snapshot_type') def test_create_group_snapshot_cg( - self, is_group_a_cg_snapshot_type, volume_get, request): + self, is_group_a_cg_snapshot_type, get_volume_type_extra_specs, + volume_get, request): is_group_a_cg_snapshot_type.return_value = True + get_volume_type_extra_specs.return_value = {} request.side_effect = [FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT), FakeResponse(200, GET_SNAPSHOTS_RESULT_PAIR), @@ -954,6 +1070,7 @@ class HBSDRESTISCSIDriverTest(test.TestCase): ret = self.driver.create_group_snapshot( self.ctxt, TEST_GROUP_SNAP[0], [TEST_SNAPSHOT[0]] ) + self.assertEqual(1, get_volume_type_extra_specs.call_count) self.assertEqual(5, request.call_count) actual = ( None, @@ -974,10 +1091,14 @@ class HBSDRESTISCSIDriverTest(test.TestCase): FakeResponse(200, GET_LDEV_RESULT), FakeResponse(200, GET_LDEV_RESULT), FakeResponse(200, GET_LDEV_RESULT), + FakeResponse(200, GET_LDEV_RESULT), + FakeResponse(200, GET_LDEV_RESULT), + FakeResponse(200, GET_LDEV_RESULT), + FakeResponse(200, GET_LDEV_RESULT), FakeResponse(202, COMPLETED_SUCCEEDED_RESULT)] ret = self.driver.delete_group_snapshot( self.ctxt, TEST_GROUP_SNAP[0], [TEST_SNAPSHOT[0]]) - self.assertEqual(10, request.call_count) + self.assertEqual(14, request.call_count) actual = ( {'status': TEST_GROUP_SNAP[0]['status']}, [{'id': TEST_SNAPSHOT[0]['id'], 'status': 'deleted'}] @@ -989,5 +1110,14 @@ class HBSDRESTISCSIDriverTest(test.TestCase): _get_oslo_driver_opts.return_value = [] ret = self.driver.get_driver_options() actual = (hbsd_common.COMMON_VOLUME_OPTS + - hbsd_rest.REST_VOLUME_OPTS) + hbsd_common.COMMON_PAIR_OPTS + + hbsd_common.COMMON_NAME_OPTS + + hbsd_rest.REST_VOLUME_OPTS + + hbsd_rest.REST_PAIR_OPTS + + hbsd_replication._REP_OPTS + + hbsd_replication.COMMON_MIRROR_OPTS + + hbsd_replication.ISCSI_MIRROR_OPTS + + hbsd_replication.REST_MIRROR_OPTS + + hbsd_replication.REST_MIRROR_API_OPTS + + hbsd_replication.REST_MIRROR_SSL_OPTS) self.assertEqual(actual, ret) |