[MERGED] osmo-gsm-tester[master]: resource: Refactor next_msisdn to be more generic

2017-11-08 Thread Pau Espin Pedrol
Pau 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 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-Reviewer: Pau Espin Pedrol 


osmo-gsm-tester[master]: resource: Refactor next_msisdn to be more generic

2017-11-07 Thread Neels Hofmeyr

Patch Set 2: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/4703
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ib04a34892aacd7e71f8f5961e7339add583f73f2
Gerrit-PatchSet: 2
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-HasComments: No


[PATCH] osmo-gsm-tester[master]: resource: Refactor next_msisdn to be more generic

2017-11-07 Thread Pau Espin Pedrol
Hello Neels Hofmeyr, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/4703

to look at the new patch set (#2).

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(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/03/4703/2

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: newpatchset
Gerrit-Change-Id: Ib04a34892aacd7e71f8f5961e7339add583f73f2
Gerrit-PatchSet: 2
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr 


osmo-gsm-tester[master]: resource: Refactor next_msisdn to be more generic

2017-11-06 Thread Neels Hofmeyr

Patch Set 1: Code-Review-1

(3 comments)

very nice except for the changing filename

https://gerrit.osmocom.org/#/c/4703/1//COMMIT_MSG
Commit Message:

Line 10: as getting different location areas for BTS.
well, getting the codes yes, not the areas themselves ;)


https://gerrit.osmocom.org/#/c/4703/1/src/osmo_gsm_tester/resource.py
File src/osmo_gsm_tester/resource.py:

Line 195: token_path = self.state_dir.child(token + 
'_last_used.state')
-1: let's rather make it 'last_used_%s.state' % token, then we will continue 
using the same state file instead of creating a new one on our tester instances.


Line 206: validate_func(next_value)
0: do you not trust the inc_func?


-- 
To view, visit https://gerrit.osmocom.org/4703
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ib04a34892aacd7e71f8f5961e7339add583f73f2
Gerrit-PatchSet: 1
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-HasComments: Yes


[PATCH] osmo-gsm-tester[master]: resource: Refactor next_msisdn to be more generic

2017-11-06 Thread Pau Espin Pedrol

Review at  https://gerrit.osmocom.org/4703

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 areas for BTS.

Change-Id: Ib04a34892aacd7e71f8f5961e7339add583f73f2
---
M src/osmo_gsm_tester/resource.py
1 file changed, 18 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/03/4703/1

diff --git a/src/osmo_gsm_tester/resource.py b/src/osmo_gsm_tester/resource.py
index 25bb00f..278fe4f 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,28 @@
 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(token + '_last_used.state')
+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)
+validate_func(next_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: newchange
Gerrit-Change-Id: Ib04a34892aacd7e71f8f5961e7339add583f73f2
Gerrit-PatchSet: 1
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol