예제 #1
0
    def test_pushns(self):
        require_user('root')
        foo = str(uuid4())
        ifA = uifname()

        with IPRoute() as ipr:
            ipr.link('add', ifname=ifA, kind='dummy')

        netnsmod.pushns(foo)
        with IPRoute() as ipr:
            assert ifA not in [
                x.get_attr('IFLA_IFNAME') for x in ipr.link('dump')
            ]
        netnsmod.popns()
        with IPRoute() as ipr:
            assert ifA in [x.get_attr('IFLA_IFNAME') for x in ipr.link('dump')]

            ipr.link('del', index=ipr.link_lookup(ifname=ifA)[0])

        netnsmod.remove(foo)
예제 #2
0
    def test_pushns(self):
        require_user('root')
        foo = str(uuid4())
        ifA = uifname()

        with IPRoute() as ipr:
            ipr.link('add', ifname=ifA, kind='dummy')

        netnsmod.pushns(foo)
        with IPRoute() as ipr:
            assert ifA not in [x.get_attr('IFLA_IFNAME') for x
                               in ipr.link('dump')]
        netnsmod.popns()
        with IPRoute() as ipr:
            assert ifA in [x.get_attr('IFLA_IFNAME') for x
                           in ipr.link('dump')]

            ipr.link('del', index=ipr.link_lookup(ifname=ifA)[0])

        netnsmod.remove(foo)
예제 #3
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)
예제 #4
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)
예제 #5
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     return netns.popns()
예제 #6
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     return netns.popns()