Skip to content

Commit

Permalink
Merge branch 'master' into fix_exporter_issue
Browse files Browse the repository at this point in the history
  • Loading branch information
NajmudheenCT authored Jun 18, 2021
2 parents 6a9bbba + ee87076 commit 28378d7
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 49 deletions.
101 changes: 64 additions & 37 deletions delfin/drivers/dell_emc/unity/unity.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def list_controllers(self, context):
if controller_info is not None:
pool_entries = controller_info.get('entries')
for pool in pool_entries:
content = pool.get('content', {})
content = pool.get('content')
if not content:
continue
health_value = content.get('health', {}).get('value')
if health_value in UnityStorDriver.HEALTH_OK:
status = constants.ControllerStatus.NORMAL
Expand Down Expand Up @@ -229,7 +231,9 @@ def get_eth_ports(self):
if ports is not None:
port_entries = ports.get('entries')
for port in port_entries:
content = port.get('content', {})
content = port.get('content')
if not content:
continue
health_value = content.get('health', {}).get('value')
if health_value in UnityStorDriver.HEALTH_OK:
status = constants.PortHealthStatus.NORMAL
Expand All @@ -243,7 +247,9 @@ def get_eth_ports(self):
ipv6 = None
ipv6_mask = None
for ip_info in ip_interfaces.get('entries'):
ip_content = ip_info.get('content', {})
ip_content = ip_info.get('content')
if not ip_content:
continue
if content.get('id') == ip_content.get(
'ipPort').get('id'):
if ip_content.get('ipProtocolVersion') == 4:
Expand All @@ -267,7 +273,7 @@ def get_eth_ports(self):
'logical_type': '',
'max_speed': int(content.get('speed')) * units.Mi,
'native_parent_id':
content.get('storageProcessor').get('id'),
content.get('storageProcessor', {}).get('id'),
'wwn': '',
'mac_address': content.get('macAddress'),
'ipv4': ipv4,
Expand All @@ -284,7 +290,9 @@ def get_fc_ports(self):
if ports is not None:
port_entries = ports.get('entries')
for port in port_entries:
content = port.get('content', {})
content = port.get('content')
if not content:
continue
health_value = content.get('health', {}).get('value')
if health_value in UnityStorDriver.HEALTH_OK:
status = constants.PortHealthStatus.NORMAL
Expand All @@ -302,7 +310,7 @@ def get_fc_ports(self):
'logical_type': '',
'max_speed': int(content.get('currentSpeed')) * units.Gi,
'native_parent_id':
content.get('storageProcessor').get('id'),
content.get('storageProcessor', {}).get('id'),
'wwn': content.get('wwn')
}
port_list.append(port_result)
Expand All @@ -326,7 +334,9 @@ def list_disks(self, context):
if disks is not None:
disk_entries = disks.get('entries')
for disk in disk_entries:
content = disk.get('content', {})
content = disk.get('content')
if not content:
continue
health_value = content.get('health', {}).get('value')
if health_value in UnityStorDriver.HEALTH_OK:
status = constants.DiskStatus.NORMAL
Expand All @@ -346,7 +356,7 @@ def list_disks(self, context):
'physical_type': constants.DiskPhysicalType.SAS,
'logical_type': '',
'native_disk_group_id':
content.get('diskGroup').get('id'),
content.get('diskGroup', {}).get('id'),
'location': content.get('slotNumber')
}
disk_list.append(disk_result)
Expand All @@ -364,7 +374,9 @@ def list_filesystems(self, context):
if files is not None:
fs_entries = files.get('entries')
for file in fs_entries:
content = file.get('content', {})
content = file.get('content')
if not content:
continue
health_value = content.get('health', {}).get('value')
if health_value in UnityStorDriver.HEALTH_OK:
status = constants.FilesystemStatus.NORMAL
Expand All @@ -385,7 +397,7 @@ def list_filesystems(self, context):
'name': content.get('name'),
'storage_id': self.storage_id,
'native_filesystem_id': content.get('id'),
'native_pool_id': content.get('pool').get('id'),
'native_pool_id': content.get('pool', {}).get('id'),
'status': status,
'type': fs_type,
'total_capacity': int(content.get('sizeTotal')),
Expand All @@ -409,16 +421,16 @@ def list_qtrees(self, context):
if qts is not None:
qts_entries = qts.get('entries')
for qtree in qts_entries:
content = qtree.get('content', {})
path = '/%s%s' % (content.get('filesystem').get('id'),
content.get('path'))
content = qtree.get('content')
if not content:
continue
qt = {
'name': content.get('path'),
'storage_id': self.storage_id,
'native_qtree_id': content.get('id'),
'native_filesystem_id':
content.get('filesystem').get('id'),
'path': path
content.get('filesystem', {}).get('id'),
'path': content.get('path')
}
qt_list.append(qt)
return qt_list
Expand All @@ -427,7 +439,19 @@ def list_qtrees(self, context):
% (six.text_type(err))
raise exception.InvalidResults(err_msg)

def get_share(self, protocol):
def get_share_qtree(self, path, qtree_list):
qtree_id = None
qts_entries = qtree_list.get('entries')
for qtree in qts_entries:
content = qtree.get('content')
if not content:
continue
if content.get('path') == path:
qtree_id = content.get('id')
break
return qtree_id

def get_share(self, protocol, qtree_list):
try:
share_list = []
if protocol == 'cifs':
Expand All @@ -437,26 +461,20 @@ def get_share(self, protocol):
shares = self.rest_handler.get_all_nfsshares()
protocol = constants.ShareProtocol.NFS
if shares is not None:
filesystems = self.rest_handler.get_all_filesystems()
share_entries = shares.get('entries')
for share in share_entries:
content = share.get('content', {})
file_entries = filesystems.get('entries')
file_name = ''
for file in file_entries:
file_content = file.get('content', {})
if file_content.get('id') == content.get(
'filesystem', {}).get('id'):
file_name = file_content.get('name')
break
path = '/%s%s' % (file_name, content.get('path'))
content = share.get('content')
if not content:
continue
fs = {
'name': content.get('name'),
'storage_id': self.storage_id,
'native_share_id': content.get('id'),
'native_qtree_id': self.get_share_qtree(
content.get('path'), qtree_list),
'native_filesystem_id':
content.get('filesystem').get('id'),
'path': path,
content.get('filesystem', {}).get('id'),
'path': content.get('path'),
'protocol': protocol
}
share_list.append(fs)
Expand All @@ -469,8 +487,9 @@ def get_share(self, protocol):
def list_shares(self, context):
try:
share_list = []
share_list.extend(self.get_share('cifs'))
share_list.extend(self.get_share('nfs'))
qtrees = self.rest_handler.get_all_qtrees()
share_list.extend(self.get_share('cifs', qtrees))
share_list.extend(self.get_share('nfs', qtrees))
return share_list
except Exception as err:
err_msg = "Failed to get shares metrics from Unity: %s"\
Expand All @@ -491,9 +510,13 @@ def get_tree_quotas(self):
file_hard_limit = 0
file_soft_limit = 0
limit_type = 'block'
content = quota.get('content', {})
content = quota.get('content')
if not content:
continue
for conf in conf_entries:
conf_content = conf.get('content', {})
conf_content = conf.get('content')
if not conf_content:
continue
if conf_content.get('id') == content.get(
'quotaConfig').get('id'):
if int(conf_content.get('quotaPolicy')) == 0:
Expand All @@ -510,7 +533,7 @@ def get_tree_quotas(self):
"type": constants.QuotaType.TREE,
"storage_id": self.storage_id,
"native_filesystem_id":
content.get('filesystem').get('id'),
content.get('filesystem', {}).get('id'),
"native_qtree_id": content.get('id'),
"capacity_hard_limit": capacity_hard_limit,
"capacity_soft_limit": capacity_soft_limit,
Expand All @@ -535,10 +558,14 @@ def get_user_quotas(self):
file_hard_limit = 0
file_soft_limit = 0
limit_type = 'block'
content = user_quota.get('content', {})
content = user_quota.get('content')
if not content:
continue
if content.get('treeQuota'):
for conf in conf_entries:
conf_content = conf.get('content', {})
conf_content = conf.get('content')
if not conf_content:
continue
if conf_content.get('treeQuota').get('id')\
== content.get('treeQuota').get('id'):
if int(conf_content.get('quotaPolicy')) == 0:
Expand All @@ -555,7 +582,7 @@ def get_user_quotas(self):
"type": constants.QuotaType.USER,
"storage_id": self.storage_id,
"native_filesystem_id":
content.get('filesystem').get('id'),
content.get('filesystem', {}).get('id'),
"native_qtree_id": content.get('id'),
"capacity_hard_limit": capacity_hard_limit,
"capacity_soft_limit": capacity_soft_limit,
Expand Down
30 changes: 18 additions & 12 deletions delfin/tests/unit/drivers/dell_emc/unity/test_emc_unity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@
'storage_id': '12345',
'native_qtree_id': 'qtree_1',
'native_filesystem_id': 'filesystem_1',
'path': '/filesystem_1/'
'path': '/'
}
]
GET_ALL_CIFSSHARE = {
Expand Down Expand Up @@ -1179,50 +1179,57 @@
'name': 'fs1',
'storage_id': '12345',
'native_share_id': 'SMBShare_2',
'native_qtree_id': 'qtree_1',
'native_filesystem_id': 'fs_1',
'path': '/fs1/',
'path': '/',
'protocol': 'cifs'
}, {
'name': 'boga',
'storage_id': '12345',
'native_share_id': 'SMBShare_14',
'native_qtree_id': 'qtree_1',
'native_filesystem_id': 'fs_16',
'path': '/fs_boga/',
'path': '/',
'protocol': 'cifs'
}, {
'name': 'fs2',
'storage_id': '12345',
'native_share_id': 'SMBShare_18',
'native_qtree_id': 'qtree_1',
'native_filesystem_id': 'fs_20',
'path': '/fs2/',
'path': '/',
'protocol': 'cifs'
}, {
'name': 'fs1',
'storage_id': '12345',
'native_share_id': 'NFSShare_2',
'native_qtree_id': 'qtree_1',
'native_filesystem_id': 'fs_1',
'path': '/fs1/',
'path': '/',
'protocol': 'nfs'
}, {
'name': 'boga',
'storage_id': '12345',
'native_share_id': 'NFSShare_14',
'native_qtree_id': 'qtree_1',
'native_filesystem_id': 'fs_16',
'path': '/fs_boga/',
'path': '/',
'protocol': 'nfs'
}, {
'name': 'fs2',
'storage_id': '12345',
'native_share_id': 'NFSShare_18',
'native_qtree_id': 'qtree_1',
'native_filesystem_id': 'fs_20',
'path': '/fs2/',
'path': '/',
'protocol': 'nfs'
}, {
'name': 'FS_MULTI1',
'storage_id': '12345',
'native_share_id': 'NFSShare_19',
'native_qtree_id': 'qtree_1',
'native_filesystem_id': 'fs_22',
'path': '/FS_MULTI1/',
'path': '/',
'protocol': 'nfs'
}
]
Expand Down Expand Up @@ -1440,13 +1447,12 @@ def test_list_qtrees(self, mock_qtree):

@mock.patch.object(RestHandler, 'get_all_nfsshares')
@mock.patch.object(RestHandler, 'get_all_cifsshares')
@mock.patch.object(RestHandler, 'get_all_filesystems')
def test_list_shares(self, mock_file, mock_cifs, mock_nfs):
@mock.patch.object(RestHandler, 'get_all_qtrees')
def test_list_shares(self, mock_qtree, mock_cifs, mock_nfs):
RestHandler.login = mock.Mock(return_value=None)
mock_cifs.return_value = GET_ALL_CIFSSHARE
mock_file.return_value = GET_ALL_FILESYSTEMS
mock_qtree.return_value = GET_ALL_QTREE
mock_nfs.return_value = GET_ALL_NFSSHARE
mock_file.return_value = GET_ALL_FILESYSTEMS
share = UnityStorDriver(**ACCESS_INFO).list_shares(context)
self.assertEqual(share, share_result)

Expand Down

0 comments on commit 28378d7

Please sign in to comment.