示例#1
0
    def test_ns_pids(self):
        def waiting_child(fd):
            while True:
                if not os.read(fd, 32):
                    exit(0)

        require_user('root')
        foo = str(uuid4())
        netnsmod.create(foo)
        netnsmod.pushns(foo)
        foo_pid, foo_fd = os.forkpty()
        if not foo_pid:
            waiting_child(foo_fd)
        netnsmod.popns()

        pids = netnsmod.ns_pids()
        try:
            assert pids[foo] == [foo_pid]
        finally:
            os.close(foo_fd)
            netnsmod.remove(foo)
示例#2
0
    def test_ns_pids(self):
        def waiting_child(fd):
            while True:
                if not os.read(fd, 32):
                    exit(0)

        require_user('root')
        foo = str(uuid4())
        netnsmod.create(foo)
        netnsmod.pushns(foo)
        foo_pid, foo_fd = os.forkpty()
        if not foo_pid:
            waiting_child(foo_fd)
        netnsmod.popns()

        pids = netnsmod.ns_pids()
        try:
            assert pids[foo] == [foo_pid]
        finally:
            os.close(foo_fd)
            netnsmod.remove(foo)
示例#3
0
def list_ns_pids(namespace):
    """List namespace process PIDs"""
    return netns.ns_pids().get(namespace, [])