def test_qmp_access(self):
        # start service
        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()
        node_name = node.get_node_name()
        port = self.conf["monitor"].get("port", 9005)

        if self.conf["monitor"].get("interface", None):
            interface = self.conf["monitor"].get("interface", None)
            ip = helper.get_interface_ip(interface)
        else:
            ip = "0.0.0.0"

        interface = self.conf["monitor"].get("interface",)
        payload = {
            "execute": "query-status"
        }
        url = "http://{}:{}/qmp/{}".format(ip, port, node_name)
        headers = {'content-type': 'application/json'}
        res = requests.post(url, headers = headers, data = json.dumps(payload), timeout = 1)
        if res.status_code == requests.codes.ok:
            return True
        else:
            return False
    def test_hmp_access(self):
        # start service
        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()
        node_name = node.get_node_name()
        port = self.conf["monitor"].get("port", 9005)

        if self.conf["monitor"].get("interface", None):
            interface = self.conf["monitor"].get("interface", None)
            ip = helper.get_interface_ip(interface)
        else:
            ip = "0.0.0.0"

        assert self.wait_port_up(ip, 9005)
        interface = self.conf["monitor"].get("interface",)
        payload = {
            "execute": "human-monitor-command",
            "arguments": {
                "command-line": "info chardev"
            }
        }
        url = "http://{}:{}/hmp/{}".format(ip, port, node_name)
        headers = {'content-type': 'application/json'}
        res = requests.post(url, headers=headers, data=json.dumps(payload), timeout=1)
        # res = requests.post(url)
        if res.status_code == requests.codes.ok:
            return True
        else:
            return False
    def test_qmp_access(self):
        # start service
        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()
        node_name = node.get_node_name()
        port = self.conf["monitor"].get("port", 9005)

        if self.conf["monitor"].get("interface", None):
            interface = self.conf["monitor"].get("interface", None)
            ip = helper.get_interface_ip(interface)
        else:
            ip = "0.0.0.0"

        assert self.wait_port_up(ip, 9005)
        interface = self.conf["monitor"].get("interface",)
        payload = {
            "execute": "query-status"
        }
        url = "http://{}:{}/qmp/{}".format(ip, port, node_name)
        headers = {'content-type': 'application/json'}
        res = requests.post(url, headers=headers, data=json.dumps(payload), timeout=1)
        if res.status_code == requests.codes.ok:
            return True
        else:
            return False
    def test_robust_error_hmp(self):
        # start service
        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()
        node_name = node.get_node_name()
        port = self.conf["monitor"].get("port", 9005)

        if self.conf["monitor"].get("interface", None):
            interface = self.conf["monitor"].get("interface", None)
            ip = helper.get_interface_ip(interface)
        else:
            ip = "0.0.0.0"

        assert self.wait_port_up(ip, 9005)
        interface = self.conf["monitor"].get("interface",)
        # send the error command
        payload = {
            "error": "error"
        }
        url = "http://{}:{}/hmp/{}".format(ip, port, node_name)
        headers = {'content-type': 'application/json'}

        res = requests.post(url, headers=headers, data=json.dumps(payload), timeout=1)
        if res.status_code == requests.codes.ok:
            return True
        else:
            return False
    def test_hmp_access(self):
        # start service
        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()
        node_name = node.get_node_name()
        port = self.conf["monitor"].get("port", 9005)

        if self.conf["monitor"].get("interface", None):
            interface = self.conf["monitor"].get("interface", None)
            ip = helper.get_interface_ip(interface)
        else:
            ip = "0.0.0.0"

        interface = self.conf["monitor"].get("interface", )
        payload = {
            "execute": "human-monitor-command",
            "arguments": {
                "command-line": "info chardev"
            }
        }
        url = "http://{}:{}/hmp/{}".format(ip, port, node_name)
        headers = {'content-type': 'application/json'}
        res = requests.post(url,
                            headers=headers,
                            data=json.dumps(payload),
                            timeout=1)
        # res = requests.post(url)
        if res.status_code == requests.codes.ok:
            return True
        else:
            return False
    def test_robust_error_hmp(self):
        # start service
        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()
        node_name = node.get_node_name()
        port = self.conf["monitor"].get("port", 9005)

        if self.conf["monitor"].get("interface", None):
            interface = self.conf["monitor"].get("interface", None)
            ip = helper.get_interface_ip(interface)
        else:
            ip = "0.0.0.0"

        interface = self.conf["monitor"].get("interface", )
        # send the error command
        payload = {"error": "error"}
        url = "http://{}:{}/hmp/{}".format(ip, port, node_name)
        headers = {'content-type': 'application/json'}

        res = requests.post(url,
                            headers=headers,
                            data=json.dumps(payload),
                            timeout=1)
        if res.status_code == requests.codes.ok:
            return True
        else:
            return False
Example #7
0
 def init(self):
     if self.__monitor_info.get("interface", None):
         self.__interface = self.__monitor_info.get("interface", None)
         self.__ip = helper.get_interface_ip(self.__interface)
     else:
         self.__ip = "0.0.0.0"
     self.__port = self.__monitor_info.get("port", 9005)
Example #8
0
 def init(self):
     if "interface" in self.__racadm_info:
         self.__interface = self.__racadm_info.get("interface", "")
         self.__ip = helper.get_interface_ip(self.__interface)
     else:
         self.__ip = "0.0.0.0"
     self.__port_idrac = self.__racadm_info.get("port", 10022)
     self.__username = self.__racadm_info.get("username", "admin")
     self.__password = self.__racadm_info.get("password", "admin")
     self.__data_src = self.__racadm_info.get("data", "auto")
Example #9
0
 def init(self):
     if "interface" in self.__racadm_info:
         self.__interface = self.__racadm_info.get("interface", "")
         self.__ip = helper.get_interface_ip(self.__interface)
     else:
         self.__ip = "0.0.0.0"
     self.__port_idrac = self.__racadm_info.get("port", 10022)
     self.__username = self.__racadm_info.get("username", "admin")
     self.__password = self.__racadm_info.get("password", "admin")
     self.__data_src = self.__racadm_info.get("data", "auto")
    def test_set_interface(self):
        # Find two valid interface with IP in to a list, e.g:
        # [{"interface":"ens160","ip":"192.168.190.9"}, {}]
        # If the list has no less than 2 interface, do this test
        valid_nic = []
        for interface in helper.get_all_interfaces():
            ip = helper.get_interface_ip(interface)
            if ip and (interface.startswith("en")
                       or interface.startswith("eth")
                       or interface.startswith("br")):
                valid_nic.append({"interface": interface, "ip": ip})

        if len(valid_nic) < 2:
            raise self.skipTest("No enough nic for test")

        print valid_nic

        # Set BMC to listen on first valid nic
        # Try to access via first one, it works
        # Try to access via second one, it fails
        self.conf["monitor"] = {
            "enable": True,
            "interface": valid_nic[0]["interface"]
        }
        print self.conf["monitor"]

        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()

        # Check if port is opened
        start = time.time()
        while helper.check_if_port_in_use(valid_nic[0]["ip"], 9005) is False:
            time.sleep(1)
            if time.time() - start > 10:
                break
        assert helper.check_if_port_in_use(valid_nic[0]["ip"], 9005) is True

        # Connect to wrong interface
        try:
            rsp = requests.get("http://{}:9005/admin".format(
                valid_nic[1]["ip"]))
        except requests.exceptions.ConnectionError:
            pass
        else:
            assert False

        # Connect to correct interface
        rsp = requests.get("http://{}:9005/admin".format(valid_nic[0]["ip"]))
        assert rsp.status_code == 200
    def test_set_interface(self):
        # Find two valid interface with IP in to a list, e.g:
        # [{"interface":"ens160","ip":"192.168.190.9"}, {}]
        # If the list has no less than 2 interface, do this test
        valid_nic = []
        for interface in helper.get_all_interfaces():
            ip = helper.get_interface_ip(interface)
            if ip and (interface.startswith("en") or interface.startswith("eth") or
                       interface.startswith("br")):
                valid_nic.append({"interface": interface, "ip": ip})

        if len(valid_nic) < 2:
            raise self.skipTest("No enough nic for test")

        print valid_nic

        # Set BMC to listen on first valid nic
        # Try to access via first one, it works
        # Try to access via second one, it fails
        self.conf["monitor"] = {
            "enable": True,
            "interface": valid_nic[0]["interface"]
        }
        print self.conf["monitor"]

        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()

        # Check if port is opened
        start = time.time()
        while helper.check_if_port_in_use(valid_nic[0]["ip"], 9005) is False:
            time.sleep(1)
            if time.time() - start > 10:
                break
        assert helper.check_if_port_in_use(valid_nic[0]["ip"], 9005) is True

        # Connect to wrong interface
        try:
            rsp = requests.get("http://{}:9005/admin".format(valid_nic[1]["ip"]))
        except requests.exceptions.ConnectionError:
            pass
        else:
            assert False

        # Connect to correct interface
        rsp = requests.get("http://{}:9005/admin".format(valid_nic[0]["ip"]))
        assert rsp.status_code == 200
Example #12
0
    def test_bmc_intf_exists_has_ip(self):
        """
        BMC will bind to specified interface and accessed through lanplus channel when interface has valid ip address
        """
        interface = None
        interface_ip = None
        intf_list = helper.get_all_interfaces()

        # look up an interface with valid ip address
        for intf in intf_list:
            interface_ip = helper.get_interface_ip(intf)
            if intf == "lo" or not interface_ip:
                continue
            if not re.search(r'^(\d+\.){3}\d+', interface_ip):
                continue
            interface = intf
            break

        # if no interface has ip, skip this test
        if not interface:
            self.skipTest(
                "No interface has IP in the environment, skip this test.")
        self.conf["bmc"] = {"interface": interface}
        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()

        # FIXME: ipmi_sim takes time to set lan configuration through lancontrol script,
        # if lan info is accessed before configuration complete, ipmitool would fail to
        # retrieve Ip Source data and then fail to close session, which would break the test.
        # Need a solution to check if lan setting is complete.
        time.sleep(2)

        mac_addr = run_command(
            "cat /sys/class/net/{}/address".format(interface))[1]

        lan_print_rst = run_command(
            "ipmitool -I lanplus -U admin -P admin -H {} lan print".format(
                interface_ip))[1]

        assert mac_addr in lan_print_rst
    def test_set_bmc_interface(self):
        """
        Set BMC listen on specified interface and won't response to another
        :return:
        """
        # Find two valid interface with IP in to a list, e.g:
        # [{"interface":"ens160","ip":"192.168.190.9"}, {}]
        # If the list has no less than 2 interface, do this test
        valid_nic = []
        for interface in helper.get_all_interfaces():
            ip = helper.get_interface_ip(interface)
            if ip:
                valid_nic.append({"interface": interface, "ip": ip})

        if len(valid_nic) < 2:
            raise self.skipTest("No enough nic for test")

        # Set BMC to listen on first valid nic
        # Try to access via first one, it works
        # Try to access via second one, it fails
        self.conf["bmc"] = {}
        self.conf["bmc"]["interface"] = valid_nic[0]["interface"]

        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()

        cmd = 'ipmitool -H {} -U admin -P admin -I lanplus raw 0x06 0x01'.\
            format(valid_nic[0]["ip"])
        ret, rsp = run_command(cmd,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
        assert ret == 0

        cmd = 'ipmitool -H {} -U admin -P admin -I lanplus raw 0x06 0x01'.\
            format(valid_nic[1]["ip"])
        ret, rsp = run_command(cmd,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
        assert ret != 0
Example #14
0
    def test_set_bmc_interface(self):
        """
        Set BMC listen on specified interface and won't response to another
        :return:
        """
        # Find two valid interface with IP in to a list, e.g:
        # [{"interface":"ens160","ip":"192.168.190.9"}, {}]
        # If the list has no less than 2 interface, do this test
        valid_nic = []
        for interface in helper.get_all_interfaces():
            ip = helper.get_interface_ip(interface)
            if ip:
                valid_nic.append({"interface": interface, "ip": ip})

        if len(valid_nic) < 2:
            raise self.skipTest("No enough nic for test")

        # Set BMC to listen on first valid nic
        # Try to access via first one, it works
        # Try to access via second one, it fails
        self.conf["bmc"] = {}
        self.conf["bmc"]["interface"] = valid_nic[0]["interface"]

        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()

        cmd = 'ipmitool -H {} -U admin -P admin -I lanplus raw 0x06 0x01'.\
            format(valid_nic[0]["ip"])
        ret, rsp = run_command(cmd,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
        assert ret == 0

        cmd = 'ipmitool -H {} -U admin -P admin -I lanplus raw 0x06 0x01'.\
            format(valid_nic[1]["ip"])
        ret, rsp = run_command(cmd,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
        assert ret != 0
Example #15
0
    def test_bmc_intf_exists_has_ip(self):
        """
        BMC will bind to specified interface and accessed through lanplus channel when interface has valid ip address
        """
        interface = None
        interface_ip = None
        intf_list = helper.get_all_interfaces()

        # look up an interface with valid ip address
        for intf in intf_list:
            interface_ip = helper.get_interface_ip(intf)
            if intf == "lo" or not interface_ip:
                continue
            interface = intf
            break

        # if no interface has ip, skip this test
        if not interface:
            self.skipTest("No interface has IP in the environment, skip this test.")
        self.conf["bmc"] = {
            "interface": interface
        }
        node = model.CNode(self.conf)
        node.init()
        node.precheck()
        node.start()

        # FIXME: ipmi_sim takes time to set lan configuration through lancontrol script,
        # if lan info is accessed before configuration complete, ipmitool would fail to
        # retrieve Ip Source data and then fail to close session, which would break the test.
        # Need a solution to check if lan setting is complete.
        time.sleep(2)

        mac_addr = run_command(
            "cat /sys/class/net/{}/address".format(interface))[1]

        lan_print_rst = run_command(
            "ipmitool -I lanplus -U admin -P admin -H {} lan print".format(interface_ip))[1]

        assert mac_addr in lan_print_rst
Example #16
0
    def init(self):
        self.__address = self.__bmc.get('address', 0x20)
        self.__main_channel = str(self.__bmc.get('main_channel', 1))
        self.__channels = self.__bmc.get('channels', self.__main_channel).split(',')
        self.__name = self.__bmc.get("name", "vbmc")
        self.__gem_enable = self.__bmc.get("gem_enable", False)

        if 'interface' in self.__bmc:
            self.__lan_interface = self.__bmc['interface']
            self.__ipmi_listen_range = helper.get_interface_ip(self.__lan_interface)
            if self.__lan_interface not in helper.get_all_interfaces():
                self.__intf_not_exists = True
            elif not self.__ipmi_listen_range:
                self.__intf_no_ip = True
        else:
            nics_list = helper.get_all_interfaces()
            self.__lan_interface = filter(lambda x: x != "lo", nics_list)[0]

        if 'lancontrol' in self.__bmc:
            self.__lancontrol_script = self.__bmc['lancontrol']
        elif self.get_workspace():
            self.__lancontrol_script = os.path.join(self.get_workspace(),
                                                    "scripts",
                                                    "lancontrol")
        else:
            self.__lancontrol_script = os.path.join(config.infrasim_template,
                                                    "lancontrol")

        if 'chassiscontrol' in self.__bmc:
            self.__chassiscontrol_script = self.__bmc['chassiscontrol']
        elif self.get_workspace():
            self.__chassiscontrol_script = os.path.join(self.get_workspace(),
                                                        "scripts",
                                                        "chassiscontrol")

        if 'startcmd' in self.__bmc:
            self.__startcmd_script = self.__bmc['startcmd']
        elif self.get_workspace():
            self.__startcmd_script = os.path.join(self.get_workspace(),
                                                  "scripts",
                                                  "startcmd")

        if self.get_workspace():
            self.__workspace = self.get_workspace()

        if self.__bmc.get("startnow") is False:
            self.__startnow = "false"

        self.__poweroff_wait = self.__bmc.get('poweroff_wait', 5)
        self.__kill_wait = self.__bmc.get('kill_wait', 1)
        self.__username = self.__bmc.get('username', "admin")
        self.__password = self.__bmc.get('password', "admin")
        self.__port_iol = self.__bmc.get('ipmi_over_lan_port', 623)
        self.__historyfru = self.__bmc.get('historyfru', 99)
        self.__peer_bmc_info_list = self.__bmc.get("peer-bmcs")
        self.__port_ipmb = self.__bmc.get('port_ipmb', 9009)

        if 'emu_file' in self.__bmc:
            self.__emu_file = self.__bmc['emu_file']
        elif self.get_workspace():
            self.__emu_file = os.path.join(self.get_workspace(),
                                           "data/{}.emu".format(self.__vendor_type))
        else:
            raise Exception("Should not here")
            self.__emu_file = os.path.join(config.infrasim_data,
                                           "{0}/{0}.emu".format(self.__vendor_type))
        # render FRU information.
        if os.path.exists(self.__emu_file):
            emu_file = FruFile(self.__emu_file)
            emu_file.ChangeFruInfo(self.__bmc)
            # update chassis pn/sn automaticlly.
            emu_file.ChangeChassisInfo(self.__bmc.get('chassis_pn'), self.__bmc.get('chassis_sn'))
            emu_file.Save(self.__emu_file, self.__bmc.get('merge_fru', True))

        if self.__node_name:
            self.__log_file = os.path.join(infrasim_logdir, self.__node_name, 'ipmi_sim.log')
        else:
            self.__log_file = os.path.join(infrasim_logdir, 'ipmi_sim.log')
        self.__full_log = self.__bmc.get('full_log')

        if self.__sol_device:
            pass
        elif self.get_workspace():
            self.__sol_device = os.path.join(self.get_workspace(), ".pty0_{}".format(self.__node_name))
        else:
            self.__sol_device = os.path.join(config.infrasim_etc, "pty0_{}".format(self.__node_name))

        if 'config_file' in self.__bmc:
            self.__config_file = self.__bmc['config_file']
            if os.path.exists(self.__config_file):
                shutil.copy(self.__config_file,
                            os.path.join(self.get_workspace(), "etc/vbmc.conf"))
        elif os.path.exists(os.path.join(self.get_workspace(), "etc/vbmc.conf")):
            self.__config_file = os.path.join(self.get_workspace(), "etc/vbmc.conf")
        elif self.get_workspace() and not self.task_is_running():
            # render template
            self.__render_template()
            self.write_bmc_config(os.path.join(self.get_workspace(), "etc/vbmc.conf"))
        else:
            raise ArgsNotCorrect("[BMC] Couldn't find vbmc.conf")

        if 'nvram_file' in self.__bmc:
            self.__nvram_file = self.__bmc['nvram_file']
            path_nvram_file = os.path.join(self.get_workspace(), "data/nvram.bin")
            if os.path.exists(self.__nvram_file) and not os.path.exists(path_nvram_file):
                shutil.copy(self.__nvram_file,
                            os.path.join(self.get_workspace(), "data/nvram.bin"))

        if 'shm_key' in self.__bmc:
            self.__shm_key = self.__bmc['shm_key']
Example #17
0
    def init(self):
        self.__address = self.__bmc.get('address', 0x20)
        self.__main_channel = str(self.__bmc.get('main_channel', 1))
        self.__channels = self.__bmc.get('channels',
                                         self.__main_channel).split(',')
        self.__name = self.__bmc.get("name", "vbmc")
        self.__gem_enable = self.__bmc.get("gem_enable", False)

        if 'interface' in self.__bmc:
            self.__lan_interface = self.__bmc['interface']
            self.__ipmi_listen_range = helper.get_interface_ip(
                self.__lan_interface)
            if self.__lan_interface not in helper.get_all_interfaces():
                self.__intf_not_exists = True
            elif not self.__ipmi_listen_range:
                self.__intf_no_ip = True
        else:
            nics_list = helper.get_all_interfaces()
            self.__lan_interface = filter(lambda x: x != "lo", nics_list)[0]

        if 'lancontrol' in self.__bmc:
            self.__lancontrol_script = self.__bmc['lancontrol']
        elif self.get_workspace():
            self.__lancontrol_script = os.path.join(self.get_workspace(),
                                                    "scripts", "lancontrol")
        else:
            self.__lancontrol_script = os.path.join(config.infrasim_template,
                                                    "lancontrol")

        if 'chassiscontrol' in self.__bmc:
            self.__chassiscontrol_script = self.__bmc['chassiscontrol']
        elif self.get_workspace():
            self.__chassiscontrol_script = os.path.join(
                self.get_workspace(), "scripts", "chassiscontrol")

        if 'startcmd' in self.__bmc:
            self.__startcmd_script = self.__bmc['startcmd']
        elif self.get_workspace():
            self.__startcmd_script = os.path.join(self.get_workspace(),
                                                  "scripts", "startcmd")

        if self.get_workspace():
            self.__workspace = self.get_workspace()

        if self.__bmc.get("startnow") is False:
            self.__startnow = "false"

        self.__poweroff_wait = self.__bmc.get('poweroff_wait', 5)
        self.__kill_wait = self.__bmc.get('kill_wait', 1)
        self.__username = self.__bmc.get('username', "admin")
        self.__password = self.__bmc.get('password', "admin")
        self.__port_iol = self.__bmc.get('ipmi_over_lan_port', 623)
        self.__historyfru = self.__bmc.get('historyfru', 99)
        self.__peer_bmc_info_list = self.__bmc.get("peer-bmcs")
        self.__port_ipmb = self.__bmc.get('port_ipmb', 9009)

        if 'emu_file' in self.__bmc:
            self.__emu_file = self.__bmc['emu_file']
        elif self.get_workspace():
            self.__emu_file = os.path.join(
                self.get_workspace(), "data/{}.emu".format(self.__vendor_type))
        else:
            self.__emu_file = os.path.join(
                config.infrasim_data, "{0}/{0}.emu".format(self.__vendor_type))

        if self.__node_name:
            self.__log_file = os.path.join(infrasim_logdir, self.__node_name,
                                           'ipmi_sim.log')
        else:
            self.__log_file = os.path.join(infrasim_logdir, 'ipmi_sim.log')
        self.__full_log = self.__bmc.get('full_log')

        if self.__sol_device:
            pass
        elif self.get_workspace():
            self.__sol_device = os.path.join(
                self.get_workspace(), ".pty0_{}".format(self.__node_name))
        else:
            self.__sol_device = os.path.join(
                config.infrasim_etc, "pty0_{}".format(self.__node_name))

        if 'config_file' in self.__bmc:
            self.__config_file = self.__bmc['config_file']
            if os.path.exists(self.__config_file):
                shutil.copy(
                    self.__config_file,
                    os.path.join(self.get_workspace(), "etc/vbmc.conf"))
        elif os.path.exists(os.path.join(self.get_workspace(),
                                         "etc/vbmc.conf")):
            self.__config_file = os.path.join(self.get_workspace(),
                                              "etc/vbmc.conf")
        elif self.get_workspace() and not self.task_is_running():
            # render template
            self.__render_template()
            self.write_bmc_config(
                os.path.join(self.get_workspace(), "etc/vbmc.conf"))
        else:
            raise ArgsNotCorrect("[BMC] Couldn't find vbmc.conf")

        if 'nvram_file' in self.__bmc:
            self.__nvram_file = self.__bmc['nvram_file']
            path_nvram_file = os.path.join(self.get_workspace(),
                                           "data/nvram.bin")
            if os.path.exists(
                    self.__nvram_file) and not os.path.exists(path_nvram_file):
                shutil.copy(
                    self.__nvram_file,
                    os.path.join(self.get_workspace(), "data/nvram.bin"))

        if 'shm_key' in self.__bmc:
            self.__shm_key = self.__bmc['shm_key']
Example #18
0
    def init(self):
        self.__address = self.__bmc.get('address', 0x20)
        self.__channel = self.__bmc.get('channel', 1)

        if 'interface' in self.__bmc:
            self.__lan_interface = self.__bmc['interface']
            self.__ipmi_listen_range = helper.get_interface_ip(self.__lan_interface)
            if self.__lan_interface not in helper.get_all_interfaces():
                self.__intf_not_exists = True
            elif not self.__ipmi_listen_range:
                self.__intf_no_ip = True
        else:
            nics_list = helper.get_all_interfaces()
            self.__lan_interface = filter(lambda x: x != "lo", nics_list)[0]

        if 'lancontrol' in self.__bmc:
            self.__lancontrol_script = self.__bmc['lancontrol']
        elif self.get_workspace():
            self.__lancontrol_script = os.path.join(self.get_workspace(),
                                                    "script",
                                                    "lancontrol")
        else:
            self.__lancontrol_script = os.path.join(config.infrasim_template,
                                                    "lancontrol")

        if 'chassiscontrol' in self.__bmc:
            self.__chassiscontrol_script = self.__bmc['chassiscontrol']
        elif self.get_workspace():
            self.__chassiscontrol_script = os.path.join(self.get_workspace(),
                                                        "script",
                                                        "chassiscontrol")

        if 'startcmd' in self.__bmc:
            self.__startcmd_script = self.__bmc['startcmd']
        elif self.get_workspace():
            self.__startcmd_script = os.path.join(self.get_workspace(),
                                                  "script",
                                                  "startcmd")

        if self.__bmc.get("startnow") is False:
            self.__startnow = "false"

        self.__poweroff_wait = self.__bmc.get('poweroff_wait', 5)
        self.__kill_wait = self.__bmc.get('kill_wait', 1)
        self.__username = self.__bmc.get('username', "admin")
        self.__password = self.__bmc.get('password', "admin")
        self.__port_iol = self.__bmc.get('ipmi_over_lan_port', 623)
        self.__historyfru = self.__bmc.get('historyfru', 99)

        if 'emu_file' in self.__bmc:
            self.__emu_file = self.__bmc['emu_file']
        elif self.get_workspace():
            self.__emu_file = os.path.join(self.get_workspace(),
                                           "data/{}.emu".format(self.__vendor_type))
        else:
            self.__emu_file = os.path.join(config.infrasim_data,
                                           "{0}/{0}.emu".format(self.__vendor_type))

        if self.__sol_device:
            pass
        elif self.get_workspace():
            self.__sol_device = os.path.join(self.get_workspace(), ".pty0")
        else:
            self.__sol_device = os.path.join(config.infrasim_etc, "pty0")

        if 'config_file' in self.__bmc:
            self.__config_file = self.__bmc['config_file']
            if os.path.exists(self.__config_file):
                shutil.copy(self.__config_file,
                            os.path.join(self.get_workspace(), "etc/vbmc.conf"))
        elif self.get_workspace() and not self._task_is_running():
            # render template
            self.__render_template()
            self.write_bmc_config(os.path.join(self.get_workspace(), "etc/vbmc.conf"))
        elif os.path.exists(os.path.join(self.get_workspace(), "etc/vbmc.conf")):
            self.__config_file = os.path.join(self.get_workspace(), "etc/vbmc.conf")
        else:
            raise ArgsNotCorrect("[BMC] Couldn't find vbmc.conf")
Example #19
0
    def init(self):
        self.__address = self.__bmc.get('address', 0x20)
        self.__channel = self.__bmc.get('channel', 1)

        if 'interface' in self.__bmc:
            self.__lan_interface = self.__bmc['interface']
            self.__ipmi_listen_range = helper.get_interface_ip(
                self.__lan_interface)
            if self.__lan_interface not in helper.get_all_interfaces():
                self.__intf_not_exists = True
            elif not self.__ipmi_listen_range:
                self.__intf_no_ip = True
        else:
            nics_list = helper.get_all_interfaces()
            self.__lan_interface = filter(lambda x: x != "lo", nics_list)[0]

        if 'lancontrol' in self.__bmc:
            self.__lancontrol_script = self.__bmc['lancontrol']
        elif self.get_workspace():
            self.__lancontrol_script = os.path.join(self.get_workspace(),
                                                    "script", "lancontrol")
        else:
            self.__lancontrol_script = os.path.join(config.infrasim_template,
                                                    "lancontrol")

        if 'chassiscontrol' in self.__bmc:
            self.__chassiscontrol_script = self.__bmc['chassiscontrol']
        elif self.get_workspace():
            self.__chassiscontrol_script = os.path.join(
                self.get_workspace(), "script", "chassiscontrol")

        if 'startcmd' in self.__bmc:
            self.__startcmd_script = self.__bmc['startcmd']
        elif self.get_workspace():
            self.__startcmd_script = os.path.join(self.get_workspace(),
                                                  "script", "startcmd")

        if self.__bmc.get("startnow") is False:
            self.__startnow = "false"

        self.__poweroff_wait = self.__bmc.get('poweroff_wait', 5)
        self.__kill_wait = self.__bmc.get('kill_wait', 1)
        self.__username = self.__bmc.get('username', "admin")
        self.__password = self.__bmc.get('password', "admin")
        self.__port_iol = self.__bmc.get('ipmi_over_lan_port', 623)
        self.__historyfru = self.__bmc.get('historyfru', 99)

        if 'emu_file' in self.__bmc:
            self.__emu_file = self.__bmc['emu_file']
        elif self.get_workspace():
            self.__emu_file = os.path.join(
                self.get_workspace(), "data/{}.emu".format(self.__vendor_type))
        else:
            self.__emu_file = os.path.join(
                config.infrasim_data, "{0}/{0}.emu".format(self.__vendor_type))

        if self.__sol_device:
            pass
        elif self.get_workspace():
            self.__sol_device = os.path.join(self.get_workspace(), ".pty0")
        else:
            self.__sol_device = os.path.join(config.infrasim_etc, "pty0")

        if 'config_file' in self.__bmc:
            self.__config_file = self.__bmc['config_file']
            if os.path.exists(self.__config_file):
                shutil.copy(
                    self.__config_file,
                    os.path.join(self.get_workspace(), "etc/vbmc.conf"))
        elif self.get_workspace() and not self._task_is_running():
            # render template
            self.__render_template()
            self.write_bmc_config(
                os.path.join(self.get_workspace(), "etc/vbmc.conf"))
        elif os.path.exists(os.path.join(self.get_workspace(),
                                         "etc/vbmc.conf")):
            self.__config_file = os.path.join(self.get_workspace(),
                                              "etc/vbmc.conf")
        else:
            raise ArgsNotCorrect("[BMC] Couldn't find vbmc.conf")