add bsc.vty: always keep a BSC VTY connection ready

The BSC's VTY port will be used to trigger manual handover, and to
retrieve a list of active lchans from the BSC, in the upcoming
handover_2G test suite, I0b2671304165a1aaae2b386af46fbd8b098e3bd8.

Change-Id: I06652db04fc9e48748f3c2196334f5352e9cc48a
diff --git a/src/osmo_gsm_tester/obj/bsc_osmo.py b/src/osmo_gsm_tester/obj/bsc_osmo.py
index 1763dcd..bd8649b 100644
--- a/src/osmo_gsm_tester/obj/bsc_osmo.py
+++ b/src/osmo_gsm_tester/obj/bsc_osmo.py
@@ -20,10 +20,11 @@
 import os
 import re
 import pprint
+import re
 
 from ..core import log, util, config, template, process
 from ..core import schema
-from . import osmo_ctrl, pcap_recorder
+from . import osmo_ctrl, osmo_vty, pcap_recorder
 
 def on_register_schemas():
     config_schema = {
@@ -48,6 +49,7 @@
         self.msc = msc
         self.mgw = mgw
         self.stp = stp
+        self.vty = None
 
     def start(self):
         self.log('Starting osmo-bsc')
@@ -79,6 +81,9 @@
         self.testenv.remember_to_stop(self.process)
         self.process.launch()
 
+        self.vty = OsmoBscVty(self)
+        self.vty.connect()
+
     def configure(self):
         self.config_file = self.run_dir.new_file('osmo-bsc.cfg')
         self.dbg(config_file=self.config_file)
@@ -150,6 +155,10 @@
     def running(self):
         return not self.process.terminated()
 
+    def cleanup(self):
+        if self.vty is not None:
+            self.vty.disconnect()
+            self.vty = None
 
 class OsmoBscCtrl(log.Origin):
     PORT = 4249
@@ -178,4 +187,9 @@
                         return True
         return False
 
+class OsmoBscVty(osmo_vty.OsmoVty):
+    def __init__(self, bsc, port=4242):
+        self.bsc = bsc
+        super().__init__(self.bsc.addr(), port)
+
 # vim: expandtab tabstop=4 shiftwidth=4