def _create_host(self, port_id, host_type): """Creates host on system with given initiator as port_id.""" LOG.info(_LI("Creating host with port %s."), port_id) label = utils.convert_uuid_to_es_fmt(uuid.uuid4()) port_label = utils.convert_uuid_to_es_fmt(uuid.uuid4()) host_type = self._get_host_type_definition(host_type) return self._client.create_host_with_port(label, host_type, port_id, port_label)
def _get_snapshot_group_for_snapshot(self, snapshot_id): label = utils.convert_uuid_to_es_fmt(snapshot_id) for group in self._client.list_snapshot_groups(): if group['label'] == label: return group msg = _("Specified snapshot group with label %s could not be found.") raise exception.NotFound(msg % label)
def _get_snapshot_group_for_snapshot(self, snapshot_id): label = utils.convert_uuid_to_es_fmt(snapshot_id) for group in self._client.list_snapshot_groups(): if group["label"] == label: return group msg = _("Specified snapshot group with label %s could not be found.") raise exception.NotFound(msg % label)
def _get_latest_volume(self, uid): label = utils.convert_uuid_to_es_fmt(uid) for vol in self._client.list_volumes(): if vol.get('label') == label: self._cache_volume(vol) return self._get_cached_volume(label) raise exception.NetAppDriverException(_("Volume %s not found."), uid)
def _create_host(self, port_ids, host_type, host_group=None): """Creates host on system with given initiator as port_id.""" LOG.info(_LI("Creating host with ports %s."), port_ids) host_label = utils.convert_uuid_to_es_fmt(uuid.uuid4()) host_type = self._get_host_type_definition(host_type) port_type = self.driver_protocol.lower() return self._client.create_host_with_ports( host_label, host_type, port_ids, group_id=host_group, port_type=port_type )
def _create_snapshot_volume(self, snapshot_id): """Creates snapshot volume for given group with snapshot_id.""" group = self._get_snapshot_group_for_snapshot(snapshot_id) LOG.debug("Creating snap vol for group %s", group["label"]) image = self._get_latest_image_in_snapshot_group(snapshot_id) label = utils.convert_uuid_to_es_fmt(uuid.uuid4()) capacity = int(image["pitCapacity"]) / units.Gi storage_pools = self._get_sorted_available_storage_pools(capacity) s_id = storage_pools[0]["volumeGroupRef"] return self._client.create_snapshot_volume(image["pitRef"], label, group["baseVolume"], s_id)
def create_host_with_ports(self, label, host_type, port_ids, port_type="iscsi", group_id=None): """Creates host on array with given port information.""" if port_type == "fc": port_ids = [six.text_type(wwpn).replace(":", "") for wwpn in port_ids] ports = [] for port_id in port_ids: port_label = utils.convert_uuid_to_es_fmt(uuid.uuid4()) port = {"type": port_type, "port": port_id, "label": port_label} ports.append(port) return self.create_host(label, host_type, ports, group_id)
def _create_snapshot_volume(self, snapshot_id): """Creates snapshot volume for given group with snapshot_id.""" group = self._get_cached_snapshot_grp(snapshot_id) LOG.debug("Creating snap vol for group %s", group['label']) image = self._get_cached_snap_grp_image(snapshot_id) label = utils.convert_uuid_to_es_fmt(uuid.uuid4()) capacity = int(image['pitCapacity']) / units.Gi storage_pools = self._get_sorted_avl_storage_pools(capacity) s_id = storage_pools[0]['volumeGroupRef'] return self._client.create_snapshot_volume(image['pitRef'], label, group['baseVolume'], s_id)
def _create_host(self, port_ids, host_type, host_group=None): """Creates host on system with given initiator as port_id.""" LOG.info(_LI("Creating host with ports %s."), port_ids) host_label = utils.convert_uuid_to_es_fmt(uuid.uuid4()) host_type = self._get_host_type_definition(host_type) port_type = self.driver_protocol.lower() return self._client.create_host_with_ports(host_label, host_type, port_ids, group_id=host_group, port_type=port_type)
def create_host_with_ports(self, label, host_type, port_ids, port_type='iscsi', group_id=None): """Creates host on array with given port information.""" if port_type == 'fc': port_ids = [six.text_type(wwpn).replace(':', '') for wwpn in port_ids] ports = [] for port_id in port_ids: port_label = utils.convert_uuid_to_es_fmt(uuid.uuid4()) port = {'type': port_type, 'port': port_id, 'label': port_label} ports.append(port) return self.create_host(label, host_type, ports, group_id)
def manage_existing(self, volume, existing_ref): """Brings an existing storage object under Cinder management.""" vol = self._get_existing_vol_with_manage_ref(volume, existing_ref) label = utils.convert_uuid_to_es_fmt(volume["id"]) if label == vol["label"]: LOG.info(_LI("Volume with given ref %s need not be renamed during" " manage operation."), existing_ref) managed_vol = vol else: managed_vol = self._client.update_volume(vol["id"], label) LOG.info( _LI("Manage operation completed for volume with new label" " %(label)s and wwn %(wwn)s."), {"label": label, "wwn": managed_vol[self.WORLDWIDENAME]}, )
def manage_existing(self, volume, existing_ref): """Brings an existing storage object under Cinder management.""" vol = self._get_existing_vol_with_manage_ref(volume, existing_ref) label = utils.convert_uuid_to_es_fmt(volume['id']) if label == vol['label']: LOG.info(_LI("Volume with given ref %s need not be renamed during" " manage operation."), existing_ref) managed_vol = vol else: managed_vol = self._client.update_volume(vol['id'], label) LOG.info(_LI("Manage operation completed for volume with new label" " %(label)s and wwn %(wwn)s."), {'label': label, 'wwn': managed_vol[self.WORLDWIDENAME]})
def create_snapshot(self, snapshot): """Creates a snapshot.""" snap_grp, snap_image = None, None snapshot_name = utils.convert_uuid_to_es_fmt(snapshot["id"]) os_vol = snapshot["volume"] vol = self._get_volume(os_vol["name_id"]) vol_size_gb = int(vol["totalSizeInBytes"]) / units.Gi pools = self._get_sorted_available_storage_pools(vol_size_gb) try: snap_grp = self._client.create_snapshot_group(snapshot_name, vol["volumeRef"], pools[0]["volumeGroupRef"]) snap_image = self._client.create_snapshot_image(snap_grp["pitGroupRef"]) LOG.info(_LI("Created snap grp with label %s."), snapshot_name) except exception.NetAppDriverException: with excutils.save_and_reraise_exception(): if snap_image is None and snap_grp: self.delete_snapshot(snapshot)
def create_volume(self, volume): """Creates a volume.""" LOG.debug("create_volume on %s", volume["host"]) # get E-series pool label as pool name eseries_pool_label = volume_utils.extract_host(volume["host"], level="pool") if eseries_pool_label is None: msg = _("Pool is not available in the volume host field.") raise exception.InvalidHost(reason=msg) eseries_volume_label = utils.convert_uuid_to_es_fmt(volume["name_id"]) # get size of the requested volume creation size_gb = int(volume["size"]) self._create_volume(eseries_pool_label, eseries_volume_label, size_gb)
def create_snapshot(self, snapshot): """Creates a snapshot.""" snap_grp, snap_image = None, None snapshot_name = utils.convert_uuid_to_es_fmt(snapshot['id']) os_vol = snapshot['volume'] vol = self._get_volume(os_vol['name_id']) vol_size_gb = int(vol['totalSizeInBytes']) / units.Gi pools = self._get_sorted_available_storage_pools(vol_size_gb) try: snap_grp = self._client.create_snapshot_group( snapshot_name, vol['volumeRef'], pools[0]['volumeGroupRef']) snap_image = self._client.create_snapshot_image( snap_grp['pitGroupRef']) LOG.info(_LI("Created snap grp with label %s."), snapshot_name) except exception.NetAppDriverException: with excutils.save_and_reraise_exception(): if snap_image is None and snap_grp: self.delete_snapshot(snapshot)
def create_volume(self, volume): """Creates a volume.""" LOG.debug('create_volume on %s', volume['host']) # get E-series pool label as pool name eseries_pool_label = volume_utils.extract_host(volume['host'], level='pool') if eseries_pool_label is None: msg = _("Pool is not available in the volume host field.") raise exception.InvalidHost(reason=msg) eseries_volume_label = utils.convert_uuid_to_es_fmt(volume['name_id']) # get size of the requested volume creation size_gb = int(volume['size']) self._create_volume(eseries_pool_label, eseries_volume_label, size_gb)
def create_volume(self, volume): """Creates a volume.""" LOG.debug('create_volume on %s' % volume['host']) # get E-series pool label as pool name eseries_pool_label = volume_utils.extract_host(volume['host'], level='pool') if eseries_pool_label is None: msg = _("Pool is not available in the volume host field.") raise exception.InvalidHost(reason=msg) eseries_volume_label = utils.convert_uuid_to_es_fmt(volume['id']) # get size of the requested volume creation size_gb = int(volume['size']) vol = self._create_volume(eseries_pool_label, eseries_volume_label, size_gb) self._cache_volume(vol)
def create_volume_from_snapshot(self, volume, snapshot): """Creates a volume from a snapshot.""" label = utils.convert_uuid_to_es_fmt(volume['id']) size = volume['size'] dst_vol = self._schedule_and_create_volume(label, size) try: src_vol = None src_vol = self._create_snapshot_volume(snapshot['id']) self._copy_volume_high_prior_readonly(src_vol, dst_vol) LOG.info(_LI("Created volume with label %s."), label) except exception.NetAppDriverException: with excutils.save_and_reraise_exception(): self._client.delete_volume(dst_vol['volumeRef']) finally: if src_vol: try: self._client.delete_snapshot_volume(src_vol['id']) except exception.NetAppDriverException as e: LOG.error(_LE("Failure deleting snap vol. Error: %s."), e) else: LOG.warning(_LW("Snapshot volume not found."))
def create_volume_from_snapshot(self, volume, snapshot): """Creates a volume from a snapshot.""" label = utils.convert_uuid_to_es_fmt(volume["id"]) size = volume["size"] dst_vol = self._schedule_and_create_volume(label, size) try: src_vol = None src_vol = self._create_snapshot_volume(snapshot["id"]) self._copy_volume_high_prior_readonly(src_vol, dst_vol) LOG.info(_LI("Created volume with label %s."), label) except exception.NetAppDriverException: with excutils.save_and_reraise_exception(): self._client.delete_volume(dst_vol["volumeRef"]) finally: if src_vol: try: self._client.delete_snapshot_volume(src_vol["id"]) except exception.NetAppDriverException as e: LOG.error(_LE("Failure deleting snap vol. Error: %s."), e) else: LOG.warning(_LW("Snapshot volume not found."))
def extend_volume(self, volume, new_size): """Extend an existing volume to the new size.""" stage_1, stage_2 = 0, 0 src_vol = self._get_volume(volume["name_id"]) src_label = src_vol["label"] stage_label = "tmp-%s" % utils.convert_uuid_to_es_fmt(uuid.uuid4()) extend_vol = {"id": uuid.uuid4(), "size": new_size} self.create_cloned_volume(extend_vol, volume) new_vol = self._get_volume(extend_vol["id"]) try: stage_1 = self._client.update_volume(src_vol["id"], stage_label) stage_2 = self._client.update_volume(new_vol["id"], src_label) new_vol = stage_2 LOG.info(_LI("Extended volume with label %s."), src_label) except exception.NetAppDriverException: if stage_1 == 0: with excutils.save_and_reraise_exception(): self._client.delete_volume(new_vol["id"]) if stage_2 == 0: with excutils.save_and_reraise_exception(): self._client.update_volume(src_vol["id"], src_label) self._client.delete_volume(new_vol["id"])
def extend_volume(self, volume, new_size): """Extend an existing volume to the new size.""" stage_1, stage_2 = 0, 0 src_vol = self._get_volume(volume['name_id']) src_label = src_vol['label'] stage_label = 'tmp-%s' % utils.convert_uuid_to_es_fmt(uuid.uuid4()) extend_vol = {'id': uuid.uuid4(), 'size': new_size} self.create_cloned_volume(extend_vol, volume) new_vol = self._get_volume(extend_vol['id']) try: stage_1 = self._client.update_volume(src_vol['id'], stage_label) stage_2 = self._client.update_volume(new_vol['id'], src_label) new_vol = stage_2 LOG.info(_LI('Extended volume with label %s.'), src_label) except exception.NetAppDriverException: if stage_1 == 0: with excutils.save_and_reraise_exception(): self._client.delete_volume(new_vol['id']) if stage_2 == 0: with excutils.save_and_reraise_exception(): self._client.update_volume(src_vol['id'], src_label) self._client.delete_volume(new_vol['id'])
def extend_volume(self, volume, new_size): """Extend an existing volume to the new size.""" stage_1, stage_2 = 0, 0 src_vol = self._get_volume(volume['name_id']) src_label = src_vol['label'] stage_label = 'tmp-%s' % utils.convert_uuid_to_es_fmt(uuid.uuid4()) extend_vol = {'id': uuid.uuid4(), 'size': new_size} self.create_cloned_volume(extend_vol, volume) new_vol = self._get_volume(extend_vol['id']) try: stage_1 = self._client.update_volume(src_vol['id'], stage_label) stage_2 = self._client.update_volume(new_vol['id'], src_label) new_vol = stage_2 self._cache_volume(new_vol) self._cache_volume(stage_1) LOG.info(_LI('Extended volume with label %s.'), src_label) except exception.NetAppDriverException: if stage_1 == 0: with excutils.save_and_reraise_exception(): self._client.delete_volume(new_vol['id']) if stage_2 == 0: with excutils.save_and_reraise_exception(): self._client.update_volume(src_vol['id'], src_label) self._client.delete_volume(new_vol['id'])
def test_convert_uuid_to_es_fmt(self): value = 'e67e931a-b2ed-4890-938b-3acc6a517fac' result = utils.convert_uuid_to_es_fmt(value) self.assertEqual('4Z7JGGVS5VEJBE4LHLGGUUL7VQ', result)
def _get_cached_snapshot_grp(self, uid): label = utils.convert_uuid_to_es_fmt(uid) snap_id = self._objects['snapshots']['label_ref'][label] return self._objects['snapshots']['ref_snap'][snap_id]
class NetAppEseriesISCSIDriverTestCase(test.TestCase): """Test case for NetApp e-series iscsi driver.""" volume = { 'id': '114774fb-e15a-4fae-8ee2-c9723e3645ef', 'size': 1, 'volume_name': 'lun1', 'host': 'hostname@backend#DDP', 'os_type': 'linux', 'provider_location': 'lun1', 'id': '114774fb-e15a-4fae-8ee2-c9723e3645ef', 'provider_auth': 'provider a b', 'project_id': 'project', 'display_name': None, 'display_description': 'lun1', 'volume_type_id': None } snapshot = { 'id': '17928122-553b-4da9-9737-e5c3dcd97f75', 'volume_id': '114774fb-e15a-4fae-8ee2-c9723e3645ef', 'size': 2, 'volume_name': 'lun1', 'volume_size': 2, 'project_id': 'project', 'display_name': None, 'display_description': 'lun1', 'volume_type_id': None } volume_sec = { 'id': 'b6c01641-8955-4917-a5e3-077147478575', 'size': 2, 'volume_name': 'lun1', 'os_type': 'linux', 'provider_location': 'lun1', 'id': 'b6c01641-8955-4917-a5e3-077147478575', 'provider_auth': None, 'project_id': 'project', 'display_name': None, 'display_description': 'lun1', 'volume_type_id': None } volume_clone = { 'id': 'b4b24b27-c716-4647-b66d-8b93ead770a5', 'size': 3, 'volume_name': 'lun1', 'os_type': 'linux', 'provider_location': 'cl_sm', 'id': 'b4b24b27-c716-4647-b66d-8b93ead770a5', 'provider_auth': None, 'project_id': 'project', 'display_name': None, 'display_description': 'lun1', 'volume_type_id': None } volume_clone_large = { 'id': 'f6ef5bf5-e24f-4cbb-b4c4-11d631d6e553', 'size': 6, 'volume_name': 'lun1', 'os_type': 'linux', 'provider_location': 'cl_lg', 'id': 'f6ef5bf5-e24f-4cbb-b4c4-11d631d6e553', 'provider_auth': None, 'project_id': 'project', 'display_name': None, 'display_description': 'lun1', 'volume_type_id': None } fake_eseries_volume_label = utils.convert_uuid_to_es_fmt(volume['id']) connector = {'initiator': 'iqn.1998-01.com.vmware:localhost-28a58148'} fake_size_gb = volume['size'] fake_eseries_pool_label = 'DDP' def setUp(self): super(NetAppEseriesISCSIDriverTestCase, self).setUp() self._custom_setup() def _custom_setup(self): configuration = self._set_config(create_configuration()) self.driver = common.NetAppDriver(configuration=configuration) self.mock_object(requests, 'Session', FakeEseriesHTTPSession) self.driver.do_setup(context='context') self.driver.check_for_setup_error() def _set_config(self, configuration): configuration.netapp_storage_family = 'eseries' configuration.netapp_storage_protocol = 'iscsi' configuration.netapp_transport_type = 'http' configuration.netapp_server_hostname = '127.0.0.1' configuration.netapp_server_port = None configuration.netapp_webservice_path = '/devmgr/vn' configuration.netapp_controller_ips = '127.0.0.2,127.0.0.3' configuration.netapp_sa_password = '******' configuration.netapp_login = '******' configuration.netapp_password = '******' configuration.netapp_storage_pools = 'DDP' return configuration def test_embedded_mode(self): configuration = self._set_config(create_configuration()) configuration.netapp_controller_ips = '127.0.0.1,127.0.0.3' driver = common.NetAppDriver(configuration=configuration) driver.do_setup(context='context') self.assertEqual(driver._client.get_system_id(), '1fa6efb5-f07b-4de4-9f0e-52e5f7ff5d1b') def test_check_system_pwd_not_sync(self): def list_system(): if getattr(self, 'test_count', None): self.test_count = 1 return {'status': 'passwordoutofsync'} return {'status': 'needsAttention'} self.driver._client.list_storage_system = mock.Mock(wraps=list_system) result = self.driver._check_storage_system() self.assertTrue(result) def test_connect(self): self.driver.check_for_setup_error() def test_create_destroy(self): self.driver.create_volume(self.volume) self.driver.delete_volume(self.volume) def test_create_vol_snapshot_destroy(self): self.driver.create_volume(self.volume) self.driver.create_snapshot(self.snapshot) self.driver.create_volume_from_snapshot(self.volume_sec, self.snapshot) self.driver.delete_snapshot(self.snapshot) self.driver.delete_volume(self.volume) def test_map_unmap(self): self.driver.create_volume(self.volume) connection_info = self.driver.initialize_connection( self.volume, self.connector) self.assertEqual(connection_info['driver_volume_type'], 'iscsi') properties = connection_info.get('data') self.assertIsNotNone(properties, 'Target portal is none') self.driver.terminate_connection(self.volume, self.connector) self.driver.delete_volume(self.volume) def test_map_already_mapped_same_host(self): self.driver.create_volume(self.volume) maps = [{ 'lunMappingRef': 'hdkjsdhjsdh', 'mapRef': '8400000060080E500023C73400300381515BFBA3', 'volumeRef': '0200000060080E500023BB34000003FB515C2293', 'lun': 2 }] self.driver._get_host_mapping_for_vol_frm_array = mock.Mock( return_value=maps) self.driver._get_free_lun = mock.Mock() info = self.driver.initialize_connection(self.volume, self.connector) self.assertEqual( self.driver._get_host_mapping_for_vol_frm_array.call_count, 1) self.assertEqual(self.driver._get_free_lun.call_count, 0) self.assertEqual(info['driver_volume_type'], 'iscsi') properties = info.get('data') self.assertIsNotNone(properties, 'Target portal is none') self.driver.terminate_connection(self.volume, self.connector) self.driver.delete_volume(self.volume) def test_map_already_mapped_diff_host(self): self.driver.create_volume(self.volume) maps = [{ 'lunMappingRef': 'hdkjsdhjsdh', 'mapRef': '7400000060080E500023C73400300381515BFBA3', 'volumeRef': 'CFDXJ67BLJH25DXCZFZD4NSF54', 'lun': 2 }] self.driver._get_host_mapping_for_vol_frm_array = mock.Mock( return_value=maps) self.driver._get_vol_mapping_for_host_frm_array = mock.Mock( return_value=[]) self.driver._get_free_lun = mock.Mock(return_value=0) self.driver._del_vol_mapping_frm_cache = mock.Mock() info = self.driver.initialize_connection(self.volume, self.connector) self.assertEqual( self.driver._get_vol_mapping_for_host_frm_array.call_count, 1) self.assertEqual( self.driver._get_host_mapping_for_vol_frm_array.call_count, 1) self.assertEqual(self.driver._get_free_lun.call_count, 1) self.assertEqual(self.driver._del_vol_mapping_frm_cache.call_count, 1) self.assertEqual(info['driver_volume_type'], 'iscsi') properties = info.get('data') self.assertIsNotNone(properties, 'Target portal is none') self.driver.terminate_connection(self.volume, self.connector) self.driver.delete_volume(self.volume) def test_cloned_volume_destroy(self): self.driver.create_volume(self.volume) self.driver.create_cloned_volume(self.snapshot, self.volume) self.driver.delete_volume(self.volume) def test_map_by_creating_host(self): self.driver.create_volume(self.volume) connector_new = {'initiator': 'iqn.1993-08.org.debian:01:1001'} connection_info = self.driver.initialize_connection( self.volume, connector_new) self.assertEqual(connection_info['driver_volume_type'], 'iscsi') properties = connection_info.get('data') self.assertIsNotNone(properties, 'Target portal is none') def test_vol_stats(self): self.driver.get_volume_stats(refresh=True) def test_create_vol_snapshot_diff_size_resize(self): self.driver.create_volume(self.volume) self.driver.create_snapshot(self.snapshot) self.driver.create_volume_from_snapshot(self.volume_clone, self.snapshot) self.driver.delete_snapshot(self.snapshot) self.driver.delete_volume(self.volume) def test_create_vol_snapshot_diff_size_subclone(self): self.driver.create_volume(self.volume) self.driver.create_snapshot(self.snapshot) self.driver.create_volume_from_snapshot(self.volume_clone_large, self.snapshot) self.driver.delete_snapshot(self.snapshot) self.driver.delete_volume(self.volume) @mock.patch.object(iscsi.NetAppEseriesISCSIDriver, '_get_volume', mock.Mock(return_value={'volumeGroupRef': 'fake_ref'})) def test_get_pool(self): self.driver._objects['pools'] = [{ 'volumeGroupRef': 'fake_ref', 'label': 'ddp1' }] pool = self.driver.get_pool({'id': 'fake-uuid'}) self.assertEqual(pool, 'ddp1') @mock.patch.object(iscsi.NetAppEseriesISCSIDriver, '_get_volume', mock.Mock(return_value={'volumeGroupRef': 'fake_ref'})) def test_get_pool_no_pools(self): self.driver._objects['pools'] = [] pool = self.driver.get_pool({'id': 'fake-uuid'}) self.assertEqual(pool, None) @mock.patch.object(iscsi.NetAppEseriesISCSIDriver, '_get_volume', mock.Mock(return_value={'volumeGroupRef': 'fake_ref'})) def test_get_pool_no_match(self): self.driver._objects['pools'] = [{ 'volumeGroupRef': 'fake_ref2', 'label': 'ddp2' }] pool = self.driver.get_pool({'id': 'fake-uuid'}) self.assertEqual(pool, None) @mock.patch.object(iscsi.NetAppEseriesISCSIDriver, '_create_volume', mock.Mock()) def test_create_volume(self): self.driver.create_volume(self.volume) self.driver._create_volume.assert_called_with( 'DDP', self.fake_eseries_volume_label, self.volume['size']) def test_create_volume_no_pool_provided_by_scheduler(self): volume = copy.deepcopy(self.volume) volume['host'] = "host@backend" # missing pool self.assertRaises(exception.InvalidHost, self.driver.create_volume, volume) @mock.patch.object(client.RestClient, 'list_storage_pools') def test_helper_create_volume_fail(self, fake_list_pools): fake_pool = {} fake_pool['label'] = self.fake_eseries_pool_label fake_pool['volumeGroupRef'] = 'foo' fake_pools = [fake_pool] fake_list_pools.return_value = fake_pools wrong_eseries_pool_label = 'hostname@backend' self.assertRaises(exception.NetAppDriverException, self.driver._create_volume, wrong_eseries_pool_label, self.fake_eseries_volume_label, self.fake_size_gb) @mock.patch.object(driver_log, 'info') @mock.patch.object(client.RestClient, 'list_storage_pools') @mock.patch.object(client.RestClient, 'create_volume', mock.MagicMock(return_value='CorrectVolume')) def test_helper_create_volume(self, storage_pools, log_info): fake_pool = {} fake_pool['label'] = self.fake_eseries_pool_label fake_pool['volumeGroupRef'] = 'foo' fake_pools = [fake_pool] storage_pools.return_value = fake_pools drv = self.driver storage_vol = drv.driver._create_volume(self.fake_eseries_pool_label, self.fake_eseries_volume_label, self.fake_size_gb) log_info.assert_called_once_with("Created volume with label %s.", self.fake_eseries_volume_label) self.assertEqual('CorrectVolume', storage_vol) @mock.patch.object(client.RestClient, 'list_storage_pools') @mock.patch.object( client.RestClient, 'create_volume', mock.MagicMock(side_effect=exception.NetAppDriverException)) @mock.patch.object(driver_log, 'info', mock.Mock()) def test_create_volume_check_exception(self, fake_list_pools): fake_pool = {} fake_pool['label'] = self.fake_eseries_pool_label fake_pool['volumeGroupRef'] = 'foo' fake_pools = [fake_pool] fake_list_pools.return_value = fake_pools self.assertRaises(exception.NetAppDriverException, self.driver._create_volume, self.fake_eseries_pool_label, self.fake_eseries_volume_label, self.fake_size_gb) def test_portal_for_vol_controller(self): volume = {'id': 'vol_id', 'currentManager': 'ctrl1'} vol_nomatch = {'id': 'vol_id', 'currentManager': 'ctrl3'} portals = [{ 'controller': 'ctrl2', 'iqn': 'iqn2' }, { 'controller': 'ctrl1', 'iqn': 'iqn1' }] portal = self.driver._get_iscsi_portal_for_vol(volume, portals) self.assertEqual(portal, {'controller': 'ctrl1', 'iqn': 'iqn1'}) portal = self.driver._get_iscsi_portal_for_vol(vol_nomatch, portals) self.assertEqual(portal, {'controller': 'ctrl2', 'iqn': 'iqn2'}) def test_portal_for_vol_any_false(self): vol_nomatch = {'id': 'vol_id', 'currentManager': 'ctrl3'} portals = [{ 'controller': 'ctrl2', 'iqn': 'iqn2' }, { 'controller': 'ctrl1', 'iqn': 'iqn1' }] self.assertRaises(exception.NetAppDriverException, self.driver._get_iscsi_portal_for_vol, vol_nomatch, portals, False) def test_get_host_right_type(self): self.driver._get_host_with_port = mock.Mock(return_value={ 'hostTypeIndex': 2, 'name': 'test' }) self.driver._get_host_type_definition = mock.Mock(return_value={ 'index': 2, 'name': 'LnxALUA' }) host = self.driver._get_or_create_host('port', 'LinuxALUA') self.assertEqual(host, {'hostTypeIndex': 2, 'name': 'test'}) self.driver._get_host_with_port.assert_called_once_with('port') self.driver._get_host_type_definition.assert_called_once_with( 'LinuxALUA') def test_get_host_update_type(self): self.driver._get_host_with_port = mock.Mock(return_value={ 'hostTypeIndex': 2, 'hostRef': 'test' }) self.driver._get_host_type_definition = mock.Mock(return_value={ 'index': 3, 'name': 'LnxALUA' }) self.driver._client.update_host_type = mock.Mock(return_value={ 'hostTypeIndex': 3, 'hostRef': 'test' }) host = self.driver._get_or_create_host('port', 'LinuxALUA') self.assertEqual(host, {'hostTypeIndex': 3, 'hostRef': 'test'}) self.driver._get_host_with_port.assert_called_once_with('port') self.driver._get_host_type_definition.assert_called_once_with( 'LinuxALUA') self.assertEqual(self.driver._client.update_host_type.call_count, 1) def test_get_host_update_type_failed(self): self.driver._get_host_with_port = mock.Mock(return_value={ 'hostTypeIndex': 2, 'hostRef': 'test', 'label': 'test' }) self.driver._get_host_type_definition = mock.Mock(return_value={ 'index': 3, 'name': 'LnxALUA' }) self.driver._client.update_host_type = mock.Mock( side_effect=exception.NetAppDriverException) host = self.driver._get_or_create_host('port', 'LinuxALUA') self.assertEqual(host, { 'hostTypeIndex': 2, 'hostRef': 'test', 'label': 'test' }) self.driver._get_host_with_port.assert_called_once_with('port') self.driver._get_host_type_definition.assert_called_once_with( 'LinuxALUA') self.assertEqual(self.driver._client.update_host_type.call_count, 1) def test_get_host_not_found(self): self.driver._get_host_with_port = mock.Mock( side_effect=exception.NotFound) self.driver._create_host = mock.Mock() self.driver._get_or_create_host('port', 'LnxALUA') self.driver._get_host_with_port.assert_called_once_with('port') self.driver._create_host.assert_called_once_with('port', 'LnxALUA') def test_setup_error_unsupported_host_type(self): configuration = self._set_config(create_configuration()) configuration.netapp_eseries_host_type = 'garbage' driver = common.NetAppDriver(configuration=configuration) self.assertRaises(exception.NetAppDriverException, driver.check_for_setup_error) def test_do_setup_all_default(self): configuration = self._set_config(create_configuration()) driver = common.NetAppDriver(configuration=configuration) driver._check_mode_get_or_register_storage_system = mock.Mock() driver.do_setup(context='context') url = urlparse.urlparse(driver._client._endpoint) port = url.port scheme = url.scheme self.assertEqual(8080, port) self.assertEqual('http', scheme) def test_do_setup_http_default_port(self): configuration = self._set_config(create_configuration()) configuration.netapp_transport_type = 'http' driver = common.NetAppDriver(configuration=configuration) driver._check_mode_get_or_register_storage_system = mock.Mock() driver.do_setup(context='context') url = urlparse.urlparse(driver._client._endpoint) port = url.port scheme = url.scheme self.assertEqual(8080, port) self.assertEqual('http', scheme) def test_do_setup_https_default_port(self): configuration = self._set_config(create_configuration()) configuration.netapp_transport_type = 'https' driver = common.NetAppDriver(configuration=configuration) driver._check_mode_get_or_register_storage_system = mock.Mock() driver.do_setup(context='context') url = urlparse.urlparse(driver._client._endpoint) port = url.port scheme = url.scheme self.assertEqual(8443, port) self.assertEqual('https', scheme) def test_do_setup_http_non_default_port(self): configuration = self._set_config(create_configuration()) configuration.netapp_server_port = 81 driver = common.NetAppDriver(configuration=configuration) driver._check_mode_get_or_register_storage_system = mock.Mock() driver.do_setup(context='context') url = urlparse.urlparse(driver._client._endpoint) port = url.port scheme = url.scheme self.assertEqual(81, port) self.assertEqual('http', scheme) def test_do_setup_https_non_default_port(self): configuration = self._set_config(create_configuration()) configuration.netapp_transport_type = 'https' configuration.netapp_server_port = 446 driver = common.NetAppDriver(configuration=configuration) driver._check_mode_get_or_register_storage_system = mock.Mock() driver.do_setup(context='context') url = urlparse.urlparse(driver._client._endpoint) port = url.port scheme = url.scheme self.assertEqual(446, port) self.assertEqual('https', scheme)
def _get_volume(self, uid): label = utils.convert_uuid_to_es_fmt(uid) try: return self._get_cached_volume(label) except KeyError: return self._get_latest_volume(uid)
class NetAppESeriesDriverTestCase(object): """Test case for NetApp e-series iscsi driver.""" volume = {'id': '114774fb-e15a-4fae-8ee2-c9723e3645ef', 'size': 1, 'volume_name': 'lun1', 'host': 'hostname@backend#DDP', 'os_type': 'linux', 'provider_location': 'lun1', 'name_id': '114774fb-e15a-4fae-8ee2-c9723e3645ef', 'provider_auth': 'provider a b', 'project_id': 'project', 'display_name': None, 'display_description': 'lun1', 'volume_type_id': None} snapshot = {'id': '17928122-553b-4da9-9737-e5c3dcd97f75', 'volume_id': '114774fb-e15a-4fae-8ee2-c9723e3645ef', 'size': 2, 'volume_name': 'lun1', 'volume_size': 2, 'project_id': 'project', 'display_name': None, 'display_description': 'lun1', 'volume_type_id': None} volume_sec = {'id': 'b6c01641-8955-4917-a5e3-077147478575', 'size': 2, 'volume_name': 'lun1', 'os_type': 'linux', 'provider_location': 'lun1', 'name_id': 'b6c01641-8955-4917-a5e3-077147478575', 'provider_auth': None, 'project_id': 'project', 'display_name': None, 'display_description': 'lun1', 'volume_type_id': None} volume_clone = {'id': 'b4b24b27-c716-4647-b66d-8b93ead770a5', 'size': 3, 'volume_name': 'lun1', 'os_type': 'linux', 'provider_location': 'cl_sm', 'name_id': 'b4b24b27-c716-4647-b66d-8b93ead770a5', 'provider_auth': None, 'project_id': 'project', 'display_name': None, 'display_description': 'lun1', 'volume_type_id': None} volume_clone_large = {'id': 'f6ef5bf5-e24f-4cbb-b4c4-11d631d6e553', 'size': 6, 'volume_name': 'lun1', 'os_type': 'linux', 'provider_location': 'cl_lg', 'name_id': 'f6ef5bf5-e24f-4cbb-b4c4-11d631d6e553', 'provider_auth': None, 'project_id': 'project', 'display_name': None, 'display_description': 'lun1', 'volume_type_id': None} fake_eseries_volume_label = utils.convert_uuid_to_es_fmt(volume['id']) fake_size_gb = volume['size'] fake_eseries_pool_label = 'DDP' fake_ref = {'source-name': 'CFDGJSLS'} fake_ret_vol = {'id': 'vol_id', 'label': 'label', 'worldWideName': 'wwn', 'capacity': '2147583648'} PROTOCOL = 'iscsi' def setUp(self): super(NetAppESeriesDriverTestCase, self).setUp() self._custom_setup() def _custom_setup(self): self.mock_object(na_utils, 'OpenStackInfo') configuration = self._set_config(self.create_configuration()) self.driver = common.NetAppDriver(configuration=configuration) self.library = self.driver.library self.mock_object(self.library, '_check_mode_get_or_register_storage_system') self.mock_object(self.driver.library, '_check_storage_system') self.driver.do_setup(context='context') self.driver.library._client._endpoint = fakes.FAKE_ENDPOINT_HTTP def _set_config(self, configuration): configuration.netapp_storage_family = 'eseries' configuration.netapp_storage_protocol = self.PROTOCOL configuration.netapp_transport_type = 'http' configuration.netapp_server_hostname = '127.0.0.1' configuration.netapp_server_port = None configuration.netapp_webservice_path = '/devmgr/vn' configuration.netapp_controller_ips = '127.0.0.2,127.0.0.3' configuration.netapp_sa_password = '******' configuration.netapp_login = '******' configuration.netapp_password = '******' configuration.netapp_storage_pools = 'DDP' configuration.netapp_enable_multiattach = False return configuration @staticmethod def create_configuration(): configuration = conf.Configuration(None) configuration.append_config_values(options.netapp_basicauth_opts) configuration.append_config_values(options.netapp_eseries_opts) configuration.append_config_values(options.netapp_san_opts) return configuration @abc.abstractmethod @mock.patch.object(na_utils, 'validate_instantiation') def test_instantiation(self, mock_validate_instantiation): pass def test_embedded_mode(self): self.mock_object(self.driver.library, '_check_mode_get_or_register_storage_system') self.mock_object(client.RestClient, '_init_features') configuration = self._set_config(self.create_configuration()) configuration.netapp_controller_ips = '127.0.0.1,127.0.0.3' driver = common.NetAppDriver(configuration=configuration) self.mock_object(client.RestClient, 'list_storage_systems', mock.Mock( return_value=[fakes.STORAGE_SYSTEM])) driver.do_setup(context='context') self.assertEqual('1fa6efb5-f07b-4de4-9f0e-52e5f7ff5d1b', driver.library._client.get_system_id()) def test_check_system_pwd_not_sync(self): def list_system(): if getattr(self, 'test_count', None): self.test_count = 1 return {'status': 'passwordoutofsync'} return {'status': 'needsAttention'} self.library._client.list_storage_system = mock.Mock(wraps=list_system) result = self.library._check_storage_system() self.assertTrue(result) def test_create_destroy(self): self.mock_object(client.RestClient, 'delete_volume', mock.Mock(return_value='None')) self.mock_object(self.driver.library, 'create_volume', mock.Mock(return_value=self.volume)) self.mock_object(self.library._client, 'list_volume', mock.Mock( return_value=fakes.VOLUME)) self.driver.create_volume(self.volume) self.driver.delete_volume(self.volume) def test_vol_stats(self): self.driver.get_volume_stats(refresh=False) def test_get_pool(self): self.mock_object(self.library, '_get_volume', mock.Mock(return_value={ 'volumeGroupRef': 'fake_ref'})) self.mock_object(self.library._client, "get_storage_pool", mock.Mock(return_value={'volumeGroupRef': 'fake_ref', 'label': 'ddp1'})) pool = self.driver.get_pool({'name_id': 'fake-uuid'}) self.assertEqual('ddp1', pool) def test_get_pool_no_pools(self): self.mock_object(self.library, '_get_volume', mock.Mock(return_value={ 'volumeGroupRef': 'fake_ref'})) self.mock_object(self.library._client, "get_storage_pool", mock.Mock(return_value=None)) pool = self.driver.get_pool({'name_id': 'fake-uuid'}) self.assertIsNone(pool) @mock.patch.object(library.NetAppESeriesLibrary, '_create_volume', mock.Mock()) def test_create_volume(self): self.driver.create_volume(self.volume) self.library._create_volume.assert_called_with( 'DDP', self.fake_eseries_volume_label, self.volume['size'], {}) def test_create_volume_no_pool_provided_by_scheduler(self): volume = copy.deepcopy(self.volume) volume['host'] = "host@backend" # missing pool self.assertRaises(exception.InvalidHost, self.driver.create_volume, volume) @mock.patch.object(client.RestClient, 'list_storage_pools') def test_helper_create_volume_fail(self, fake_list_pools): fake_pool = {} fake_pool['label'] = self.fake_eseries_pool_label fake_pool['volumeGroupRef'] = 'foo' fake_pool['raidLevel'] = 'raidDiskPool' fake_pools = [fake_pool] fake_list_pools.return_value = fake_pools wrong_eseries_pool_label = 'hostname@backend' self.assertRaises(exception.NetAppDriverException, self.library._create_volume, wrong_eseries_pool_label, self.fake_eseries_volume_label, self.fake_size_gb) @mock.patch.object(library.LOG, 'info') @mock.patch.object(client.RestClient, 'list_storage_pools') @mock.patch.object(client.RestClient, 'create_volume', mock.MagicMock(return_value='CorrectVolume')) def test_helper_create_volume(self, storage_pools, log_info): fake_pool = {} fake_pool['label'] = self.fake_eseries_pool_label fake_pool['volumeGroupRef'] = 'foo' fake_pool['raidLevel'] = 'raidDiskPool' fake_pools = [fake_pool] storage_pools.return_value = fake_pools storage_vol = self.library._create_volume( self.fake_eseries_pool_label, self.fake_eseries_volume_label, self.fake_size_gb) log_info.assert_called_once_with("Created volume with label %s.", self.fake_eseries_volume_label) self.assertEqual('CorrectVolume', storage_vol) @mock.patch.object(client.RestClient, 'list_storage_pools') @mock.patch.object(client.RestClient, 'create_volume', mock.MagicMock( side_effect=exception.NetAppDriverException)) @mock.patch.object(library.LOG, 'info', mock.Mock()) def test_create_volume_check_exception(self, fake_list_pools): fake_pool = {} fake_pool['label'] = self.fake_eseries_pool_label fake_pool['volumeGroupRef'] = 'foo' fake_pool['raidLevel'] = 'raidDiskPool' fake_pools = [fake_pool] fake_list_pools.return_value = fake_pools self.assertRaises(exception.NetAppDriverException, self.library._create_volume, self.fake_eseries_pool_label, self.fake_eseries_volume_label, self.fake_size_gb) def test_portal_for_vol_controller(self): volume = {'id': 'vol_id', 'currentManager': 'ctrl1'} vol_nomatch = {'id': 'vol_id', 'currentManager': 'ctrl3'} portals = [{'controller': 'ctrl2', 'iqn': 'iqn2'}, {'controller': 'ctrl1', 'iqn': 'iqn1'}] portal = self.library._get_iscsi_portal_for_vol(volume, portals) self.assertEqual({'controller': 'ctrl1', 'iqn': 'iqn1'}, portal) portal = self.library._get_iscsi_portal_for_vol(vol_nomatch, portals) self.assertEqual({'controller': 'ctrl2', 'iqn': 'iqn2'}, portal) def test_portal_for_vol_any_false(self): vol_nomatch = {'id': 'vol_id', 'currentManager': 'ctrl3'} portals = [{'controller': 'ctrl2', 'iqn': 'iqn2'}, {'controller': 'ctrl1', 'iqn': 'iqn1'}] self.assertRaises(exception.NetAppDriverException, self.library._get_iscsi_portal_for_vol, vol_nomatch, portals, False) def test_setup_error_unsupported_host_type(self): configuration = self._set_config(self.create_configuration()) configuration.netapp_host_type = 'garbage' driver = common.NetAppDriver(configuration=configuration) self.assertRaises(exception.NetAppDriverException, driver.library.check_for_setup_error) def test_check_host_type_default(self): configuration = self._set_config(self.create_configuration()) driver = common.NetAppDriver(configuration=configuration) driver.library._check_host_type() self.assertEqual('LnxALUA', driver.library.host_type) def test_do_setup_all_default(self): configuration = self._set_config(self.create_configuration()) driver = common.NetAppDriver(configuration=configuration) driver.library._check_mode_get_or_register_storage_system = mock.Mock() mock_invoke = self.mock_object(client, 'RestClient') driver.do_setup(context='context') mock_invoke.assert_called_with(**fakes.FAKE_CLIENT_PARAMS) def test_do_setup_http_default_port(self): configuration = self._set_config(self.create_configuration()) configuration.netapp_transport_type = 'http' driver = common.NetAppDriver(configuration=configuration) driver.library._check_mode_get_or_register_storage_system = mock.Mock() mock_invoke = self.mock_object(client, 'RestClient') driver.do_setup(context='context') mock_invoke.assert_called_with(**fakes.FAKE_CLIENT_PARAMS) def test_do_setup_https_default_port(self): configuration = self._set_config(self.create_configuration()) configuration.netapp_transport_type = 'https' driver = common.NetAppDriver(configuration=configuration) driver.library._check_mode_get_or_register_storage_system = mock.Mock() mock_invoke = self.mock_object(client, 'RestClient') driver.do_setup(context='context') FAKE_EXPECTED_PARAMS = dict(fakes.FAKE_CLIENT_PARAMS, port=8443, scheme='https') mock_invoke.assert_called_with(**FAKE_EXPECTED_PARAMS) def test_do_setup_http_non_default_port(self): configuration = self._set_config(self.create_configuration()) configuration.netapp_server_port = 81 driver = common.NetAppDriver(configuration=configuration) driver.library._check_mode_get_or_register_storage_system = mock.Mock() mock_invoke = self.mock_object(client, 'RestClient') driver.do_setup(context='context') FAKE_EXPECTED_PARAMS = dict(fakes.FAKE_CLIENT_PARAMS, port=81) mock_invoke.assert_called_with(**FAKE_EXPECTED_PARAMS) def test_do_setup_https_non_default_port(self): configuration = self._set_config(self.create_configuration()) configuration.netapp_transport_type = 'https' configuration.netapp_server_port = 446 driver = common.NetAppDriver(configuration=configuration) driver.library._check_mode_get_or_register_storage_system = mock.Mock() mock_invoke = self.mock_object(client, 'RestClient') driver.do_setup(context='context') FAKE_EXPECTED_PARAMS = dict(fakes.FAKE_CLIENT_PARAMS, port=446, scheme='https') mock_invoke.assert_called_with(**FAKE_EXPECTED_PARAMS) def test_setup_good_controller_ip(self): configuration = self._set_config(self.create_configuration()) configuration.netapp_controller_ips = '127.0.0.1' driver = common.NetAppDriver(configuration=configuration) driver.library._check_mode_get_or_register_storage_system def test_setup_good_controller_ips(self): configuration = self._set_config(self.create_configuration()) configuration.netapp_controller_ips = '127.0.0.2,127.0.0.1' driver = common.NetAppDriver(configuration=configuration) driver.library._check_mode_get_or_register_storage_system def test_setup_missing_controller_ip(self): configuration = self._set_config(self.create_configuration()) configuration.netapp_controller_ips = None driver = common.NetAppDriver(configuration=configuration) self.assertRaises(exception.InvalidInput, driver.do_setup, context='context') def test_setup_error_invalid_controller_ip(self): configuration = self._set_config(self.create_configuration()) configuration.netapp_controller_ips = '987.65.43.21' driver = common.NetAppDriver(configuration=configuration) self.mock_object(na_utils, 'resolve_hostname', mock.Mock(side_effect=socket.gaierror)) self.assertRaises( exception.NoValidHost, driver.library._check_mode_get_or_register_storage_system) def test_setup_error_invalid_first_controller_ip(self): configuration = self._set_config(self.create_configuration()) configuration.netapp_controller_ips = '987.65.43.21,127.0.0.1' driver = common.NetAppDriver(configuration=configuration) self.mock_object(na_utils, 'resolve_hostname', mock.Mock(side_effect=socket.gaierror)) self.assertRaises( exception.NoValidHost, driver.library._check_mode_get_or_register_storage_system) def test_setup_error_invalid_second_controller_ip(self): configuration = self._set_config(self.create_configuration()) configuration.netapp_controller_ips = '127.0.0.1,987.65.43.21' driver = common.NetAppDriver(configuration=configuration) self.mock_object(na_utils, 'resolve_hostname', mock.Mock(side_effect=socket.gaierror)) self.assertRaises( exception.NoValidHost, driver.library._check_mode_get_or_register_storage_system) def test_setup_error_invalid_both_controller_ips(self): configuration = self._set_config(self.create_configuration()) configuration.netapp_controller_ips = '564.124.1231.1,987.65.43.21' driver = common.NetAppDriver(configuration=configuration) self.mock_object(na_utils, 'resolve_hostname', mock.Mock(side_effect=socket.gaierror)) self.assertRaises( exception.NoValidHost, driver.library._check_mode_get_or_register_storage_system) def test_manage_existing_get_size(self): self.library._get_existing_vol_with_manage_ref = mock.Mock( return_value=self.fake_ret_vol) size = self.driver.manage_existing_get_size(self.volume, self.fake_ref) self.assertEqual(3, size) self.library._get_existing_vol_with_manage_ref.assert_called_once_with( self.fake_ref) def test_get_exist_vol_source_name_missing(self): self.library._client.list_volume = mock.Mock( side_effect=exception.InvalidInput) self.assertRaises(exception.ManageExistingInvalidReference, self.library._get_existing_vol_with_manage_ref, {'id': '1234'}) @ddt.data('source-id', 'source-name') def test_get_exist_vol_source_not_found(self, attr_name): def _get_volume(v_id): d = {'id': '1', 'name': 'volume1', 'worldWideName': '0'} if v_id in d: return d[v_id] else: raise exception.VolumeNotFound(message=v_id) self.library._client.list_volume = mock.Mock(wraps=_get_volume) self.assertRaises(exception.ManageExistingInvalidReference, self.library._get_existing_vol_with_manage_ref, {attr_name: 'name2'}) self.library._client.list_volume.assert_called_once_with( 'name2') def test_get_exist_vol_with_manage_ref(self): fake_ret_vol = {'id': 'right'} self.library._client.list_volume = mock.Mock(return_value=fake_ret_vol) actual_vol = self.library._get_existing_vol_with_manage_ref( {'source-name': 'name2'}) self.library._client.list_volume.assert_called_once_with('name2') self.assertEqual(fake_ret_vol, actual_vol) @mock.patch.object(utils, 'convert_uuid_to_es_fmt') def test_manage_existing_same_label(self, mock_convert_es_fmt): self.library._get_existing_vol_with_manage_ref = mock.Mock( return_value=self.fake_ret_vol) mock_convert_es_fmt.return_value = 'label' self.driver.manage_existing(self.volume, self.fake_ref) self.library._get_existing_vol_with_manage_ref.assert_called_once_with( self.fake_ref) mock_convert_es_fmt.assert_called_once_with( '114774fb-e15a-4fae-8ee2-c9723e3645ef') @mock.patch.object(utils, 'convert_uuid_to_es_fmt') def test_manage_existing_new(self, mock_convert_es_fmt): self.library._get_existing_vol_with_manage_ref = mock.Mock( return_value=self.fake_ret_vol) mock_convert_es_fmt.return_value = 'vol_label' self.library._client.update_volume = mock.Mock( return_value={'id': 'update', 'worldWideName': 'wwn'}) self.driver.manage_existing(self.volume, self.fake_ref) self.library._get_existing_vol_with_manage_ref.assert_called_once_with( self.fake_ref) mock_convert_es_fmt.assert_called_once_with( '114774fb-e15a-4fae-8ee2-c9723e3645ef') self.library._client.update_volume.assert_called_once_with( 'vol_id', 'vol_label') @mock.patch.object(library.LOG, 'info') def test_unmanage(self, log_info): self.library._get_volume = mock.Mock(return_value=self.fake_ret_vol) self.driver.unmanage(self.volume) self.library._get_volume.assert_called_once_with( '114774fb-e15a-4fae-8ee2-c9723e3645ef') self.assertEqual(1, log_info.call_count) @mock.patch.object(library.NetAppESeriesLibrary, 'ensure_export', mock.Mock()) def test_ensure_export(self): self.driver.ensure_export('context', self.fake_ret_vol) self.assertTrue(self.library.ensure_export.called) @mock.patch.object(library.NetAppESeriesLibrary, 'extend_volume', mock.Mock()) def test_extend_volume(self): capacity = 10 self.driver.extend_volume(self.fake_ret_vol, capacity) self.library.extend_volume.assert_called_with(self.fake_ret_vol, capacity)
def _get_volume(self, uid): label = utils.convert_uuid_to_es_fmt(uid) return self._get_volume_with_label_wwn(label)
def _get_cached_snapshot_grp(self, uid): label = utils.convert_uuid_to_es_fmt(uid) snap_id = self._objects["snapshots"]["label_ref"][label] return self._objects["snapshots"]["ref_snap"][snap_id]