Example #1
0
 def precheck(self):
     # Check if parameters are valid
     # bridge exists?
     if self.__network_mode == "bridge":
         if self.__bridge_name is None:
             if "br0" not in helper.get_all_interfaces():
                 raise ArgsNotCorrect("[CNetwork] ERROR: network_name(br0) does not exist")
         else:
             if self.__bridge_name not in helper.get_all_interfaces():
                 raise ArgsNotCorrect("[CNetwork] ERROR: network_name({}) does not exist".
                                      format(self.__bridge_name))
         if "mac" not in self.__network:
             raise ArgsNotCorrect("[CNetwork] ERROR: mac address is not specified for "
                                  "target network:\n{}".
                                  format(json.dumps(self.__network, indent=4)))
         else:
             list_addr = self.__mac_address.split(":")
             if len(list_addr) != 6:
                 raise ArgsNotCorrect("[CNetwork] ERROR: mac address invalid: {}".
                                      format(self.__mac_address))
             for each_addr in list_addr:
                 try:
                     int(each_addr, 16)
                 except:
                     raise ArgsNotCorrect("[CNetwork] ERROR: mac address invalid: {}".
                                          format(self.__mac_address))
Example #2
0
 def precheck(self):
     # Check if parameters are valid
     # bridge exists?
     if self.__network_mode == "bridge":
         if self.__bridge_name is None:
             if "br0" not in helper.get_all_interfaces():
                 raise ArgsNotCorrect(
                     "[CNetwork] ERROR: network_name(br0) does not exist")
         else:
             if self.__bridge_name not in helper.get_all_interfaces():
                 raise ArgsNotCorrect(
                     "[CNetwork] ERROR: network_name({}) does not exist".
                     format(self.__bridge_name))
         if "mac" not in self.__network:
             raise ArgsNotCorrect(
                 "[CNetwork] ERROR: mac address is not specified for "
                 "target network:\n{}".format(
                     json.dumps(self.__network, indent=4)))
         else:
             list_addr = self.__mac_address.split(":")
             if len(list_addr) != 6:
                 raise ArgsNotCorrect(
                     "[CNetwork] ERROR: mac address invalid: {}".format(
                         self.__mac_address))
             for each_addr in list_addr:
                 try:
                     int(each_addr, 16)
                 except Exception:
                     raise ArgsNotCorrect(
                         "[CNetwork] ERROR: mac address invalid: {}".format(
                             self.__mac_address))
Example #3
0
def init_infrasim_conf(node_type):

    splash_path = os.path.join(config.get_infrasim_root(),
                               "data/boot_logo.jpg")
    # Prepare default network
    networks = []
    nics_list = helper.get_all_interfaces()
    eth_nic = filter(lambda x: x != "lo", nics_list)[0]
    mac = create_mac_address()
    networks.append({"nic": eth_nic, "mac": mac})

    # create_infrasim_directories
    if not os.path.exists(config.infrasim_home):
        os.mkdir(config.infrasim_home)
        os.mkdir(config.infrasim_node_config_map)

    # create_infrasim_log_directories
    if not os.path.exists(infrasim_logdir):
        os.mkdir(infrasim_logdir)

    # Prepare default disk
    disks = []
    disks.append({"size": 8})

    # Render infrasim.yml
    infrasim_conf = ""
    with open(config.infrasim_config_template, "r") as f:
        infrasim_conf = f.read()
    template = jinja2.Template(infrasim_conf)
    infrasim_conf = template.render(node_type=node_type,
                                    disks=disks,
                                    networks=networks,
                                    splash_path=splash_path)
    with open(config.infrasim_default_config, "w") as f:
        f.write(infrasim_conf)
Example #4
0
def init_infrasim_conf(node_type):

    splash_path = os.path.join(config.get_infrasim_root(), "data/boot_logo.jpg")
    # Prepare default network
    networks = []
    nics_list = helper.get_all_interfaces()
    eth_nic = filter(lambda x: x != "lo", nics_list)[0]
    mac = create_mac_address()
    networks.append({"nic": eth_nic, "mac": mac})

    # create_infrasim_directories
    if not os.path.exists(config.infrasim_home):
        os.mkdir(config.infrasim_home)
        os.mkdir(config.infrasim_node_config_map)

    # create_infrasim_log_directories
    if not os.path.exists(infrasim_logdir):
        os.mkdir(infrasim_logdir)

    # Prepare default disk
    disks = []
    disks.append({"size": 8})

    # Render infrasim.yml
    infrasim_conf = ""
    with open(config.infrasim_config_template, "r") as f:
        infrasim_conf = f.read()
    template = jinja2.Template(infrasim_conf)
    infrasim_conf = template.render(node_type=node_type, disks=disks, networks=networks, splash_path=splash_path)
    with open(config.infrasim_default_config, "w") as f:
        f.write(infrasim_conf)
    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 #7
0
def init_infrasim_conf(node_type):

    splash_path = os.path.join(config.get_infrasim_root(),
                               "data/boot_logo.jpg")
    # Prepare default network
    networks = []
    nics_list = helper.get_all_interfaces()
    eth_nic = filter(lambda x: x != "lo", nics_list)[0]
    mac = create_mac_address()
    networks.append({"nic": eth_nic, "mac": mac})

    # Prepare default UUID
    uuid_num = str(uuid.uuid4())

    # Prepare default serial number
    sn = pre_serial_number + ''.join(
        random.SystemRandom().choice(string.digits) for _ in range(3))

    # create_infrasim_directories
    if not os.path.exists(config.infrasim_home):
        os.mkdir(config.infrasim_home)
    if not os.path.exists(config.infrasim_node_config_map):
        os.mkdir(config.infrasim_node_config_map)
    if not os.path.exists(config.infrasim_chassis_config_map):
        os.mkdir(config.infrasim_chassis_config_map)

    # create_infrasim_log_directories
    if not os.path.exists(infrasim_logdir):
        os.mkdir(infrasim_logdir)

    # Prepare default disk
    disks = []
    disks.append({"size": 8})

    # Render infrasim.yml
    infrasim_conf = ""
    with open(config.infrasim_config_template, "r") as f:
        infrasim_conf = f.read()
    template = jinja2.Template(infrasim_conf)
    infrasim_conf = template.render(node_type=node_type,
                                    disks=disks,
                                    networks=networks,
                                    splash_path=splash_path,
                                    uuid=uuid_num,
                                    serial_number=sn)
    with open(config.infrasim_default_config, "w") as f:
        f.write(infrasim_conf)
    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 #10
0
def init_infrasim_conf(node_type):

    splash_path = os.path.join(config.get_infrasim_root(), "data/boot_logo.jpg")
    # Prepare default network
    networks = []
    nics_list = helper.get_all_interfaces()
    eth_nic = filter(lambda x: x != "lo", nics_list)[0]
    mac = create_mac_address()
    networks.append({"nic": eth_nic, "mac": mac})

    # Prepare default UUID
    uuid_num = str(uuid.uuid4())

    # Prepare default serial number
    sn = pre_serial_number + ''.join(random.SystemRandom().choice(string.digits) for _ in range(3))

    # create_infrasim_directories
    if not os.path.exists(config.infrasim_home):
        os.mkdir(config.infrasim_home)
    if not os.path.exists(config.infrasim_node_config_map):
        os.mkdir(config.infrasim_node_config_map)
    if not os.path.exists(config.infrasim_chassis_config_map):
        os.mkdir(config.infrasim_chassis_config_map)

    # create_infrasim_log_directories
    if not os.path.exists(infrasim_logdir):
        os.mkdir(infrasim_logdir)

    # Prepare default disk
    disks = []
    disks.append({"size": 8})

    # Render infrasim.yml
    infrasim_conf = ""
    with open(config.infrasim_config_template, "r") as f:
        infrasim_conf = f.read()
    template = jinja2.Template(infrasim_conf)
    infrasim_conf = template.render(node_type=node_type, disks=disks, networks=networks,
                                    splash_path=splash_path, uuid=uuid_num, serial_number=sn)
    with open(config.infrasim_default_config, "w") as f:
        f.write(infrasim_conf)
Example #11
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 #12
0
def init_infrasim_conf(node_type):

    # Prepare default network
    networks = []
    nics_list = helper.get_all_interfaces()
    eth_nic = filter(lambda x: x != "lo", nics_list)[0]
    mac = create_mac_address()
    networks.append({"nic": eth_nic, "mac": mac})

    # Prepare default disk
    disks = []
    disks.append({"size": 8})

    # Render infrasim.yml
    infrasim_conf = ""
    with open(config.infrasim_config_template, "r") as f:
        infrasim_conf = f.read()
    template = jinja2.Template(infrasim_conf)
    infrasim_conf = template.render(node_type=node_type, disks=disks, networks=networks)
    with open(config.infrasim_default_config, "w") as f:
        f.write(infrasim_conf)
Example #13
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 #14
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 #15
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 #16
0
    def precheck(self):
        # check if ipmi_sim exists
        try:
            run_command("which {}".format(self.__bin))
        except CommandRunFailed:
            self.logger.exception("[BMC] Cannot find {}".format(self.__bin))
            raise CommandNotFound(self.__bin)

        # check configuration file exists
        if not os.path.isfile(self.__config_file):
            raise ArgsNotCorrect("[BMC] Target config file doesn't exist: {}".
                                 format(self.__config_file))

        if not os.path.isfile(self.__emu_file):
            raise ArgsNotCorrect("[BMC] Target emulation file doesn't exist: {}".
                                 format(self.__emu_file))
        # check script exists
        if not os.path.exists(self.__lancontrol_script):
            raise ArgsNotCorrect("[BMC] Lan control script {} doesn\'t exist".
                                 format(self.__lancontrol_script))

        if not os.path.exists(self.__chassiscontrol_script):
            raise ArgsNotCorrect("[BMC] Chassis control script {} doesn\'t exist".
                                 format(self.__chassiscontrol_script))

        if not os.path.exists(self.__startcmd_script):
            raise ArgsNotCorrect("[BMC] startcmd script {} doesn\'t exist".
                                 format(self.__startcmd_script))

        if not os.path.exists(self.__workspace):
            raise ArgsNotCorrect("[BMC] workspace  {} doesn\'t exist".
                                 format(self.__workspace))

        # check if main channel is included in all lan channels
        if self.__main_channel not in self.__channels:
            raise ArgsNotCorrect("[BMC] main channel {} should be included in channels {}".
                                 format(self.__main_channel, self.__channels))

        # check if self.__port_qemu_ipmi in use
        if helper.check_if_port_in_use("0.0.0.0", self.__port_qemu_ipmi):
            raise ArgsNotCorrect("[BMC] Port {} is already in use.".
                                 format(self.__port_qemu_ipmi))

        if helper.check_if_port_in_use("0.0.0.0", self.__port_ipmi_console):
            raise ArgsNotCorrect("[BMC] Port {} is already in use.".
                                 format(self.__port_ipmi_console))

        # check lan interface exists
        if self.__lan_interface not in helper.get_all_interfaces():
            self.logger.warning("[BMC] Specified BMC interface {} doesn\'t exist.".
                                format(self.__lan_interface))

        # check if lan interface has IP address
        elif not self.__ipmi_listen_range:
            self.logger.warning("[BMC] No IP is found on BMC interface {}.".
                                format(self.__lan_interface))

        # check attribute
        if self.__poweroff_wait < 0:
            raise ArgsNotCorrect("[BMC] poweroff_wait is expected to be >= 0, "
                                 "it's set to {} now".
                                 format(self.__poweroff_wait))

        if not isinstance(self.__poweroff_wait, int):
            raise ArgsNotCorrect("[BMC] poweroff_wait is expected to be integer, "
                                 "it's set to {} now".
                                 format(self.__poweroff_wait))

        if self.__kill_wait < 0:
            raise ArgsNotCorrect("[BMC] kill_wait is expected to be >= 0, "
                                 "it's set to {} now".
                                 format(self.__kill_wait))

        if not isinstance(self.__kill_wait, int):
            raise ArgsNotCorrect("[BMC] kill_wait is expected to be integer, "
                                 "it's set to {} now".
                                 format(self.__kill_wait))

        if self.__port_iol < 0:
            raise ArgsNotCorrect("[BMC] Port for IOL(IPMI over LAN) is expected "
                                 "to be >= 0, it's set to {} now".
                                 format(self.__port_iol))

        if not isinstance(self.__port_iol, int):
            raise ArgsNotCorrect("[BMC] Port for IOL(IPMI over LAN) is expected "
                                 "to be integer, it's set to {} now".
                                 format(self.__port_iol))

        if self.__historyfru < 0:
            raise ArgsNotCorrect("[BMC] History FRU is expected to be >= 0, "
                                 "it's set to {} now".
                                 format(self.__historyfru))

        if not isinstance(self.__historyfru, int):
            raise ArgsNotCorrect("[BMC] History FRU is expected to be integer, "
                                 "it's set to {} now".
                                 format(self.__historyfru))

        self.__check_peer_bmc_info()
Example #17
0
    def precheck(self):
        # check if ipmi_sim exists
        try:
            run_command("which {}".format(self.__bin))
        except CommandRunFailed:
            self.logger.exception("[BMC] Cannot find {}".format(self.__bin))
            raise CommandNotFound(self.__bin)

        # check configuration file exists
        if not os.path.isfile(self.__config_file):
            raise ArgsNotCorrect(
                "[BMC] Target config file doesn't exist: {}".format(
                    self.__config_file))

        if not os.path.isfile(self.__emu_file):
            raise ArgsNotCorrect(
                "[BMC] Target emulation file doesn't exist: {}".format(
                    self.__emu_file))
        # check script exists
        if not os.path.exists(self.__lancontrol_script):
            raise ArgsNotCorrect(
                "[BMC] Lan control script {} doesn\'t exist".format(
                    self.__lancontrol_script))

        if not os.path.exists(self.__chassiscontrol_script):
            raise ArgsNotCorrect(
                "[BMC] Chassis control script {} doesn\'t exist".format(
                    self.__chassiscontrol_script))

        if not os.path.exists(self.__startcmd_script):
            raise ArgsNotCorrect(
                "[BMC] startcmd script {} doesn\'t exist".format(
                    self.__startcmd_script))

        if not os.path.exists(self.__workspace):
            raise ArgsNotCorrect("[BMC] workspace  {} doesn\'t exist".format(
                self.__workspace))

        # check if main channel is included in all lan channels
        if self.__main_channel not in self.__channels:
            raise ArgsNotCorrect(
                "[BMC] main channel {} should be included in channels {}".
                format(self.__main_channel, self.__channels))

        # check if self.__port_qemu_ipmi in use
        if helper.check_if_port_in_use("0.0.0.0", self.__port_qemu_ipmi):
            raise ArgsNotCorrect("[BMC] Port {} is already in use.".format(
                self.__port_qemu_ipmi))

        if helper.check_if_port_in_use("0.0.0.0", self.__port_ipmi_console):
            raise ArgsNotCorrect("[BMC] Port {} is already in use.".format(
                self.__port_ipmi_console))

        # check lan interface exists
        if self.__lan_interface not in helper.get_all_interfaces():
            self.logger.warning(
                "[BMC] Specified BMC interface {} doesn\'t exist.".format(
                    self.__lan_interface))

        # check if lan interface has IP address
        elif not self.__ipmi_listen_range:
            self.logger.warning(
                "[BMC] No IP is found on BMC interface {}.".format(
                    self.__lan_interface))

        # check attribute
        if self.__poweroff_wait < 0:
            raise ArgsNotCorrect("[BMC] poweroff_wait is expected to be >= 0, "
                                 "it's set to {} now".format(
                                     self.__poweroff_wait))

        if not isinstance(self.__poweroff_wait, int):
            raise ArgsNotCorrect(
                "[BMC] poweroff_wait is expected to be integer, "
                "it's set to {} now".format(self.__poweroff_wait))

        if self.__kill_wait < 0:
            raise ArgsNotCorrect("[BMC] kill_wait is expected to be >= 0, "
                                 "it's set to {} now".format(self.__kill_wait))

        if not isinstance(self.__kill_wait, int):
            raise ArgsNotCorrect("[BMC] kill_wait is expected to be integer, "
                                 "it's set to {} now".format(self.__kill_wait))

        if self.__port_iol < 0:
            raise ArgsNotCorrect(
                "[BMC] Port for IOL(IPMI over LAN) is expected "
                "to be >= 0, it's set to {} now".format(self.__port_iol))

        if not isinstance(self.__port_iol, int):
            raise ArgsNotCorrect(
                "[BMC] Port for IOL(IPMI over LAN) is expected "
                "to be integer, it's set to {} now".format(self.__port_iol))

        if self.__historyfru < 0:
            raise ArgsNotCorrect("[BMC] History FRU is expected to be >= 0, "
                                 "it's set to {} now".format(
                                     self.__historyfru))

        if not isinstance(self.__historyfru, int):
            raise ArgsNotCorrect(
                "[BMC] History FRU is expected to be integer, "
                "it's set to {} now".format(self.__historyfru))

        self.__check_peer_bmc_info()
Example #18
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 #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")