This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Neels Hofmeyr gerrit-no-reply at lists.osmocom.orgNeels Hofmeyr has submitted this change and it was merged. Change subject: resource: Handle lists correctly in item_matches ...................................................................... resource: Handle lists correctly in item_matches We want to handle lists in the same way as we handle them in combine(). Without this commit, reserve()->find() failed to match objects containing dictionaries inside lists correctly (such as trx configs). A few attributes are added to trx_list of some resources in suite_test/resources.conf to show a case in which resource reservation would fail without this patch. It failed because before this patch, dictionaries inside lists are compared to be equal instead of being compared element by element to see if one dictionary is a subset of the other one (for each element in the lists). Change-Id: I8588d5b788b9f74a9cc84b8bdcb049921788bb48 --- M selftest/resource_test.ok M selftest/resource_test.py M selftest/suite_test.ok M selftest/suite_test/resources.conf M src/osmo_gsm_tester/resource.py 5 files changed, 57 insertions(+), 9 deletions(-) Approvals: Neels Hofmeyr: Looks good to me, approved Jenkins Builder: Verified diff --git a/selftest/resource_test.ok b/selftest/resource_test.ok index d366cf9..416e477 100644 --- a/selftest/resource_test.ok +++ b/selftest/resource_test.ok @@ -243,3 +243,9 @@ ~~~ end: currently reserved +- item_matches: +1st subset matches correctly, pass +2nd subset matches correctly, pass +3rd subset should not match, pass +3rd subset should not match, pass +4th subset should not match, pass diff --git a/selftest/resource_test.py b/selftest/resource_test.py index d72eb72..ca723af 100755 --- a/selftest/resource_test.py +++ b/selftest/resource_test.py @@ -94,4 +94,27 @@ print(f.read()) print('~~~ end: currently reserved\n') +print('- item_matches:') +superset = { 'hello': 'world', 'foo': 'bar', 'ordered_list': [{'xkey': 'xvalue'},{'ykey': 'yvalue'}], 'unordered_list_set': [1, 2, 3]} + +subset = { 'foo': 'bar', 'ordered_list': [{'xkey': 'xvalue'},{'ykey': 'yvalue'}], 'unordered_list_set': [2, 1] } +if resource.item_matches(superset, subset): + print('1st subset matches correctly, pass') + +subset = { 'ordered_list': [{},{'ykey': 'yvalue'}], 'unordered_list_set': [] } +if resource.item_matches(superset, subset): + print('2nd subset matches correctly, pass') + +subset = { 'ordered_list': [{'ykey': 'yvalue'}, {'xkey': 'xvalue'}] } +if not resource.item_matches(superset, subset): + print('3rd subset should not match, pass') + +subset = { 'ordered_list': [{'xkey': 'xvalue'}, {'ykey': 'yvalue'}, {'zkey': 'zvalue'}] } +if not resource.item_matches(superset, subset): + print('3rd subset should not match, pass') + +subset = { 'unordered_list_set': [4] } +if not resource.item_matches(superset, subset): + print('4th subset should not match, pass') + # vim: expandtab tabstop=4 shiftwidth=4 diff --git a/selftest/suite_test.ok b/selftest/suite_test.ok index 365fcaa..9c73588 100644 --- a/selftest/suite_test.ok +++ b/selftest/suite_test.ok @@ -240,24 +240,27 @@ tst {combining_scenarios='resources'}: DBG: {definition_conf={bts=[{}, {}, {}], ip_address=[{}], modem=[{}, {}]}} [test_suite↪{combining_scenarios='resources'}] [suite.py:[LINENR]] tst {combining_scenarios='resources', scenario='foo'}: [RESOURCE_DICT] tst test_suite: Reserving 3 x bts (candidates: 6) [resource.py:[LINENR]] -tst test_suite: DBG: Picked - _hash: f1cab48db5b9004986e2030cb71730a5c55e823e +tst test_suite: DBG: Picked - _hash: 89e45aaea42027162cc33f4389f055077338c82b addr: 10.42.42.52 band: GSM-1800 ipa_unit_id: '6' label: Ettus B200 launch_trx: 'True' trx_list: - - nominal_power: '10' + - max_power_red: '2' + nominal_power: '10' - nominal_power: '12' type: osmo-bts-trx -- _hash: 1d00bd0d6643db5590cdbefff3152e70500abefc +- _hash: 076ff06a4b719e61779492d3fb99f42a6635bb72 addr: 10.42.42.53 band: GSM-1800 ipa_unit_id: '7' label: sysmoCell 5000 trx_list: - - nominal_power: '10' - - nominal_power: '12' + - max_power_red: '3' + nominal_power: '10' + - max_power_red: '0' + nominal_power: '12' trx_remote_ip: 10.42.42.112 type: osmo-bts-trx - _hash: 07d9c8aaa940b674efcbbabdd69f58a6ce4e94f9 diff --git a/selftest/suite_test/resources.conf b/selftest/suite_test/resources.conf index 001d286..440e55c 100644 --- a/selftest/suite_test/resources.conf +++ b/selftest/suite_test/resources.conf @@ -36,6 +36,7 @@ launch_trx: true trx_list: - nominal_power: 10 + max_power_red: 2 - nominal_power: 12 - label: sysmoCell 5000 @@ -46,7 +47,9 @@ trx_remote_ip: 10.42.42.112 trx_list: - nominal_power: 10 + max_power_red: 3 - nominal_power: 12 + max_power_red: 0 - label: sysmoCell 5000 type: osmo-bts-trx @@ -57,6 +60,7 @@ trx_list: - nominal_power: 10 - nominal_power: 12 + max_power_red: 1 arfcn: - arfcn: 512 diff --git a/src/osmo_gsm_tester/resource.py b/src/osmo_gsm_tester/resource.py index 8206767..150e28b 100644 --- a/src/osmo_gsm_tester/resource.py +++ b/src/osmo_gsm_tester/resource.py @@ -431,10 +431,22 @@ if is_list(wanted_item): if not is_list(item): return False - # multiple possible values - for val in wanted_item: - if val not in item: - return False + # Validate that all elements in both lists are of the same type: + t = util.list_validate_same_elem_type(wanted_item + item) + if t is None: + return True # both lists are empty, return + # For lists of complex objects, we expect them to be sorted lists: + if t in (dict, list, tuple): + for i in range(max(len(wanted_item), len(item))): + log.ctx(idx=i) + subitem = item[i] if i < len(item) else util.empty_instance_type(t) + wanted_subitem = wanted_item[i] if i < len(wanted_item) else util.empty_instance_type(t) + if not item_matches(subitem, wanted_subitem, ignore_keys=ignore_keys): + return False + else: # for lists of basic elements, we handle them as unsorted sets: + for val in wanted_item: + if val not in item: + return False return True return item == wanted_item -- To view, visit https://gerrit.osmocom.org/3952 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: merged Gerrit-Change-Id: I8588d5b788b9f74a9cc84b8bdcb049921788bb48 Gerrit-PatchSet: 4 Gerrit-Project: osmo-gsm-tester Gerrit-Branch: master Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>