blob: b0572f4376c2a054c7069483efd9f849522743af [file] [log] [blame]
Pau Espin Pedrolfeb66e72019-03-04 18:37:04 +01001# osmo_gsm_tester: specifics for running a osmo-pcu for OC-2G
2#
3# Copyright (C) 2019 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
22from . import log, config, util, template, process
23
24class OsmoPcuOC2G(log.Origin):
25
26 REMOTE_DIR = '/osmo-gsm-tester-pcu'
27 PCU_OC2G_BIN = 'osmo-pcu'
28 PCU_OC2G_CFG = 'osmo-pcu-oc2g.cfg'
29
30 def __init__(self, suite_run, btsoc2g, conf):
31 super().__init__(log.C_RUN, self.PCU_OC2G_BIN)
32 self.run_dir = None
33 self.bsc = None
34 self.inst = None
35 self.remote_inst = None
36 self.remote_dir = None
37 self.btsoc2g = None
38 self.suite_run = suite_run
39 self.btsoc2g = btsoc2g
40 self.conf = conf
41 self.remote_env = {}
42 self.remote_user = 'root'
43
44 def start(self, keepalive=False):
45 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
46 self.configure()
47
48 self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-pcu-oc2g')))
49 lib = self.inst.child('lib')
50 if not os.path.isdir(lib):
51 raise log.Error('No lib/ in', self.inst)
52 if not self.inst.isfile('bin', OsmoPcuOC2G.PCU_OC2G_BIN):
53 raise log.Error('No osmo-pcu-oc2g binary in', self.inst)
54
55 self.remote_dir = util.Dir(OsmoPcuOC2G.REMOTE_DIR)
56 self.remote_inst = util.Dir(self.remote_dir.child(os.path.basename(str(self.inst))))
57
58 self.run_remote('rm-remote-dir', ('test', '!', '-d', OsmoPcuOC2G.REMOTE_DIR, '||', 'rm', '-rf', OsmoPcuOC2G.REMOTE_DIR))
59 self.run_remote('mk-remote-dir', ('mkdir', '-p', OsmoPcuOC2G.REMOTE_DIR))
60 self.run_local('scp-inst-to-btsoc2g',
61 ('scp', '-r', str(self.inst), '%s@%s:%s' % (self.remote_user, self.btsoc2g.remote_addr(), str(self.remote_inst))))
62
63 remote_run_dir = self.remote_dir.child(OsmoPcuOC2G.PCU_OC2G_BIN)
64 self.run_remote('mk-remote-run-dir', ('mkdir', '-p', remote_run_dir))
65
66 remote_config_file = self.remote_dir.child(OsmoPcuOC2G.PCU_OC2G_CFG)
67 self.run_local('scp-cfg-to-btsoc2g',
68 ('scp', '-r', self.config_file, '%s@%s:%s' % (self.remote_user, self.btsoc2g.remote_addr(), remote_config_file)))
69
70 remote_lib = self.remote_inst.child('lib')
71 remote_binary = self.remote_inst.child('bin', OsmoPcuOC2G.PCU_OC2G_BIN)
72 self.launch_remote(OsmoPcuOC2G.PCU_OC2G_BIN,
73 ('LD_LIBRARY_PATH=%s' % remote_lib,
74 remote_binary, '-c', remote_config_file, '-r', '1',
75 '-i', self.btsoc2g.bsc.addr()),
76 remote_cwd=remote_run_dir, keepalive=keepalive)
77
78 def _process_remote(self, name, popen_args, remote_cwd=None):
79 run_dir = self.run_dir.new_dir(name)
80 return process.RemoteProcess(name, run_dir, self.remote_user, self.btsoc2g.remote_addr(), remote_cwd,
81 popen_args)
82
83 def run_remote(self, name, popen_args, remote_cwd=None):
84 proc = self._process_remote(name, popen_args, remote_cwd)
85 proc.launch()
86 proc.wait()
87 if proc.result != 0:
88 log.ctx(proc)
89 raise log.Error('Exited in error')
90
91 def launch_remote(self, name, popen_args, remote_cwd=None, keepalive=False):
92 proc = self._process_remote(name, popen_args, remote_cwd)
93 self.suite_run.remember_to_stop(proc, keepalive)
94 proc.launch()
95
96 def run_local(self, name, popen_args):
97 run_dir = self.run_dir.new_dir(name)
98 proc = process.Process(name, run_dir, popen_args)
99 proc.launch()
100 proc.wait()
101 if proc.result != 0:
102 log.ctx(proc)
103 raise log.Error('Exited in error')
104
105 def configure(self):
106 self.config_file = self.run_dir.new_file(OsmoPcuOC2G.PCU_OC2G_CFG)
107 self.dbg(config_file=self.config_file)
108
109 values = { 'osmo_pcu_oc2g': config.get_defaults('osmo_pcu_oc2g') }
110 config.overlay(values, self.suite_run.config())
111 config.overlay(values, {
112 'osmo_pcu_oc2g': {
113 'pcu_socket_path': self.btsoc2g.pcu_socket_path()
114 }
115 })
116 config.overlay(values, { 'osmo_pcu_oc2g': self.conf })
117
118 self.dbg('OSMO-PCU-OC2G CONFIG:\n' + pprint.pformat(values))
119
120 with open(self.config_file, 'w') as f:
121 r = template.render(OsmoPcuOC2G.PCU_OC2G_CFG, values)
122 self.dbg(r)
123 f.write(r)
124
125# vim: expandtab tabstop=4 shiftwidth=4