summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2018-03-28 19:17:34 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2018-04-04 12:38:09 +0200
commit9a4631c789b1a141a95ae39c92372e9b00b77239 (patch)
tree86258965a04626310ebf08dae637b58cf359ee85
parentbf176e420ee20e526fc408a8a16d4dc7811ce703 (diff)
Drop event_loop global functions and import MainLoop
Take the chance to identify and drop modules importing event_loop but not using it. Change-Id: Ifa1940cd00138ebc72fbcfd45a0e28246f7a5ed9
-rw-r--r--src/osmo_gsm_tester/bts.py2
-rw-r--r--src/osmo_gsm_tester/bts_nanobts.py11
-rw-r--r--src/osmo_gsm_tester/bts_octphy.py2
-rw-r--r--src/osmo_gsm_tester/bts_osmo.py2
-rw-r--r--src/osmo_gsm_tester/bts_osmotrx.py5
-rw-r--r--src/osmo_gsm_tester/esme.py9
-rw-r--r--src/osmo_gsm_tester/event_loop.py30
-rw-r--r--src/osmo_gsm_tester/modem.py31
-rw-r--r--src/osmo_gsm_tester/pcu_osmo.py2
-rw-r--r--src/osmo_gsm_tester/pcu_sysmo.py2
-rw-r--r--src/osmo_gsm_tester/powersupply.py5
-rw-r--r--src/osmo_gsm_tester/powersupply_sispm.py5
-rw-r--r--src/osmo_gsm_tester/process.py5
-rw-r--r--src/osmo_gsm_tester/suite.py9
-rw-r--r--src/osmo_gsm_tester/test.py5
15 files changed, 53 insertions, 72 deletions
diff --git a/src/osmo_gsm_tester/bts.py b/src/osmo_gsm_tester/bts.py
index 289b697..02e5df7 100644
--- a/src/osmo_gsm_tester/bts.py
+++ b/src/osmo_gsm_tester/bts.py
@@ -21,7 +21,7 @@ import os
import pprint
import tempfile
from abc import ABCMeta, abstractmethod
-from . import log, config, util, template, process, event_loop, pcu_osmo
+from . import log, config, util, template, process, pcu_osmo
class Bts(log.Origin, metaclass=ABCMeta):
suite_run = None
diff --git a/src/osmo_gsm_tester/bts_nanobts.py b/src/osmo_gsm_tester/bts_nanobts.py
index 1d4a14a..9599022 100644
--- a/src/osmo_gsm_tester/bts_nanobts.py
+++ b/src/osmo_gsm_tester/bts_nanobts.py
@@ -22,8 +22,9 @@ import pprint
import tempfile
import re
from abc import ABCMeta, abstractmethod
-from . import log, config, util, template, process, event_loop, pcap_recorder, bts, pcu
+from . import log, config, util, template, process, pcap_recorder, bts, pcu
from . import powersupply
+from .event_loop import MainLoop
class NanoBts(bts.Bts):
@@ -130,7 +131,7 @@ class NanoBts(bts.Bts):
# Let some time for BTS to restart. It takes much more than 20 secs, and
# this way we make sure we don't catch responses in abisip-find prior to
# BTS restarting.
- event_loop.sleep(self, 20)
+ MainLoop.sleep(self, 20)
self.log('Starting to connect to', self.bsc)
ipfind = AbisIpFind(self.suite_run, self.run_dir, local_bind_ip, 'postconf')
@@ -139,7 +140,7 @@ class NanoBts(bts.Bts):
self.log('nanoBTS configured and running')
ipfind.stop()
- event_loop.wait(self, self.bsc.bts_is_connected, self, timeout=600)
+ MainLoop.wait(self, self.bsc.bts_is_connected, self, timeout=600)
self.log('nanoBTS connected to BSC')
#According to roh, it can be configured to use a static IP in a permanent way:
@@ -227,7 +228,7 @@ class AbisIpFind(log.Origin):
return self.get_line_by_ip(ipaddr) is not None
def wait_bts_ready(self, ipaddr):
- event_loop.wait(self, self.bts_ready, ipaddr)
+ MainLoop.wait(self, self.bts_ready, ipaddr)
class IpAccessConfig(log.Origin):
@@ -265,7 +266,7 @@ class IpAccessConfig(log.Origin):
self.env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
self.proc = self.launch_process(IpAccessConfig.BIN_IPACCESS_CONFIG, *args)
try:
- event_loop.wait(self, self.proc.terminated)
+ MainLoop.wait(self, self.proc.terminated)
except Exception as e:
self.proc.terminate()
raise e
diff --git a/src/osmo_gsm_tester/bts_octphy.py b/src/osmo_gsm_tester/bts_octphy.py
index f5fa90b..f48afcc 100644
--- a/src/osmo_gsm_tester/bts_octphy.py
+++ b/src/osmo_gsm_tester/bts_octphy.py
@@ -20,7 +20,7 @@
import os
import pprint
import tempfile
-from . import log, config, util, template, process, event_loop, pcu_osmo, bts_osmo
+from . import log, config, util, template, process, pcu_osmo, bts_osmo
class OsmoBtsOctphy(bts_osmo.OsmoBtsMainUnit):
diff --git a/src/osmo_gsm_tester/bts_osmo.py b/src/osmo_gsm_tester/bts_osmo.py
index 60b9695..be87b9d 100644
--- a/src/osmo_gsm_tester/bts_osmo.py
+++ b/src/osmo_gsm_tester/bts_osmo.py
@@ -21,7 +21,7 @@ import os
import pprint
import tempfile
from abc import ABCMeta, abstractmethod
-from . import log, config, util, template, process, event_loop, bts, pcu_osmo
+from . import log, config, util, template, process, bts, pcu_osmo
class OsmoBts(bts.Bts, metaclass=ABCMeta):
proc_bts = None
diff --git a/src/osmo_gsm_tester/bts_osmotrx.py b/src/osmo_gsm_tester/bts_osmotrx.py
index ba7258e..bdfb97c 100644
--- a/src/osmo_gsm_tester/bts_osmotrx.py
+++ b/src/osmo_gsm_tester/bts_osmotrx.py
@@ -20,7 +20,8 @@
import os
import pprint
import tempfile
-from . import log, config, util, template, process, event_loop, pcu_osmo, bts_osmo
+from . import log, config, util, template, process, pcu_osmo, bts_osmo
+from .event_loop import MainLoop
class OsmoBtsTrx(bts_osmo.OsmoBtsMainUnit):
##############
@@ -125,7 +126,7 @@ class OsmoBtsTrx(bts_osmo.OsmoBtsMainUnit):
self.trx = OsmoTrx(self.suite_run, self.conf, self.trx_remote_ip(), self.remote_addr())
self.trx.start()
self.log('Waiting for osmo-trx to start up...')
- event_loop.wait(self, self.trx.trx_ready)
+ MainLoop.wait(self, self.trx.trx_ready)
self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-bts')))
lib = self.inst.child('lib')
diff --git a/src/osmo_gsm_tester/esme.py b/src/osmo_gsm_tester/esme.py
index 63a1ded..78421f6 100644
--- a/src/osmo_gsm_tester/esme.py
+++ b/src/osmo_gsm_tester/esme.py
@@ -23,7 +23,8 @@ import smpplib.command
import smpplib.consts
import smpplib.exceptions
-from . import log, util, event_loop, sms
+from . import log, util, sms
+from .event_loop import MainLoop
# if you want to know what's happening inside python-smpplib
#import logging
@@ -82,14 +83,14 @@ class Esme(log.Origin):
def start_listening(self):
self.listening = True
- event_loop.register_poll_func(self.poll)
+ MainLoop.register_poll_func(self.poll)
def stop_listening(self):
if not self.listening:
return
self.listening = False
# Empty the queue before processing the unbind + disconnect PDUs
- event_loop.unregister_poll_func(self.poll)
+ MainLoop.unregister_poll_func(self.poll)
self.poll()
def connect(self):
@@ -176,7 +177,7 @@ class Esme(log.Origin):
umref, self.pdus_pending = self.sms_send(sms_obj, mode, receipt)
self.dbg('pdus_pending:', self.pdus_pending)
self.client.set_message_sent_handler(self._process_pdus_pending)
- event_loop.wait(self, lambda: len(self.pdus_pending) == 0, timeout=10)
+ MainLoop.wait(self, lambda: len(self.pdus_pending) == 0, timeout=10)
return umref
finally:
self.client.set_message_sent_handler(old_func)
diff --git a/src/osmo_gsm_tester/event_loop.py b/src/osmo_gsm_tester/event_loop.py
index 068eca9..a9683dd 100644
--- a/src/osmo_gsm_tester/event_loop.py
+++ b/src/osmo_gsm_tester/event_loop.py
@@ -112,35 +112,7 @@ class EventLoop:
self.wait_no_raise(log_obj, lambda: False, [], {}, timeout=seconds, timestep=seconds)
-evloop = EventLoop()
-
-def register_poll_func(func):
- global evloop
- evloop.register_poll_func(func)
-
-def unregister_poll_func(func):
- global evloop
- evloop.unregister_poll_func(func)
-
-def poll():
- global evloop
- evloop.poll()
-
-def wait_no_raise(log_obj, condition, condition_args, condition_kwargs, timeout, timestep):
- global evloop
- evloop.wait_no_raise(log_obj, condition, condition_args, condition_kwargs, timeout, timestep)
-
-def wait(log_obj, condition, *condition_args, timeout=300, timestep=1, **condition_kwargs):
- global evloop
- evloop.wait(log_obj, condition, *condition_args, timeout=timeout, timestep=timestep, **condition_kwargs)
-
-def sleep(log_obj, seconds):
- global evloop
- evloop.sleep(log_obj, seconds)
-
-def defer(handler, *args, **kwargs):
- global evloop
- evloop.defer(handler, *args, **kwargs)
+MainLoop = EventLoop()
# vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/osmo_gsm_tester/modem.py b/src/osmo_gsm_tester/modem.py
index 8d41935..2f742ea 100644
--- a/src/osmo_gsm_tester/modem.py
+++ b/src/osmo_gsm_tester/modem.py
@@ -17,7 +17,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from . import log, util, event_loop, sms
+from . import log, util, sms
+from .event_loop import MainLoop
from pydbus import SystemBus, Variant
import time
@@ -54,7 +55,7 @@ class DeferredDBus:
self.subscription_id = dbus_iface.connect(self.receive_signal)
def receive_signal(self, *args, **kwargs):
- event_loop.defer(self.handler, *args, **kwargs)
+ MainLoop.defer(self.handler, *args, **kwargs)
def dbus_connect(dbus_iface, handler):
'''This function shall be used instead of directly connecting DBus signals.
@@ -296,13 +297,13 @@ class ModemDbusInteraction(log.Origin):
def set_bool(self, name, bool_val, iface=I_MODEM):
# to make sure any pending signals are received before we send out more DBus requests
- event_loop.poll()
+ MainLoop.poll()
val = bool(bool_val)
self.log('Setting', name, val)
self.interface(iface).SetProperty(name, Variant('b', val))
- event_loop.wait(self, self.property_is, name, bool_val)
+ MainLoop.wait(self, self.property_is, name, bool_val)
def set_powered(self, powered=True):
self.set_bool('Powered', powered)
@@ -410,10 +411,10 @@ class Modem(log.Origin):
if not self.is_powered():
self.set_powered()
# wait for SimManager iface to appear after we power on
- event_loop.wait(self, self.dbus.has_interface, I_SIMMGR, timeout=10)
+ MainLoop.wait(self, self.dbus.has_interface, I_SIMMGR, timeout=10)
simmgr = self.dbus.interface(I_SIMMGR)
# If properties are requested quickly, it may happen that Sim property is still not there.
- event_loop.wait(self, lambda: simmgr.GetProperties().get('SubscriberIdentity', None) is not None, timeout=10)
+ MainLoop.wait(self, lambda: simmgr.GetProperties().get('SubscriberIdentity', None) is not None, timeout=10)
props = simmgr.GetProperties()
self.dbg('got SIM properties', props)
self._imsi = props.get('SubscriberIdentity', None)
@@ -473,8 +474,8 @@ class Modem(log.Origin):
# waiting for that. Make it async and try to register when the scan is
# finished.
register_func = self.scan_cb_register_automatic if mcc_mnc is None else self.scan_cb_register
- result_handler = lambda obj, result, user_data: event_loop.defer(register_func, result, user_data)
- error_handler = lambda obj, e, user_data: event_loop.defer(self.scan_cb_error_handler, e, mcc_mnc)
+ result_handler = lambda obj, result, user_data: MainLoop.defer(register_func, result, user_data)
+ error_handler = lambda obj, e, user_data: MainLoop.defer(self.scan_cb_error_handler, e, mcc_mnc)
dbus_async_call(netreg, netreg.Scan, timeout=30, cancellable=self.cancellable,
result_handler=result_handler, error_handler=error_handler,
user_data=mcc_mnc)
@@ -539,7 +540,7 @@ class Modem(log.Origin):
self.cancellable.cancel()
# Cancel op is applied as a signal coming from glib mainloop, so we
# need to run it and wait for the callbacks to handle cancellations.
- event_loop.poll()
+ MainLoop.poll()
# once it has been triggered, create a new one for next operation:
self.cancellable = Gio.Cancellable.new()
@@ -550,20 +551,20 @@ class Modem(log.Origin):
self.set_powered(False)
req_ifaces = self._required_ifaces()
for iface in req_ifaces:
- event_loop.wait(self, lambda: not self.dbus.has_interface(iface), timeout=10)
+ MainLoop.wait(self, lambda: not self.dbus.has_interface(iface), timeout=10)
def power_cycle(self):
'Power the modem and put it online, power cycle it if it was already on'
req_ifaces = self._required_ifaces()
if self.is_powered():
self.dbg('Power cycling')
- event_loop.sleep(self, 1.0) # workaround for ofono bug OS#3064
+ MainLoop.sleep(self, 1.0) # workaround for ofono bug OS#3064
self.power_off()
else:
self.dbg('Powering on')
self.set_powered()
self.set_online()
- event_loop.wait(self, self.dbus.has_interface, *req_ifaces, timeout=10)
+ MainLoop.wait(self, self.dbus.has_interface, *req_ifaces, timeout=10)
def connect(self, mcc_mnc=None):
'Connect to MCC+MNC'
@@ -616,7 +617,7 @@ class Modem(log.Origin):
# Activate can only be called after we are attached
ctx.SetProperty('Active', Variant('b', True))
- event_loop.wait(self, lambda: ctx.GetProperties()['Active'] == True)
+ MainLoop.wait(self, lambda: ctx.GetProperties()['Active'] == True)
self.log('context activated', path=ctx_path, apn=apn, user=user, properties=ctx.GetProperties())
return ctx_path
@@ -624,7 +625,7 @@ class Modem(log.Origin):
self.dbg('deactivate_context', path=ctx_id)
ctx = systembus_get(ctx_id)
ctx.SetProperty('Active', Variant('b', False))
- event_loop.wait(self, lambda: ctx.GetProperties()['Active'] == False)
+ MainLoop.wait(self, lambda: ctx.GetProperties()['Active'] == False)
self.dbg('deactivate_context active=false, removing', path=ctx_id)
connmgr = self.dbus.interface(I_CONNMGR)
connmgr.RemoveContext(ctx_id)
@@ -689,7 +690,7 @@ class Modem(log.Origin):
else:
caller_msisdn = str(caller_msisdn_or_modem)
self.dbg('Waiting for incoming call from:', caller_msisdn)
- event_loop.wait(self, lambda: self._find_call_msisdn_state(caller_msisdn, 'incoming') is not None, timeout=timeout)
+ MainLoop.wait(self, lambda: self._find_call_msisdn_state(caller_msisdn, 'incoming') is not None, timeout=timeout)
return self._find_call_msisdn_state(caller_msisdn, 'incoming')
def call_answer(self, call_id):
diff --git a/src/osmo_gsm_tester/pcu_osmo.py b/src/osmo_gsm_tester/pcu_osmo.py
index deaeb80..6ab97de 100644
--- a/src/osmo_gsm_tester/pcu_osmo.py
+++ b/src/osmo_gsm_tester/pcu_osmo.py
@@ -20,7 +20,7 @@
import os
import pprint
import tempfile
-from . import log, config, util, template, process, event_loop, pcu
+from . import log, config, util, template, process, pcu
class OsmoPcu(pcu.Pcu):
inst = None
diff --git a/src/osmo_gsm_tester/pcu_sysmo.py b/src/osmo_gsm_tester/pcu_sysmo.py
index fd1b272..675de50 100644
--- a/src/osmo_gsm_tester/pcu_sysmo.py
+++ b/src/osmo_gsm_tester/pcu_sysmo.py
@@ -19,7 +19,7 @@
import os
import pprint
-from . import log, config, util, template, process, event_loop
+from . import log, config, util, template, process
class OsmoPcuSysmo(log.Origin):
suite_run = None
diff --git a/src/osmo_gsm_tester/powersupply.py b/src/osmo_gsm_tester/powersupply.py
index 8d52157..86fc010 100644
--- a/src/osmo_gsm_tester/powersupply.py
+++ b/src/osmo_gsm_tester/powersupply.py
@@ -18,7 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from abc import ABCMeta, abstractmethod
-from . import log, event_loop
+from . import log
+from .event_loop import MainLoop
class PowerSupply(log.Origin, metaclass=ABCMeta):
@@ -46,7 +47,7 @@ class PowerSupply(log.Origin, metaclass=ABCMeta):
def power_cycle(self, sleep=0):
"""Turns off the device, waits N.N seconds, then turn on the device."""
self.power_set(False)
- event_loop.sleep(self, sleep)
+ MainLoop.sleep(self, sleep)
self.power_set(True)
diff --git a/src/osmo_gsm_tester/powersupply_sispm.py b/src/osmo_gsm_tester/powersupply_sispm.py
index 91604b4..b35592f 100644
--- a/src/osmo_gsm_tester/powersupply_sispm.py
+++ b/src/osmo_gsm_tester/powersupply_sispm.py
@@ -20,7 +20,8 @@
import sispm
from usb.core import USBError
-from . import log, event_loop
+from . import log
+from .event_loop import MainLoop
from .powersupply import PowerSupply
class PowerSupplySispm(PowerSupply):
@@ -50,7 +51,7 @@ class PowerSupplySispm(PowerSupply):
except USBError as e:
if e.errno == 16 or e.errno==110:
self.log('skip usb error, retry', repr(e))
- event_loop.sleep(self, 0.1)
+ MainLoop.sleep(self, 0.1)
continue
raise e
diff --git a/src/osmo_gsm_tester/process.py b/src/osmo_gsm_tester/process.py
index 4c55fe9..8ae6a55 100644
--- a/src/osmo_gsm_tester/process.py
+++ b/src/osmo_gsm_tester/process.py
@@ -23,7 +23,8 @@ import subprocess
import signal
from datetime import datetime
-from . import log, event_loop
+from . import log
+from .event_loop import MainLoop
from .util import Dir
class Process(log.Origin):
@@ -204,7 +205,7 @@ class Process(log.Origin):
return self.result is not None
def wait(self, timeout=300):
- event_loop.wait(self, self.terminated, timeout=timeout)
+ MainLoop.wait(self, self.terminated, timeout=timeout)
class RemoteProcess(Process):
diff --git a/src/osmo_gsm_tester/suite.py b/src/osmo_gsm_tester/suite.py
index 106994e..a7f91c5 100644
--- a/src/osmo_gsm_tester/suite.py
+++ b/src/osmo_gsm_tester/suite.py
@@ -21,7 +21,8 @@ import os
import sys
import time
import pprint
-from . import config, log, template, util, resource, schema, event_loop, test
+from . import config, log, template, util, resource, schema, test
+from .event_loop import MainLoop
from . import osmo_nitb, osmo_hlr, osmo_mgcpgw, osmo_mgw, osmo_msc, osmo_bsc, osmo_stp, osmo_ggsn, osmo_sgsn, modem, esme
class Timeout(Exception):
@@ -150,7 +151,7 @@ class SuiteRun(log.Origin):
try:
log.large_separator(self.trial.name(), self.name(), sublevel=2)
self.mark_start()
- event_loop.register_poll_func(self.poll)
+ MainLoop.register_poll_func(self.poll)
if not self.reserved_resources:
self.reserve_resources()
for t in self.tests:
@@ -175,7 +176,7 @@ class SuiteRun(log.Origin):
self.stop_processes()
self.objects_cleanup()
self.free_resources()
- event_loop.unregister_poll_func(self.poll)
+ MainLoop.unregister_poll_func(self.poll)
self.duration = time.time() - self.start_timestamp
passed, skipped, failed = self.count_test_results()
@@ -344,7 +345,7 @@ class SuiteRun(log.Origin):
sys.__stdout__.write(msg)
sys.__stdout__.write('\n')
sys.__stdout__.flush()
- entered = util.input_polling('> ', event_loop.poll)
+ entered = util.input_polling('> ', MainLoop.poll)
self.log('prompt entered:', repr(entered))
return entered
diff --git a/src/osmo_gsm_tester/test.py b/src/osmo_gsm_tester/test.py
index 82b290f..59d503c 100644
--- a/src/osmo_gsm_tester/test.py
+++ b/src/osmo_gsm_tester/test.py
@@ -54,8 +54,9 @@ class Test(log.Origin):
log.large_separator(self.suite_run.trial.name(), self.suite_run.name(), self.name(), sublevel=3)
self.status = Test.UNKNOWN
self.start_timestamp = time.time()
- from . import suite, event_loop, sms
- testenv.setup(self.suite_run, self, suite, event_loop, sms)
+ from . import suite, sms
+ from .event_loop import MainLoop
+ testenv.setup(self.suite_run, self, suite, MainLoop, sms)
with self.redirect_stdout():
util.run_python_file('%s.%s' % (self.suite_run.definition.name(), self.basename),
self.path)