Skip to content

Commit

Permalink
Merge pull request openmainframeproject#753 from wngzhe/wngzhe-add-ut…
Browse files Browse the repository at this point in the history
…-case-for-fcp-template

[master] add unit test scenario for db create and edit fcp template.
  • Loading branch information
dongyanyang authored Sep 20, 2023
2 parents f2345f5 + 0cacb1e commit dc79f86
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 11 deletions.
37 changes: 29 additions & 8 deletions zvmsdk/tests/unit/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,15 +1436,17 @@ def test_edit_fcp_template(self):
default_sp_list=[])
fcp_info = [
('1a02', 'wwpn_npiv_1', 'wwpn_phy_1', '27', '02e4', 'active', 'user1'),
('1b02', 'wwpn_npiv_1', 'wwpn_phy_1', '27', '02e4', 'active', 'user1')]
('1b02', 'wwpn_npiv_1', 'wwpn_phy_1', '27', '02e4', 'active', 'user1'),
('1c03', 'wwpn_npiv_1', 'wwpn_phy_1', '27', '02e3', 'active', 'user1'),
('1d04', 'wwpn_npiv_1', 'wwpn_phy_1', '27', '02e1', 'active', 'user1')]
self.db_op.bulk_insert_zvm_fcp_info_into_fcp_table(fcp_info)
reserve_info = (('1a02', '1b02'), 'user1', 'fake_id_1111')
self.db_op.reserve_fcps(*reserve_info)
self.increase_connections('1a02')
self.increase_connections('1b02')
# case-3.1:
# delete (1a01,1b03) from 'fake_id_0000' must fail
fcp_device_list = '1A00,1A02-1A03;1B00-1B02'
fcp_device_list = '1A00,1A02-1A03;1B00-1B02, 1C03, 1D04'
not_allow_for_del = {'1a01', '1b03'}
detail = ("The FCP devices ({}) are missing from the FCP device list."
.format(utils.shrink_fcp_list(list(not_allow_for_del))))
Expand All @@ -1453,8 +1455,20 @@ def test_edit_fcp_template(self):
self.assertIn(detail, str(cm.exception))
# case-3.2:
# delete (1a01,1b03) from 'fake_id_1111' must success
self.db_op.edit_fcp_template('fake_id_1111', fcp_devices=fcp_device_list)

ret_val = self.db_op.edit_fcp_template('fake_id_1111', fcp_devices=fcp_device_list)
pchids_add = ret_val.get('fcp_template').get('pchids').get('add')
pchids_all = ret_val.get('fcp_template').get('pchids').get('all')
pchids_del = ret_val.get('fcp_template').get('pchids').get('delete')
expect_add = {'all': ['02E1', '02E3'], 'first_used_by_templates': ['02E1', '02E3']}
expect_add['all'].sort()
pchids_add['all'].sort()
expect_add['first_used_by_templates'].sort()
pchids_add['first_used_by_templates'].sort()
pchids_all.sort()
self.assertListEqual(expect_add['all'], pchids_add['all'])
self.assertListEqual(expect_add['first_used_by_templates'], pchids_add['first_used_by_templates'])
self.assertEqual({'all': [], 'not_exist_in_any_template': []}, pchids_del)
self.assertEqual(['02E1', '02E3', '02E4'], pchids_all)
# case4
# DML: table template_fcp_mapping
# (based on the preparation done in case2)
Expand All @@ -1463,9 +1477,16 @@ def test_edit_fcp_template(self):
# c. update fcp path :
# change 1a01,1a03 from path0 to path1
# change 1b01,1b03 from path1 to path0
kwargs['fcp_devices'] = '1A00,1B01,1B03;1B00,1A01,1A03'
self.db_op.edit_fcp_template(
tmpl_id, fcp_devices=kwargs['fcp_devices'])
kwargs['fcp_devices'] = '1A00,1B01,1B03;1B00,1A01,1A03, 1C03'
ret_val = self.db_op.edit_fcp_template(tmpl_id, fcp_devices=kwargs['fcp_devices'])
pchids_add = ret_val.get('fcp_template').get('pchids').get('add')
pchids_all = ret_val.get('fcp_template').get('pchids').get('all')
pchids_del = ret_val.get('fcp_template').get('pchids').get('delete')
expect_add = {'all': ['02E3'], 'first_used_by_templates': []}
self.assertListEqual(expect_add['all'], pchids_add['all'])
self.assertListEqual(expect_add['first_used_by_templates'], pchids_add['first_used_by_templates'])
self.assertEqual({'all': [], 'not_exist_in_any_template': []}, pchids_del)
self.assertListEqual(['02E4', '02E3'], pchids_all)
expected = utils.expand_fcp_list(kwargs['fcp_devices'])
_, fcp_detail = self.db_op.get_fcp_templates_details([tmpl_id])
fcp_in_db = {0: set(), 1: set()}
Expand Down Expand Up @@ -1499,7 +1520,7 @@ def test_edit_fcp_template(self):
'pchids': {
'add': add_pchids,
'delete': delete_dict,
'all': ['02E4']
'all': ['02E4', '02E3']
}
}}
self.assertEqual(expected, tmpl_basic)
Expand Down
56 changes: 53 additions & 3 deletions zvmsdk/tests/unit/test_volumeop.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,11 +996,34 @@ def test_create_fcp_template(self,
'desc1', 1),
('fakehos2-1111-1111-1111-111111111111', 'name2',
'desc2', 0)]
zhypinfo = {"cpc": {"sequence_code": "0000000000082F57", 'layer_name': "M54"},
"lpar": {"layer_name": "ZVM4OCP3"}}

mock_get_zhypinfo.return_value = zhypinfo
zhypinfo = {
'cpc': {
'layer_type_num': '1',
'layer_category_num': '2',
'layer_type': 'CEC',
'layer_category': 'HOST',
'layer_name': 'M54',
'manufacturer': 'IBM',
'type': '3906',
'model_capacity': '701',
'model': 'M04',
'type_name': 'IBM z14',
'sequence_code': '0000000000082F57',
},
'lpar': {
'layer_type_num': '2',
'layer_category_num': '1',
'layer_type': 'LPAR',
'layer_category': 'GUEST',
'partition_number': '14',
'partition_char': 'Shared',
'partition_char_num': '2',
'layer_name': 'ZVM4OCP3',
}
}
mock_get_zvm_name.return_value = 'BOEM5403'
mock_get_zhypinfo.return_value = zhypinfo
template_id_list = [tmpl[0] for tmpl in templates]
self._insert_data_into_template_table(templates)
# parameters of new template
Expand Down Expand Up @@ -1109,6 +1132,33 @@ def test_edit_fcp_template(self,
'host_default': False,
'default_sp_list': ['sp1'],
'min_fcp_paths_count': 2}

zhypinfo = {
'cpc': {
'layer_type_num': '1',
'layer_category_num': '2',
'layer_type': 'CEC',
'layer_category': 'HOST',
'layer_name': 'M54',
'manufacturer': 'IBM',
'type': '3906',
'model_capacity': '701',
'model': 'M04',
'type_name': 'IBM z14',
'sequence_code': '0000000000082F57',
},
'lpar': {
'layer_type_num': '2',
'layer_category_num': '1',
'layer_type': 'LPAR',
'layer_category': 'GUEST',
'partition_number': '14',
'partition_char': 'Shared',
'partition_char_num': '2',
'layer_name': 'ZVM4OCP3',
}
}
mock_get_zhypinfo.return_value = zhypinfo
mock_zvm_name.return_value = 'BOEM5403'
self.fcpops.edit_fcp_template(tmpl_id, **kwargs)
mock_db_edit_tmpl.assert_called_once_with(tmpl_id, **kwargs)
Expand Down

0 comments on commit dc79f86

Please sign in to comment.