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 | from . import log, config, util, template |
| 21 | |
| 22 | class SysmoBts(log.Origin): |
| 23 | suite_run = None |
| 24 | nitb = None |
| 25 | run_dir = None |
| 26 | |
| 27 | def __init__(self, suite_run, conf): |
| 28 | self.suite_run = suite_run |
| 29 | self.conf = conf |
| 30 | self.set_name('osmo-bts-sysmo') |
| 31 | self.set_log_category(log.C_RUN) |
| 32 | |
| 33 | def start(self): |
| 34 | if self.nitb is None: |
| 35 | raise RuntimeError('BTS needs to be added to a NITB before it can be started') |
| 36 | self.log('Starting sysmoBTS to connect to', self.nitb) |
| 37 | self.run_dir = util.Dir(self.suite_run.trial.get_run_dir().new_dir(self.name())) |
| 38 | self.configure() |
| 39 | self.err('SysmoBts is not yet implemented') |
| 40 | |
| 41 | def configure(self): |
| 42 | if self.nitb is None: |
| 43 | raise RuntimeError('BTS needs to be added to a NITB before it can be configured') |
| 44 | self.config_file = self.run_dir.new_file('osmo-bts-sysmo.cfg') |
| 45 | self.dbg(config_file=self.config_file) |
| 46 | |
| 47 | values = { 'osmo_bts_sysmo': config.get_defaults('osmo_bts_sysmo') } |
| 48 | config.overlay(values, self.suite_run.config()) |
| 49 | config.overlay(values, { 'osmo_bts_sysmo': { 'oml_remote_ip': self.nitb.addr() } }) |
| 50 | config.overlay(values, { 'osmo_bts_sysmo': self.conf }) |
| 51 | self.dbg(conf=values) |
| 52 | |
| 53 | with open(self.config_file, 'w') as f: |
| 54 | r = template.render('osmo-bts-sysmo.cfg', values) |
| 55 | self.dbg(r) |
| 56 | f.write(r) |
| 57 | |
| 58 | def conf_for_nitb(self): |
| 59 | values = config.get_defaults('nitb_bts') |
| 60 | config.overlay(values, config.get_defaults('osmo_bts_sysmo')) |
| 61 | config.overlay(values, self.conf) |
| 62 | config.overlay(values, { 'type': 'sysmobts' }) |
| 63 | self.dbg(conf=values) |
| 64 | return values |
| 65 | |
| 66 | def set_nitb(self, nitb): |
| 67 | self.nitb = nitb |
| 68 | |
| 69 | # vim: expandtab tabstop=4 shiftwidth=4 |