Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 1 | # osmo_gsm_tester: specifics for running an osmo-bts-octphy |
| 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 OsmoBtsOctphy(log.Origin): |
| 24 | suite_run = None |
| 25 | nitb = None |
| 26 | run_dir = None |
| 27 | inst = None |
| 28 | env = None |
| 29 | |
| 30 | BIN_BTS_OCTPHY = 'osmo-bts-octphy' |
| 31 | CONF_BTS_OCTPHY = 'osmo-bts-octphy.cfg' |
| 32 | |
| 33 | def __init__(self, suite_run, conf): |
| 34 | self.suite_run = suite_run |
| 35 | self.conf = conf |
| 36 | self.set_name(OsmoBtsOctphy.BIN_BTS_OCTPHY) |
| 37 | self.set_log_category(log.C_RUN) |
| 38 | self.env = {} |
| 39 | |
| 40 | def start(self): |
| 41 | if self.nitb is None: |
| 42 | raise RuntimeError('BTS needs to be added to a NITB before it can be started') |
| 43 | self.suite_run.poll() |
| 44 | |
| 45 | self.log('Starting to connect to', self.nitb) |
| 46 | self.run_dir = util.Dir(self.suite_run.trial.get_run_dir().new_dir(self.name())) |
| 47 | self.configure() |
| 48 | |
| 49 | self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst(OsmoBtsOctphy.BIN_BTS_OCTPHY))) |
| 50 | lib = self.inst.child('lib') |
| 51 | if not os.path.isdir(lib): |
| 52 | raise RuntimeError('No lib/ in %r' % self.inst) |
Pau Espin Pedrol | e39c6f1 | 2017-05-08 16:21:38 +0200 | [diff] [blame] | 53 | self.env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) } |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 54 | |
Your Name | 44af341 | 2017-04-13 03:11:59 +0200 | [diff] [blame] | 55 | self.launch_process(OsmoBtsOctphy.BIN_BTS_OCTPHY, '-r', '1', '-c', os.path.abspath(self.config_file)) |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 56 | self.suite_run.poll() |
| 57 | |
| 58 | def launch_process(self, binary_name, *args): |
| 59 | binary = os.path.abspath(self.inst.child('bin', binary_name)) |
| 60 | run_dir = self.run_dir.new_dir(binary_name) |
| 61 | if not os.path.isfile(binary): |
| 62 | raise RuntimeError('Binary missing: %r' % binary) |
| 63 | proc = process.Process(binary_name, run_dir, |
| 64 | (binary,) + args, |
| 65 | env=self.env) |
| 66 | self.suite_run.remember_to_stop(proc) |
| 67 | proc.launch() |
| 68 | |
| 69 | def configure(self): |
| 70 | if self.nitb is None: |
| 71 | raise RuntimeError('BTS needs to be added to a NITB before it can be configured') |
| 72 | self.config_file = self.run_dir.new_file(OsmoBtsOctphy.CONF_BTS_OCTPHY) |
| 73 | self.dbg(config_file=self.config_file) |
| 74 | |
| 75 | values = dict(osmo_bts_octphy=config.get_defaults('osmo_bts_octphy')) |
| 76 | config.overlay(values, self.suite_run.config()) |
| 77 | config.overlay(values, dict(osmo_bts_octphy=dict(oml_remote_ip=self.nitb.addr()))) |
| 78 | config.overlay(values, dict(osmo_bts_octphy=self.conf)) |
| 79 | self.dbg(conf=values) |
| 80 | |
| 81 | with open(self.config_file, 'w') as f: |
| 82 | r = template.render(OsmoBtsOctphy.CONF_BTS_OCTPHY, values) |
| 83 | self.dbg(r) |
| 84 | f.write(r) |
| 85 | |
| 86 | def conf_for_nitb(self): |
| 87 | values = config.get_defaults('nitb_bts') |
| 88 | config.overlay(values, config.get_defaults('osmo_bts_octphy')) |
| 89 | config.overlay(values, self.conf) |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 90 | self.dbg(conf=values) |
| 91 | return values |
| 92 | |
| 93 | def set_nitb(self, nitb): |
| 94 | self.nitb = nitb |
| 95 | |
| 96 | # vim: expandtab tabstop=4 shiftwidth=4 |