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/nitb_osmo.py b/src/osmo_gsm_tester/obj/nitb_osmo.py
index ea00a75..a978b71 100644
--- a/src/osmo_gsm_tester/obj/nitb_osmo.py
+++ b/src/osmo_gsm_tester/obj/nitb_osmo.py
@@ -36,6 +36,7 @@
         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 @@
         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 @@
             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 @@
         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):