Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 1 | # 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 | |
| 20 | import os |
| 21 | import pprint |
Pau Espin Pedrol | e1a58bd | 2020-04-10 20:46:07 +0200 | [diff] [blame] | 22 | from ..core import config, util, template, process |
Pau Espin Pedrol | e8bbcbf | 2020-04-10 19:51:31 +0200 | [diff] [blame] | 23 | from . import pcu |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 24 | |
Pau Espin Pedrol | 150abb4 | 2018-03-08 17:27:35 +0100 | [diff] [blame] | 25 | class OsmoPcu(pcu.Pcu): |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 26 | |
| 27 | BIN_PCU = 'osmo-pcu' |
| 28 | PCU_OSMO_CFG = 'osmo-pcu.cfg' |
| 29 | |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 30 | def __init__(self, testenv, bts, conf): |
| 31 | super().__init__(testenv, bts, conf, OsmoPcu.BIN_PCU) |
Pau Espin Pedrol | 5860367 | 2018-08-09 13:45:55 +0200 | [diff] [blame] | 32 | self.run_dir = None |
| 33 | self.inst = None |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 34 | self.conf = conf |
| 35 | self.env = {} |
| 36 | |
Pau Espin Pedrol | b1526b9 | 2018-05-22 20:32:30 +0200 | [diff] [blame] | 37 | def start(self, keepalive=False): |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 38 | self.run_dir = util.Dir(self.testenv.suite().get_run_dir().new_dir(self.name())) |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 39 | self.configure() |
| 40 | |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 41 | self.inst = util.Dir(os.path.abspath(self.testenv.suite().trial().get_inst('osmo-pcu'))) |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 42 | 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 Pedrol | b1526b9 | 2018-05-22 20:32:30 +0200 | [diff] [blame] | 47 | self.launch_process(keepalive, OsmoPcu.BIN_PCU, '-r', '1', |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 48 | '-c', os.path.abspath(self.config_file), |
| 49 | '-i', self.bts.bsc.addr()) |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 50 | self.testenv.poll() |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 51 | |
Pau Espin Pedrol | b1526b9 | 2018-05-22 20:32:30 +0200 | [diff] [blame] | 52 | def launch_process(self, keepalive, binary_name, *args): |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 53 | 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 Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 60 | self.testenv.remember_to_stop(proc, keepalive) |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 61 | 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 Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 69 | config.overlay(values, self.testenv.suite().config()) |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 70 | config.overlay(values, { |
| 71 | 'osmo_pcu': { |
Pau Espin Pedrol | ba213a3 | 2020-04-06 17:17:41 +0200 | [diff] [blame] | 72 | 'bts_addr': self.bts.remote_addr(), |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 73 | 'pcu_socket_path': self.bts.pcu_socket_path(), |
Pau Espin Pedrol | 29b7132 | 2020-04-06 18:14:29 +0200 | [diff] [blame] | 74 | 'egprs_enabled': self.egprs_enabled(), |
Pau Espin Pedrol | e85f5c9 | 2017-11-23 13:33:21 +0100 | [diff] [blame] | 75 | } |
| 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 |