Exemplo n.º 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
Exemplo n.º 2
0
 def _init_sub_node(self, *args):
     nodes = self.__chassis.get("nodes")
     for node in nodes:
         node_obj = CNode(node)
         node_obj.set_node_name(node["name"])
         self.__node_list[node["name"]] = node_obj
     self.process_by_node_names("init", *args)
Exemplo n.º 3
0
def start_socat(conf_file=VM_DEFAULT_CONFIG):
    try:
        with open(conf_file, 'r') as f_yml:
            conf = yaml.load(f_yml)

        node = CNode(conf)
        if "name" in conf:
            node.set_node_name(conf["name"])
        node.init_workspace()

        socat = CSocat()
        # Read SOL device, serial port from conf
        # and set to socat
        if "sol_device" in conf:
            socat.set_sol_device(conf["sol_device"])
        if "serial_port" in conf:
            socat.set_port_serial(conf["serial_port"])

        socat.set_workspace(node.workspace)
        socat.init()
        socat.precheck()
        cmd = socat.get_commandline()

        run_command(cmd+" &", True, None, None)
        time.sleep(3)
        logger.info("socat start")
    except CommandRunFailed as e:
        raise e
Exemplo n.º 4
0
def start_socat(conf_file=config.infrasim_default_config):
    try:
        with open(conf_file, 'r') as f_yml:
            conf = yaml_load(f_yml)

        node = CNode(conf)
        if "name" in conf:
            node.set_node_name(conf["name"])

        node.init()

        socat = CSocat()
        # Read SOL device, serial port from conf
        # and set to socat
        if "sol_device" in conf:
            socat.set_sol_device(conf["sol_device"])
        if "serial_socket" in conf:
            socat.set_socket_serial(conf["serial_socket"])

        socat.set_workspace(node.workspace.get_workspace())
        socat.init()
        socat.precheck()
        cmd = socat.get_commandline()

        run_command(cmd + " &", True, None, None)
        time.sleep(3)
        logger.info("socat start")
    except CommandRunFailed as e:
        logger.error(e.value)
        raise e
    except InfraSimError as e:
        logger.error(e.value)
        raise e
Exemplo n.º 5
0
 def _init_sub_node(self, *args):
     nodes = self.__chassis.get("nodes")
     for node in nodes:
         node_obj = CNode(node)
         node_obj.set_node_name(node["name"])
         self.__node_list[node["name"]] = node_obj
     self.process_by_node_names("init", *args)
Exemplo n.º 6
0
def start_ipmi(conf_file=config.infrasim_default_config):
    try:
        with open(conf_file, 'r') as f_yml:
            conf = yaml_load(f_yml)

        node = CNode(node_info=conf)
        if "name" in conf:
            node.set_node_name(conf["name"])

        node.init()

        bmc = CBMC(conf.get('bmc', {}))
        node_name = conf["name"] if "name" in conf else "node-0"
        bmc.set_task_name("{}-bmc".format(node_name))
        bmc.set_log_path(os.path.join(config.infrasim_log_dir, node_name, "openipmi.log"))
        bmc.set_type(conf["type"])
        bmc.enable_sol(False)
        bmc.set_workspace(node.workspace.get_workspace())
        bmc.init()
        bmc.precheck()
        cmd = bmc.get_commandline()
        logger.debug(cmd)
        run_command(cmd + " &", True, None, None)

        logger.info("bmc start")
    except CommandRunFailed as e:
        logger.error(e.value)
        raise e
    except ArgsNotCorrect as e:
        logger.error(e.value)
        raise e
    except InfraSimError as e:
        logger.error(e.value)
        raise e
Exemplo n.º 7
0
    def tearDownClass(cls):

        with open(cls.TMP_CONF_FILE, "r") as yml_file:
            node_info = yaml.load(yml_file)

        node = CNode(node_info)
        node.init()

        if os.path.exists(cls.TMP_CONF_FILE):
            os.unlink(cls.TMP_CONF_FILE)

        workspace = os.path.join(config.infrasim_home, "test")
        if os.path.exists(workspace):
            shutil.rmtree(workspace)
Exemplo n.º 8
0
    def setUpClass(cls):
        node_info = {}
        fake_config = fixtures.FakeConfig()
        node_info = fake_config.get_node_info()
        node_info["ipmi_console_port"] = 9100
        node_info["ipmi_console_ssh"] = 9400
        cls.bmc_conf = os.path.join(os.environ["HOME"], ".infrasim",
                                    node_info["name"], "etc", "vbmc.conf")

        with open(cls.TMP_CONF_FILE, "w") as f:
            yaml.dump(node_info, f, default_flow_style=False)

        node = CNode(node_info)
        node.init()
        node.precheck()
        node.start()

        # Wait ipmi_sim sever coming up.
        # FIXME: good way???
        print "Wait ipmi-console start in about 15s..."
        time.sleep(15)

        ipmi_console_thread = threading.Thread(target=ipmiconsole.start,
                                               args=(node_info["name"], ))
        ipmi_console_thread.setDaemon(True)
        ipmi_console_thread.start()

        # ipmiconsole.start(node_info["name"])

        # Wait SSH server coming up
        # FIXME: Need a good way to check if SSH server is listening
        # on port 9300
        time.sleep(20)
    def tearDownClass(cls):

        with open(cls.TMP_CONF_FILE, "r") as yml_file:
            node_info = yaml.load(yml_file)

        node = CNode(node_info)
        node.init()
        node.stop()

        if os.path.exists(cls.TMP_CONF_FILE):
            os.unlink(cls.TMP_CONF_FILE)

        workspace = os.path.join(config.infrasim_home, "test")
        if os.path.exists(workspace):
            shutil.rmtree(workspace)
Exemplo n.º 10
0
 def _start_node(self, node_info):
     fake_node_obj = CNode(node_info)
     fake_node_obj.init()
     try:
         fake_node_obj.precheck()
         fake_node_obj.start()
     except Exception as e:
         raise e
     return fake_node_obj
Exemplo n.º 11
0
    def setUpClass(cls):
        node_info = {}
        fake_config = fixtures.FakeConfig()
        node_info = fake_config.get_node_info()

        with open(cls.TMP_CONF_FILE, "w") as f:
            yaml.dump(node_info, f, default_flow_style=False)

        node = CNode(node_info)
        node.init()
        node.precheck()
        node.start()

        # Wait ipmi_sim sever coming up.
        # FIXME: good way???
        print "Wait ipmi-console start in about 30s..."
        time.sleep(15)

        ipmi_console_thread = threading.Thread(target=console.start, args=(node_info["name"],))
        ipmi_console_thread.setDaemon(True)
        ipmi_console_thread.start()

        # Wait SSH server coming up
        # FIXME: Need a good way to check if SSH server is listening
        # on port 9300
        time.sleep(20)
        cls.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        cls.ssh.connect('127.0.0.1', username='', password='', port=9300)
        cls.channel = cls.ssh.invoke_shell()
Exemplo n.º 12
0
    def setUpClass(cls):
        node_info = {}
        fake_config = fixtures.FakeConfig()
        node_info = fake_config.get_node_info()
        node_info["ipmi_console_port"] = 9100
        node_info["ipmi_console_ssh"] = 9400
        cls.bmc_conf = os.path.join(os.environ["HOME"], ".infrasim",
                                    node_info["name"], "etc", "vbmc.conf")

        with open(cls.TMP_CONF_FILE, "w") as f:
            yaml.dump(node_info, f, default_flow_style=False)

        node = CNode(node_info)
        node.init()
        node.precheck()
        node.start()

        # Wait ipmi_sim sever coming up.
        # FIXME: good way???
        print "Wait ipmi-console start in about 30s..."
        time.sleep(15)

        ipmi_console_thread = threading.Thread(target=console.start, args=(node_info["name"],))
        ipmi_console_thread.setDaemon(True)
        ipmi_console_thread.start()

        # console.start(node_info["name"])

        # Wait SSH server coming up
        # FIXME: Need a good way to check if SSH server is listening
        # on port 9300
        time.sleep(20)
    def setUpClass(cls):
        node_info = {}
        fake_config = fixtures.FakeConfig()
        node_info = fake_config.get_node_info()

        with open(cls.TMP_CONF_FILE, "w") as f:
            yaml.dump(node_info, f, default_flow_style=False)

        node = CNode(node_info)
        node.init()
        node.precheck()
        node.start()

        # Wait ipmi_sim sever coming up.
        # FIXME: good way???
        print "Wait ipmi-console start in about 15s..."
        time.sleep(15)

        ipmi_console_thread = threading.Thread(target=ipmiconsole.start, args=(node_info["name"],))
        ipmi_console_thread.setDaemon(True)
        ipmi_console_thread.start()

        # Wait SSH server coming up
        # FIXME: Need a good way to check if SSH server is listening
        # on port 9300
        cls.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # Retry SSH to make sure ipmi console started
        for i in range(6):
            try:
                time.sleep(10)
                cls.ssh.connect('127.0.0.1', username='', password='', port=9300)
            except paramiko.ssh_exception.NoValidConnectionsError, e:
                if i == 5:
                    raise e
                continue
Exemplo n.º 14
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")
    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")
 def _start_node(self, node_info):
     fake_node_obj = CNode(node_info)
     fake_node_obj.init()
     try:
         fake_node_obj.precheck()
         fake_node_obj.start()
     except Exception as e:
         raise e
     return fake_node_obj
Exemplo n.º 17
0
    def tearDownClass(cls):
        cls.channel.send('quit\n')
        cls.channel.close()
        cls.ssh.close()

        with open(cls.TMP_CONF_FILE, "r") as yml_file:
            node_info = yaml.load(yml_file)

        console.stop(node_info["name"])

        node = CNode(node_info)
        node.init()
        node.stop()

        if os.path.exists(cls.TMP_CONF_FILE):
            os.unlink(cls.TMP_CONF_FILE)

        workspace = os.path.join(config.infrasim_home, "test")
        if os.path.exists(workspace):
            shutil.rmtree(workspace)
Exemplo n.º 18
0
def start_socat(conf_file=config.infrasim_default_config):
    try:
        with open(conf_file, 'r') as f_yml:
            conf = yaml.load(f_yml)

        node = CNode(conf)
        if "name" in conf:
            node.set_node_name(conf["name"])

        node.init()

        socat = CSocat()
        # Read SOL device, serial port from conf
        # and set to socat
        if "sol_device" in conf:
            socat.set_sol_device(conf["sol_device"])
        if "serial_socket" in conf:
            socat.set_socket_serial(conf["serial_socket"])

        socat.set_workspace(node.workspace.get_workspace())
        socat.init()
        socat.precheck()
        cmd = socat.get_commandline()

        run_command(cmd+" &", True, None, None)
        time.sleep(3)
        logger.info("socat start")
    except CommandRunFailed as e:
        logger.error(e.value)
        raise e
    except InfraSimError as e:
        logger.error(e.value)
        raise e
Exemplo n.º 19
0
def start_ipmi(conf_file=config.infrasim_default_config):
    try:
        with open(conf_file, 'r') as f_yml:
            conf = yaml.load(f_yml)

        node = CNode(node_info=conf)
        if "name" in conf:
            node.set_node_name(conf["name"])

        node.init()

        bmc = CBMC(conf.get('bmc', {}))
        node_name = conf["name"] if "name" in conf else "node-0"
        bmc.set_task_name("{}-bmc".format(node_name))
        bmc.set_log_path(os.path.join(config.infrasim_log_dir, node_name, "openipmi.log"))
        bmc.set_type(conf["type"])
        bmc.enable_sol(False)
        bmc.set_workspace(node.workspace.get_workspace())
        bmc.init()
        bmc.precheck()
        cmd = bmc.get_commandline()
        logger.debug(cmd)
        run_command(cmd + " &", True, None, None)

        logger.info("bmc start")
    except CommandRunFailed as e:
        logger.error(e.value)
        raise e
    except ArgsNotCorrect as e:
        logger.error(e.value)
        raise e
    except InfraSimError as e:
        logger.error(e.value)
        raise e
Exemplo n.º 20
0
def start_socat(conf_file=VM_DEFAULT_CONFIG):
    try:
        with open(conf_file, 'r') as f_yml:
            conf = yaml.load(f_yml)

        node = CNode(conf)
        if "name" in conf:
            node.set_node_name(conf["name"])
        node.init_workspace()

        socat = CSocat()
        # Read SOL device, serial port from conf
        # and set to socat
        if "sol_device" in conf:
            socat.set_sol_device(conf["sol_device"])
        if "serial_port" in conf:
            socat.set_port_serial(conf["serial_port"])

        socat.set_workspace(node.workspace)
        socat.init()
        socat.precheck()
        cmd = socat.get_commandline()

        run_command(cmd + " &", True, None, None)
        time.sleep(3)
        logger.info("socat start")
    except CommandRunFailed as e:
        raise e
Exemplo n.º 21
0
    def setUpClass(cls):
        node_info = {}
        fake_config = fixtures.FakeConfig()
        node_info = fake_config.get_node_info()
        cls.bmc_conf = os.path.join(config.infrasim_home, node_info["name"],
                                    "data", "vbmc.conf")

        with open(cls.TMP_CONF_FILE, "w") as f:
            yaml.dump(node_info, f, default_flow_style=False)

        node = CNode(node_info)
        node.init()
        node.precheck()
        node.start()
Exemplo n.º 22
0
    def setUpClass(cls):
        node_info = {}
        fake_config = fixtures.FakeConfig()
        node_info = fake_config.get_node_info()
        cls.bmc_conf = os.path.join(config.infrasim_home, node_info["name"], "data", "vbmc.conf")

        with open(cls.TMP_CONF_FILE, "w") as f:
            yaml.dump(node_info, f, default_flow_style=False)

        node = CNode(node_info)
        node.init()
        node.precheck()
        node.start()
 def _start_node(node_info, node_name, node_type):
     fake_node_obj = CNode(node_info)
     fake_node_obj.init()
     fake_node_obj.precheck()
     node_dir = os.path.join(config.infrasim_home, node_name)
     emu_dir = os.path.join(node_dir, "data")
     emu_file = os.path.join(emu_dir, node_type + ".emu")
     if node_name == "test0":
         f = open(emu_file, "ab")
         f.write("\n" + add_content0[0] + "\n" + add_content0[1])
         f.close()
     if node_name == "test1":
         f = open(emu_file, "ab")
         f.write("\n" + add_content1[0] + "\n" + add_content1[1])
         f.close()
     fake_node_obj.start()
     return fake_node_obj
Exemplo n.º 24
0
    def setUpClass(cls):
        node_info = {}
        fake_config = fixtures.FakeConfig()
        node_info = fake_config.get_node_info()
        cls.bmc_conf = os.path.join(os.environ["HOME"], ".infrasim",
                                    node_info["name"], "data", "vbmc.conf")

        with open(cls.TMP_CONF_FILE, "w") as f:
            yaml.dump(node_info, f, default_flow_style=False)

        node = CNode(node_info)
        node.init()
        node.precheck()
        node.start()

        # Wait ipmi_sim start.
        time.sleep(2)
    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
        time.sleep(20)

        node.stop()

        # 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
Exemplo n.º 26
0
    def setUpClass(cls):
        node_info = {}
        fake_config = fixtures.FakeConfig()
        node_info = fake_config.get_node_info()
        node_info["bmc"] = {}
        node_info["bmc"]["interface"] = "lo"
        node_info["bmc"]["ipmi_over_lan_port"] = 625
        node_info["ipmi_console_ssh"] = 9401
        node_info["ipmi_console_port"] = 9101
        cls.bmc_conf = os.path.join(config.infrasim_home, node_info["name"],
                                    "data", "vbmc.conf")

        with open(cls.TMP_CONF_FILE, "w") as f:
            yaml.dump(node_info, f, default_flow_style=False)

        node = CNode(node_info)
        node.init()
        node.precheck()
        node.start()
 def _start_node(node_info, node_name, node_type):
     fake_node_obj = CNode(node_info)
     fake_node_obj.init()
     fake_node_obj.precheck()
     node_dir = os.path.join(config.infrasim_home, node_name)
     emu_dir = os.path.join(node_dir, "data")
     emu_file = os.path.join(emu_dir, node_type + ".emu")
     if node_name == "test0":
         f = open(emu_file, "ab")
         f.write("\n" + add_content0[0] + "\n" + add_content0[1])
         f.close()
     if node_name == "test1":
         f = open(emu_file, "ab")
         f.write("\n" + add_content1[0] + "\n" + add_content1[1])
         f.close()
     fake_node_obj.start()
     return fake_node_obj
Exemplo n.º 28
0
    def setUpClass(cls):
        node_info = {}
        fake_config = fixtures.FakeConfig()
        node_info = fake_config.get_node_info()
        node_info["bmc"] = {}
        node_info["bmc"]["interface"] = "lo"
        node_info["bmc"]["ipmi_over_lan_port"] = 625
        node_info["ipmi_console_ssh"] = 9401
        node_info["ipmi_console_port"] = 9101
        cls.bmc_conf = os.path.join(config.infrasim_home, node_info["name"], "data", "vbmc.conf")

        with open(cls.TMP_CONF_FILE, "w") as f:
            yaml.dump(node_info, f, default_flow_style=False)

        node = CNode(node_info)
        node.init()
        node.precheck()
        node.start()
Exemplo n.º 29
0
    def setUpClass(cls):
        node_info = {}
        fake_config = fixtures.FakeConfig()
        node_info = fake_config.get_node_info()

        with open(cls.TMP_CONF_FILE, "w") as f:
            yaml.dump(node_info, f, default_flow_style=False)

        node = CNode(node_info)
        node.init()
        node.precheck()
        node.start()

        # Wait ipmi_sim sever coming up.
        # FIXME: good way???
        print "Wait ipmi-console start in about 15s..."
        time.sleep(15)

        ipmi_console_thread = threading.Thread(target=ipmiconsole.start,
                                               args=(node_info["name"], ))
        ipmi_console_thread.setDaemon(True)
        ipmi_console_thread.start()

        # Wait SSH server coming up
        # FIXME: Need a good way to check if SSH server is listening
        # on port 9300
        cls.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # Retry SSH to make sure ipmi console started
        for i in range(6):
            try:
                time.sleep(10)
                cls.ssh.connect('127.0.0.1',
                                username='',
                                password='',
                                port=9300)
            except paramiko.ssh_exception.NoValidConnectionsError, e:
                if i == 5:
                    raise e
                continue
    def tearDownClass(cls):

        cls.channel.close()
        cls.ssh.close()

        with open(cls.TMP_CONF_FILE, "r") as yml_file:
            node_info = yaml.load(yml_file)

        ipmiconsole.stop(node_info["name"])

        node = CNode(node_info)
        node.init()
        node.stop()

        if os.path.exists(cls.TMP_CONF_FILE):
            os.unlink(cls.TMP_CONF_FILE)

        workspace = os.path.join(config.infrasim_home, "test")
        if os.path.exists(workspace):
            shutil.rmtree(workspace)
Exemplo n.º 31
0
 def _start_node(self, node_info):
     fake_node_obj = CNode(node_info)
     fake_node_obj.init()
     fake_node_obj.precheck()
     fake_node_obj.start()
     return fake_node_obj
    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
Exemplo n.º 33
0
 def init(self, *args):
     for node in self.__chassis['nodes']:
         node_obj = CNode(node)
         node_obj.set_node_name(node["name"])
         self.__node_list[node["name"]] = node_obj
     self.process_by_node_names("init", *args)