From 4e36f7c0c7b7be972d4342a092bfb3b999ffdac2 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Mon, 28 Aug 2017 13:29:28 +0200 Subject: resource: Fix list comparison in item_matches In following commits, cipher attribute containing a list of supported ciphers is introdued in osmo-gsm-tester. While developing the feature, it was found that resources containing lists are not being handled correctly. Previous implementation regarding lists in several ways: - In the list coe path, both item and wanted_item are expected to be lists. Python doesn't support to check for sublists using the "in" operand. - want_item basically contains the scenario dic, and item is each of the items available as resource of a given type. Thus, we want to check that item supports the subset of features requested by the scenario, ie. that the list in the scenario is a subset of the ones in the3 item and not the opposite. The following failing scenario is going to be checked during "make check" when the cipher attribute is added: BTS supporting cipher a50 and a51, and scenario requesting a50 succeeds. If this commit is remove, the test no longer passes, and it fails with: osmo_gsm_tester.resource.NoResourceExn: No matching resource available for bts = {'type': 'osmo-bts-sysmo', 'ciphers': ['a5 1']} Change-Id: I27b372aa5906feac2843f24f5cdd0d9578d44b4d --- src/osmo_gsm_tester/resource.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/osmo_gsm_tester/resource.py b/src/osmo_gsm_tester/resource.py index c55140a..da543f7 100644 --- a/src/osmo_gsm_tester/resource.py +++ b/src/osmo_gsm_tester/resource.py @@ -441,9 +441,12 @@ def item_matches(item, wanted_item, ignore_keys=None): return True if is_list(wanted_item): - # multiple possible values - if item not in wanted_item: + if not is_list(item): return False + # multiple possible values + for val in wanted_item: + if val not in item: + return False return True return item == wanted_item -- cgit v1.2.3