Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 1 | # osmo_gsm_tester: specifics for running an osmo-bts-trx |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 2 | # |
| 3 | # Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH |
| 4 | # |
| 5 | # Author: Neels Hofmeyr <neels@hofmeyr.de> |
| 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify |
Harald Welte | 2720534 | 2017-06-03 09:51:45 +0200 | [diff] [blame] | 8 | # it under the terms of the GNU General Public License as |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 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 |
Harald Welte | 2720534 | 2017-06-03 09:51:45 +0200 | [diff] [blame] | 15 | # GNU General Public License for more details. |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 16 | # |
Harald Welte | 2720534 | 2017-06-03 09:51:45 +0200 | [diff] [blame] | 17 | # You should have received a copy of the GNU General Public License |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | import os |
Neels Hofmeyr | 943c81d | 2017-05-22 20:16:03 +0200 | [diff] [blame] | 21 | import pprint |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 22 | from abc import ABCMeta, abstractmethod |
Pau Espin Pedrol | e1a58bd | 2020-04-10 20:46:07 +0200 | [diff] [blame] | 23 | from ..core import log, config, util, template, process, remote |
Pau Espin Pedrol | ea8c3d4 | 2020-05-04 12:05:05 +0200 | [diff] [blame] | 24 | from ..core import schema |
Pau Espin Pedrol | e1a58bd | 2020-04-10 20:46:07 +0200 | [diff] [blame] | 25 | from ..core.event_loop import MainLoop |
Pau Espin Pedrol | e8bbcbf | 2020-04-10 19:51:31 +0200 | [diff] [blame] | 26 | from . import powersupply, bts_osmo |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 27 | |
Pau Espin Pedrol | ea8c3d4 | 2020-05-04 12:05:05 +0200 | [diff] [blame] | 28 | def on_register_schemas(): |
| 29 | resource_schema = { |
| 30 | 'osmo_trx.launch_trx': schema.BOOL_STR, |
| 31 | 'osmo_trx.type': schema.STR, |
| 32 | 'osmo_trx.clock_reference': schema.OSMO_TRX_CLOCK_REF, |
| 33 | 'osmo_trx.trx_ip': schema.IPV4, |
| 34 | 'osmo_trx.remote_user': schema.STR, |
| 35 | 'osmo_trx.dev_args': schema.STR, |
| 36 | 'osmo_trx.multi_arfcn': schema.BOOL_STR, |
| 37 | 'osmo_trx.max_trxd_version': schema.UINT, |
| 38 | 'osmo_trx.channels[].rx_path': schema.STR, |
| 39 | 'osmo_trx.channels[].tx_path': schema.STR, |
| 40 | } |
| 41 | schema.register_resource_schema('bts', resource_schema) |
| 42 | |
Pau Espin Pedrol | c9817a5 | 2017-12-13 19:52:27 +0100 | [diff] [blame] | 43 | class OsmoBtsTrx(bts_osmo.OsmoBtsMainUnit): |
Pau Espin Pedrol | 2e54295 | 2017-12-14 19:08:51 +0100 | [diff] [blame] | 44 | ############## |
| 45 | # PROTECTED |
| 46 | ############## |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 47 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 48 | BIN_BTS_TRX = 'osmo-bts-trx' |
| 49 | BIN_PCU = 'osmo-pcu' |
| 50 | |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 51 | CONF_BTS_TRX = 'osmo-bts-trx.cfg' |
| 52 | |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 53 | def __init__(self, testenv, conf): |
| 54 | super().__init__(testenv, conf, OsmoBtsTrx.BIN_BTS_TRX, 'osmo_bts_trx') |
Pau Espin Pedrol | 5860367 | 2018-08-09 13:45:55 +0200 | [diff] [blame] | 55 | self.run_dir = None |
| 56 | self.inst = None |
| 57 | self.trx = None |
Pau Espin Pedrol | 55cee16 | 2019-09-10 13:47:04 +0200 | [diff] [blame] | 58 | self.pwsup_list = [] |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 59 | self.env = {} |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 60 | self.gen_conf = {} |
Pau Espin Pedrol | 404e150 | 2017-08-22 11:17:43 +0200 | [diff] [blame] | 61 | |
| 62 | def trx_remote_ip(self): |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 63 | conf_ip = self.conf.get('osmo_trx', {}).get('trx_ip', None) |
Pau Espin Pedrol | 404e150 | 2017-08-22 11:17:43 +0200 | [diff] [blame] | 64 | if conf_ip is not None: |
| 65 | return conf_ip |
| 66 | # if 'trx_remote_ip' is not configured, use same IP as BTS |
| 67 | return self.remote_addr() |
| 68 | |
Pau Espin Pedrol | b1526b9 | 2018-05-22 20:32:30 +0200 | [diff] [blame] | 69 | def launch_process(self, keepalive, binary_name, *args): |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 70 | binary = os.path.abspath(self.inst.child('bin', binary_name)) |
| 71 | run_dir = self.run_dir.new_dir(binary_name) |
| 72 | if not os.path.isfile(binary): |
| 73 | raise RuntimeError('Binary missing: %r' % binary) |
| 74 | proc = process.Process(binary_name, run_dir, |
| 75 | (binary,) + args, |
| 76 | env=self.env) |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 77 | self.testenv.remember_to_stop(proc, keepalive) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 78 | proc.launch() |
Neels Hofmeyr | fd39f3e | 2017-05-07 02:02:35 +0200 | [diff] [blame] | 79 | return proc |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 80 | |
| 81 | def configure(self): |
Neels Hofmeyr | c4ba4a6 | 2017-05-18 19:31:44 +0200 | [diff] [blame] | 82 | if self.bsc is None: |
| 83 | raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be configured') |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 84 | self.config_file = self.run_dir.new_file(OsmoBtsTrx.CONF_BTS_TRX) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 85 | self.dbg(config_file=self.config_file) |
| 86 | |
| 87 | values = dict(osmo_bts_trx=config.get_defaults('osmo_bts_trx')) |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 88 | config.overlay(values, dict(osmo_bts_trx=dict(osmo_trx=config.get_defaults('osmo_trx')))) |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 89 | config.overlay(values, self.testenv.suite().config()) |
Pau Espin Pedrol | 329b6f4 | 2017-08-08 13:55:24 +0200 | [diff] [blame] | 90 | config.overlay(values, { |
| 91 | 'osmo_bts_trx': { |
| 92 | 'oml_remote_ip': self.bsc.addr(), |
Pau Espin Pedrol | 15aae98 | 2017-09-08 13:55:54 +0200 | [diff] [blame] | 93 | 'pcu_socket_path': self.pcu_socket_path(), |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 94 | 'osmo_trx': { |
| 95 | 'bts_ip': self.remote_addr(), |
| 96 | 'trx_ip': self.trx_remote_ip(), |
Pau Espin Pedrol | 29b7132 | 2020-04-06 18:14:29 +0200 | [diff] [blame] | 97 | 'egprs': 'enable' if self.egprs_enabled() else 'disable', |
Pau Espin Pedrol | 44b7ea1 | 2018-09-17 20:24:13 +0200 | [diff] [blame] | 98 | 'channels': [{} for trx_i in range(self.num_trx())] |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 99 | } |
Pau Espin Pedrol | 329b6f4 | 2017-08-08 13:55:24 +0200 | [diff] [blame] | 100 | } |
| 101 | }) |
| 102 | config.overlay(values, { 'osmo_bts_trx': self.conf }) |
Neels Hofmeyr | 943c81d | 2017-05-22 20:16:03 +0200 | [diff] [blame] | 103 | |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 104 | self.gen_conf = values |
Neels Hofmeyr | 943c81d | 2017-05-22 20:16:03 +0200 | [diff] [blame] | 105 | self.dbg('OSMO-BTS-TRX CONFIG:\n' + pprint.pformat(values)) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 106 | |
| 107 | with open(self.config_file, 'w') as f: |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 108 | r = template.render(OsmoBtsTrx.CONF_BTS_TRX, values) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 109 | self.dbg(r) |
| 110 | f.write(r) |
| 111 | |
Pau Espin Pedrol | 55cee16 | 2019-09-10 13:47:04 +0200 | [diff] [blame] | 112 | self.pwsup_list = [None] * self.num_trx() |
| 113 | # Construct trx_list appending with empty dicts if needed: |
| 114 | conf_trx_list = self.conf.get('trx_list', []) |
| 115 | conf_trx_list = conf_trx_list + [{}] * (self.num_trx() - len(conf_trx_list)) |
| 116 | for trx_i in range(self.num_trx()): |
| 117 | pwsup_opt = conf_trx_list[trx_i].get('power_supply', {}) |
| 118 | if not pwsup_opt: |
| 119 | self.dbg('no power_supply configured for TRX %d' % trx_i) |
| 120 | continue |
| 121 | pwsup_type = pwsup_opt.get('type') |
| 122 | if not pwsup_type: |
| 123 | raise log.Error('No type attribute provided in power_supply conf for TRX %d!' % trx_i) |
| 124 | self.pwsup_list[trx_i] = powersupply.get_instance_by_type(pwsup_type, pwsup_opt) |
| 125 | |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 126 | def launch_trx_enabled(self): |
| 127 | return util.str2bool(self.gen_conf['osmo_bts_trx'].get('osmo_trx', {}).get('launch_trx')) |
| 128 | |
| 129 | def get_osmo_trx_type(self): |
| 130 | return self.gen_conf['osmo_bts_trx'].get('osmo_trx', {}).get('type') |
| 131 | |
Pau Espin Pedrol | 2e54295 | 2017-12-14 19:08:51 +0100 | [diff] [blame] | 132 | ######################## |
| 133 | # PUBLIC - INTERNAL API |
| 134 | ######################## |
Neels Hofmeyr | c4ba4a6 | 2017-05-18 19:31:44 +0200 | [diff] [blame] | 135 | def conf_for_bsc(self): |
Pau Espin Pedrol | e519462 | 2018-05-07 13:36:58 +0200 | [diff] [blame] | 136 | values = self.conf_for_bsc_prepare() |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 137 | self.dbg(conf=values) |
| 138 | return values |
| 139 | |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 140 | def conf_for_osmotrx(self): |
| 141 | return dict(osmo_trx=self.gen_conf['osmo_bts_trx'].get('osmo_trx', {})) |
| 142 | |
Pau Espin Pedrol | 55cee16 | 2019-09-10 13:47:04 +0200 | [diff] [blame] | 143 | def cleanup(self): |
| 144 | i = 0 |
| 145 | for pwsup in self.pwsup_list: |
| 146 | if pwsup: |
| 147 | self.dbg('Powering off TRX %d' % i) |
| 148 | pwsup.power_set(False) |
| 149 | i = i + 1 |
| 150 | self.pwsup_list = [] |
| 151 | |
Pau Espin Pedrol | 2e54295 | 2017-12-14 19:08:51 +0100 | [diff] [blame] | 152 | ################### |
| 153 | # PUBLIC (test API included) |
| 154 | ################### |
Pau Espin Pedrol | b1526b9 | 2018-05-22 20:32:30 +0200 | [diff] [blame] | 155 | def start(self, keepalive=False): |
Pau Espin Pedrol | 2e54295 | 2017-12-14 19:08:51 +0100 | [diff] [blame] | 156 | if self.bsc is None: |
| 157 | raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be started') |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 158 | self.testenv.poll() |
Pau Espin Pedrol | 2e54295 | 2017-12-14 19:08:51 +0100 | [diff] [blame] | 159 | |
| 160 | self.log('Starting to connect to', self.bsc) |
Pau Espin Pedrol | 2a2d846 | 2020-05-11 10:56:52 +0200 | [diff] [blame] | 161 | self.run_dir = util.Dir(self.testenv.test().get_run_dir().new_dir(self.name())) |
Pau Espin Pedrol | 2e54295 | 2017-12-14 19:08:51 +0100 | [diff] [blame] | 162 | self.configure() |
| 163 | |
Pau Espin Pedrol | 55cee16 | 2019-09-10 13:47:04 +0200 | [diff] [blame] | 164 | # Power cycle all TRX if needed (right now only TRX0 for SC5): |
| 165 | i = 0 |
| 166 | for pwsup in self.pwsup_list: |
| 167 | if pwsup: |
| 168 | self.dbg('Powering cycling TRX %d' % i) |
| 169 | pwsup.power_cycle(1.0) |
| 170 | i = i + 1 |
| 171 | |
Pau Espin Pedrol | 2e54295 | 2017-12-14 19:08:51 +0100 | [diff] [blame] | 172 | if self.launch_trx_enabled(): |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 173 | self.trx = OsmoTrx.get_instance_by_type(self.get_osmo_trx_type(), self.testenv, self.conf_for_osmotrx()) |
Pau Espin Pedrol | b1526b9 | 2018-05-22 20:32:30 +0200 | [diff] [blame] | 174 | self.trx.start(keepalive) |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 175 | self.log('Waiting for %s to start up...' % self.trx.name()) |
Pau Espin Pedrol | 664e383 | 2020-06-10 19:30:33 +0200 | [diff] [blame] | 176 | MainLoop.wait(self.trx.trx_ready) |
Pau Espin Pedrol | 2e54295 | 2017-12-14 19:08:51 +0100 | [diff] [blame] | 177 | |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 178 | self.inst = util.Dir(os.path.abspath(self.testenv.suite().trial().get_inst('osmo-bts'))) |
Pau Espin Pedrol | 2e54295 | 2017-12-14 19:08:51 +0100 | [diff] [blame] | 179 | lib = self.inst.child('lib') |
| 180 | if not os.path.isdir(lib): |
| 181 | raise RuntimeError('No lib/ in %r' % self.inst) |
| 182 | self.env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) } |
| 183 | |
Pau Espin Pedrol | b1526b9 | 2018-05-22 20:32:30 +0200 | [diff] [blame] | 184 | self.proc_bts = self.launch_process(keepalive, OsmoBtsTrx.BIN_BTS_TRX, '-r', '1', |
Pau Espin Pedrol | 2e54295 | 2017-12-14 19:08:51 +0100 | [diff] [blame] | 185 | '-c', os.path.abspath(self.config_file), |
Pau Espin Pedrol | c93707f | 2019-08-05 18:19:45 +0200 | [diff] [blame] | 186 | '-i', self.bsc.addr()) |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 187 | self.testenv.poll() |
Pau Espin Pedrol | 2e54295 | 2017-12-14 19:08:51 +0100 | [diff] [blame] | 188 | |
Pau Espin Pedrol | 55cee16 | 2019-09-10 13:47:04 +0200 | [diff] [blame] | 189 | |
| 190 | ################################################################################ |
| 191 | # TRX |
| 192 | ################################################################################ |
| 193 | |
| 194 | class Trx(log.Origin, metaclass=ABCMeta): |
| 195 | ############## |
| 196 | # PROTECTED |
| 197 | ############## |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 198 | def __init__(self, testenv, conf, name): |
Pau Espin Pedrol | 55cee16 | 2019-09-10 13:47:04 +0200 | [diff] [blame] | 199 | super().__init__(log.C_RUN, name) |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 200 | self.testenv = testenv |
Pau Espin Pedrol | 55cee16 | 2019-09-10 13:47:04 +0200 | [diff] [blame] | 201 | self.conf = conf |
Pau Espin Pedrol | 2a2d846 | 2020-05-11 10:56:52 +0200 | [diff] [blame] | 202 | self.run_dir = util.Dir(self.testenv.test().get_run_dir().new_dir(self.name())) |
Pau Espin Pedrol | 55cee16 | 2019-09-10 13:47:04 +0200 | [diff] [blame] | 203 | self.listen_ip = conf.get('osmo_trx', {}).get('trx_ip') |
| 204 | self.remote_user = conf.get('osmo_trx', {}).get('remote_user', None) |
| 205 | |
| 206 | @classmethod |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 207 | def get_instance_by_type(cls, type, testenv, conf): |
Pau Espin Pedrol | 55cee16 | 2019-09-10 13:47:04 +0200 | [diff] [blame] | 208 | KNOWN_OSMOTRX_TYPES = { |
| 209 | 'uhd': OsmoTrxUHD, |
| 210 | 'lms': OsmoTrxLMS, |
| 211 | 'sc5': TrxSC5 |
| 212 | } |
| 213 | osmo_trx_class = KNOWN_OSMOTRX_TYPES.get(type) |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 214 | return osmo_trx_class(testenv, conf) |
Pau Espin Pedrol | 55cee16 | 2019-09-10 13:47:04 +0200 | [diff] [blame] | 215 | |
| 216 | ############## |
| 217 | # PUBLIC (test API included) |
| 218 | ############## |
| 219 | @abstractmethod |
| 220 | def start(self, keepalive=False): |
| 221 | pass |
| 222 | |
| 223 | @abstractmethod |
| 224 | def trx_ready(self): |
| 225 | pass |
| 226 | |
| 227 | class OsmoTrx(Trx, metaclass=ABCMeta): |
Pau Espin Pedrol | 4773853 | 2017-08-15 16:20:07 +0200 | [diff] [blame] | 228 | |
Pau Espin Pedrol | edcc8d2 | 2018-03-04 19:58:23 +0100 | [diff] [blame] | 229 | CONF_OSMO_TRX = 'osmo-trx.cfg' |
Pau Espin Pedrol | a9006df | 2018-10-01 12:26:39 +0200 | [diff] [blame] | 230 | REMOTE_DIR = '/osmo-gsm-tester-trx/last_run' |
Pau Espin Pedrol | 302c756 | 2018-10-02 13:08:02 +0200 | [diff] [blame] | 231 | WRAPPER_SCRIPT = 'ssh_sigkiller.sh' |
Pau Espin Pedrol | 4773853 | 2017-08-15 16:20:07 +0200 | [diff] [blame] | 232 | |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 233 | ############## |
| 234 | # PROTECTED |
| 235 | ############## |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 236 | def __init__(self, testenv, conf): |
| 237 | super().__init__(testenv, conf, self.binary_name()) |
Pau Espin Pedrol | 4773853 | 2017-08-15 16:20:07 +0200 | [diff] [blame] | 238 | self.env = {} |
Pau Espin Pedrol | a9006df | 2018-10-01 12:26:39 +0200 | [diff] [blame] | 239 | self.log("OSMOTRX CONF: %r" % conf) |
Pau Espin Pedrol | a9006df | 2018-10-01 12:26:39 +0200 | [diff] [blame] | 240 | self.bts_ip = conf.get('osmo_trx', {}).get('bts_ip') |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 241 | self.inst = None |
| 242 | self.proc_trx = None |
| 243 | |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 244 | @abstractmethod |
| 245 | def binary_name(self): |
| 246 | 'Used by base class. Subclass can create different OsmoTRX implementations.' |
| 247 | pass |
Pau Espin Pedrol | 4773853 | 2017-08-15 16:20:07 +0200 | [diff] [blame] | 248 | |
Pau Espin Pedrol | edcc8d2 | 2018-03-04 19:58:23 +0100 | [diff] [blame] | 249 | def configure(self): |
| 250 | self.config_file = self.run_dir.new_file(OsmoTrx.CONF_OSMO_TRX) |
| 251 | self.dbg(config_file=self.config_file) |
| 252 | |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 253 | values = self.conf |
Pau Espin Pedrol | 1ff0376 | 2018-10-02 15:50:48 +0200 | [diff] [blame] | 254 | |
| 255 | # we don't need to enable multi-arfcn for single channel |
| 256 | if len(values.get('osmo_trx', {}).get('channels', [])) > 1: |
| 257 | multi_arfcn_bool = util.str2bool(values.get('osmo_trx', {}).get('multi_arfcn', False)) |
| 258 | else: |
| 259 | multi_arfcn_bool = False |
Pau Espin Pedrol | 94eab26 | 2018-09-17 20:25:55 +0200 | [diff] [blame] | 260 | config.overlay(values, { 'osmo_trx': { 'multi_arfcn': multi_arfcn_bool } }) |
Pau Espin Pedrol | edcc8d2 | 2018-03-04 19:58:23 +0100 | [diff] [blame] | 261 | |
| 262 | self.dbg('OSMO-TRX CONFIG:\n' + pprint.pformat(values)) |
| 263 | |
| 264 | with open(self.config_file, 'w') as f: |
| 265 | r = template.render(OsmoTrx.CONF_OSMO_TRX, values) |
| 266 | self.dbg(r) |
| 267 | f.write(r) |
| 268 | |
Pau Espin Pedrol | a9006df | 2018-10-01 12:26:39 +0200 | [diff] [blame] | 269 | def launch_process_local(self, keepalive, binary_name, *args): |
Pau Espin Pedrol | 4773853 | 2017-08-15 16:20:07 +0200 | [diff] [blame] | 270 | binary = os.path.abspath(self.inst.child('bin', binary_name)) |
| 271 | run_dir = self.run_dir.new_dir(binary_name) |
| 272 | if not os.path.isfile(binary): |
| 273 | raise RuntimeError('Binary missing: %r' % binary) |
| 274 | proc = process.Process(binary_name, run_dir, |
| 275 | (binary,) + args, |
| 276 | env=self.env) |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 277 | self.testenv.remember_to_stop(proc, keepalive) |
Pau Espin Pedrol | 4773853 | 2017-08-15 16:20:07 +0200 | [diff] [blame] | 278 | proc.launch() |
| 279 | return proc |
| 280 | |
Pau Espin Pedrol | dd71022 | 2019-11-26 14:33:09 +0100 | [diff] [blame] | 281 | def start_remotely(self, keepalive): |
| 282 | # Run remotely through ssh. We need to run osmo-trx under a wrapper |
| 283 | # script since osmo-trx ignores SIGHUP and will keep running after |
| 284 | # we close local ssh session. The wrapper script catches SIGHUP and |
| 285 | # sends SIGINT to it. |
Pau Espin Pedrol | 2eafb03 | 2020-01-29 17:56:14 +0100 | [diff] [blame] | 286 | |
| 287 | rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self.listen_ip) |
| 288 | |
| 289 | remote_prefix_dir = util.Dir(OsmoTrx.REMOTE_DIR) |
| 290 | remote_run_dir = util.Dir(remote_prefix_dir.child(self.binary_name())) |
Pau Espin Pedrol | dd71022 | 2019-11-26 14:33:09 +0100 | [diff] [blame] | 291 | remote_config_file = remote_run_dir.child(OsmoTrx.CONF_OSMO_TRX) |
| 292 | |
Pau Espin Pedrol | 2eafb03 | 2020-01-29 17:56:14 +0100 | [diff] [blame] | 293 | have_inst = rem_host.inst_compatible_for_remote() |
Pau Espin Pedrol | dd71022 | 2019-11-26 14:33:09 +0100 | [diff] [blame] | 294 | if have_inst: |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 295 | self.inst = util.Dir(os.path.abspath(self.testenv.suite().trial().get_inst('osmo-trx'))) |
Pau Espin Pedrol | dd71022 | 2019-11-26 14:33:09 +0100 | [diff] [blame] | 296 | |
Pau Espin Pedrol | 2eafb03 | 2020-01-29 17:56:14 +0100 | [diff] [blame] | 297 | rem_host.recreate_remote_dir(remote_prefix_dir) |
| 298 | if have_inst: |
| 299 | self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst)))) |
| 300 | rem_host.create_remote_dir(self.remote_inst) |
| 301 | rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir) |
| 302 | rem_host.create_remote_dir(remote_run_dir) |
| 303 | rem_host.scp('scp-cfg-to-remote', self.config_file, remote_config_file) |
Pau Espin Pedrol | dd71022 | 2019-11-26 14:33:09 +0100 | [diff] [blame] | 304 | |
| 305 | if have_inst: |
Pau Espin Pedrol | f6d45ad | 2020-02-11 14:39:15 +0100 | [diff] [blame] | 306 | remote_env = { 'LD_LIBRARY_PATH': self.remote_inst.child('lib') } |
Pau Espin Pedrol | dd71022 | 2019-11-26 14:33:09 +0100 | [diff] [blame] | 307 | remote_binary = self.remote_inst.child('bin', self.binary_name()) |
Pau Espin Pedrol | 2eafb03 | 2020-01-29 17:56:14 +0100 | [diff] [blame] | 308 | args = (remote_binary, '-C', remote_config_file) |
Pau Espin Pedrol | dd71022 | 2019-11-26 14:33:09 +0100 | [diff] [blame] | 309 | else: # Use whatever is available i nremote system PATH: |
Pau Espin Pedrol | f6d45ad | 2020-02-11 14:39:15 +0100 | [diff] [blame] | 310 | remote_env = {} |
Pau Espin Pedrol | 2eafb03 | 2020-01-29 17:56:14 +0100 | [diff] [blame] | 311 | remote_binary = self.binary_name() |
| 312 | args = (remote_binary, '-C', remote_config_file) |
Pau Espin Pedrol | 0d64f16 | 2020-05-25 15:44:09 +0200 | [diff] [blame] | 313 | # Run remotely through ssh. We need to run binary under a wrapper |
| 314 | # script since osmo-trx ignores SIGHUP and will keep running after |
| 315 | # we close local ssh session. The wrapper script catches SIGHUP and |
| 316 | # sends SIGINT to it. |
| 317 | self.proc_trx = rem_host.RemoteProcessSafeExit(self.binary_name(), remote_run_dir, args, remote_env=remote_env) |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 318 | self.testenv.remember_to_stop(self.proc_trx, keepalive) |
Pau Espin Pedrol | 2eafb03 | 2020-01-29 17:56:14 +0100 | [diff] [blame] | 319 | self.proc_trx.launch() |
Pau Espin Pedrol | dd71022 | 2019-11-26 14:33:09 +0100 | [diff] [blame] | 320 | |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 321 | ############## |
| 322 | # PUBLIC (test API included) |
| 323 | ############## |
| 324 | def start(self, keepalive=False): |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 325 | self.configure() |
Pau Espin Pedrol | dd71022 | 2019-11-26 14:33:09 +0100 | [diff] [blame] | 326 | if self.remote_user: |
| 327 | self.start_remotely(keepalive) |
| 328 | return |
| 329 | # Run locally if ssh user is not set |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 330 | self.inst = util.Dir(os.path.abspath(self.testenv.suite().trial().get_inst('osmo-trx'))) |
Pau Espin Pedrol | dd71022 | 2019-11-26 14:33:09 +0100 | [diff] [blame] | 331 | lib = self.inst.child('lib') |
| 332 | self.env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) } |
| 333 | self.proc_trx = self.launch_process_local(keepalive, self.binary_name(), |
| 334 | '-C', os.path.abspath(self.config_file)) |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 335 | |
Pau Espin Pedrol | 4773853 | 2017-08-15 16:20:07 +0200 | [diff] [blame] | 336 | def trx_ready(self): |
| 337 | if not self.proc_trx or not self.proc_trx.is_running: |
| 338 | return False |
| 339 | return '-- Transceiver active with' in (self.proc_trx.get_stdout() or '') |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 340 | |
| 341 | class OsmoTrxUHD(OsmoTrx): |
| 342 | BIN_TRX = 'osmo-trx-uhd' |
| 343 | |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 344 | def __init__(self, testenv, conf): |
| 345 | super().__init__(testenv, conf) |
Pau Espin Pedrol | 0d45504 | 2018-08-27 17:07:41 +0200 | [diff] [blame] | 346 | |
| 347 | def binary_name(self): |
| 348 | return OsmoTrxUHD.BIN_TRX |
| 349 | |
Pau Espin Pedrol | e789f0c | 2018-08-27 18:45:01 +0200 | [diff] [blame] | 350 | class OsmoTrxLMS(OsmoTrx): |
| 351 | BIN_TRX = 'osmo-trx-lms' |
| 352 | |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 353 | def __init__(self, testenv, conf): |
| 354 | super().__init__(testenv, conf) |
Pau Espin Pedrol | e789f0c | 2018-08-27 18:45:01 +0200 | [diff] [blame] | 355 | |
| 356 | def binary_name(self): |
| 357 | return OsmoTrxLMS.BIN_TRX |
| 358 | |
Pau Espin Pedrol | 55cee16 | 2019-09-10 13:47:04 +0200 | [diff] [blame] | 359 | class TrxSC5(Trx): |
| 360 | |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 361 | def __init__(self, testenv, conf): |
| 362 | super().__init__(testenv, conf, "sc5-trx") |
Pau Espin Pedrol | 55cee16 | 2019-09-10 13:47:04 +0200 | [diff] [blame] | 363 | self.ready = False |
| 364 | |
| 365 | def start(self, keepalive=False): |
| 366 | name = "ssh_sc5_ccli" |
| 367 | run_dir = self.run_dir.new_dir(name) |
| 368 | popen_args = ('/cx/bin/ccli', '-c', 'gsm.unlock') |
| 369 | proc = process.RemoteProcess(name, run_dir, self.remote_user, self.listen_ip, None, |
| 370 | popen_args) |
| 371 | keep_trying = 10 |
| 372 | while keep_trying > 0: |
| 373 | if proc.respawn_sync(raise_nonsuccess=False) == 0 and 'OK' in (proc.get_stdout() or ''): |
| 374 | break |
| 375 | keep_trying = keep_trying - 1 |
| 376 | self.log('Configuring SC5 TRX failed, retrying %d more times' % keep_trying) |
Pau Espin Pedrol | 664e383 | 2020-06-10 19:30:33 +0200 | [diff] [blame] | 377 | MainLoop.sleep(5) |
Pau Espin Pedrol | 55cee16 | 2019-09-10 13:47:04 +0200 | [diff] [blame] | 378 | if keep_trying == 0: |
| 379 | raise log.Error('Failed configuring SC5!') |
| 380 | self.ready = True |
| 381 | |
| 382 | def trx_ready(self): |
| 383 | return self.ready |
| 384 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 385 | # vim: expandtab tabstop=4 shiftwidth=4 |