Create bts abstract classes to avoid code duplication and ease development

A lot of code can be shared by all osmocom related BTS we currently use
(sysmo, octphy, trx). This commits moves all this easily shareable code
to an abstract class OsmoBts which all (osmocom) BTS use.

Some bits of code do not apply for osmo-bts-sysmo but it's still shared
by BTS running in the main unit (octphy, trx), for instance the pcu
socket handling. Those are put together in OsmoBtsMainUnit.

This way we have:
log.Origin<-OsmoBts<-OsmoBtsMainUnit<-OsmoBtsOctphy
log.Origin<-OsmoBts<-OsmoBtsMainUnit<-OsmoBtsTrx
log.Origin<-OsmoBts<-OsmoBtsSysmo

Also take the chance to categorize the different APIs in the new
abstract class based on their use and scope.

Some code changes while moving which were required:
- A new protected abstract API "create_pcu", which returns an object of
"pcu" interface. Subclasses implement this API returning either a
PcySysmo or a PcuOsmo object. This is needed to abstract the pcu()
getter into the base class.
- For BTS running in the main unit, pcu_sk_tmp_dir object is allocated
when first used (API pcu_socket_path()) instead of doing it in the
constructor. This is moved into OsmoBtsMainUnit

Change-Id: I86db35a7f2497d37360b2c56affa8bf6bf704ee2
diff --git a/src/osmo_gsm_tester/bts_octphy.py b/src/osmo_gsm_tester/bts_octphy.py
index f25823c..fd8d078 100644
--- a/src/osmo_gsm_tester/bts_octphy.py
+++ b/src/osmo_gsm_tester/bts_octphy.py
@@ -20,56 +20,21 @@
 import os
 import pprint
 import tempfile
-from . import log, config, util, template, process, event_loop, pcu_osmo
+from . import log, config, util, template, process, event_loop, pcu_osmo, bts_osmo
 
-class OsmoBtsOctphy(log.Origin):
-    suite_run = None
-    bsc = None
-    sgsn = None
+class OsmoBtsOctphy(bts_osmo.OsmoBtsMainUnit):
     run_dir = None
     inst = None
     env = None
-    pcu_sk_tmp_dir = None
-    values = None
-    lac = None
-    rac = None
-    cellid = None
-    bvci = None
-    proc_bts = None
-    _pcu = None
 
     BIN_BTS_OCTPHY = 'osmo-bts-octphy'
 
     CONF_BTS_OCTPHY = 'osmo-bts-octphy.cfg'
 
     def __init__(self, suite_run, conf):
-        super().__init__(log.C_RUN, OsmoBtsOctphy.BIN_BTS_OCTPHY)
-        self.suite_run = suite_run
-        self.conf = conf
+        super().__init__(suite_run, conf, OsmoBtsOctphy.BIN_BTS_OCTPHY)
         self.env = {}
         self.values = {}
-        self.pcu_sk_tmp_dir = tempfile.mkdtemp('', 'ogtpcusk')
-        if len(self.pcu_socket_path().encode()) > 107:
-            raise log.Error('Path for pcu socket is longer than max allowed len for unix socket path (107):', self.pcu_socket_path())
-
-    def cleanup(self):
-        if self.pcu_sk_tmp_dir:
-            try:
-                os.remove(self.pcu_socket_path())
-            except OSError:
-                pass
-            os.rmdir(self.pcu_sk_tmp_dir)
-
-    def pcu(self):
-        if self._pcu is None:
-            self._pcu = pcu_osmo.OsmoPcu(self.suite_run, self, self.conf)
-        return self._pcu
-
-    def pcu_socket_path(self):
-        return os.path.join(self.pcu_sk_tmp_dir, 'pcu_bts')
-
-    def remote_addr(self):
-        return self.conf.get('addr')
 
     def start(self):
         if self.bsc is None:
@@ -185,27 +150,4 @@
         self.dbg(conf=values)
         return values
 
-    def ready_for_pcu(self):
-        if not self.proc_bts or not self.proc_bts.is_running:
-            return False
-        return 'BTS is up' in (self.proc_bts.get_stderr() or '')
-
-    def set_bsc(self, bsc):
-        self.bsc = bsc
-
-    def set_sgsn(self, sgsn):
-        self.sgsn = sgsn
-
-    def set_lac(self, lac):
-        self.lac = lac
-
-    def set_rac(self, rac):
-        self.rac = rac
-
-    def set_cellid(self, cellid):
-        self.cellid = cellid
-
-    def set_bvci(self, bvci):
-        self.bvci = bvci
-
 # vim: expandtab tabstop=4 shiftwidth=4