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