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.orgPau Espin Pedrol has submitted this change and it was merged. Change subject: resource: Refactor next_msisdn to be more generic ...................................................................... resource: Refactor next_msisdn to be more generic The logic in next_msisdn can be later re-used for other purposes, such as getting different location area codes for BTS. Change-Id: Ib04a34892aacd7e71f8f5961e7339add583f73f2 --- M src/osmo_gsm_tester/resource.py 1 file changed, 17 insertions(+), 15 deletions(-) Approvals: Neels Hofmeyr: Looks good to me, approved Jenkins Builder: Verified diff --git a/src/osmo_gsm_tester/resource.py b/src/osmo_gsm_tester/resource.py index 25bb00f..ecafa2f 100644 --- a/src/osmo_gsm_tester/resource.py +++ b/src/osmo_gsm_tester/resource.py @@ -38,7 +38,6 @@ USED_KEY = '_used' RESOURCES_CONF = 'resources.conf' -LAST_USED_MSISDN_FILE = 'last_used_msisdn.state' RESERVED_RESOURCES_FILE = 'reserved_resources.state' R_IP_ADDRESS = 'ip_address' @@ -189,24 +188,27 @@ if not self._remember_to_free: self.unregister_exit_handler() - def next_msisdn(self, origin): + def next_persistent_value(self, token, first_val, validate_func, inc_func, origin): origin_id = origin.origin_id() with self.state_dir.lock(origin_id): - msisdn_path = self.state_dir.child(LAST_USED_MSISDN_FILE) - log.ctx(msisdn_path) - last_msisdn = '1000' - if os.path.exists(msisdn_path): - if not os.path.isfile(msisdn_path): - raise RuntimeError('path should be a file but is not: %r' % msisdn_path) - with open(msisdn_path, 'r') as f: - last_msisdn = f.read().strip() - schema.msisdn(last_msisdn) + token_path = self.state_dir.child('last_used_%s.state' % token) + log.ctx(token_path) + last_value = first_val + if os.path.exists(token_path): + if not os.path.isfile(token_path): + raise RuntimeError('path should be a file but is not: %r' % token_path) + with open(token_path, 'r') as f: + last_value = f.read().strip() + validate_func(last_value) - next_msisdn = util.msisdn_inc(last_msisdn) - with open(msisdn_path, 'w') as f: - f.write(next_msisdn) - return next_msisdn + next_value = inc_func(last_value) + with open(token_path, 'w') as f: + f.write(next_value) + return next_value + + def next_msisdn(self, origin): + return self.next_persistent_value('msisdn', '1000', schema.msisdn, util.msisdn_inc, origin) class NoResourceExn(log.Error): -- To view, visit https://gerrit.osmocom.org/4703 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib04a34892aacd7e71f8f5961e7339add583f73f2 Gerrit-PatchSet: 3 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>