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
diff --git a/src/osmo_gsm_tester/obj/osmo_vty.py b/src/osmo_gsm_tester/obj/osmo_vty.py
index 3f8abf7..6fee5dc 100644
--- a/src/osmo_gsm_tester/obj/osmo_vty.py
+++ b/src/osmo_gsm_tester/obj/osmo_vty.py
@@ -38,6 +38,9 @@
Using 'with' ensures that the connection is closed again.
There should not be nested 'with' statements on this object.
+
+ Note that test env objects (like tenv.bsc()) may keep a VTY connected until the test exits. A 'with' should not
+ be used on those.
'''
##############
diff --git a/src/osmo_gsm_tester/testenv.py b/src/osmo_gsm_tester/testenv.py
index a74891d..ebc8f91 100644
--- a/src/osmo_gsm_tester/testenv.py
+++ b/src/osmo_gsm_tester/testenv.py
@@ -235,7 +235,9 @@
from .obj.bsc_osmo import OsmoBsc
if ip_address is None:
ip_address = self.ip_address()
- return OsmoBsc(self, msc, mgw, stp, ip_address)
+ bsc_obj = OsmoBsc(self, msc, mgw, stp, ip_address)
+ self.register_for_cleanup(bsc_obj)
+ return bsc_obj
def stp(self, ip_address=None):
from .obj.stp_osmo import OsmoStp