def test_create_with_host(self): h = Host('test', None, LinuxCLI(), lambda n: None, lambda n: None) h2 = Host('test2', None, NetNSCLI('test2'), CREATENSCMD, REMOVENSCMD) h2.create() p = Interface(name='testp', host=h2, ip_addr=['10.0.0.1']) i = VirtualInterface(name='testi', host=h, ip_addr=['192.168.0.2'], far_interface=p) i.create() # should create and set peer on far host self.assertTrue(h2.cli.grep_cmd('ip l', 'testp')) self.assertTrue(LinuxCLI().grep_cmd('ip l', 'testi')) self.assertFalse(LinuxCLI().grep_cmd('ip l', 'testi.p')) i.config_addr() # the far iface should be controllable on its own just like any interface p.add_ip('192.168.1.2') p.up() self.assertTrue(h2.cli.grep_cmd('ip a | grep testp | grep inet | sed -e "s/^ *//" | cut -f 2 -d " "', '192.168.1.2')) i.remove() # should remove both interfaces self.assertFalse(h2.cli.grep_cmd('ip l', 'testp')) self.assertFalse(LinuxCLI().grep_cmd('ip l', 'testi')) h2.remove()
def test_use_active_iface(self): cli = LinuxCLI(log_cmd=True) h = Host('test', None, cli, lambda name: None, lambda name: None) i = Interface('testi', h, ip_addr=['192.168.0.2']) cli.cmd('ip l add dev testi type dummy') self.assertTrue(cli.grep_cmd('ip l | grep testi', 'state DOWN')) i.up() time.sleep(1) self.assertTrue(cli.grep_cmd('ip l | grep testi', 'UP')) i.down() self.assertFalse(cli.grep_cmd('ip l | grep testi', 'UP')) cli.cmd('ip l del testi')