Exemple #1
0
    def __init__(self, seed):
        service_path = PathConfiguration.test_networkmanager_service_path()
        self._conn = dbus.SessionBus()
        env = os.environ.copy()
        env['NM_TEST_NETWORKMANAGER_SERVICE_SEED'] = seed
        p = subprocess.Popen([sys.executable, service_path],
                             stdin=subprocess.PIPE,
                             env=env)

        start = NM.utils_get_timestamp_msec()
        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 (NM.utils_get_timestamp_msec() - start) >= 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
Exemple #2
0
 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 = NM.utils_get_timestamp_msec()
     while True:
         if p.poll() is not None:
             return p.returncode
         if start + (timeout * 1000) < NM.utils_get_timestamp_msec():
             raise Exception("timeout expired")
         time.sleep(0.05)
Exemple #3
0
    def get_access_points(self, scan):
        if scan is None:  # automatically scan if needed
            age = NM.utils_get_timestamp_msec() - self._nm_dev.get_last_scan()
            scan = bool(age > 30_000)

        if scan:
            timeout = monotonic() + 60
            last = self._nm_dev.get_last_scan()
            self.request_scan()

            while monotonic() < timeout:
                sleep(0.25)
                if self._nm_dev.get_last_scan() > last:
                    break
            else:
                raise TimeoutError("scan did not complete")

        aps = self._nm_dev.get_access_points()
        return [self._accesspoint_to_dict(ap) for ap in aps]
Exemple #4
0
def do_show(client):
    ts = NM.utils_get_timestamp_msec()
    for c in client.get_checkpoints():
        show(c, ts)
Exemple #5
0
def do_show(nmc):
    ts = NM.utils_get_timestamp_msec()
    for c in nmc.get_checkpoints():
        show(c, ts)