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/.
Pau Espin Pedrol gerrit-no-reply at lists.osmocom.orgHello Neels Hofmeyr, Jenkins Builder,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/3722
to look at the new patch set (#2).
config: Fix combination of lists
It can make sense to recursively call combine() for a list containing
complex structures like dictionaries or lists. However, for a list of
simple types (eg. integers or strings), we just want to merge both lists
and we only need to check if the value is already there. This case won't
work if we call combine for each element of the list because for a
simple case it will just end up checking if a[i] == b[i]. A sample unit
test is provided with this commit which shows the kind of issue it
fixes.
This kind of operation is needed in later commits where cipher attribute
is introduced. Without this patch, having following 2 scenarios and
trying them to use together "-s foosuite:cipher-a50+ciphera51" will
fail:
cipher_a50.conf:
bts:
- ciphers:
- 'a5 0'
cipher_a51.conf
bts:
- ciphers:
- 'a5 1'
ValueError: cannot combine dicts, conflicting items (values 'a5 0' and 'a5 1')
Change-Id: Ib7a38f10eb9de338a77bf1fa3afceb9df1532015
---
M selftest/config_test.ok
M selftest/config_test.py
M src/osmo_gsm_tester/config.py
3 files changed, 16 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/22/3722/2
diff --git a/selftest/config_test.ok b/selftest/config_test.ok
index 80b5a06..11bb833 100644
--- a/selftest/config_test.ok
+++ b/selftest/config_test.ok
@@ -93,3 +93,5 @@
Validation: Error
--- imsi[]: ERR: ValueError: Invalid IMSI: None
Validation: Error
+- Combine lists:
+{'a_list': ['x', 'z', 'y']}
diff --git a/selftest/config_test.py b/selftest/config_test.py
index 61ec73a..bf4a2e1 100755
--- a/selftest/config_test.py
+++ b/selftest/config_test.py
@@ -8,7 +8,7 @@
import pprint
import copy
-from osmo_gsm_tester import config, log, schema
+from osmo_gsm_tester import config, log, schema, util
example_config_file = 'test.cfg'
example_config = os.path.join(_prep.script_dir, 'config_test', example_config_file)
@@ -27,6 +27,7 @@
'bts[].trx[].timeslots[]' : schema.STR,
'bts[].trx[].band' : schema.BAND,
'a_dict.foo' : schema.INT,
+ 'a_list[]': util.is_list,
'addr[]' : schema.IPV4,
'hwaddr[]' : schema.HWADDR,
'imsi[]' : schema.IMSI,
@@ -112,4 +113,11 @@
c['imsi'][2] = None
val(c)
+print('- Combine lists:')
+a = {}
+b = {}
+a['a_list'] = ['x', 'z']
+b['a_list'] = [ 'y' ]
+config.combine(a, b)
+print(a)
# vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/osmo_gsm_tester/config.py b/src/osmo_gsm_tester/config.py
index f6e81ac..392cd04 100644
--- a/src/osmo_gsm_tester/config.py
+++ b/src/osmo_gsm_tester/config.py
@@ -246,7 +246,11 @@
raise ValueError('cannot combine list with a value of type: %r' % type(src))
for i in range(len(src)):
log.ctx(idx=i)
- combine(dest[i], src[i])
+ assert type(dest[i]) == type(src[i])
+ if is_dict(dest[i]) or is_list(dest[i]):
+ combine(dest[i], src[i])
+ elif src[i] not in dest:
+ dest.append(src[i])
return
if dest == src:
return
--
To view, visit https://gerrit.osmocom.org/3722
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Ib7a38f10eb9de338a77bf1fa3afceb9df1532015
Gerrit-PatchSet: 2
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>
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>