[MERGED] osmo-gsm-tester[master]: ms: Create a starter for virtphy and mobile application

2018-04-05 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: ms: Create a starter for virtphy and mobile application
..


ms: Create a starter for virtphy and mobile application

In the long run we might not want to start the virtphy but
for now virtphy+mobile belong together. Start virtphy first
as mobile will not handle a missing socket gracefully.

Change-Id: I5c6d742842d7f3e0a1858436ef3f8634d8c0582d
---
A src/osmo_ms_driver/starter.py
1 file changed, 119 insertions(+), 0 deletions(-)

Approvals:
  Pau Espin Pedrol: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/osmo_ms_driver/starter.py b/src/osmo_ms_driver/starter.py
new file mode 100644
index 000..243dedc
--- /dev/null
+++ b/src/osmo_ms_driver/starter.py
@@ -0,0 +1,119 @@
+# osmo_ms_driver: Starter for processes
+# Help to start processes over time.
+#
+# Copyright (C) 2018 by Holger Hans Peter Freyther
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see .
+
+from osmo_gsm_tester import log, template
+
+import os
+import os.path
+import subprocess
+import time
+
+_devnull = open(os.devnull, 'w')
+#_devnull = open('/dev/stdout', 'w')
+
+class Launcher(log.Origin):
+def __init__(self, base_name, name_number, tmp_dir):
+super().__init__(log.C_RUN, "{}/{}".format(base_name, name_number))
+self._name_number = name_number
+self._tmp_dir = tmp_dir
+
+def name_number(self):
+return self._name_number
+
+class OsmoVirtPhy(Launcher):
+def __init__(self, name_number, tmp_dir):
+super().__init__("osmo-ms-virt-phy", name_number, tmp_dir)
+self._phy_filename = os.path.join(self._tmp_dir, "osmocom_l2_" + 
self._name_number)
+
+def phy_filename(self):
+return self._phy_filename
+
+def start(self, loop):
+if len(self._phy_filename.encode()) > 107:
+raise log.Error('Path for unix socket is longer than max allowed 
len for unix socket path (107):', self._phy_filename)
+
+self.log("Starting virtphy process")
+args = ["virtphy", "--l1ctl-sock=" + self._phy_filename]
+self.log(' '.join(args))
+self._vphy_proc = subprocess.Popen(args, stderr=_devnull, 
stdout=_devnull)
+
+def verify_ready(self):
+while True:
+if os.path.exists(self._phy_filename):
+return
+time.sleep(0.2)
+
+def kill(self):
+"""Clean up things."""
+if self._vphy_proc:
+self._vphy_proc.kill()
+
+class OsmoMobile(Launcher):
+def __init__(self, name_number, tmp_dir, lua_tmpl, cfg_tmpl, 
imsi_ki_generator, phy_filename, ev_server_path):
+super().__init__("osmo-ms-mob", name_number, tmp_dir)
+self._lua_template = lua_tmpl
+self._cfg_template = cfg_tmpl
+self._imsi_ki_generator = imsi_ki_generator
+self._phy_filename = phy_filename
+self._ev_server_path = ev_server_path
+
+def write_lua_cfg(self):
+lua_support = os.path.join(os.path.dirname(__file__), 'lua')
+cfg = {
+'test': {
+'event_path': self._ev_server_path,
+'lua_support': lua_support,
+}
+}
+lua_cfg_file = os.path.join(self._tmp_dir, "lua_" + self._name_number 
+ ".lua")
+lua_script = template.render(self._lua_template, cfg)
+with open(lua_cfg_file, 'w') as w:
+w.write(lua_script)
+return lua_cfg_file
+
+def write_mob_cfg(self, lua_filename, phy_filename):
+(imsi, ki) = next(self._imsi_ki_generator)
+cfg = {
+'test': {
+'script': lua_filename,
+'virt_phy': phy_filename,
+'imsi': imsi,
+'ki_comp128': ki,
+'ms_number': self._name_number,
+}
+}
+mob_cfg_file = os.path.join(self._tmp_dir, "mob_" + self._name_number 
+ ".cfg")
+mob_vty = template.render(self._cfg_template, cfg)
+with open(mob_cfg_file, 'w') as w:
+w.write(mob_vty)
+return mob_cfg_file
+
+def start(self, loop):
+lua_filename = self.write_lua_cfg()
+mob_filename = self.write_mob_cfg(lua_filename, self._phy_filename)
+
+self.log("Starting process")
+# Let the kernel pick an unused port for the VTY.
+

osmo-gsm-tester[master]: ms: Create a starter for virtphy and mobile application

2018-03-07 Thread Pau Espin Pedrol

Patch Set 7: Code-Review+2

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I5c6d742842d7f3e0a1858436ef3f8634d8c0582d
Gerrit-PatchSet: 7
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Reviewer: neels 
Gerrit-HasComments: No


[PATCH] osmo-gsm-tester[master]: ms: Create a starter for virtphy and mobile application

2018-03-07 Thread Holger Freyther
Hello Pau Espin Pedrol, Harald Welte, Jenkins Builder,

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

https://gerrit.osmocom.org/6917

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

ms: Create a starter for virtphy and mobile application

In the long run we might not want to start the virtphy but
for now virtphy+mobile belong together. Start virtphy first
as mobile will not handle a missing socket gracefully.

Change-Id: I5c6d742842d7f3e0a1858436ef3f8634d8c0582d
---
A src/osmo_ms_driver/starter.py
1 file changed, 119 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/17/6917/7

diff --git a/src/osmo_ms_driver/starter.py b/src/osmo_ms_driver/starter.py
new file mode 100644
index 000..243dedc
--- /dev/null
+++ b/src/osmo_ms_driver/starter.py
@@ -0,0 +1,119 @@
+# osmo_ms_driver: Starter for processes
+# Help to start processes over time.
+#
+# Copyright (C) 2018 by Holger Hans Peter Freyther
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see .
+
+from osmo_gsm_tester import log, template
+
+import os
+import os.path
+import subprocess
+import time
+
+_devnull = open(os.devnull, 'w')
+#_devnull = open('/dev/stdout', 'w')
+
+class Launcher(log.Origin):
+def __init__(self, base_name, name_number, tmp_dir):
+super().__init__(log.C_RUN, "{}/{}".format(base_name, name_number))
+self._name_number = name_number
+self._tmp_dir = tmp_dir
+
+def name_number(self):
+return self._name_number
+
+class OsmoVirtPhy(Launcher):
+def __init__(self, name_number, tmp_dir):
+super().__init__("osmo-ms-virt-phy", name_number, tmp_dir)
+self._phy_filename = os.path.join(self._tmp_dir, "osmocom_l2_" + 
self._name_number)
+
+def phy_filename(self):
+return self._phy_filename
+
+def start(self, loop):
+if len(self._phy_filename.encode()) > 107:
+raise log.Error('Path for unix socket is longer than max allowed 
len for unix socket path (107):', self._phy_filename)
+
+self.log("Starting virtphy process")
+args = ["virtphy", "--l1ctl-sock=" + self._phy_filename]
+self.log(' '.join(args))
+self._vphy_proc = subprocess.Popen(args, stderr=_devnull, 
stdout=_devnull)
+
+def verify_ready(self):
+while True:
+if os.path.exists(self._phy_filename):
+return
+time.sleep(0.2)
+
+def kill(self):
+"""Clean up things."""
+if self._vphy_proc:
+self._vphy_proc.kill()
+
+class OsmoMobile(Launcher):
+def __init__(self, name_number, tmp_dir, lua_tmpl, cfg_tmpl, 
imsi_ki_generator, phy_filename, ev_server_path):
+super().__init__("osmo-ms-mob", name_number, tmp_dir)
+self._lua_template = lua_tmpl
+self._cfg_template = cfg_tmpl
+self._imsi_ki_generator = imsi_ki_generator
+self._phy_filename = phy_filename
+self._ev_server_path = ev_server_path
+
+def write_lua_cfg(self):
+lua_support = os.path.join(os.path.dirname(__file__), 'lua')
+cfg = {
+'test': {
+'event_path': self._ev_server_path,
+'lua_support': lua_support,
+}
+}
+lua_cfg_file = os.path.join(self._tmp_dir, "lua_" + self._name_number 
+ ".lua")
+lua_script = template.render(self._lua_template, cfg)
+with open(lua_cfg_file, 'w') as w:
+w.write(lua_script)
+return lua_cfg_file
+
+def write_mob_cfg(self, lua_filename, phy_filename):
+(imsi, ki) = next(self._imsi_ki_generator)
+cfg = {
+'test': {
+'script': lua_filename,
+'virt_phy': phy_filename,
+'imsi': imsi,
+'ki_comp128': ki,
+'ms_number': self._name_number,
+}
+}
+mob_cfg_file = os.path.join(self._tmp_dir, "mob_" + self._name_number 
+ ".cfg")
+mob_vty = template.render(self._cfg_template, cfg)
+with open(mob_cfg_file, 'w') as w:
+w.write(mob_vty)
+return mob_cfg_file
+
+def start(self, loop):
+lua_filename = self.write_lua_cfg()
+mob_filename = self.write_mob_cfg(lua_filename, self._phy_filename)
+
+self.log("Starting process")
+# Let the kernel pick an unused port for the VTY.
+args = ["mobile", "-c", 

osmo-gsm-tester[master]: ms: Create a starter for virtphy and mobile application

2018-03-07 Thread Pau Espin Pedrol

Patch Set 6: Code-Review-1

(2 comments)

https://gerrit.osmocom.org/#/c/6917/6/src/osmo_ms_driver/starter.py
File src/osmo_ms_driver/starter.py:

Line 58: import time
You forgot to fix this one.


Line 88: 
You forgot to fix this one.


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I5c6d742842d7f3e0a1858436ef3f8634d8c0582d
Gerrit-PatchSet: 6
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Reviewer: neels 
Gerrit-HasComments: Yes


osmo-gsm-tester[master]: ms: Create a starter for virtphy and mobile application

2018-03-06 Thread Pau Espin Pedrol

Patch Set 5:

(1 comment)

https://gerrit.osmocom.org/#/c/6917/5/src/osmo_ms_driver/starter.py
File src/osmo_ms_driver/starter.py:

Line 107: def start_mobile(self, loop):
> You are the maintainer but I wouldn't do it:
* What's the issue with it being generic given that is called from a known 
class? Usually you have 1 class per file, so if you know the object, just grep 
for "start(" in the class file.

* I asked you to call it start() because it was already being called 
start_mobile(), if you had called it launch_process_mobile() I would have 
pointed out that it would make more sense to have it called launch_process(), 
because imho if you are in class Foo, it doesn't make sense to have a method 
do_foo() but better call it do(), as foo is already known from the object. In 
our objects used for tests we usually have a public API called start() because 
we don't care about whether it creates a process or not underneath, everything 
is managed internally by the object. Even more, in the Modem (ofono) class, we 
only have a connect() signal which does all the initialization and starts 
registration, because so far we didn't need other steps (basically because the 
modem attempts to connect to the network as quick as it is powered on). That 
being said, if other implementations require more fine grained actions/steps, 
we can improve the API used in osmo-gsm-tester tests.

So, to keep it in a similar fashion with other existing objects (bts, bsc, 
msc), for future inclusion it would be nice to have it called start() too, and 
add that API to the Modem object (in ofono we'd probably keep doing everything 
in the connect() anyway).

As it's not yet merged with the other osmo-gsm-tester stuff (different 
directory) there no hard requirement on how to call it, but for later inclusion 
it may ease already providing similar naming.


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I5c6d742842d7f3e0a1858436ef3f8634d8c0582d
Gerrit-PatchSet: 5
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Reviewer: neels 
Gerrit-HasComments: Yes


osmo-gsm-tester[master]: ms: Create a starter for virtphy and mobile application

2018-03-06 Thread Holger Freyther

Patch Set 5:

(1 comment)

https://gerrit.osmocom.org/#/c/6917/5/src/osmo_ms_driver/starter.py
File src/osmo_ms_driver/starter.py:

Line 107: def start_mobile(self, loop):
> Can now be called start(), as it's already in the mobile class.
You are the maintainer but I wouldn't do it:

* start is too generic. Good luck finding the right method with git grep. ;)
* As you pointed out the virtphy and mob are two very different things (and 
launched at two different phases of the test process) and we don't benefit from 
the "start" polymorphism. By definition they are not compatible/the same (in 
terms of duck typing) and by not having the same methods it will fail with an 
exception..

If you want to pick a common name I would pick: launch_process. It describes 
what it is done (launch a process), one can git grep for it, and most likely it 
will stay the same (we continue to launch processes).


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I5c6d742842d7f3e0a1858436ef3f8634d8c0582d
Gerrit-PatchSet: 5
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Reviewer: neels 
Gerrit-HasComments: Yes


osmo-gsm-tester[master]: ms: Create a starter for virtphy and mobile application

2018-03-05 Thread Pau Espin Pedrol

Patch Set 5:

(3 comments)

https://gerrit.osmocom.org/#/c/6917/5/src/osmo_ms_driver/starter.py
File src/osmo_ms_driver/starter.py:

Line 58: import time
What about moving the import to the top with the other ones?


Line 88: 
Extra line, can be removed


Line 107: def start_mobile(self, loop):
Can now be called start(), as it's already in the mobile class.


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I5c6d742842d7f3e0a1858436ef3f8634d8c0582d
Gerrit-PatchSet: 5
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Reviewer: neels 
Gerrit-HasComments: Yes


[PATCH] osmo-gsm-tester[master]: ms: Create a starter for virtphy and mobile application

2018-02-28 Thread Holger Freyther
Hello Pau Espin Pedrol, Harald Welte, Jenkins Builder,

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

https://gerrit.osmocom.org/6917

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

ms: Create a starter for virtphy and mobile application

In the long run we might not want to start the virtphy but
for now virtphy+mobile belong together. Start virtphy first
as mobile will not handle a missing socket gracefully.

Change-Id: I5c6d742842d7f3e0a1858436ef3f8634d8c0582d
---
A src/osmo_ms_driver/starter.py
1 file changed, 120 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/17/6917/5

diff --git a/src/osmo_ms_driver/starter.py b/src/osmo_ms_driver/starter.py
new file mode 100644
index 000..dc67f90
--- /dev/null
+++ b/src/osmo_ms_driver/starter.py
@@ -0,0 +1,120 @@
+# osmo_ms_driver: Starter for processes
+# Help to start processes over time.
+#
+# Copyright (C) 2018 by Holger Hans Peter Freyther
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see .
+
+from osmo_gsm_tester import log, template
+
+import os
+import os.path
+import subprocess
+
+_devnull = open(os.devnull, 'w')
+#_devnull = open('/dev/stdout', 'w')
+
+class Launcher(log.Origin):
+def __init__(self, base_name, name_number, tmp_dir):
+super().__init__(log.C_RUN, "{}/{}".format(base_name, name_number))
+self._name_number = name_number
+self._tmp_dir = tmp_dir
+
+def name_number(self):
+return self._name_number
+
+class OsmoVirtPhy(Launcher):
+def __init__(self, name_number, tmp_dir):
+super().__init__("osmo-ms-virt-phy", name_number, tmp_dir)
+self._phy_filename = os.path.join(self._tmp_dir, "osmocom_l2_" + 
self._name_number)
+
+def phy_filename(self):
+return self._phy_filename
+
+def start_virtphy(self, loop):
+if len(self._phy_filename.encode()) > 107:
+raise log.Error('Path for unix socket is longer than max allowed 
len for unix socket path (107):', self._phy_filename)
+
+self.log("Starting virtphy process")
+args = ["virtphy", "--l1ctl-sock=" + self._phy_filename]
+self.log(' '.join(args))
+self._vphy_proc = subprocess.Popen(args, stderr=_devnull, 
stdout=_devnull)
+
+def verify_phy_ready(self):
+while True:
+if os.path.exists(self._phy_filename):
+return
+import time
+time.sleep(0.2)
+
+def kill(self):
+"""Clean up things."""
+if self._vphy_proc:
+self._vphy_proc.kill()
+
+class OsmoMobile(Launcher):
+def __init__(self, name_number, tmp_dir, lua_tmpl, cfg_tmpl, 
imsi_ki_generator, phy_filename, ev_server_path):
+super().__init__("osmo-ms-mob", name_number, tmp_dir)
+self._lua_template = lua_tmpl
+self._cfg_template = cfg_tmpl
+self._imsi_ki_generator = imsi_ki_generator
+self._phy_filename = phy_filename
+self._ev_server_path = ev_server_path
+
+def write_lua_cfg(self):
+lua_support = os.path.join(os.path.dirname(__file__), 'lua')
+cfg = {
+'test': {
+'event_path': self._ev_server_path,
+'lua_support': lua_support,
+}
+}
+lua_cfg_file = os.path.join(self._tmp_dir, "lua_" + self._name_number 
+ ".lua")
+lua_script = template.render(self._lua_template, cfg)
+with open(lua_cfg_file, 'w') as w:
+w.write(lua_script)
+return lua_cfg_file
+
+
+def write_mob_cfg(self, lua_filename, phy_filename):
+(imsi, ki) = next(self._imsi_ki_generator)
+cfg = {
+'test': {
+'script': lua_filename,
+'virt_phy': phy_filename,
+'imsi': imsi,
+'ki_comp128': ki,
+'ms_number': self._name_number,
+}
+}
+mob_cfg_file = os.path.join(self._tmp_dir, "mob_" + self._name_number 
+ ".cfg")
+mob_vty = template.render(self._cfg_template, cfg)
+with open(mob_cfg_file, 'w') as w:
+w.write(mob_vty)
+return mob_cfg_file
+
+def start_mobile(self, loop):
+lua_filename = self.write_lua_cfg()
+mob_filename = self.write_mob_cfg(lua_filename, self._phy_filename)
+
+self.log("Starting process")
+# Let the kernel pick an unused port for the VTY.
+  

osmo-gsm-tester[master]: ms: Create a starter for virtphy and mobile application

2018-02-26 Thread Harald Welte

Patch Set 3: Code-Review+1

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I5c6d742842d7f3e0a1858436ef3f8634d8c0582d
Gerrit-PatchSet: 3
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Reviewer: neels 
Gerrit-HasComments: No


osmo-gsm-tester[master]: ms: Create a starter for virtphy and mobile application

2018-02-25 Thread Pau Espin Pedrol

Patch Set 3: Code-Review-1

I think it makes a lot of sense separating these already in this commit. Better 
have a OsmoMobile and OsmoVirtPhy classes (put them in the same file if it is 
easier for you). Have a look for instance at osmo_bsc.py or bts_osmo_trx.py.

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

Gerrit-MessageType: comment
Gerrit-Change-Id: I5c6d742842d7f3e0a1858436ef3f8634d8c0582d
Gerrit-PatchSet: 3
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Reviewer: neels 
Gerrit-HasComments: No


[PATCH] osmo-gsm-tester[master]: ms: Create a starter for virtphy and mobile application

2018-02-25 Thread Holger Freyther

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

ms: Create a starter for virtphy and mobile application

In the long run we might not want to start the virtphy but
for now virtphy+mobile belong together. Start virtphy first
as mobile will not handle a missing socket gracefully.

Change-Id: I5c6d742842d7f3e0a1858436ef3f8634d8c0582d
---
A src/osmo_ms_driver/starter.py
1 file changed, 110 insertions(+), 0 deletions(-)


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

diff --git a/src/osmo_ms_driver/starter.py b/src/osmo_ms_driver/starter.py
new file mode 100644
index 000..8b6c591
--- /dev/null
+++ b/src/osmo_ms_driver/starter.py
@@ -0,0 +1,110 @@
+# osmo_ms_driver: Starter for processes
+# Help to start processes over time.
+#
+# Copyright (C) 2018 by Holger Hans Peter Freyther
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see .
+
+from osmo_gsm_tester import log, template
+
+import os
+import os.path
+import subprocess
+
+_devnull = open(os.devnull, 'w')
+#_devnull = open('/dev/stdout', 'w')
+
+class Launcher(log.Origin):
+"""
+I launch an OsmocomBB mobile and the virtphy. In the future we
+might want to test with real phones and then don't launch the
+virtphy. This needs to be handled once we move to bare iron.
+
+>>> Launcher("", "mobile", "mobile.tmpl", {})
+osmo-ms/
+"""
+def __init__(self, name_number, tmp_dir, lua_tmpl, cfg_tmpl, 
imsi_ki_generator, ev_server_path):
+super().__init__(log.C_RUN, "osmo-ms/" + name_number)
+self._lua_template = lua_tmpl
+self._cfg_template = cfg_tmpl
+self._name_number = name_number
+self._tmp_dir = tmp_dir
+self._imsi_ki_generator = imsi_ki_generator
+self._ev_server_path = ev_server_path
+
+def name_number(self):
+return self._name_number
+
+def write_lua_cfg(self):
+lua_support = os.path.join(os.path.dirname(__file__), 'lua')
+cfg = {
+'test': {
+'event_path': self._ev_server_path,
+'lua_support': lua_support,
+}
+}
+lua_cfg_file = os.path.join(self._tmp_dir, "lua_" + self._name_number 
+ ".lua")
+lua_script = template.render(self._lua_template, cfg)
+with open(lua_cfg_file, 'w') as w:
+w.write(lua_script)
+return lua_cfg_file
+
+def write_mob_cfg(self, lua_filename, phy_filename):
+(imsi, ki) = next(self._imsi_ki_generator)
+cfg = {
+'test': {
+'script': lua_filename,
+'virt_phy': phy_filename,
+'imsi': imsi,
+'ki_comp128': ki,
+'ms_number': self._name_number,
+}
+}
+mob_cfg_file = os.path.join(self._tmp_dir, "mob_" + self._name_number 
+ ".cfg")
+mob_vty = template.render(self._cfg_template, cfg)
+with open(mob_cfg_file, 'w') as w:
+w.write(mob_vty)
+return mob_cfg_file
+
+def start_virtphy(self, loop):
+self._phy_filename = os.path.join(self._tmp_dir, "osmocom_l2_" + 
self._name_number)
+
+self.log("Starting virtphy process")
+args = ["virtphy", "--l1ctl-sock=" + self._phy_filename]
+self.log(' '.join(args))
+self._vphy_proc = subprocess.Popen(args, stderr=_devnull, 
stdout=_devnull)
+
+def verify_phy_ready(self):
+while True:
+if os.path.exists(self._phy_filename):
+return
+import time
+time.sleep(0.2)
+
+def start_mobile(self, loop):
+lua_filename = self.write_lua_cfg()
+mob_filename = self.write_mob_cfg(lua_filename, self._phy_filename)
+
+self.log("Starting process")
+# Let the kernel pick an unused port for the VTY.
+args = ["mobile", "-c", mob_filename, "--vty-port=0"]
+self.log(' '.join(args))
+self._omob_proc = subprocess.Popen(args, stderr=_devnull, 
stdout=_devnull)
+
+def kill(self):
+"""Clean up things."""
+if self._vphy_proc:
+self._vphy_proc.kill()
+if self._omob_proc:
+self._omob_proc.kill()

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5c6d742842d7f3e0a1858436ef3f8634d8c0582d
Gerrit-PatchSet: 1