def test_ns_create_delete(self): global ivn_file global fake_node1 global fake_node2 topo = Topology(ivn_file) topo.create() result1 = subprocess.check_output(['ovs-vsctl', 'list-br']) self.assertIn("br-int", result1, "vswitch is missing") result2 = subprocess.check_output( ['ovs-vsctl', 'list-ports', 'br-int']) self.assertIn("vint0", result2, "ports is missing") self.assertIn("vint1", result2, "ports is missing") result = subprocess.check_output(["ip", "netns", "list"]) reobj = re.search(r'node1ns(\s?\(id:\s?\d+\))?', result) assert reobj reobj = re.search(r'node0ns(\s?\(id:\s?\d+\))?', result) assert reobj a_boot_image = cloud_img.gen_qemuimg(fixtures.cloud_img_ubuntu_16_04, "mytest0.img") b_boot_image = cloud_img.gen_qemuimg(fixtures.cloud_img_ubuntu_16_04, "mytest1.img") newnetwork0 = create_new_networkconfig(node0_mac0, "192.168.188.211", "192.168.188.1", node0_mac1) newnetwork1 = create_new_networkconfig(node1_mac0, "192.168.188.210", "192.168.188.1", node1_mac1) a_iso = cloud_img.geniso("my-seed0.iso", "305c9cc1-2f5a-4e76-b28e-ed8313fa283e", newnetwork0) b_iso = cloud_img.geniso("my-seed1.iso", "305c9cc1-2f5a-4e76-b28e-ed8313fa283f", newnetwork1) fake_node1 = self.start_node_with_config('test0', 'node0ns', a_boot_image, a_iso) fake_node2 = self.start_node_with_config('test1', 'node1ns', b_boot_image, b_iso) self._verify_node_in_netns(fake_node1, "node0ns") self._verify_node_in_netns(fake_node2, "node1ns") node1_ssh = self.client_ssh('192.168.188.211') node2_ssh = self.client_ssh('192.168.188.210') self.ping_peer(node1_ssh, '192.168.188.210') self.ping_peer(node2_ssh, '192.168.188.211') test_ivn._stop_node(fake_node1) test_ivn._stop_node(fake_node2) cloud_img.clear_files() fake_node1 = None fake_node2 = None topo.delete() result = subprocess.check_output(["ip", "netns", "list"]) self.assertNotIn("node1ns", result, "delete node1ns failed") self.assertNotIn("node0ns", result, "delete node0ns failed") result1 = subprocess.check_output(['ovs-vsctl', 'list-br']) self.assertNotIn("br-int", result1, "delete vswitch success")
def test_ns_create_delete(self): global ivn_file topo = Topology(ivn_file) topo.create() result = subprocess.check_output(["ip", "netns", "list"]) reobj = re.search(r'node1ns(\s?\(id:\s?\d+\))?', result) assert reobj reobj = re.search(r'node0ns(\s?\(id:\s?\d+\))?', result) assert reobj topo.delete() result = subprocess.check_output(["ip", "netns", "list"]) self.assertNotIn("node1ns", result, "delete node1ns failed") self.assertNotIn("node0ns", result, "delete node0ns failed")
def setup_module(): global ivn_cfg_file os.environ["PATH"] = new_path if os.path.exists(fixtures.a_boot_image) is False: raise Exception("Not found image {}".format(fixtures.a_boot_image)) if os.path.exists(fixtures.b_boot_image) is False: shutil.copy(fixtures.a_boot_image, fixtures.b_boot_image) with open("/tmp/trace_items", "w") as fo: fo.write("comm_log\n") fo.write("comm_failed\n") ivn_cfg_file = saved_config_file() # check the existence of required namespace. cmd = ["ip", "netns", "list"] result = subprocess.check_output(cmd) if "node1ns " not in result or "node0ns " not in result: topo = Topology(ivn_cfg_file) topo.create()
def test_ns_create_delete(self): global ivn_file global fake_node1 global fake_node2 topo = Topology(ivn_file) topo.create() result1 = subprocess.check_output(['ovs-vsctl', 'list-br']) self.assertIn("br-int", result1, "vswitch is missing") result2 = subprocess.check_output( ['ovs-vsctl', 'list-ports', 'br-int']) self.assertIn("vint0", result2, "ports is missing") self.assertIn("vint1", result2, "ports is missing") result = subprocess.check_output(["ip", "netns", "list"]) reobj = re.search(r'node1ns(\s?\(id:\s?\d+\))?', result) assert reobj reobj = re.search(r'node0ns(\s?\(id:\s?\d+\))?', result) assert reobj fake_node1 = self.start_node_with_config('test0', 'node0ns', a_boot_image, a_iso) fake_node2 = self.start_node_with_config('test1', 'node1ns', b_boot_image, b_iso) self._verify_node_in_netns(fake_node1, "node0ns") self._verify_node_in_netns(fake_node2, "node1ns") node1_ssh = self.client_ssh('192.168.188.211') node2_ssh = self.client_ssh('192.168.188.210') self.ping_peer(node1_ssh, '192.168.188.210') self.ping_peer(node2_ssh, '192.168.188.211') test_ivn._stop_node(fake_node1) test_ivn._stop_node(fake_node2) cloud_img.clear_files() fake_node1 = None fake_node2 = None topo.delete() result = subprocess.check_output(["ip", "netns", "list"]) self.assertNotIn("node1ns", result, "delete node1ns failed") self.assertNotIn("node0ns", result, "delete node0ns failed") result1 = subprocess.check_output(['ovs-vsctl', 'list-br']) self.assertNotIn("br-int", result1, "delete vswitch success")
#!/usr/bin/env python from ivn.core import Topology import sys if __name__ == "__main__": if sys.argv[1] == "create": topo = Topology("./config.yml") topo.create() elif sys.argv[1] == "delete": topo = Topology("./config.yml") topo.delete() else: print sys.argv[1]
def setup_module(): global ivn_file os.environ['PATH'] = new_path ivn_file = saved_config_file() topo = Topology(ivn_file) topo.create()