Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 1 | # osmo_gsm_tester: specifics for running a sysmoBTS |
| 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 | |
Neels Hofmeyr | 5356d0a | 2017-04-10 03:45:30 +0200 | [diff] [blame] | 20 | import os |
Neels Hofmeyr | 943c81d | 2017-05-22 20:16:03 +0200 | [diff] [blame] | 21 | import pprint |
Pau Espin Pedrol | 2eafb03 | 2020-01-29 17:56:14 +0100 | [diff] [blame] | 22 | from . import log, config, util, template, process, remote, pcu_sysmo, bts_osmo |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 23 | |
Pau Espin Pedrol | c9817a5 | 2017-12-13 19:52:27 +0100 | [diff] [blame] | 24 | class SysmoBts(bts_osmo.OsmoBts): |
Pau Espin Pedrol | 81aaeef | 2017-12-14 19:14:12 +0100 | [diff] [blame] | 25 | ############## |
| 26 | # PROTECTED |
| 27 | ############## |
Neels Hofmeyr | 5356d0a | 2017-04-10 03:45:30 +0200 | [diff] [blame] | 28 | |
Pau Espin Pedrol | ce35d91 | 2017-11-23 11:01:24 +0100 | [diff] [blame] | 29 | REMOTE_DIR = '/osmo-gsm-tester-bts' |
Neels Hofmeyr | 5356d0a | 2017-04-10 03:45:30 +0200 | [diff] [blame] | 30 | BTS_SYSMO_BIN = 'osmo-bts-sysmo' |
| 31 | BTS_SYSMO_CFG = 'osmo-bts-sysmo.cfg' |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 32 | |
| 33 | def __init__(self, suite_run, conf): |
Pau Espin Pedrol | e519462 | 2018-05-07 13:36:58 +0200 | [diff] [blame] | 34 | super().__init__(suite_run, conf, SysmoBts.BTS_SYSMO_BIN, 'osmo_bts_sysmo') |
Pau Espin Pedrol | 5860367 | 2018-08-09 13:45:55 +0200 | [diff] [blame] | 35 | self.run_dir = None |
| 36 | self.inst = None |
| 37 | self.remote_inst = None |
| 38 | self.remote_dir = None |
Pau Espin Pedrol | 2eafb03 | 2020-01-29 17:56:14 +0100 | [diff] [blame] | 39 | self.proc_bts = None |
Pau Espin Pedrol | 3895fec | 2017-04-28 16:13:03 +0200 | [diff] [blame] | 40 | self.remote_user = 'root' |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 41 | |
Pau Espin Pedrol | 81aaeef | 2017-12-14 19:14:12 +0100 | [diff] [blame] | 42 | def _direct_pcu_enabled(self): |
| 43 | return util.str2bool(self.conf.get('direct_pcu')) |
| 44 | |
Pau Espin Pedrol | 81aaeef | 2017-12-14 19:14:12 +0100 | [diff] [blame] | 45 | def create_pcu(self): |
| 46 | return pcu_sysmo.OsmoPcuSysmo(self.suite_run, self, self.conf) |
| 47 | |
| 48 | def configure(self): |
| 49 | if self.bsc is None: |
| 50 | raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be configured') |
| 51 | |
| 52 | self.config_file = self.run_dir.new_file(SysmoBts.BTS_SYSMO_CFG) |
| 53 | self.dbg(config_file=self.config_file) |
| 54 | |
| 55 | values = { 'osmo_bts_sysmo': config.get_defaults('osmo_bts_sysmo') } |
| 56 | config.overlay(values, self.suite_run.config()) |
| 57 | config.overlay(values, { |
| 58 | 'osmo_bts_sysmo': { |
| 59 | 'oml_remote_ip': self.bsc.addr(), |
| 60 | 'pcu_socket_path': self.pcu_socket_path(), |
| 61 | } |
| 62 | }) |
| 63 | config.overlay(values, { 'osmo_bts_sysmo': self.conf }) |
| 64 | |
| 65 | self.dbg('SYSMOBTS CONFIG:\n' + pprint.pformat(values)) |
| 66 | |
| 67 | with open(self.config_file, 'w') as f: |
| 68 | r = template.render(SysmoBts.BTS_SYSMO_CFG, values) |
| 69 | self.dbg(r) |
| 70 | f.write(r) |
| 71 | |
| 72 | ######################## |
| 73 | # PUBLIC - INTERNAL API |
| 74 | ######################## |
| 75 | def pcu_socket_path(self): |
| 76 | return os.path.join(SysmoBts.REMOTE_DIR, 'pcu_bts') |
| 77 | |
| 78 | def conf_for_bsc(self): |
Pau Espin Pedrol | e519462 | 2018-05-07 13:36:58 +0200 | [diff] [blame] | 79 | values = self.conf_for_bsc_prepare() |
Pau Espin Pedrol | 81aaeef | 2017-12-14 19:14:12 +0100 | [diff] [blame] | 80 | self.dbg(conf=values) |
| 81 | return values |
| 82 | |
| 83 | ################### |
| 84 | # PUBLIC (test API included) |
| 85 | ################### |
Pau Espin Pedrol | 302c756 | 2018-10-02 13:08:02 +0200 | [diff] [blame] | 86 | # We get log from ssh stdout instead of usual stderr. |
| 87 | def ready_for_pcu(self): |
| 88 | if not self.proc_bts or not self.proc_bts.is_running: |
| 89 | return False |
| 90 | return 'BTS is up' in (self.proc_bts.get_stdout() or '') |
| 91 | |
Pau Espin Pedrol | b1526b9 | 2018-05-22 20:32:30 +0200 | [diff] [blame] | 92 | def start(self, keepalive=False): |
Neels Hofmeyr | 1a7a3f0 | 2017-06-10 01:18:27 +0200 | [diff] [blame] | 93 | if self.bsc is None: |
| 94 | raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be started') |
| 95 | log.log('Starting sysmoBTS to connect to', self.bsc) |
Pau Espin Pedrol | d091233 | 2017-06-14 13:27:08 +0200 | [diff] [blame] | 96 | self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name())) |
Neels Hofmeyr | 1a7a3f0 | 2017-06-10 01:18:27 +0200 | [diff] [blame] | 97 | self.configure() |
Neels Hofmeyr | 5356d0a | 2017-04-10 03:45:30 +0200 | [diff] [blame] | 98 | |
Neels Hofmeyr | 1a7a3f0 | 2017-06-10 01:18:27 +0200 | [diff] [blame] | 99 | self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst(SysmoBts.BTS_SYSMO_BIN))) |
| 100 | lib = self.inst.child('lib') |
| 101 | if not os.path.isdir(lib): |
| 102 | raise log.Error('No lib/ in', self.inst) |
| 103 | if not self.inst.isfile('bin', SysmoBts.BTS_SYSMO_BIN): |
| 104 | raise log.Error('No osmo-bts-sysmo binary in', self.inst) |
Neels Hofmeyr | 5356d0a | 2017-04-10 03:45:30 +0200 | [diff] [blame] | 105 | |
Pau Espin Pedrol | 2eafb03 | 2020-01-29 17:56:14 +0100 | [diff] [blame] | 106 | rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self.remote_addr()) |
| 107 | remote_prefix_dir = util.Dir(SysmoBts.REMOTE_DIR) |
| 108 | self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst)))) |
| 109 | remote_run_dir = util.Dir(remote_prefix_dir.child(SysmoBts.BTS_SYSMO_BIN)) |
Pau Espin Pedrol | e4358a9 | 2018-10-01 11:27:55 +0200 | [diff] [blame] | 110 | remote_config_file = remote_run_dir.child(SysmoBts.BTS_SYSMO_CFG) |
Pau Espin Pedrol | ce35d91 | 2017-11-23 11:01:24 +0100 | [diff] [blame] | 111 | |
Pau Espin Pedrol | 2eafb03 | 2020-01-29 17:56:14 +0100 | [diff] [blame] | 112 | rem_host.recreate_remote_dir(self.remote_inst) |
| 113 | rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir) |
| 114 | rem_host.create_remote_dir(remote_run_dir) |
| 115 | rem_host.scp('scp-cfg-to-remote', self.config_file, remote_config_file) |
| 116 | |
| 117 | rem_host.run_remote_sync('reload-dsp-firmware', ('/bin/sh', '-c', '"cat /lib/firmware/sysmobts-v?.bit > /dev/fpgadl_par0 ; cat /lib/firmware/sysmobts-v?.out > /dev/dspdl_dm644x_0"')) |
| 118 | |
| 119 | remote_lib = self.remote_inst.child('lib') |
| 120 | remote_binary = self.remote_inst.child('bin', SysmoBts.BTS_SYSMO_BIN) |
Pau Espin Pedrol | ce35d91 | 2017-11-23 11:01:24 +0100 | [diff] [blame] | 121 | args = ('LD_LIBRARY_PATH=%s' % remote_lib, |
| 122 | remote_binary, '-c', remote_config_file, '-r', '1', |
| 123 | '-i', self.bsc.addr()) |
| 124 | |
| 125 | if self._direct_pcu_enabled(): |
| 126 | args += ('-M',) |
| 127 | |
Pau Espin Pedrol | 2eafb03 | 2020-01-29 17:56:14 +0100 | [diff] [blame] | 128 | self.proc_bts = rem_host.RemoteProcess(SysmoBts.BTS_SYSMO_BIN, args) |
| 129 | self.suite_run.remember_to_stop(self.proc_bts, keepalive) |
| 130 | self.proc_bts.launch() |
Neels Hofmeyr | 5356d0a | 2017-04-10 03:45:30 +0200 | [diff] [blame] | 131 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 132 | # vim: expandtab tabstop=4 shiftwidth=4 |