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
diff --git a/src/osmo_gsm_tester/obj/bsc_osmo.py b/src/osmo_gsm_tester/obj/bsc_osmo.py
index 510063a..877db29 100644
--- a/src/osmo_gsm_tester/obj/bsc_osmo.py
+++ b/src/osmo_gsm_tester/obj/bsc_osmo.py
@@ -50,6 +50,7 @@
self.mgw = mgw
self.stp = stp
self.vty = None
+ self.ctrl = None
def start(self):
self.log('Starting osmo-bsc')
@@ -84,6 +85,9 @@
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 @@
# 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 @@
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):