Пример #1
0
def Trigger(tc):
    tbspec = parser.JsonParse(GlobalOptions.testbed_json)
    for instance in tbspec.Instances:
        #Check if the node is HPE or not
        if hasattr(instance, 'NodeServer'):
            if instance.NodeServer != "hpe":
                api.Logger.info("Node is not an HPE server")
                result = api.types.status.SUCCESS
                continue
        else:
            api.Logger.info("CIMC ip is {} - ucs server".format(
                instance.NodeCimcIP))
            result = api.types.status.SUCCESS
            continue

        api.Logger.info("Node server ip is {}".format(instance.NodeCimcIP))
        child = pexpect.spawn("telnet %s 8" % instance.NodeCimcIP)
        try:
            child.expect(">")
            child.sendline("plat_inv dump tbl 0")
            child.expect(">\r\n>")
            plat_inv_dump = child.before
            plat_inv_dump_str = plat_inv_dump.decode("utf-8")
            plat_inv_dump_str = plat_inv_dump_str.replace(" ", "")
            newlist = plat_inv_dump_str.splitlines(True)
            for i in range(len(newlist)):
                if (newlist[i].find("pci_vendor_id:0x1dd8") != -1):
                    i2c_seg_str = newlist[i - 5].split(":")[1]
                    break
            i2c_seg = int(i2c_seg_str, 16)
            child.sendline("i2c s %d" % i2c_seg)
            child.expect(">\r\n>")
            child.sendline("i2c s")
            child.expect(">\r\n>")
            child.sendline("i2c a 0xa0 w 0x0F r 21")
            child.expect(">\r\n>")
            fru_manufacturing = child.before
            fru_manufacturing_data = fru_manufacturing.decode("utf-8")
            fru_manufacturing_str = fru_manufacturing_data.split(
                'Data length 21:')[1]
            fru_manufacturing_str = fru_manufacturing_str.replace("\r\n", "")
            fru_manufacturing_str = fru_manufacturing_str.replace(
                "\x1b[0m", "")
            fru_manufacturing_str = fru_manufacturing_str.replace("\t", "")
            fru_manufacturing_str = fru_manufacturing_str.strip()
            manu_list = fru_manufacturing_str.split(" ")
            res = ""
            for i in range(len(manu_list)):
                res = res + chr(int(manu_list[i], 16))
            api.Logger.info("Manufacturing string from fru is {}".format(res))
            if (res == "PENSANDO SYSTEMS INC."):
                result = api.types.status.SUCCESS
            else:
                result = api.types.status.FAILURE
        except pexpect.TIMEOUT:
            api.Logger.error("Time out encountered exiting")
            result = api.types.status.FAILURE

        child.close()
    return result
Пример #2
0
def Trigger(tc):
    tbspec = parser.JsonParse(GlobalOptions.testbed_json)
    for instance in tbspec.Instances:
        #Check if the node is HPE or not
        if hasattr(instance, 'NodeServer'):
            if instance.NodeServer != "hpe":
                api.Logger.info("Node is not an HPE server")
                result = api.types.status.SUCCESS
                continue
        else:
            api.Logger.info("CIMC ip is {} - ucs server".format(
                instance.NodeCimcIP))
            result = api.types.status.SUCCESS
            continue

        api.Logger.info("Node server ip is {}".format(instance.NodeCimcIP))
        child = pexpect.spawn("telnet %s 8" % instance.NodeCimcIP)
        try:
            child.expect(">")
            child.sendline("plat_inv dump tbl 0")
            child.expect(">\r\n>")
            plat_inv_dump = child.before
            plat_inv_dump_str = plat_inv_dump.decode("utf-8")
            plat_inv_dump_str = plat_inv_dump_str.replace(" ", "")
            newlist = plat_inv_dump_str.splitlines(True)
            for i in range(len(newlist)):
                if (newlist[i].find("pci_vendor_id:0x1dd8") != -1):
                    i2c_seg_str = newlist[i - 5].split(":")[1]
                    break
            i2c_seg = int(i2c_seg_str, 16)
            child.sendline("i2c s %d" % i2c_seg)
            child.expect(">\r\n>")
            child.sendline("i2c s")
            child.expect(">\r\n>")
            child.sendline("i2c a 0x94 w 0x16 r 1")
            child.expect(">\r\n>")
            cpld_temp_core = child.before
            cpld_temp_core_data = cpld_temp_core.decode("utf-8")
            cpld_temp_core_str = cpld_temp_core_data.split(
                'Response Data length 1:')[1]
            cpld_temp_core_str = cpld_temp_core_str.replace("\r\n", "")
            cpld_temp_core_str = cpld_temp_core_str.replace("\x1b[0m", "")
            cpld_temp_core_str = cpld_temp_core_str.replace("\t", "")
            cpld_temp_core_str = cpld_temp_core_str.strip()
            res = int(cpld_temp_core_str, 16)
            api.Logger.info("Core temperature is {}".format(res))
            if (res != 0):
                result = api.types.status.SUCCESS
            else:
                result = api.types.status.FAILURE
        except pexpect.TIMEOUT:
            api.Logger.error("Time out encountered exiting")
            result = api.types.status.FAILURE

        child.close()
    return result
Пример #3
0
def __load_linux_driver(node, node_os, manifest_file):

    image_manifest = parser.JsonParse(manifest_file)
    driver_images = list(filter(lambda x: x.OS == node_os, image_manifest.Drivers))[0].Images[0]
    if driver_images is None: 
        api.Logger.error("Unable to load image manifest") 
        return api.types.status.FAILURE

    drImgFile = os.path.join(Gl, driver_images.drivers_pkg)
    api.Logger.info("Fullpath for driver image: " + drImgFile)
    resp = api.CopyToHost(node, [drImgFile], "")
    if not api.IsApiResponseOk(resp):
        api.Logger.error("Failed to copy %s" % drImgFile)
        return api.types.status.FAILURE

    rundir = os.path.basename(driver_images.drivers_pkg).split('.')[0]
    req = api.Trigger_CreateExecuteCommandsRequest(serial = True)
    api.Trigger_AddHostCommand(req, node, "tar -xf " + os.path.basename(driver_images.drivers_pkg))
    api.Trigger_AddHostCommand(req, node, "./build.sh", rundir=rundir)

    resp = api.Trigger(req)

    if not api.IsApiResponseOk(resp):
        api.Logger.error("TriggerCommand for driver build failed")
        return api.types.status.FAILURE

    for cmd in resp.commands:
        if cmd.exit_code != 0 and cmd.command != './build.sh':  # Build.sh could fail -ignored (FIXME)
            api.Logger.error("Failed to exec cmds to build/load new driver")
            return api.types.status.FAILURE

    api.Logger.info("New driver image is built on target host. Prepare to load")

    if host.UnloadDriver(node_os, node) != api.types.status.SUCCESS:
        api.Logger.error("Failed to unload current driver - proceeding")

    req = api.Trigger_CreateExecuteCommandsRequest(serial = True)
    if node_os == OS_TYPE_LINUX: 
        api.Trigger_AddHostCommand(req, node, "insmod " + 
                os.path.join(rundir, "drivers/eth/ionic/ionic.ko"))
    elif node_os == OS_TYPE_BSD: 
        api.Trigger_AddHostCommand(req, node, "kldload " + 
                os.path.join(rundir, "drivers/eth/ionic/ionic.ko"))
    resp = api.Trigger(req)

    if not api.Trigger_IsSuccess(resp):
        api.Logger.error("TriggerCommand for driver installation failed")
        return api.types.status.FAILURE

    return api.types.status.SUCCESS
Пример #4
0
 def __read_testbed_json(self):
     self.__tbspec = parser.JsonParse(GlobalOptions.testbed_json)
     if not self.__tbspec.Instances:
         msg = 'failed to process testbed file {0}. no instances found'.format(GlobalOptions.testbed_json)
         print(msg)
         Logger.debug(msg)
         sys.exit(types.status.OFFLINE_TESTBED)
     try:
         for instance in self.__tbspec.Instances:
             if hasattr(self.__tbspec.Provision, "Vars") and hasattr(self.__tbspec.Provision.Vars, 'BmOs') and instance.Type == "bm":
                 instance.NodeOs = self.__tbspec.Provision.Vars.BmOs
             if hasattr(self.__tbspec.Provision, "Vars") and hasattr(self.__tbspec.Provision.Vars, 'VmOs') and instance.Type == "vm":
                 instance.NodeOs = self.__tbspec.Provision.Vars.VmOs
         return
     except:
         print('failed parsing testbed json')
         Logger.debug("failed parsing testbed json. error was: {0}".format(traceback.format_exc()))
         Logger.debug("failed on node instance: {0}".format(instance.__dict__))
         sys.exit(types.status.OFFLINE_TESTBED)
Пример #5
0
def __load_esxi_driver(node, node_os, manifest_file):
    image_manifest = parser.JsonParse(manifest_file)
    driver_images = list(filter(lambda x: x.OS == node_os, image_manifest.Drivers))[0].Images[0]
    if driver_images is None: 
        api.Logger.error("Unable to load image manifest") 
        return api.types.status.FAILURE

    drImgFile = os.path.join(GlobalOptions.topdir, driver_images.drivers_pkg)
    if driver_images.pkg_file_type == "SrcBundle":
        # Copy and extract the file and find ionic*.vib file to load
        os.system("tar -xf " + drImgFile)
        pkgdir = os.path.basename(driver_images.drivers_pkg).split('.')[0]
        plist = list(Path(pkgdir).rglob('*.vib'))
        if not plist:
            api.Logger.error("Unable to find VIB file in driver-pkg: %s" % driver_images.drivers_pkg)
            return api.types.status.FAILURE
        vib_file = str(plist[0].absolute())
    elif driver_images.pkg_file_type == "VIB":
        vib_file = drImgFile
    else:
        api.Logger.error("Unknown format for driver-pkg: %s - aborting" % driver_images.drivers_pkg)
        return api.types.status.FAILURE

    api.Logger.info("Loading %s on node: %s" % (vib_file, node))
    resp = api.CopyToEsx(node, [vib_file], host_dir="")
    if not api.IsApiResponseOk(resp):
        api.Logger.error("Failed to copy %s", driver_images.drivers_pkg)
        return api.types.status.FAILURE

    req = api.Trigger_CreateExecuteCommandsRequest(serial = True)
    api.Trigger_AddHostCommand(req, node, 
            "sshpass -p %s ssh -o  UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no %s@%s esxcli software vib install -v=/tmp/%s -f" % 
            (api.GetTestbedEsxPassword(), api.GetTestbedEsxUsername(), api.GetEsxHostIpAddress(node), os.path.basename(vib_file)))

    resp = api.Trigger(req)
    if not api.Trigger_IsSuccess(resp): 
        api.Logger.error("Failed to install driver") 
        return api.types.status.FAILURE

    return api.types.status.SUCCESS
Пример #6
0
    def __build_image_object(self, processor):
        manifest_file = self.GetImageManifestFile()
        image_info = parser.JsonParse(manifest_file)
        images = parser.Dict2Object({})

        image_tag = GlobalOptions.pipeline
        if hasattr(self.__spec, 'image_manifest') and hasattr(self.__spec.image_manifest, 'build'): 
            setattr(images, 'build', self.__spec.image_manifest.build)
            image_tag += "-" + images.build

        all_fw_images = list(filter(lambda x: x.Processor == processor, image_info.Firmwares))
        if all_fw_images and len(all_fw_images) == 1:
            fw_images = list(filter(lambda x: x.tag == image_tag, all_fw_images[0].Images))
            if fw_images and len(fw_images) == 1:
                setattr(images, 'naples', fw_images[0].image)

        # Derive venice-image
        venice = False
        if hasattr(self.__spec, 'image_manifest') and hasattr(self.__spec.image_manifest, 'venice'): 
            venice = self.__spec.image_manifest.venice 
        if venice and image_info.Venice:
            setattr(images, 'venice', image_info.Venice[0].Image)

        # Derive driver-images
        driver = False
        if hasattr(self.__spec, 'image_manifest') and hasattr(self.__spec.image_manifest, 'driver'):
            driver = self.__spec.image_manifest.driver
        if driver:
            setattr(images, 'driver', image_info.Drivers)

        naples_sim = False
        if hasattr(self.__spec, 'image_manifest') and hasattr(self.__spec.image_manifest, 'naples_sim'):
            naples_sim = self.__spec.image_manifest.naples_sim
        if naples_sim:
            setattr(images, 'naples_sim', image_info.Simulation[0].Image)

        setattr(images, 'penctl', image_info.PenCtl[0].Image)
        return images
Пример #7
0
def LoadFirmware(nodes, node_os, target_version):

    if target_version != 'latest':
        resp = api.DownloadAssets(release_version = target_version)
        if not api.IsApiResponseOk(resp):
            api.Logger.error("Failed to download assets for %s" % target_version)
            return resp

    manifest_file = os.path.join(api.GetTopDir(), 'images', target_version + '.json')

    image_manifest = parser.JsonParse(manifest_file)
    fw_images = list(filter(lambda x: x.naples_type == "capri", image_manifest.Firmwares))[0] 
    if fw_images is None: 
        api.Logger.error("Unable to load image manifest") 
        return api.types.status.FAILURE

    api.Logger.info("Fullpath for firmware image to load: %s " % fw_images.image)

    if node_os == OS_TYPE_LINUX:
        fw_version, _ = GetLinuxFwDriverVersion(node)
    else:
        fw_version = None

    fwImgFile = os.path.join(GlobalOptions.topdir, fw_images.image)
    for node in nodes:
        if fw_version == '1.1.1-E-15':
            # Naples with Fw 1.1.1-E-15 has no OOB and IntMgmt Ip is fixed 
            resp = api.CopyToNaples(node, [fwImgFile], image_manifest.Version, 
                                    via_oob=False, naples_dir="data", 
                                    nic_mgmt_ip=GetNicIntMgmtIP(node))
            if not api.IsApiResponseOk(resp):
                api.Logger.info("Failed to copy naples_fw.tar with via_oob=True")
                return api.types.status.FAILURE

            for cmd in resp.commands:
                if cmd.exit_code != 0:
                    api.Logger.error("Failed to copy %s naples_fw.tar via_oob=True" % image_manifest.Version) 
                    return api.types.status.FAILURE
        else:
            resp = api.CopyToNaples(node, [fwImgFile], image_manifest.Version, via_oob=True, naples_dir="data")
            if not api.IsApiResponseOk(resp):
                api.Logger.info("Failed to copy naples_fw.tar with via_oob=True")
                return api.types.status.FAILURE

            for cmd in resp.commands:
                if cmd.exit_code != 0:
                    api.Logger.error("Failed to copy %s naples_fw.tar via_oob=True" % image_manifest.Version)

                    # Try with via_oob=False
                    resp = api.CopyToNaples(node, [fwImgFile], image_manifest.Version, via_oob=False, naples_dir="data")
                    if not api.Trigger_IsSuccess(resp): 
                        api.Logger.error("Failed to copy naples_fw.tar to target naples") 
                        return api.types.status.FAILURE

    req = api.Trigger_CreateExecuteCommandsRequest(serial = True)
    api.Trigger_AddNaplesCommand(req, node, "sync")
    api.Trigger_AddNaplesCommand(req, node, "/nic/tools/sysupdate.sh -p /data/naples_fw.tar", timeout=120)

    resp = api.Trigger(req)
    if not api.Trigger_IsSuccess(resp): 
        api.Logger.error("sysupdate.sh cmd failed") 
        return api.types.status.FAILURE

    api.RestartNodes([node])

    if node_os == OS_TYPE_LINUX: 
        return LinuxReInitMgmtIP(node)
    elif node_os == OS_TYPE_ESX:
        return ESXiReInitMgmtIP(node)

    return api.types.status.SUCCESS
Пример #8
0
    "/naples/memtun.log",
]


def run_commands(cmdlist, node_name):
    global topdir
    localdir = "%s/iota/logs/%s/nodes/%s/" % (topdir, GlobalOptions.testsuite,
                                              node_name)
    os.system("mkdir -p %s" % localdir)
    for logdir in logdirs:
        fullcmd = "%s%s:%s %s" % (SSHCMD, node_name, logdir, localdir)
        print("  %s" % fullcmd)
        os.system(fullcmd)
    return


def collect_logs(node_name):
    print("Collecting Logs for Node: %s" % node_name)
    run_commands(logdirs, node_name)
    return


import iota.harness.infra.utils.parser as parser
from multiprocessing.dummy import Pool as ThreadPool
tbspec = parser.JsonParse(GlobalOptions.testbed_json)
pool = ThreadPool(len(tbspec.Instances))
nodes = []
for instance in tbspec.Instances:
    nodes.append(instance.Name)
results = pool.map(collect_logs, nodes)