From fedc39b6a82335a20374bfcac8f5b7056a31b8a6 Mon Sep 17 00:00:00 2001 From: Joseph Vazhappilly Date: Thu, 6 Jan 2022 16:04:43 +0530 Subject: [PATCH] Remove native_port_id from masking view model --- delfin/api/v1/masking_views.py | 1 - delfin/db/sqlalchemy/models.py | 1 - delfin/drivers/driver.py | 4 +- delfin/drivers/fake_storage/__init__.py | 3 - delfin/task_manager/tasks/resources.py | 90 ++----------------- delfin/tests/unit/fake_data.py | 2 - .../tests/unit/task_manager/test_resources.py | 53 ++++++++--- 7 files changed, 51 insertions(+), 103 deletions(-) diff --git a/delfin/api/v1/masking_views.py b/delfin/api/v1/masking_views.py index d57526503..624cac953 100644 --- a/delfin/api/v1/masking_views.py +++ b/delfin/api/v1/masking_views.py @@ -28,7 +28,6 @@ def __init__(self): 'native_storage_volume_group_id', 'native_storage_host_id', 'native_volume_id', - 'native_port_id', 'native_masking_view_id'] def _get_masking_view_search_options(self): diff --git a/delfin/db/sqlalchemy/models.py b/delfin/db/sqlalchemy/models.py index 1af242f4c..815f5c5d1 100644 --- a/delfin/db/sqlalchemy/models.py +++ b/delfin/db/sqlalchemy/models.py @@ -361,7 +361,6 @@ class MaskingView(BASE, DelfinBase): native_port_group_id = Column(String(255)) native_storage_host_id = Column(String(255)) native_volume_id = Column(String(255)) - native_port_id = Column(String(255)) native_masking_view_id = Column(String(255)) diff --git a/delfin/drivers/driver.py b/delfin/drivers/driver.py index 8ed771175..8df9ea381 100644 --- a/delfin/drivers/driver.py +++ b/delfin/drivers/driver.py @@ -277,7 +277,6 @@ def list_masking_views(self, context): native_volume_group_id: Native id of volume grp at backend side native_storage_host_id: Native id of host at backend side native_volume_id: Native id of volume at backend side - native_port_id: Native id of port at backend side storage_id: Storage id at delfin side Masking view filling guidelines: @@ -293,8 +292,7 @@ def list_masking_views(self, context): | native_storage_host_id) From volume side: Mandatorily one of the (native_volume_group_id | native_volume_id) - From port side: Optionally One of the (native_port_group_id - | native_port_id) + From port side: Optionally (native_port_group_id) """ raise NotImplementedError( "Driver API list_masking_views() is not Implemented") diff --git a/delfin/drivers/fake_storage/__init__.py b/delfin/drivers/fake_storage/__init__.py index 248a57893..d94ba77ee 100644 --- a/delfin/drivers/fake_storage/__init__.py +++ b/delfin/drivers/fake_storage/__init__.py @@ -1081,7 +1081,6 @@ def list_masking_views(self, ctx): native_port_group_id = "port_group_" + str(idx) native_storage_host_id = "" native_volume_id = "" - native_port_id = "" else: native_storage_host_group_id = "" @@ -1089,7 +1088,6 @@ def list_masking_views(self, ctx): native_port_group_id = "" native_storage_host_id = "storage_host_" + str(idx) native_volume_id = "volume_" + str(idx) - native_port_id = "port_" + str(idx) f = { "name": "masking_view_" + str(idx), @@ -1101,7 +1099,6 @@ def list_masking_views(self, ctx): "native_port_group_id": native_port_group_id, "native_storage_host_id": native_storage_host_id, "native_volume_id": native_volume_id, - "native_port_id": native_port_id } masking_view_list.append(f) return masking_view_list diff --git a/delfin/task_manager/tasks/resources.py b/delfin/task_manager/tasks/resources.py index bbf693351..725efe104 100644 --- a/delfin/task_manager/tasks/resources.py +++ b/delfin/task_manager/tasks/resources.py @@ -19,9 +19,6 @@ from delfin import coordination from delfin import db -from delfin.db.sqlalchemy.models import StorageHostGrpHostRel -from delfin.db.sqlalchemy.models import VolGrpVolRel -from delfin.db.sqlalchemy.models import PortGrpPortRel from delfin import exception from delfin.common import constants from delfin.drivers import api as driverapi @@ -84,77 +81,6 @@ def _check_deleted(func, *args, **kwargs): return _check_deleted -def _build_storage_host_group_relations(ctx, storage_id, - storage_host_groups): - """ Builds storage host group to host relations.""" - db.storage_host_grp_host_rels_delete_by_storage(ctx, - storage_id) - storage_host_grp_relation_list = [] - for storage_host_group in storage_host_groups: - storage_hosts = storage_host_group.pop('storage_hosts', None) - if not storage_hosts: - continue - storage_hosts = storage_hosts.split(',') - - for storage_host in storage_hosts: - storage_host_group_relation = { - StorageHostGrpHostRel.storage_id.name: storage_id, - StorageHostGrpHostRel.native_storage_host_group_id.name: - storage_host_group['native_storage_host_group_id'], - StorageHostGrpHostRel.native_storage_host_id.name: - storage_host - } - storage_host_grp_relation_list \ - .append(storage_host_group_relation) - - db.storage_host_grp_host_rels_create( - ctx, storage_host_grp_relation_list) - - -def _build_volume_group_relations(ctx, storage_id, volume_groups): - """ Builds volume group to volume relations.""" - db.vol_grp_vol_rels_delete_by_storage(ctx, storage_id) - volume_group_relation_list = [] - for volume_group in volume_groups: - volumes = volume_group.pop('volumes', None) - if not volumes: - continue - volumes = volumes.split(',') - - for volume in volumes: - volume_group_relation = { - VolGrpVolRel.storage_id.name: storage_id, - VolGrpVolRel.native_volume_group_id.name: - volume_group['native_volume_group_id'], - VolGrpVolRel.native_volume_id.name: volume} - volume_group_relation_list.append(volume_group_relation) - - db.vol_grp_vol_rels_create(ctx, volume_group_relation_list) - - -def _build_port_group_relations(ctx, storage_id, port_groups): - """ Builds resource group to resource relations.""" - db.port_grp_port_rels_delete_by_storage(ctx, storage_id) - - port_group_relation_list = [] - for port_group in port_groups: - ports = port_group.pop('ports', None) - if not ports: - continue - ports = ports.split(',') - - for port in ports: - port_group_relation = { - PortGrpPortRel.storage_id.name: storage_id, - PortGrpPortRel.native_port_group_id .name: - port_group['native_port_group_id'], - PortGrpPortRel.native_port_id.name: port - } - port_group_relation_list.append(port_group_relation) - - db.port_grp_port_rels_create(ctx, port_group_relation_list) - - class StorageResourceTask(object): NATIVE_RESOURCE_ID = None @@ -618,13 +544,13 @@ def sync(self): try: # Collect the storage host group list from driver and database. # Build relation between host grp and host to be handled here. - storage_host_group_obj = self.driver_api \ + storage_hg_obj = self.driver_api \ .list_storage_host_groups(self.context, self.storage_id) - storage_host_groups = storage_host_group_obj['storage_host_groups'] - storage_host_rels = storage_host_group_obj['storage_host_grp_host_rels'] + storage_host_groups = storage_hg_obj['storage_host_groups'] + storage_host_rels = storage_hg_obj['storage_host_grp_host_rels'] if storage_host_groups: - db.storage_host_grp_host_rels_delete_by_storage(self.context, - self.storage_id) + db.storage_host_grp_host_rels_delete_by_storage( + self.context, self.storage_id) db.storage_host_grp_host_rels_create( self.context, storage_host_rels) LOG.info('Building host group relations successful for ' @@ -691,8 +617,10 @@ def sync(self): port_groups = port_groups_obj['port_groups'] port_group_relation_list = port_groups_obj['port_grp_port_rels'] if port_groups: - db.port_grp_port_rels_delete_by_storage(self.context, self.storage_id) - db.port_grp_port_rels_create(self.context, port_group_relation_list) + db.port_grp_port_rels_delete_by_storage( + self.context, self.storage_id) + db.port_grp_port_rels_create( + self.context, port_group_relation_list) LOG.info('Building port group relations successful for ' 'storage id:{0}'.format(self.storage_id)) diff --git a/delfin/tests/unit/fake_data.py b/delfin/tests/unit/fake_data.py index 92d22fe67..643bbd275 100644 --- a/delfin/tests/unit/fake_data.py +++ b/delfin/tests/unit/fake_data.py @@ -266,7 +266,6 @@ def fake_masking_view_create(): 'updated_at': '2020-06-10T07:17:08.707356', 'native_storage_host_id': 'storage_host_1', 'native_volume_id': 'volume_1', - 'native_port_id': 'port_1', 'native_masking_view_id': 'masking_view_1', } return fake_masking_views @@ -282,7 +281,6 @@ def fake_expected_masking_views_create(): "storage_id": '12c2d52f-01bc-41f5-b73f-7abf6f38a2a6', "native_storage_host_id": "storage_host_1", "native_volume_id": "volume_1", - "native_port_id": "port_1", "native_storage_host_group_id": None, "native_port_group_id": None, "native_volume_group_id": None, diff --git a/delfin/tests/unit/task_manager/test_resources.py b/delfin/tests/unit/task_manager/test_resources.py index dd39bc9ef..ca8fea81c 100644 --- a/delfin/tests/unit/task_manager/test_resources.py +++ b/delfin/tests/unit/task_manager/test_resources.py @@ -203,7 +203,7 @@ } ] -storage_host_groups_list = [{ +storage_hg_list = [{ "id": "4e62c66a-39ef-43f2-9690-e936ca876574", "name": "storage_host_group_" + str(id), "description": "storage_host_group_" + str(id), @@ -212,7 +212,16 @@ } ] -port_groups_list = [{ +storage_host_groups_list = { + 'storage_host_groups': storage_hg_list, + 'storage_host_grp_host_rels': '' +} +empty_shgs_list = { + 'storage_host_groups': list(), + 'storage_host_grp_host_rels': '' +} + +pg_list = [{ "id": "4e62c66a-39ef-43f2-9690-e936ca876574", "name": "port_group_" + str(id), "description": "port_group_" + str(id), @@ -221,7 +230,17 @@ } ] -volume_groups_list = [{ +port_groups_list = { + "port_groups": pg_list, + "port_grp_port_rels": '', +} + +empty_port_groups_list = { + "port_groups": list(), + "port_grp_port_rels": '', +} + +vg_list = [{ "id": "4e62c66a-39ef-43f2-9690-e936ca876574", "name": "volume_group_" + str(id), "description": "volume_group_" + str(id), @@ -230,6 +249,16 @@ } ] +volume_groups_list = { + 'volume_groups': vg_list, + 'vol_grp_vol_rels': '' +} + +empty_volume_groups_list = { + 'volume_groups': list(), + 'vol_grp_vol_rels': '' +} + masking_views_list = [{ "id": "4e62c66a-39ef-43f2-9690-e936ca876574", "name": "masking_view_" + str(id), @@ -855,14 +884,14 @@ def test_sync_successful(self, mock_storage_host_group_create, mock_list_storage_host_groups.return_value \ = storage_host_groups_list mock_storage_host_groups_get_all.return_value \ - = storage_host_groups_list + = storage_hg_list storage_host_group_obj.sync() self.assertTrue(mock_storage_host_group_update.called) # Delete the storage host groups to DB - mock_list_storage_host_groups.return_value = list() + mock_list_storage_host_groups.return_value = empty_shgs_list mock_storage_host_groups_get_all.return_value \ - = storage_host_groups_list + = storage_hg_list storage_host_group_obj.sync() self.assertTrue(mock_storage_host_group_del.called) @@ -907,14 +936,14 @@ def test_sync_successful(self, mock_volume_group_create, mock_list_volume_groups.return_value \ = volume_groups_list mock_volume_groups_get_all.return_value \ - = volume_groups_list + = vg_list volume_group_obj.sync() self.assertTrue(mock_volume_group_update.called) # Delete the volume groups to DB - mock_list_volume_groups.return_value = list() + mock_list_volume_groups.return_value = empty_volume_groups_list mock_volume_groups_get_all.return_value \ - = volume_groups_list + = vg_list volume_group_obj.sync() self.assertTrue(mock_volume_group_del.called) @@ -960,14 +989,14 @@ def test_sync_successful(self, mock_port_group_create, mock_list_port_groups.return_value \ = port_groups_list mock_port_groups_get_all.return_value \ - = port_groups_list + = pg_list port_group_obj.sync() self.assertTrue(mock_port_group_update.called) # Delete the storage host groups to DB - mock_list_port_groups.return_value = list() + mock_list_port_groups.return_value = empty_port_groups_list mock_port_groups_get_all.return_value \ - = port_groups_list + = pg_list port_group_obj.sync() self.assertTrue(mock_port_group_del.called)