def __init__(self): service_path = PathConfiguration.test_networkmanager_service_path() self._conn = dbus.SessionBus() p = subprocess.Popen([sys.executable, service_path], stdin=subprocess.PIPE) start = nmex.nm_boot_time_ns() while True: if p.poll() is not None: p.stdin.close() if p.returncode == 77: raise unittest.SkipTest( 'the stub service %s exited with status 77' % (service_path)) raise Exception('the stub service %s exited unexpectedly' % (service_path)) nmobj = self._conn_get_main_object(self._conn) if nmobj is not None: break if (nmex.nm_boot_time_ns() - start) / 1000000 >= 2000: p.stdin.close() p.kill() Util.popen_wait(p, 1000) raise Exception( "after starting stub service the D-Bus name was not claimed in time" ) self._nmobj = nmobj self._nmiface = dbus.Interface( nmobj, "org.freedesktop.NetworkManager.LibnmGlibTest") self._p = p
def popen_wait(p, timeout=None): # wait() has a timeout argument only since 3.3 if Util.python_has_version(3, 3): return p.wait(timeout) if timeout is None: return p.wait() start = nmex.nm_boot_time_ns() while True: if p.poll() is not None: return p.returncode if start + (timeout * 1000000000) < nmex.nm_boot_time_ns(): raise Exception("timeout expired") time.sleep(0.05)