Pau Espin Pedrol | feb66e7 | 2019-03-04 18:37:04 +0100 | [diff] [blame] | 1 | # osmo_gsm_tester: specifics for running a osmo-bts-oc2g |
| 2 | # |
| 3 | # Copyright (C) 2019 by sysmocom - s.f.m.c. GmbH |
| 4 | # |
| 5 | # Author: Pau Espin Pedrol <pespin@sysmocom.de> |
| 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as |
| 9 | # published by the Free Software Foundation, either version 3 of the |
| 10 | # License, or (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | import os |
| 21 | import pprint |
Pau Espin Pedrol | e1a58bd | 2020-04-10 20:46:07 +0200 | [diff] [blame] | 22 | from ..core import log, config, util, template, process, remote |
Pau Espin Pedrol | e8bbcbf | 2020-04-10 19:51:31 +0200 | [diff] [blame] | 23 | from . import pcu_oc2g, bts_osmo |
Pau Espin Pedrol | feb66e7 | 2019-03-04 18:37:04 +0100 | [diff] [blame] | 24 | |
| 25 | class OsmoBtsOC2G(bts_osmo.OsmoBts): |
| 26 | ############## |
| 27 | # PROTECTED |
| 28 | ############## |
| 29 | |
| 30 | REMOTE_DIR = '/osmo-gsm-tester-bts' |
| 31 | BTS_OC2G_BIN = 'osmo-bts-oc2g' |
| 32 | BTS_OC2G_CFG = 'osmo-bts-oc2g.cfg' |
| 33 | |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 34 | def __init__(self, testenv, conf): |
| 35 | super().__init__(testenv, conf, OsmoBtsOC2G.BTS_OC2G_BIN, 'osmo_bts_oc2g') |
Pau Espin Pedrol | feb66e7 | 2019-03-04 18:37:04 +0100 | [diff] [blame] | 36 | self.run_dir = None |
| 37 | self.inst = None |
| 38 | self.remote_inst = None |
| 39 | self.remote_dir = None |
Pau Espin Pedrol | bd552f9 | 2020-04-10 02:18:05 +0200 | [diff] [blame] | 40 | self.proc_bts = None |
Pau Espin Pedrol | feb66e7 | 2019-03-04 18:37:04 +0100 | [diff] [blame] | 41 | self.remote_user = 'root' |
| 42 | |
| 43 | def _direct_pcu_enabled(self): |
| 44 | return util.str2bool(self.conf.get('direct_pcu')) |
| 45 | |
Pau Espin Pedrol | feb66e7 | 2019-03-04 18:37:04 +0100 | [diff] [blame] | 46 | def create_pcu(self): |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 47 | return pcu_oc2g.OsmoPcuOC2G(self.testenv, self, self.conf) |
Pau Espin Pedrol | feb66e7 | 2019-03-04 18:37:04 +0100 | [diff] [blame] | 48 | |
| 49 | def configure(self): |
| 50 | if self.bsc is None: |
| 51 | raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be configured') |
| 52 | |
| 53 | self.config_file = self.run_dir.new_file(OsmoBtsOC2G.BTS_OC2G_CFG) |
| 54 | self.dbg(config_file=self.config_file) |
| 55 | |
| 56 | values = { 'osmo_bts_oc2g': config.get_defaults('osmo_bts_oc2g') } |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 57 | config.overlay(values, self.testenv.suite().config()) |
Pau Espin Pedrol | feb66e7 | 2019-03-04 18:37:04 +0100 | [diff] [blame] | 58 | config.overlay(values, { |
| 59 | 'osmo_bts_oc2g': { |
| 60 | 'oml_remote_ip': self.bsc.addr(), |
| 61 | 'pcu_socket_path': self.pcu_socket_path(), |
| 62 | } |
| 63 | }) |
| 64 | config.overlay(values, { 'osmo_bts_oc2g': self.conf }) |
| 65 | |
| 66 | self.dbg('OSMO-BTS-OC2G CONFIG:\n' + pprint.pformat(values)) |
| 67 | |
| 68 | with open(self.config_file, 'w') as f: |
| 69 | r = template.render(OsmoBtsOC2G.BTS_OC2G_CFG, values) |
| 70 | self.dbg(r) |
| 71 | f.write(r) |
| 72 | |
| 73 | ######################## |
| 74 | # PUBLIC - INTERNAL API |
| 75 | ######################## |
| 76 | def pcu_socket_path(self): |
| 77 | return os.path.join(OsmoBtsOC2G.REMOTE_DIR, 'pcu_bts') |
| 78 | |
| 79 | def conf_for_bsc(self): |
| 80 | values = self.conf_for_bsc_prepare() |
Pau Espin Pedrol | feb66e7 | 2019-03-04 18:37:04 +0100 | [diff] [blame] | 81 | self.dbg(conf=values) |
| 82 | return values |
| 83 | |
| 84 | ################### |
| 85 | # PUBLIC (test API included) |
| 86 | ################### |
| 87 | # We get log from ssh stdout instead of usual stderr. |
| 88 | def ready_for_pcu(self): |
| 89 | if not self.proc_bts or not self.proc_bts.is_running: |
| 90 | return False |
| 91 | return 'BTS is up' in (self.proc_bts.get_stdout() or '') |
| 92 | |
| 93 | def start(self, keepalive=False): |
| 94 | if self.bsc is None: |
| 95 | raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be started') |
| 96 | log.log('Starting OsmoBtsOC2G to connect to', self.bsc) |
Pau Espin Pedrol | 2a2d846 | 2020-05-11 10:56:52 +0200 | [diff] [blame] | 97 | self.run_dir = util.Dir(self.testenv.test().get_run_dir().new_dir(self.name())) |
Pau Espin Pedrol | feb66e7 | 2019-03-04 18:37:04 +0100 | [diff] [blame] | 98 | self.configure() |
| 99 | |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 100 | self.inst = util.Dir(os.path.abspath(self.testenv.suite().trial().get_inst(OsmoBtsOC2G.BTS_OC2G_BIN))) |
Pau Espin Pedrol | feb66e7 | 2019-03-04 18:37:04 +0100 | [diff] [blame] | 101 | lib = self.inst.child('lib') |
| 102 | if not os.path.isdir(lib): |
| 103 | raise log.Error('No lib/ in', self.inst) |
| 104 | if not self.inst.isfile('bin', OsmoBtsOC2G.BTS_OC2G_BIN): |
| 105 | raise log.Error('No osmo-bts-oc2g binary in', self.inst) |
| 106 | |
Pau Espin Pedrol | 2eafb03 | 2020-01-29 17:56:14 +0100 | [diff] [blame] | 107 | rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self.remote_addr()) |
| 108 | remote_prefix_dir = util.Dir(OsmoBtsOC2G.REMOTE_DIR) |
| 109 | self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst)))) |
| 110 | remote_run_dir = util.Dir(remote_prefix_dir.child(OsmoBtsOC2G.BTS_OC2G_BIN)) |
Pau Espin Pedrol | feb66e7 | 2019-03-04 18:37:04 +0100 | [diff] [blame] | 111 | remote_config_file = remote_run_dir.child(OsmoBtsOC2G.BTS_OC2G_CFG) |
Pau Espin Pedrol | feb66e7 | 2019-03-04 18:37:04 +0100 | [diff] [blame] | 112 | |
Pau Espin Pedrol | 2eafb03 | 2020-01-29 17:56:14 +0100 | [diff] [blame] | 113 | rem_host.recreate_remote_dir(self.remote_inst) |
| 114 | rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir) |
| 115 | rem_host.create_remote_dir(remote_run_dir) |
| 116 | rem_host.scp('scp-cfg-to-remote', self.config_file, remote_config_file) |
| 117 | |
| 118 | remote_lib = self.remote_inst.child('lib') |
| 119 | remote_binary = self.remote_inst.child('bin', OsmoBtsOC2G.BTS_OC2G_BIN) |
Pau Espin Pedrol | feb66e7 | 2019-03-04 18:37:04 +0100 | [diff] [blame] | 120 | args = ('LD_LIBRARY_PATH=%s' % remote_lib, |
| 121 | remote_binary, '-c', remote_config_file, '-r', '1', |
| 122 | '-i', self.bsc.addr()) |
| 123 | |
| 124 | if self._direct_pcu_enabled(): |
| 125 | args += ('-M',) |
| 126 | |
Pau Espin Pedrol | bd552f9 | 2020-04-10 02:18:05 +0200 | [diff] [blame] | 127 | self.proc_bts = rem_host.RemoteProcess(OsmoBtsOC2G.BTS_OC2G_BIN, args) |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 128 | self.testenv.remember_to_stop(self.proc_bts, keepalive) |
Pau Espin Pedrol | bd552f9 | 2020-04-10 02:18:05 +0200 | [diff] [blame] | 129 | self.proc_bts.launch() |
Pau Espin Pedrol | feb66e7 | 2019-03-04 18:37:04 +0100 | [diff] [blame] | 130 | # vim: expandtab tabstop=4 shiftwidth=4 |