blob: f5eb8f774adfe3cdbfed4ed4e1b86e89c7c3aacc [file] [log] [blame]
Neels Hofmeyr17c139e2017-04-12 02:42:02 +02001# 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
20import os
21from . import log, config, util, template, process
22
23class 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 Pedrole39c6f12017-05-08 16:21:38 +020053 self.env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
Neels Hofmeyr17c139e2017-04-12 02:42:02 +020054
Pau Espin Pedrol6ab98982017-05-12 16:07:35 +020055 self.launch_process(OsmoBtsOctphy.BIN_BTS_OCTPHY, '-r', '1',
56 '-c', os.path.abspath(self.config_file),
57 '-i', self.nitb.addr())
Neels Hofmeyr17c139e2017-04-12 02:42:02 +020058 self.suite_run.poll()
59
60 def launch_process(self, binary_name, *args):
61 binary = os.path.abspath(self.inst.child('bin', binary_name))
62 run_dir = self.run_dir.new_dir(binary_name)
63 if not os.path.isfile(binary):
64 raise RuntimeError('Binary missing: %r' % binary)
65 proc = process.Process(binary_name, run_dir,
66 (binary,) + args,
67 env=self.env)
68 self.suite_run.remember_to_stop(proc)
69 proc.launch()
70
71 def configure(self):
72 if self.nitb is None:
73 raise RuntimeError('BTS needs to be added to a NITB before it can be configured')
74 self.config_file = self.run_dir.new_file(OsmoBtsOctphy.CONF_BTS_OCTPHY)
75 self.dbg(config_file=self.config_file)
76
77 values = dict(osmo_bts_octphy=config.get_defaults('osmo_bts_octphy'))
78 config.overlay(values, self.suite_run.config())
79 config.overlay(values, dict(osmo_bts_octphy=dict(oml_remote_ip=self.nitb.addr())))
80 config.overlay(values, dict(osmo_bts_octphy=self.conf))
81 self.dbg(conf=values)
82
83 with open(self.config_file, 'w') as f:
84 r = template.render(OsmoBtsOctphy.CONF_BTS_OCTPHY, values)
85 self.dbg(r)
86 f.write(r)
87
88 def conf_for_nitb(self):
89 values = config.get_defaults('nitb_bts')
90 config.overlay(values, config.get_defaults('osmo_bts_octphy'))
91 config.overlay(values, self.conf)
Neels Hofmeyr17c139e2017-04-12 02:42:02 +020092 self.dbg(conf=values)
93 return values
94
95 def set_nitb(self, nitb):
96 self.nitb = nitb
97
98# vim: expandtab tabstop=4 shiftwidth=4