diff --git a/etc/infrasim.full.yml.example b/etc/infrasim.full.yml.example index 945a045..670d10b 100644 --- a/etc/infrasim.full.yml.example +++ b/etc/infrasim.full.yml.example @@ -155,6 +155,7 @@ bmc: historyfru: 20 config_file: emu_file: chassis/node1/quanta_d51.emu + ipmi_over_lan_port: 623 # SSH to this port to visit ipmi-console ipmi_console_ssh: 9300 diff --git a/infrasim/ipmicons/common.py b/infrasim/ipmicons/common.py index 8207b3f..175e22a 100644 --- a/infrasim/ipmicons/common.py +++ b/infrasim/ipmicons/common.py @@ -103,7 +103,7 @@ def init_env(instance): if ip == "::" or ip == "0.0.0.0": env.VBMC_IP = "localhost" else: - env.VBMC_IP = "ip" + env.VBMC_IP = ip logger.info("VBMC_IP: {}".format(env.VBMC_IP)) env.VBMC_PORT = int(s_vbmc.group("vbmc_port")) logger.info("VBMC_PORT: {}".format(env.VBMC_PORT)) diff --git a/test/unit/test_ipmi_console.py b/test/unit/test_ipmi_console.py new file mode 100644 index 0000000..e44f520 --- /dev/null +++ b/test/unit/test_ipmi_console.py @@ -0,0 +1,164 @@ +#!/usr/bin/env python +''' +********************************************************* +Copyright @ 2015 EMC Corporation All Rights Reserved +********************************************************* +''' +# -*- coding: utf-8 -*- + +from infrasim.ipmicons import sdr +from infrasim.ipmicons.command import Command_Handler +from infrasim.ipmicons import common +from infrasim.model import CNode +from infrasim import config +from test import fixtures +import unittest +import yaml +import shutil +import time +import os + +ch = Command_Handler() + + +class test_ipmi_console(unittest.TestCase): + @classmethod + def setUpClass(cls): + pass + + @classmethod + def tearDownClass(cls): + pass + + def test_sensor_value_get_discrete(self): + sensor_d = sdr.build_sensors(name="discrete_sample", + ID=0x10, + mc=32, + value="0xca10", + tp=0x00) + sensor_d.set_event_type(0x6f) + + ch.get_sensor_value(["0x10"]) + assert "0xca10" in common.msg_queue.get() + + def test_sensor_value_get_analog(self): + sensor_a = sdr.build_sensors(name="analog_sample", + ID=0x11, + mc=32, + value=0x63, + tp=0x00) + sensor_a.set_event_type(0x01) + sensor_a.set_m_lb(0x58) + sensor_a.set_m_ub(0x00) + sensor_a.set_b_lb(0x00) + sensor_a.set_b_ub(0x00) + sensor_a.set_exp(0x00) + sensor_a.set_su2(18) + + ch.get_sensor_value(["0x11"]) + assert "analog_sample : 8712.000 RPM" in common.msg_queue.get() + + +class test_ipmi_console_default_env(unittest.TestCase): + + TMP_CONF_FILE = "/tmp/test.yml" + bmc_conf = "" + + @classmethod + 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) + + @classmethod + 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.precheck() + 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) + + def test_ipmi_console_env(self): + common.init_env("test") + assert common.env.PORT_SSH_FOR_CLIENT == 9300 + assert common.env.PORT_TELNET_TO_VBMC == 9000 + assert common.env.VBMC_IP == "localhost" + assert common.env.VBMC_PORT == 623 + + +class test_ipmi_console_customized_env(unittest.TestCase): + + TMP_CONF_FILE = "/tmp/test.yml" + bmc_conf = "" + + @classmethod + 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(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) + + @classmethod + 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.precheck() + 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) + + def test_ipmi_console_env(self): + common.init_env("test") + assert common.env.PORT_SSH_FOR_CLIENT == 9401 + assert common.env.PORT_TELNET_TO_VBMC == 9101 + assert common.env.VBMC_IP == "127.0.0.1" + assert common.env.VBMC_PORT == 625 diff --git a/test/unit/test_ipmi_console_command.py b/test/unit/test_ipmi_console_command.py deleted file mode 100644 index 93e37aa..0000000 --- a/test/unit/test_ipmi_console_command.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python -''' -********************************************************* -Copyright @ 2015 EMC Corporation All Rights Reserved -********************************************************* -''' -# -*- coding: utf-8 -*- - -from infrasim.ipmicons import sdr -from infrasim.ipmicons.command import Command_Handler -from infrasim.ipmicons.common import msg_queue -import unittest - -ch = Command_Handler() - - -class test_ipmi_console(unittest.TestCase): - @classmethod - def setUpClass(cls): - pass - - @classmethod - def tearDownClass(cls): - pass - - def test_sensor_value_get_discrete(self): - sensor_d = sdr.build_sensors(name="discrete_sample", - ID=0x10, - mc=32, - value="0xca10", - tp=0x00) - sensor_d.set_event_type(0x6f) - - ch.get_sensor_value(["0x10"]) - assert "0xca10" in msg_queue.get() - - def test_sensor_value_get_analog(self): - sensor_a = sdr.build_sensors(name="analog_sample", - ID=0x11, - mc=32, - value=0x63, - tp=0x00) - sensor_a.set_event_type(0x01) - sensor_a.set_m_lb(0x58) - sensor_a.set_m_ub(0x00) - sensor_a.set_b_lb(0x00) - sensor_a.set_b_ub(0x00) - sensor_a.set_exp(0x00) - sensor_a.set_su2(18) - - ch.get_sensor_value(["0x11"]) - assert "analog_sample : 8712.000 RPM" in msg_queue.get()