Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notfound_fcps_are_not_counted_in_fcp_template_detail_api #817

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions zvmsdk/tests/unit/test_volumeop.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,12 +1395,14 @@ def test_get_fcp_templates_details(self, mock_sync, mock_raw, mock_get_zhypinfo,
template_sp_mapping = [('sp1', template_id_1), ('sp2', template_id_2)]
self.fcp_vol_mgr._insert_data_into_template_sp_mapping_table(template_sp_mapping)

# fcp_info_list_1 contains fcp with type: available
fcp_info_list_1 = [
# available
('1a00', '', 0, 0, 'c05076de3300a83c',
'c05076de33002641', '27', '02e4', 'free', '',
'')
]
# fcp_info_list_2 contains fcp with type: allocated, unallocated_but_active
fcp_info_list_2 = [
# allocated
('1b00', 'user2', 1, 1, 'c05076de3300c83c',
Expand All @@ -1413,6 +1415,7 @@ def test_get_fcp_templates_details(self, mock_sync, mock_raw, mock_get_zhypinfo,
('1b02', 'user2', 1, 1, 'c05076de3300d83c',
'c05076de33002641', '27', '02e4', 'active', '',
template_id_2)]
# fcp_info_list_3 contains fcp with type: allocated, unallocated_but_active
fcp_info_list_3 = [
# allocated
('1c00', 'user3', 1, 1, 'c05076de3300c83c',
Expand All @@ -1425,21 +1428,36 @@ def test_get_fcp_templates_details(self, mock_sync, mock_raw, mock_get_zhypinfo,
fcp_id_list_1 = [fcp_info[0] for fcp_info in fcp_info_list_1]
fcp_id_list_2 = [fcp_info[0] for fcp_info in fcp_info_list_2]
fcp_id_list_3 = [fcp_info[0] for fcp_info in fcp_info_list_3]
# insert fcps into fcp table
self.db_op.bulk_delete_from_fcp_table(fcp_id_list_1)
self._insert_data_into_fcp_table(fcp_info_list_1)
self.db_op.bulk_delete_from_fcp_table(fcp_id_list_2)
self._insert_data_into_fcp_table(fcp_info_list_2)
self.db_op.bulk_delete_from_fcp_table(fcp_id_list_3)
self._insert_data_into_fcp_table(fcp_info_list_3)
template_fcp = [('1a00', template_id_1, 0),
('1f00', template_id_1, 0),
('1x00', template_id_1, 1),
('1b00', template_id_2, 0),
('1b01', template_id_2, 1),
('1b02', template_id_2, 1),
('1c00', template_id_3, 0),
('1c02', template_id_3, 0)]
fcp_id_list_1.append('1x00')

template_fcp = [
# template_id_1,
# makeup notfound FCP devices:
# path0: 1f00
# path1: 0005, 0007, 0019, 001a, 001b
('1a00', template_id_1, 0),
('1f00', template_id_1, 0),
('0005', template_id_1, 1),
('0007', template_id_1, 1),
('0019', template_id_1, 1),
('001a', template_id_1, 1),
('001b', template_id_1, 1),
# template_id_2
('1b00', template_id_2, 0),
('1b01', template_id_2, 1),
('1b02', template_id_2, 1),
# template_id_3
('1c00', template_id_3, 0),
('1c02', template_id_3, 0)]
# makeup notfound FCP devices
# fcp_id_list_1.append('0007')
# # insert fcps into fcp template_fcp_mapping
self.db_op.bulk_delete_fcp_from_template(fcp_id_list_1, template_id_1)
self.db_op.bulk_delete_fcp_from_template(fcp_id_list_2, template_id_2)
self.db_op.bulk_delete_fcp_from_template(fcp_id_list_3, template_id_3)
Expand All @@ -1462,7 +1480,7 @@ def test_get_fcp_templates_details(self, mock_sync, mock_raw, mock_get_zhypinfo,
"statistics": {
0: {
"total": "1A00, 1F00",
"total_count": {'02E4': 1},
"total_count": {'02E4': 1, 'notfound': 1},
"single_fcp": "1A00, 1F00",
"range_fcp": "",
"available": "1A00",
Expand All @@ -1477,23 +1495,23 @@ def test_get_fcp_templates_details(self, mock_sync, mock_raw, mock_get_zhypinfo,
"chpids": {"27": "1A00"},
'pchids': {'02E4': '27'}},
1: {
"total": "1X00",
"total_count": {},
"single_fcp": "1X00",
"range_fcp": "",
"total": "0005, 0007, 0019 - 001B",
"total_count": {'notfound': 5},
"single_fcp": "0005, 0007",
"range_fcp": "0019 - 001B",
"available": "",
"available_count": {},
"allocated": "",
"reserve_only": "",
"connection_only": "",
"unallocated_but_active": {},
"allocated_but_free": "",
"notfound": "1X00",
"notfound": "0005, 0007, 0019 - 001B",
"offline": "",
"chpids": {},
'pchids': {}}
}
}
}
expected_2 = {
"id": template_id_2,
"name": "name2",
Expand Down
6 changes: 3 additions & 3 deletions zvmsdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ def __transform_fcp_list_into_str(local_fcp_list):
if start_fcp + count == end_fcp:
# e.g. hex(int('1A01',16)) is '0x1a01'
section_str = '{} - {}'.format(
hex(start_fcp)[2:], hex(end_fcp)[2:])
hex(start_fcp)[2:].zfill(4), hex(end_fcp)[2:].zfill(4))
fcp_section.append(section_str)
# Case 3: not all the FCPs are continuous.
else:
Expand All @@ -1110,12 +1110,12 @@ def __transform_fcp_list_into_str(local_fcp_list):
if start_fcp != end_fcp:
# e.g. hex(int('1A01',16)) is '0x1a01'
section_str = '{} - {}'.format(
hex(start_fcp)[2:], hex(end_fcp)[2:])
hex(start_fcp)[2:].zfill(4), hex(end_fcp)[2:].zfill(4))
# e.g.
# when start_fcp is '1A05',
# end_fcp is '1A05'
else:
section_str = hex(start_fcp)[2:]
section_str = hex(start_fcp)[2:].zfill(4)
fcp_section.append(section_str)
break
# recursively transform if FCP list still not empty
Expand Down
25 changes: 21 additions & 4 deletions zvmsdk/volumeop.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,9 +1349,10 @@ def _update_template_fcp_statistics_usage(self, statistics_usage,
# from template_fcp_mapping table
# Show upper case for FCP id
fcp_id = fcp_id.upper()
# If a fcp not found in z/VM, will not insert into fcp table, then the
# db query result will be None. So connections not None represents
# the fcp is found in z/VM
# If a fcp not found in z/VM, will not insert into fcp table, then
# (assigner_id, connections, reserved, chpid, pchid, state, owner)
# of raw_item are all None.
# So connections not None represents the fcp is found in z/VM
if connections is not None:
# Store each FCP in section "total"
statistics_usage[template_id][path_id]["total"].append(fcp_id)
Expand Down Expand Up @@ -1461,6 +1462,7 @@ def _update_template_fcp_statistics_usage(self, statistics_usage,
LOG.warning("Found a FCP device "
"%s in FCP Multipath Template %s, but not found in "
"z/VM." % (str(fcp_id), str(template_id)))

return statistics_usage

def _shrink_fcp_list_in_statistics_usage(self, statistics_usage):
Expand Down Expand Up @@ -1517,6 +1519,21 @@ def _split_singe_range_fcp_list(self, statistics_usage):
template_statistics[path]['range_fcp'] = ', '.join(range_fcp)
template_statistics[path]['single_fcp'] = ', '.join(single_fcp)

def _count_notfound_fcp_in_total_count(self, statistics_usage):
"""count notfound FCP devices in total_count section"""
for template_statistics in statistics_usage.values():
for path in template_statistics:
if template_statistics[path]['notfound']:
# template_statistics[path]['notfound'] is str, ex:
# '0007, 001D, 1A16 - 1A18'
# expand_fcp_list returns dict, ex:
# {0: {'0007' ,'001D', '1A16', '1A17', '1A18'}
count_of_notfound_fcp = len(
utils.expand_fcp_list(
template_statistics[path]['notfound'])[0])
template_statistics[
path]['total_count']['notfound'] = count_of_notfound_fcp

def get_fcp_templates(self, template_id_list=None, assigner_id=None,
default_sp_list=None, host_default=None):
"""Get template base info by template_id_list or filters
Expand Down Expand Up @@ -1832,7 +1849,6 @@ def get_fcp_templates_details(self, template_id_list=None, raw=False,
self._sync_db_with_zvm()
statistics_usage = {}
raw_usage = {}
template_info = {}
Copy link
Contributor Author

@jackydalong jackydalong Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the template_info is not used, so remove it
image

ret = []

# tmpl_cmd result format:
Expand Down Expand Up @@ -1890,6 +1906,7 @@ def get_fcp_templates_details(self, template_id_list=None, raw=False,
% statistics_usage)
self._shrink_fcp_list_in_statistics_usage(statistics_usage)
self._split_singe_range_fcp_list(statistics_usage)
self._count_notfound_fcp_in_total_count(statistics_usage)
LOG.info("statistic FCP usage after shrink: %s"
% statistics_usage)
# update base info with statistics_usage
Expand Down
Loading