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 |
| 8 | # it under the terms of the GNU Affero 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 Affero General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU Affero General Public License |
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | import os |
| 21 | from . import log, config, util, template, process |
| 22 | |
| 23 | class OsmoBtsTrx(log.Origin): |
| 24 | suite_run = None |
| 25 | nitb = None |
| 26 | run_dir = None |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 27 | inst = None |
| 28 | env = None |
| 29 | |
| 30 | BIN_TRX = 'osmo-trx' |
| 31 | BIN_BTS_TRX = 'osmo-bts-trx' |
| 32 | BIN_PCU = 'osmo-pcu' |
| 33 | |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 34 | CONF_BTS_TRX = 'osmo-bts-trx.cfg' |
| 35 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 36 | def __init__(self, suite_run, conf): |
| 37 | self.suite_run = suite_run |
| 38 | self.conf = conf |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 39 | self.set_name(OsmoBtsTrx.BIN_BTS_TRX) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 40 | self.set_log_category(log.C_RUN) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 41 | self.env = {} |
| 42 | |
| 43 | def start(self): |
| 44 | if self.nitb is None: |
| 45 | raise RuntimeError('BTS needs to be added to a NITB before it can be started') |
| 46 | self.suite_run.poll() |
| 47 | |
| 48 | self.log('Starting to connect to', self.nitb) |
| 49 | self.run_dir = util.Dir(self.suite_run.trial.get_run_dir().new_dir(self.name())) |
| 50 | self.configure() |
| 51 | |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 52 | self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst(OsmoBtsTrx.BIN_BTS_TRX))) |
Your Name | 3c6673a | 2017-04-08 18:52:39 +0200 | [diff] [blame] | 53 | lib = self.inst.child('lib') |
| 54 | if not os.path.isdir(lib): |
| 55 | raise RuntimeError('No lib/ in %r' % self.inst) |
| 56 | self.env = { 'LD_LIBRARY_PATH': lib } |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 57 | |
| 58 | self.launch_process(OsmoBtsTrx.BIN_TRX) |
| 59 | self.launch_process(OsmoBtsTrx.BIN_BTS_TRX, '-r', '1', '-c', os.path.abspath(self.config_file)) |
| 60 | #self.launch_process(OsmoBtsTrx.BIN_PCU, '-r', '1') |
| 61 | self.suite_run.poll() |
| 62 | |
| 63 | def launch_process(self, binary_name, *args): |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 64 | binary = os.path.abspath(self.inst.child('bin', binary_name)) |
| 65 | run_dir = self.run_dir.new_dir(binary_name) |
| 66 | if not os.path.isfile(binary): |
| 67 | raise RuntimeError('Binary missing: %r' % binary) |
| 68 | proc = process.Process(binary_name, run_dir, |
| 69 | (binary,) + args, |
| 70 | env=self.env) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 71 | self.suite_run.remember_to_stop(proc) |
| 72 | proc.launch() |
| 73 | |
| 74 | def configure(self): |
| 75 | if self.nitb is None: |
| 76 | raise RuntimeError('BTS needs to be added to a NITB before it can be configured') |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 77 | self.config_file = self.run_dir.new_file(OsmoBtsTrx.CONF_BTS_TRX) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 78 | self.dbg(config_file=self.config_file) |
| 79 | |
| 80 | values = dict(osmo_bts_trx=config.get_defaults('osmo_bts_trx')) |
| 81 | config.overlay(values, self.suite_run.config()) |
| 82 | config.overlay(values, dict(osmo_bts_trx=dict(oml_remote_ip=self.nitb.addr()))) |
| 83 | config.overlay(values, dict(osmo_bts_trx=self.conf)) |
| 84 | self.dbg(conf=values) |
| 85 | |
| 86 | with open(self.config_file, 'w') as f: |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 87 | r = template.render(OsmoBtsTrx.CONF_BTS_TRX, values) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 88 | self.dbg(r) |
| 89 | f.write(r) |
| 90 | |
| 91 | def conf_for_nitb(self): |
| 92 | values = config.get_defaults('nitb_bts') |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 93 | config.overlay(values, config.get_defaults('osmo_bts_trx')) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 94 | config.overlay(values, self.conf) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 95 | self.dbg(conf=values) |
| 96 | return values |
| 97 | |
| 98 | def set_nitb(self, nitb): |
| 99 | self.nitb = nitb |
| 100 | |
| 101 | # vim: expandtab tabstop=4 shiftwidth=4 |