Skip to content

Commit

Permalink
Remove native_port_id from masking view model
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-v committed Jan 10, 2022
1 parent 2eb0e9a commit fedc39b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 103 deletions.
1 change: 0 additions & 1 deletion delfin/api/v1/masking_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion delfin/db/sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down
4 changes: 1 addition & 3 deletions delfin/drivers/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand Down
3 changes: 0 additions & 3 deletions delfin/drivers/fake_storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,15 +1081,13 @@ 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 = ""
native_volume_group_id = ""
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),
Expand All @@ -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
90 changes: 9 additions & 81 deletions delfin/task_manager/tasks/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 '
Expand Down Expand Up @@ -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))

Expand Down
2 changes: 0 additions & 2 deletions delfin/tests/unit/fake_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down
53 changes: 41 additions & 12 deletions delfin/tests/unit/task_manager/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit fedc39b

Please sign in to comment.