示例#1
0
    def test_ipmi_console_stops_followed_by_vbmc_stop(self):
        node_info = FakeConfig().get_node_info()
        self.node_name = node_info.get("name", "test")
        self.node_workspace = os.path.join(config.infrasim_home,
                                           self.node_name)
        node = CNode(node_info)
        node.init()
        node.precheck()
        node.start()
        time.sleep(3)

        ps_ipmi_console_cmd = "ps ax | grep ipmi-console"
        start_ipmi_console_cmd = "ipmi-console start {}".format(self.node_name)

        returncode = run_command(start_ipmi_console_cmd,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)[0]
        self.assertEqual(returncode, 0)
        output = run_command(ps_ipmi_console_cmd,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)[1]
        assert start_ipmi_console_cmd in output

        node.stop()
        # ipmi-console polls every 3s to see vbmc status, so wait 10s for it
        time.sleep(10)
        output = run_command(ps_ipmi_console_cmd,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)[1]
        assert start_ipmi_console_cmd not in output
    def test_two_nodes_running_in_same_net_namespace(self):
        self._setup_netns("test")
        fake_node1 = FakeConfig().get_node_info()
        fake_node1["name"] = "test1"
        fake_node1["namespace"] = "test"
        fake_node_obj_1 = self._start_node(fake_node1)

        fake_node2 = FakeConfig().get_node_info()
        fake_node2["name"] = "test2"
        fake_node2["namespace"] = "test"
        assert_raises(ArgsNotCorrect, self._start_node, fake_node2)
        self._stop_node(fake_node_obj_1)
        self._teardown_netns("test")
 def setUp(self):
     node_info = FakeConfig().get_node_info()
     with open(self.test_config_path, "w") as fp:
         yaml.dump(node_info, fp, default_flow_style=False)
     os.system("infrasim config add {} {}".format(self.test_name, self.test_config_path))
     os.system("infrasim node start {}".format(self.test_name))
     os.system("infrasim node stop {}".format(self.test_name))
    def node_cfg_up(node_name, ns_name, boot_image, node_type):
        global add_content0
        global add_content1
        fake_node = None
        fake_node = copy.deepcopy(FakeConfig().get_node_info())
        fake_node['name'] = node_name
        fake_node['type'] = node_type
        fake_node['namespace'] = ns_name
        fake_node['compute']['storage_backend'][0]["drives"][0][
            "file"] = boot_image
        fake_node["compute"]["networks"][0]["port_forward"] = [{
            "outside":
            8022,
            "inside":
            22,
            "protocal":
            "tcp"
        }]
        fake_node["bmc"] = {}
        fake_node["bmc"]["peer-bmcs"] = [{"port_ipmb": 9009}]

        if node_name == "test0":
            fake_node["bmc"]["address"] = 0x1c
            fake_node["bmc"]["peer-bmcs"][0]["addr"] = 0x1e
            fake_node["bmc"]["peer-bmcs"][0]["host"] = "192.168.188.92"
            fake_node["bmc"]["peer-bmcs"][0]["port_ipmb"] = 9009
        else:
            fake_node["bmc"]["address"] = 0x1e
            fake_node["bmc"]["peer-bmcs"][0]["addr"] = 0x1c
            fake_node["bmc"]["peer-bmcs"][0]["host"] = "192.168.188.91"
            fake_node["bmc"]["peer-bmcs"][0]["port_ipmb"] = 9009

        fake_node_up = test_bmc_communication._start_node(
            fake_node, node_name, node_type)
        return fake_node_up
示例#5
0
 def test_start_stop_specified_ipmi_console(self):
     self.node_name = "test"
     self.node_workspace = os.path.join(config.infrasim_home,
                                        self.node_name)
     node_config_path = "test.yml"
     node_info = FakeConfig().get_node_info()
     with open(node_config_path, "w") as fp:
         yaml.dump(node_info, fp, default_flow_style=False)
     os.system("infrasim config add {} {}".format(self.node_name,
                                                  node_config_path))
     os.system("infrasim node start {}".format(self.node_name))
     os.system("ipmi-console start {}".format(self.node_name))
     time.sleep(20)
     ipmi_start_cmd = 'ps ax | grep ipmi-console'
     returncode, output = run_command(ipmi_start_cmd,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE)
     os.system("ipmi-console stop {}".format(self.node_name))
     ipmi_stop_cmd = 'ps ax | grep ipmi-console'
     returncode1, output1 = run_command(ipmi_stop_cmd,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE)
     self.assertEqual(returncode, 0)
     self.assertEqual(returncode, 0)
     assert 'ipmi-console start {}'.format(self.node_name) in output
     self.assertEqual(returncode1, 0)
     assert 'ipmi-console start {}'.format(self.node_name) not in output1
     node_map = NodeMap()
     node_map.delete(self.node_name)
    def test_ipmi_console_stops_followed_by_node_destroy(self):
        node_info = FakeConfig().get_node_info()
        self.node_name = node_info.get("name", "test")
        self.node_workspace = os.path.join(
            config.infrasim_home, self.node_name)
        node = CNode(node_info)
        node.init()
        node.precheck()
        node.start()
        time.sleep(3)

        ps_ipmi_console_cmd = "ps ax | grep ipmi-console"
        start_ipmi_console_cmd = "ipmi-console start {}".format(
            self.node_name)

        returncode = run_command(
            start_ipmi_console_cmd, stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)[0]
        self.assertEqual(returncode, 0)
        output = run_command(
            ps_ipmi_console_cmd, stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)[1]
        assert start_ipmi_console_cmd in output
        time.sleep(20)

        node.stop()
        node.terminate_workspace()

        # ipmi-console polls every 3s to see vbmc status, wait a while for
        # possible resource collection
        for _ in range(10):
            time.sleep(3)
            output = run_command(
                ps_ipmi_console_cmd, stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)[1]
            if start_ipmi_console_cmd not in output:
                break
            else:
                assert False
    def test_one_node_runnning_in_one_net_namespace(self):
        # create netns
        self._setup_netns("test")
        fake_node = FakeConfig().get_node_info()
        fake_node["name"] = "test"
        fake_node["namespace"] = "test"
        fake_node_obj = self._start_node(fake_node)
        time.sleep(2)

        self._verify_node_in_netns(fake_node_obj, "test")

        self._stop_node(fake_node_obj)
        self._teardown_netns("test")
    def test_ipmi_console_stops_followed_by_node_destroy(self):
        node_info = FakeConfig().get_node_info()
        self.node_name = node_info.get("name", "test")
        self.node_workspace = os.path.join(config.infrasim_home,
                                           self.node_name)
        node = CNode(node_info)
        node.init()
        node.precheck()
        node.start()
        time.sleep(3)

        ps_ipmi_console_cmd = "ps ax | grep ipmi-console"
        start_ipmi_console_cmd = "ipmi-console start {}".format(self.node_name)

        returncode = run_command(start_ipmi_console_cmd,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)[0]
        self.assertEqual(returncode, 0)
        output = run_command(ps_ipmi_console_cmd,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)[1]
        assert start_ipmi_console_cmd in output
        time.sleep(20)

        node.stop()
        node.terminate_workspace()

        # ipmi-console polls every 3s to see vbmc status, wait a while for
        # possible resource collection
        for _ in range(10):
            time.sleep(3)
            output = run_command(ps_ipmi_console_cmd,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)[1]
            if start_ipmi_console_cmd not in output:
                break
            else:
                assert False
    def test_two_nodes_running_in_different_net_namespace(self):
        self._setup_netns("test1")
        self._setup_netns("test2")

        fake_node1 = FakeConfig().get_node_info()
        fake_node1["name"] = "test1"
        fake_node1["namespace"] = "test1"
        fake_node_obj_1 = self._start_node(fake_node1)

        fake_node2 = FakeConfig().get_node_info()
        fake_node2["name"] = "test2"
        fake_node2["namespace"] = "test2"
        fake_node_obj_2 = self._start_node(fake_node2)

        time.sleep(2)

        self._verify_node_in_netns(fake_node_obj_1, "test1")
        self._verify_node_in_netns(fake_node_obj_2, "test2")

        self._stop_node(fake_node_obj_1)
        self._stop_node(fake_node_obj_2)

        self._teardown_netns("test1")
        self._teardown_netns("test2")
    def test_update_config(self):
        self.nm.add(self.test_name, self.init_config)
        self.assertTrue(os.path.exists(self.test_config))
        new_info = FakeConfig().get_node_info()
        new_info["name"] = "didi"
        new_info["type"] = "dell_r730"
        with open(self.tmp_config, "w") as fp:
            yaml.dump(new_info, fp, default_flow_style=False)

        self.nm.update(self.test_name, self.tmp_config)
        with open(self.test_config) as fp:
            node_info = YAMLLoader(fp).get_data()
            assert node_info["type"] == "dell_r730"
            assert node_info["name"] == "test"
        os.remove(self.tmp_config)
    def test_update_config_then_start_node(self):
        """
        CLI test: node will apply updated config if there's no runtime workspace
        """
        node_info = FakeConfig().get_node_info()
        node_info["type"] = "dell_r730xd"
        with open(self.test_config_path, "w") as fp:
            yaml.dump(node_info, fp, default_flow_style=False)

        output_update = run_command("infrasim config update {} {}".format(self.test_name, self.test_config_path))
        self.assertEqual(output_update[0], 0)
        output_start = run_command("infrasim node start {}".format(self.test_name))
        self.assertEqual(output_start[0], 0)
        output_ps_qemu = run_command("ps ax | grep qemu")
        self.assertEqual(output_ps_qemu[0], 0)

        assert "{}'s configuration mapping is updated".format(self.test_name) in output_update[1]
        assert "dell_r730xd" in output_ps_qemu[1]
示例#12
0
 def start_node_with_config(self, node_name, ns_name, boot_image, iso):
     fake_node = copy.deepcopy(FakeConfig().get_node_info())
     fake_node['name'] = node_name
     fake_node['namespace'] = ns_name
     fake_node['compute']['storage_backend'][0]["drives"][0][
         "file"] = boot_image
     if "test0" in node_name:
         fake_node['compute']['cdrom'] = {}
         fake_node['compute']['cdrom']['file'] = iso
         fake_node["compute"]["networks"].append({
             "device": "e1000",
             "network_mode": "bridge",
             "network_name": "br0",
             "mac": node0_mac0
         })
         fake_node["compute"]["networks"][0]["port_forward"] = [{
             "outside":
             8022,
             "inside":
             22,
             "protocal":
             "tcp"
         }]
         fake_node["compute"]["networks"][0]["mac"] = node0_mac1
     if "test1" in node_name:
         fake_node['compute']['cdrom'] = {}
         fake_node['compute']['cdrom']['file'] = iso
         fake_node["compute"]["networks"].append({
             "device": "e1000",
             "network_mode": "bridge",
             "network_name": "br0",
             "mac": node1_mac0
         })
         fake_node["compute"]["networks"][0]["port_forward"] = [{
             "outside":
             8022,
             "inside":
             22,
             "protocal":
             "tcp"
         }]
         fake_node["compute"]["networks"][0]["mac"] = node1_mac1
     fake_node_up = self._start_node(fake_node)
     return fake_node_up
示例#13
0
    def test_one_node_running_in_two_different_net_namespace(self):
        self._setup_netns("test1")
        self._setup_netns("test2")

        fake_node = FakeConfig().get_node_info()
        fake_node["name"] = "test"
        fake_node["namespace"] = "test1"
        fake_node_obj_1 = self._start_node(fake_node)
        time.sleep(1)

        fake_node["namespace"] = "test2"
        fake_node_obj_2 = CNode(fake_node)
        fake_node_obj_2.precheck()
        for task in fake_node_obj_2.get_task_list():
            assert task.get_task_pid() > 0

        self._stop_node(fake_node_obj_1)
        self._teardown_netns("test1")
        self._teardown_netns("test2")