blob: ea8e6528eb3ffd593867ed5db041ba61339d8bd5 [file] [log] [blame]
Pau Espin Pedrole9d4af82017-11-09 13:01:00 +01001# osmo_gsm_tester: specifics for running an osmo-mgw
2#
3# Copyright (C) 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
22
Holger Hans Peter Freyther91067232019-02-27 04:33:21 +000023from . import log, util, config, template, process, pcap_recorder
Pau Espin Pedrole9d4af82017-11-09 13:01:00 +010024
25class OsmoMgw(log.Origin):
Pau Espin Pedrole9d4af82017-11-09 13:01:00 +010026
27 def __init__(self, suite_run, ip_address):
28 super().__init__(log.C_RUN, 'osmo-mgw_%s' % ip_address.get('addr'))
Pau Espin Pedrol58603672018-08-09 13:45:55 +020029 self.run_dir = None
30 self.config_file = None
31 self.process = None
Pau Espin Pedrole9d4af82017-11-09 13:01:00 +010032 self.suite_run = suite_run
33 self.ip_address = ip_address
Pau Espin Pedrolfed578e2019-06-19 17:18:43 +020034 self.use_osmux = "off"
Pau Espin Pedrole9d4af82017-11-09 13:01:00 +010035
36 def start(self):
37 self.log('Starting osmo-mgw')
38 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
39 self.configure()
40 inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-mgw')))
41 binary = inst.child('bin', 'osmo-mgw')
42 if not os.path.isfile(binary):
43 raise RuntimeError('Binary missing: %r' % binary)
44 lib = inst.child('lib')
45 if not os.path.isdir(lib):
46 raise RuntimeError('No lib/ in %r' % inst)
47
Pau Espin Pedrol9cc1d082017-11-20 17:40:25 +010048 pcap_recorder.PcapRecorder(self.suite_run, self.run_dir.new_dir('pcap'), None,
Pau Espin Pedrole9d4af82017-11-09 13:01:00 +010049 'host %s and port not 22' % self.addr())
50
51 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
52
53 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
54 self.process = process.Process(self.name(), self.run_dir,
55 (binary, '-c',
56 os.path.abspath(self.config_file)),
57 env=env)
58 self.suite_run.remember_to_stop(self.process)
59 self.process.launch()
60
61 def configure(self):
62 self.config_file = self.run_dir.new_file('osmo-mgw.cfg')
63 self.dbg(config_file=self.config_file)
64
65 values = dict(mgw=config.get_defaults('mgw'))
66 config.overlay(values, self.suite_run.config())
Pau Espin Pedrolfed578e2019-06-19 17:18:43 +020067 config.overlay(values, { 'mgw': {
68 'ip_address': self.ip_address,
69 'use_osmux': self.use_osmux
70 }
71 })
Pau Espin Pedrole9d4af82017-11-09 13:01:00 +010072
73 self.dbg('MGW CONFIG:\n' + pprint.pformat(values))
74
75 with open(self.config_file, 'w') as f:
76 r = template.render('osmo-mgw.cfg', values)
77 self.dbg(r)
78 f.write(r)
79
80 def addr(self):
81 return self.ip_address.get('addr')
82
83 def conf_for_client(self):
84 return dict(mgw=dict(ip_address=self.ip_address))
85
86 def running(self):
87 return not self.process.terminated()
88
Pau Espin Pedrolfed578e2019-06-19 17:18:43 +020089 def set_use_osmux(self, use=False, force=False):
90 if not use:
91 self.use_osmux = "off"
92 else:
93 if not force:
94 self.use_osmux = "on"
95 else:
96 self.use_osmux = "only"
97
98
Pau Espin Pedrole9d4af82017-11-09 13:01:00 +010099# vim: expandtab tabstop=4 shiftwidth=4