util: Add setcap_net_raw API

Some binaries such as osmo-bts-ocpty require specific capabilities, and
we need to provide them in case osmo-gsm-tester is not run as root.

Process class from process module is imported inside the method after
module initialization in order to avoid circular dependency of relative
imports, which is only available since python 3.5.

Change-Id: If3eb24461c02173dc80837a4cc83f9f2420c7816
This commit is contained in:
Pau Espin 2017-10-25 16:16:25 +02:00
parent 2753204d3b
commit 33c154bf32
1 changed files with 13 additions and 0 deletions

View File

@ -49,6 +49,19 @@ def ip_to_iface(ip):
pass
return None
def setcap_net_raw(binary, run_dir):
'''
This functionality requires specific setup on the host running
osmo-gsm-tester. See osmo-gsm-tester manual for more information.
'''
from .process import Process
SETCAP_NET_BIN = 'osmo-gsm-tester_setcap_net_raw.sh'
proc = Process(SETCAP_NET_BIN, run_dir, ['sudo', 'osmo-gsm-tester_setcap_net_raw.sh', binary])
proc.launch()
proc.wait()
if proc.result != 0:
raise RuntimeError('%s finished with err code %d' % (SETCAP_NET_BIN, proc.result))
class listdict(dict):
'a dict of lists { "a": [1, 2, 3], "b": [1, 2] }'