keep Ctrl connections open for bsc, msc and nitb objects

The pattern to use 'with' to keep a CTRL connection open adds indents to
every test script that wants to avoid multiple reconnections to the
CTRL. Instead, keeping a single open connection that is cleaned up on
{bsc,msc,nitb} object cleanup ensures that a) the program started up
successfully and opened a CTRL port, b) always has a CTRL open without
having to worry about it and c) keeps test scripts less
complex/indented/crufted.

(These are all current users of the OsmoCtrl API.)

Change-Id: I53fedbe569c5ccbc4b1a17dafe1f8d1bb8200b24
changes/70/21670/1
Neels Hofmeyr 2 years ago
parent 5b04ef213e
commit 012a17da6a
  1. 16
      src/osmo_gsm_tester/obj/bsc_osmo.py
  2. 11
      src/osmo_gsm_tester/obj/msc_osmo.py
  3. 16
      src/osmo_gsm_tester/obj/nitb_osmo.py
  4. 8
      src/osmo_gsm_tester/testenv.py

@ -50,6 +50,7 @@ class OsmoBsc(log.Origin):
self.mgw = mgw
self.stp = stp
self.vty = None
self.ctrl = None
def start(self):
self.log('Starting osmo-bsc')
@ -84,6 +85,9 @@ class OsmoBsc(log.Origin):
self.vty = OsmoBscVty(self)
self.vty.connect()
self.ctrl = OsmoBscCtrl(self)
self.ctrl.connect()
def configure(self):
self.config_file = self.run_dir.new_file('osmo-bsc.cfg')
self.dbg(config_file=self.config_file)
@ -149,10 +153,8 @@ class OsmoBsc(log.Origin):
# over this list, we have a 1:1 match in indexes.
return self.bts.index(bts)
def bts_is_connected(self, bts, use_ctrl=None):
if use_ctrl is None:
use_ctrl = self.ctrl()
return use_ctrl.bts_is_connected(self.bts_num(bts))
def bts_is_connected(self, bts):
return self.ctrl.bts_is_connected(self.bts_num(bts))
def running(self):
return not self.process.terminated()
@ -161,9 +163,9 @@ class OsmoBsc(log.Origin):
if self.vty is not None:
self.vty.disconnect()
self.vty = None
def ctrl(self):
return OsmoBscCtrl(self)
if self.ctrl is not None:
self.ctrl.disconnect()
self.ctrl = None
class OsmoBscCtrl(osmo_ctrl.OsmoCtrl):
def __init__(self, bsc, port=4249):

@ -49,6 +49,7 @@ class OsmoMsc(log.Origin):
self.mgw = mgw
self.stp = stp
self.smsc = smsc.Smsc((ip_address.get('addr'), 2775))
self.ctrl = None
def start(self):
self.log('Starting osmo-msc')
@ -75,6 +76,9 @@ class OsmoMsc(log.Origin):
self.testenv.remember_to_stop(self.process)
self.process.launch()
self.ctrl = OsmoMscCtrl(self)
self.ctrl.connect()
def configure(self):
self.config_file = self.run_dir.new_file('osmo-msc.cfg')
self.dbg(config_file=self.config_file)
@ -147,7 +151,7 @@ class OsmoMsc(log.Origin):
return all([(imsi in attached) for imsi in imsis])
def imsi_list_attached(self):
return OsmoMscCtrl(self).subscriber_list_active()
return self.ctrl.subscriber_list_active()
def set_emergency_call_msisdn(self, msisdn):
self.dbg('Setting Emergency Call MSISDN', msisdn=msisdn)
@ -156,6 +160,11 @@ class OsmoMsc(log.Origin):
def running(self):
return not self.process.terminated()
def cleanup(self):
if self.ctrl is not None:
self.ctrl.disconnect()
self.ctrl = None
class OsmoMscCtrl(osmo_ctrl.OsmoCtrl):
def __init__(self, msc, port=4255):

@ -36,6 +36,7 @@ class OsmoNitb(log.Origin):
self.ip_address = ip_address
self.bts = []
self.smsc = smsc.Smsc((ip_address.get('addr'), 2775))
self.ctrl = None
def start(self):
self.log('Starting osmo-nitb')
@ -62,6 +63,9 @@ class OsmoNitb(log.Origin):
self.testenv.remember_to_stop(self.process)
self.process.launch()
self.ctrl = OsmoNitbCtrl(self)
self.ctrl.connect()
def configure(self):
self.config_file = self.run_dir.new_file('osmo-nitb.cfg')
self.dbg(config_file=self.config_file)
@ -134,11 +138,11 @@ class OsmoNitb(log.Origin):
raise log.Error("Auth algo %r selected and no KI specified" % algo)
self.log('Add subscriber', msisdn=msisdn, imsi=modem.imsi())
OsmoNitbCtrl(self).subscriber_add(modem.imsi(), msisdn, modem.ki(), algo)
return self.ctrl.subscriber_add(modem.imsi(), msisdn, modem.ki(), algo)
def subscriber_delete(self, modem):
self.log('Delete subscriber', imsi=modem.imsi())
OsmoNitbCtrl(self).subscriber_delete(modem.imsi())
return self.ctrl.subscriber_delete(modem.imsi())
def subscriber_attached(self, *modems):
return self.imsi_attached(*[m.imsi() for m in modems])
@ -149,14 +153,18 @@ class OsmoNitb(log.Origin):
return all([(imsi in attached) for imsi in imsis])
def imsi_list_attached(self):
return OsmoNitbCtrl(self).subscriber_list_active()
return self.ctrl.subscriber_list_active()
def bts_is_connected(self, bts):
return OsmoNitbCtrl(self).bts_is_connected(self.bts_num(bts))
return self.ctrl.bts_is_connected(self.bts_num(bts))
def running(self):
return not self.process.terminated()
def cleanup(self):
if self.ctrl is not None:
self.ctrl.disconnect()
self.ctrl = None
class OsmoNitbCtrl(osmo_ctrl.OsmoCtrl):
def __init__(self, nitb, port=4249):

@ -194,7 +194,9 @@ class TestEnv(log_module.Origin):
from .obj.nitb_osmo import OsmoNitb
if ip_address is None:
ip_address = self.ip_address()
return OsmoNitb(self, ip_address)
nitb_obj = OsmoNitb(self, ip_address)
self.register_for_cleanup(nitb_obj)
return nitb_obj
def hlr(self, ip_address=None):
from .obj.hlr_osmo import OsmoHlr
@ -230,7 +232,9 @@ class TestEnv(log_module.Origin):
from .obj import msc_osmo
if ip_address is None:
ip_address = self.ip_address()
return msc_osmo.OsmoMsc(self, hlr, mgcpgw, stp, ip_address)
msc_obj = msc_osmo.OsmoMsc(self, hlr, mgcpgw, stp, ip_address)
self.register_for_cleanup(msc_obj)
return msc_obj
def bsc(self, msc, mgw, stp, ip_address=None):
from .obj.bsc_osmo import OsmoBsc

Loading…
Cancel
Save