blob: c6a2a0e920e5fcb123f1544aea687dd7a7341f7f [file] [log] [blame]
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +01001# osmo_gsm_tester: specifics for running an osmo-pcu
2#
3# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
4#
5# Author: Pau Espin Pedrol <pespin@sysmocom.de>
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU 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 General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20import os
21import pprint
Pau Espin Pedrole1a58bd2020-04-10 20:46:07 +020022from ..core import config, util, template, process
Pau Espin Pedrole8bbcbf2020-04-10 19:51:31 +020023from . import pcu
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010024
Pau Espin Pedrol150abb42018-03-08 17:27:35 +010025class OsmoPcu(pcu.Pcu):
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010026
27 BIN_PCU = 'osmo-pcu'
28 PCU_OSMO_CFG = 'osmo-pcu.cfg'
29
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020030 def __init__(self, testenv, bts, conf):
31 super().__init__(testenv, bts, conf, OsmoPcu.BIN_PCU)
Pau Espin Pedrol58603672018-08-09 13:45:55 +020032 self.run_dir = None
33 self.inst = None
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010034 self.conf = conf
35 self.env = {}
36
Pau Espin Pedrolb1526b92018-05-22 20:32:30 +020037 def start(self, keepalive=False):
Pau Espin Pedrol2a2d8462020-05-11 10:56:52 +020038 self.run_dir = util.Dir(self.testenv.test().get_run_dir().new_dir(self.name()))
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010039 self.configure()
40
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020041 self.inst = util.Dir(os.path.abspath(self.testenv.suite().trial().get_inst('osmo-pcu')))
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010042 lib = self.inst.child('lib')
43 if not os.path.isdir(lib):
44 raise RuntimeError('No lib/ in %r' % self.inst)
45 self.env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
46
Pau Espin Pedrolb1526b92018-05-22 20:32:30 +020047 self.launch_process(keepalive, OsmoPcu.BIN_PCU, '-r', '1',
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010048 '-c', os.path.abspath(self.config_file),
49 '-i', self.bts.bsc.addr())
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020050 self.testenv.poll()
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010051
Pau Espin Pedrolb1526b92018-05-22 20:32:30 +020052 def launch_process(self, keepalive, binary_name, *args):
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010053 binary = os.path.abspath(self.inst.child('bin', binary_name))
54 run_dir = self.run_dir.new_dir(binary_name)
55 if not os.path.isfile(binary):
56 raise RuntimeError('Binary missing: %r' % binary)
57 proc = process.Process(binary_name, run_dir,
58 (binary,) + args,
59 env=self.env)
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020060 self.testenv.remember_to_stop(proc, keepalive)
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010061 proc.launch()
62 return proc
63
64 def configure(self):
65 self.config_file = self.run_dir.new_file(OsmoPcu.PCU_OSMO_CFG)
66 self.dbg(config_file=self.config_file)
67
68 values = dict(osmo_pcu=config.get_defaults('osmo_pcu'))
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020069 config.overlay(values, self.testenv.suite().config())
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010070 config.overlay(values, {
71 'osmo_pcu': {
Pau Espin Pedrolba213a32020-04-06 17:17:41 +020072 'bts_addr': self.bts.remote_addr(),
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010073 'pcu_socket_path': self.bts.pcu_socket_path(),
Pau Espin Pedrol29b71322020-04-06 18:14:29 +020074 'egprs_enabled': self.egprs_enabled(),
Pau Espin Pedrole85f5c92017-11-23 13:33:21 +010075 }
76 })
77 config.overlay(values, { 'osmo_pcu': self.conf })
78
79 self.dbg('OSMO-PCU CONFIG:\n' + pprint.pformat(values))
80
81 with open(self.config_file, 'w') as f:
82 r = template.render(OsmoPcu.PCU_OSMO_CFG, values)
83 self.dbg(r)
84 f.write(r)
85
86# vim: expandtab tabstop=4 shiftwidth=4