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 |
| 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 |
| 27 | processes = None |
| 28 | inst = None |
| 29 | env = None |
| 30 | |
| 31 | BIN_TRX = 'osmo-trx' |
| 32 | BIN_BTS_TRX = 'osmo-bts-trx' |
| 33 | BIN_PCU = 'osmo-pcu' |
| 34 | |
| 35 | def __init__(self, suite_run, conf): |
| 36 | self.suite_run = suite_run |
| 37 | self.conf = conf |
| 38 | self.set_name('osmo-bts-trx') |
| 39 | self.set_log_category(log.C_RUN) |
| 40 | self.processes = {} |
| 41 | self.inst = None |
| 42 | self.env = {} |
| 43 | |
| 44 | def start(self): |
| 45 | if self.nitb is None: |
| 46 | raise RuntimeError('BTS needs to be added to a NITB before it can be started') |
| 47 | self.suite_run.poll() |
| 48 | |
| 49 | self.log('Starting to connect to', self.nitb) |
| 50 | self.run_dir = util.Dir(self.suite_run.trial.get_run_dir().new_dir(self.name())) |
| 51 | self.configure() |
| 52 | |
| 53 | self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-bts-trx'))) |
Your Name | 3c6673a | 2017-04-08 18:52:39 +0200 | [diff] [blame] | 54 | lib = self.inst.child('lib') |
| 55 | if not os.path.isdir(lib): |
| 56 | raise RuntimeError('No lib/ in %r' % self.inst) |
| 57 | self.env = { 'LD_LIBRARY_PATH': lib } |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 58 | |
| 59 | self.launch_process(OsmoBtsTrx.BIN_TRX) |
| 60 | self.launch_process(OsmoBtsTrx.BIN_BTS_TRX, '-r', '1', '-c', os.path.abspath(self.config_file)) |
| 61 | #self.launch_process(OsmoBtsTrx.BIN_PCU, '-r', '1') |
| 62 | self.suite_run.poll() |
| 63 | |
| 64 | def launch_process(self, binary_name, *args): |
| 65 | if self.processes.get(binary_name) is not None: |
| 66 | raise RuntimeError('Attempt to launch twice: %r' % binary_name) |
| 67 | |
| 68 | binary = os.path.abspath(self.inst.child('bin', binary_name)) |
| 69 | run_dir = self.run_dir.new_dir(binary_name) |
| 70 | if not os.path.isfile(binary): |
| 71 | raise RuntimeError('Binary missing: %r' % binary) |
| 72 | proc = process.Process(binary_name, run_dir, |
| 73 | (binary,) + args, |
| 74 | env=self.env) |
| 75 | self.processes[binary_name] = proc |
| 76 | self.suite_run.remember_to_stop(proc) |
| 77 | proc.launch() |
| 78 | |
| 79 | def configure(self): |
| 80 | if self.nitb is None: |
| 81 | raise RuntimeError('BTS needs to be added to a NITB before it can be configured') |
| 82 | self.config_file = self.run_dir.new_file('osmo-bts-trx.cfg') |
| 83 | self.dbg(config_file=self.config_file) |
| 84 | |
| 85 | values = dict(osmo_bts_trx=config.get_defaults('osmo_bts_trx')) |
| 86 | config.overlay(values, self.suite_run.config()) |
| 87 | config.overlay(values, dict(osmo_bts_trx=dict(oml_remote_ip=self.nitb.addr()))) |
| 88 | config.overlay(values, dict(osmo_bts_trx=self.conf)) |
| 89 | self.dbg(conf=values) |
| 90 | |
| 91 | with open(self.config_file, 'w') as f: |
| 92 | r = template.render('osmo-bts-trx.cfg', values) |
| 93 | self.dbg(r) |
| 94 | f.write(r) |
| 95 | |
| 96 | def conf_for_nitb(self): |
| 97 | values = config.get_defaults('nitb_bts') |
| 98 | config.overlay(values, config.get_defaults('osmo_bts_sysmo')) |
| 99 | config.overlay(values, self.conf) |
| 100 | config.overlay(values, { 'type': 'sysmobts' }) |
| 101 | self.dbg(conf=values) |
| 102 | return values |
| 103 | |
| 104 | def set_nitb(self, nitb): |
| 105 | self.nitb = nitb |
| 106 | |
| 107 | # vim: expandtab tabstop=4 shiftwidth=4 |