def test_release(self): require_user('root') nsid = self.alloc_nsname() nsp = NSPopen(nsid, ['true'], flags=os.O_CREAT, stdout=subprocess.PIPE) nsp.communicate() nsp.wait() nsp.release() try: print(nsp.returncode) except RuntimeError: pass
def test_release(self): require_user('root') nsid = self.alloc_nsname() nsp = NSPopen(nsid, ['true'], flags=os.O_CREAT, stdout=subprocess.PIPE) nsp.communicate() nsp.wait() nsp.release() try: print(nsp.returncode) except RuntimeError: pass
def managed_nspopen(*args, **kwds): proc = NSPopen(*args, **kwds) try: yield proc finally: if proc.poll() is None: # send SIGKILL to the process and wait for it to die if it's still # running proc.kill() proc.communicate() # release proxy process resourecs proc.release()
def managed_nspopen(*args, **kwds): proc = NSPopen(*args, **kwds) try: yield proc finally: if proc.poll() is None: # send SIGKILL to the process and wait for it to die if it's still # running proc.kill() # If it's not dead after 2 seconds we throw an error proc.communicate(timeout=2) # release proxy process resourecs proc.release()
def test_api_object(self): require_user('root') nsid = self.alloc_nsname() nsp = NSPopen(nsid, ['true'], flags=os.O_CREAT, stdout=subprocess.PIPE) smp = subprocess.Popen(['true'], stdout=subprocess.PIPE) nsp.communicate() smp.communicate() api_nspopen = set(dir(nsp)) api_popen = set(dir(smp)) minimal = set(('communicate', 'kill', 'wait')) assert minimal & (api_nspopen & api_popen) == minimal smp.wait() nsp.wait() assert nsp.returncode == smp.returncode == 0 nsp.release()
def test_api_object(self): require_user('root') nsid = self.alloc_nsname() nsp = NSPopen(nsid, ['true'], flags=os.O_CREAT, stdout=subprocess.PIPE) smp = subprocess.Popen(['true'], stdout=subprocess.PIPE) nsp.communicate() smp.communicate() api_nspopen = set(dir(nsp)) api_popen = set(dir(smp)) minimal = set(('communicate', 'kill', 'wait')) assert minimal & (api_nspopen & api_popen) == minimal smp.wait() nsp.wait() assert nsp.returncode == smp.returncode == 0 nsp.release()
def test_basic(self): require_user('root') nsid = self.alloc_nsname() # create NS and run a child nsp = NSPopen(nsid, ['ip', '-o', 'link'], stdout=subprocess.PIPE, flags=os.O_CREAT) ret = nsp.communicate()[0].decode('utf-8') host_links = [x.get_attr('IFLA_IFNAME') for x in self.ip.get_links()] netns_links = [x.split(':')[1].split('@')[0].strip() for x in ret.split('\n') if len(x)] assert nsp.wait() == nsp.returncode == 0 assert set(host_links) & set(netns_links) == set(netns_links) assert set(netns_links) < set(host_links) assert not set(netns_links) > set(host_links) nsp.release()
def test_basic(self): require_user('root') nsid = self.alloc_nsname() # create NS and run a child nsp = NSPopen(nsid, ['ip', '-o', 'link'], stdout=subprocess.PIPE, flags=os.O_CREAT) ret = nsp.communicate()[0].decode('utf-8') host_links = [x.get_attr('IFLA_IFNAME') for x in self.ip.get_links()] netns_links = [x.split(':')[1].split('@')[0].strip() for x in ret.split('\n') if len(x)] assert nsp.wait() == nsp.returncode == 0 assert set(host_links) & set(netns_links) == set(netns_links) assert set(netns_links) < set(host_links) assert not set(netns_links) > set(host_links) nsp.release()
'qdisc', 'add', 'dev', veth, 'root', 'netem', 'delay', f'{args.delay}ms', f'{int(args.delay)/2}ms', 'loss', f'{args.loss}%', '25%', ], stdout=subprocess.PIPE, ) nsp.communicate() nsp.wait() nsp.release() if args.verbose: print(f'netem: add {nsname}/{veth}, ' f'{args.delay}, {args.loss}') # create the tap # # for some reason we should create the tap inteface first, # and only then bring it up, thus two commit() calls (ndb.interfaces.create(kind='tuntap', ifname=tap_name, mode='tap').commit().set('state', 'up').commit()) if args.verbose: print(f'link: add main/{tap_name}')