Ejemplo n.º 1
0
def displayOperationStatus(passOrFail, customValue=''):
    if passOrFail:
        Print(
            "                                                                                                   PASS [Completed%s]"
            % customValue)
    else:
        Print(
            "                                                                                                   FAIL [%s]"
            % time.asctime(time.localtime()))
Ejemplo n.º 2
0
def valid_arguments(options, g_storage_conf):
    """ validate arguments """
    if not options.storage_type in [
            "hba", "nfs", "cifs", "iscsi", "isl", "fcoe"
    ]:
        Print(
            "Error: storage type (hba, nfs, cifs, isl, fcoe or iscsi) is required"
        )
        return 0

    for element in __commonparams__:
        if not getattr(options, element[0]):
            if element[4] == "required":
                Print("Error: %s argument (%s: %s) for storage type %s" \
                       % (element[4], element[5], element[1], options.storage_type))
                return 0
            else:
                g_storage_conf[element[0]] = ""
        value = getattr(options, element[0])
        g_storage_conf[element[0]] = value

    if options.storage_type == "nfs":
        subargs = __nfs_args__
    elif options.storage_type == "cifs":
        subargs = __cifs_args__
    elif options.storage_type in ["hba", "fcoe"]:
        subargs = __hba_args__
    elif options.storage_type == "isl":
        subargs = __isl_args__
    elif options.storage_type == "iscsi":
        subargs = __iscsi_args__

    for element in subargs:
        if not getattr(options, element[0]):
            if element[4] == "required":
                Print("Error: %s argument (%s: %s) for storage type %s" \
                       % (element[4], element[5], element[1], options.storage_type))
                DisplayUsage(options.storage_type)
                return 0
            else:
                g_storage_conf[element[0]] = ""
        value = getattr(options, element[0])
        g_storage_conf[element[0]] = value

    return 1
Ejemplo n.º 3
0
def DisplayStorageSpecificUsage(storage_type):
    if storage_type == 'iscsi':
        DisplayiSCSIOptions()
    elif storage_type == 'nfs':
        DisplayNfsOptions()
    elif storage_type == 'cifs':
        DisplayCIFSOptions()
    elif storage_type in ['hba', 'fcoe']:
        DisplayHBAOptions()
    elif storage_type == 'isl':
        DisplayiSLOptions()
    elif storage_type is None:
        DisplayiSCSIOptions()
        Print("")
        DisplayNfsOptions()
        Print("")
        DisplayCIFSOptions()
        Print("")
        DisplayHBAOptions()
        Print("")
        DisplayiSLOptions()
Ejemplo n.º 4
0
def Attach_VDI(session, vdi_ref, vm_ref):
    vbd_ref = None

    try:
        Print("   Create a VBD on the VDI and plug it into VM requested")
        freedevs = session.xenapi.VM.get_allowed_VBD_devices(vm_ref)
        XenCertPrint("Got free devs as %s" % freedevs)
        if not len(freedevs):
            err_str = "No free devs found for VM: %s!" % vm_ref
            XenCertPrint(err_str)
            raise Exception(err_str)
        XenCertPrint("Allowed devs: %s (using %s)" % (freedevs, freedevs[0]))

        # Populate VBD args
        args = {}
        args['VM'] = vm_ref
        args['VDI'] = vdi_ref
        args['userdevice'] = freedevs[0]
        args['bootable'] = False
        args['mode'] = 'RW'
        args['type'] = 'Disk'
        args['unpluggable'] = True
        args['empty'] = False
        args['other_config'] = {}
        args['qos_algorithm_type'] = ''
        args['qos_algorithm_params'] = {}
        XenCertPrint("The VBD create parameters are %s" % args)

        vbd_ref = session.xenapi.VBD.create(args)
        session.xenapi.VBD.plug(vbd_ref)
        XenCertPrint("Created new VBD %s" % vbd_ref)

        return vbd_ref

    except Exception, e:
        Print("   Exception Creating VBD and plugging it into VM: %s" % vm_ref)
        raise
Ejemplo n.º 5
0
def GetLunInformation(id):
    retVal = True
    listLunInfo = []
    try:
        # take in a host id, then list all files in /dev/disk/by_scsibus of the form *-5* then extract
        list = glob.glob('/dev/disk/by-scsibus/*-%s:*' % id)
        if len(list) == 0:
            retVal = False
        else:
            for file in list:
                map = {}
                basename = os.path.basename(file)
                map['SCSIid'] = basename.split('-')[0]
                map['id'] = basename.split('-')[1].split(':')[3]
                map['device'] = os.path.realpath(file)
                listLunInfo.append(map)
    except Exception, e:
        Print("Failed to get lun information for host id: %s, error: %s" %
              (id, str(e)))
        retVal = False
Ejemplo n.º 6
0
def PlugAndUnplugPBDs(session, sr_ref, count):
    PrintOnSameLine(
        "      Unplugging and plugging PBDs over %d iterations. Iteration number: "
        % count)
    try:
        checkPoint = 0
        for j in range(0, count):
            PrintOnSameLine(str(j))
            PrintOnSameLine('..')
            pbds = session.xenapi.SR.get_PBDs(sr_ref)
            XenCertPrint("Got the list of pbds for the sr %s as %s" %
                         (sr_ref, pbds))
            for pbd in pbds:
                XenCertPrint("Looking at PBD: %s" % pbd)
                session.xenapi.PBD.unplug(pbd)
                session.xenapi.PBD.plug(pbd)
            checkPoint += 1

        PrintOnSameLine('\b\b  ')
        PrintOnSameLine('\n')
    except Exception, e:
        Print("     Exception: %s" % str(e))
        displayOperationStatus(False)
Ejemplo n.º 7
0
def CreateMaxSizeVDIAndVBD(session, sr_ref):
    vdi_ref = None
    vbd_ref = None
    retVal = True
    vdi_size = 0

    try:
        try:
            Print("   Create a VDI on the SR of the maximum available size.")
            session.xenapi.SR.scan(sr_ref)
            pSize = session.xenapi.SR.get_physical_size(sr_ref)
            pUtil = session.xenapi.SR.get_physical_utilisation(sr_ref)
            vdi_size_act = actualSRFreeSpace(int(pSize) - int(pUtil))
            vdi_size = str(min(
                1073741824, vdi_size_act))  # 1073741824 is by wkc hack (1GB)
            XenCertPrint("Actual SR free space: %d, and used VDI size %s" %
                         (vdi_size_act, vdi_size))

            # Populate VDI args
            args = {}
            args['name_label'] = 'XenCertTestVDI'
            args['SR'] = sr_ref
            args['name_description'] = ''
            args['virtual_size'] = vdi_size
            args['type'] = 'user'
            args['sharable'] = False
            args['read_only'] = False
            args['other_config'] = {}
            args['sm_config'] = {}
            args['xenstore_data'] = {}
            args['tags'] = []
            XenCertPrint("The VDI create parameters are %s" % args)
            vdi_ref = session.xenapi.VDI.create(args)
            XenCertPrint("Created new VDI %s" % vdi_ref)
            displayOperationStatus(True)
        except Exception, e:
            displayOperationStatus(False)
            raise Exception(str(e))

        Print("   Create a VBD on this VDI and plug it into dom0")
        try:
            vm_uuid = _get_localhost_uuid()
            XenCertPrint("Got vm_uuid as %s" % vm_uuid)
            vm_ref = session.xenapi.VM.get_by_uuid(vm_uuid)
            XenCertPrint("Got vm_ref as %s" % vm_ref)

            freedevs = session.xenapi.VM.get_allowed_VBD_devices(vm_ref)
            XenCertPrint("Got free devs as %s" % freedevs)
            if not len(freedevs):
                raise Exception("No free devs found for VM: %s!" % vm_ref)
            XenCertPrint("Allowed devs: %s (using %s)" %
                         (freedevs, freedevs[0]))

            # Populate VBD args
            args = {}
            args['VM'] = vm_ref
            args['VDI'] = vdi_ref
            args['userdevice'] = freedevs[0]
            args['bootable'] = False
            args['mode'] = 'RW'
            args['type'] = 'Disk'
            args['unpluggable'] = True
            args['empty'] = False
            args['other_config'] = {}
            args['qos_algorithm_type'] = ''
            args['qos_algorithm_params'] = {}
            XenCertPrint("The VBD create parameters are %s" % args)
            vbd_ref = session.xenapi.VBD.create(args)
            XenCertPrint("Created new VBD %s" % vbd_ref)
            session.xenapi.VBD.plug(vbd_ref)

            displayOperationStatus(True)
        except Exception, e:
            displayOperationStatus(False)
            raise Exception(str(e))
Ejemplo n.º 8
0
                    if len(HBAFilter) != 0:
                        if HBAFilter.has_key(adapter):
                            scsiIdList.append(SCSIid)
                    else:
                        scsiIdList.append(SCSIid)

                XenCertPrint("The HBA information list being returned is: %s" %
                             list)
            except Exception, e:
                XenCertPrint("Failed to parse %s probe xml. Exception: %s" %
                             (sr_type, str(e)))

    except Exception, e:
        XenCertPrint("There was an exception in GetHBAInformation: %s." %
                     str(e))
        Print("Exception: %s" % str(e))
        retVal = False

    XenCertPrint(
        "GetHBAInformation - returning adapter list: %s and scsi id list: %s."
        % (list, scsiIdList))
    return (retVal, list, scsiIdList)


# the following details from the file name, put it into a list and return the list.
def GetLunInformation(id):
    retVal = True
    listLunInfo = []
    try:
        # take in a host id, then list all files in /dev/disk/by_scsibus of the form *-5* then extract
        list = glob.glob('/dev/disk/by-scsibus/*-%s:*' % id)
Ejemplo n.º 9
0
def showReport(msg, result, checkPoints=1, totalCheckPoints=1, time=0):
    Print("%-50s: %s, Pass percentage: %d, Completed: %s" %
          (msg, TAG_PASS if result else TAG_FAIL,
           int((checkPoints * 100) / totalCheckPoints), time))
Ejemplo n.º 10
0
def DisplayiSCSIOptions():
    Print(" Storage type iscsi:\n")
    for item in __iscsi_args__:
        printHelpItem(item)
Ejemplo n.º 11
0
def printHelpItem(item):
    Print(" %s %-20s\t[%s] %s" % (item[5], item[0], item[4], item[1]))
Ejemplo n.º 12
0
def DisplayCommonOptions():
    Print("usage: XenCert [arguments seen below] \n\
\n\
Common options:\n")
    for item in __common__:
        printHelpItem(item)
Ejemplo n.º 13
0
def DisplayTestSpecificOptions():
    Print("Test specific options:")
    Print("Multipathing test options (-m above):\n")
    for item in __commonparams__:
        printHelpItem(item)
Ejemplo n.º 14
0
def DisplayiSLOptions():
    Print(" Storage type isl:\n")
    for item in __isl_args__:
        printHelpItem(item)
Ejemplo n.º 15
0
def DisplayHBAOptions():
    Print(" Storage type hba:\n")
    for item in __hba_args__:
        printHelpItem(item)
Ejemplo n.º 16
0
def DisplayCIFSOptions():
    Print(" Storage type cifs:\n")
    for item in __cifs_args__:
        printHelpItem(item)
Ejemplo n.º 17
0
def DisplayNfsOptions():
    Print(" Storage type nfs:\n")
    for item in __nfs_args__:
        printHelpItem(item)
Ejemplo n.º 18
0
def PerformSRControlPathTests(session, sr_ref):
    e = None
    try:
        checkPoint = 0
        vdi_ref = None
        vbd_ref = None
        retVal = True

        (retVal, vdi_ref, vbd_ref,
         vdi_size) = CreateMaxSizeVDIAndVBD(session, sr_ref)
        if not retVal:
            raise Exception("Failed to create max size VDI and VBD.")

        checkPoint += 2
        # Now try to zero out the entire disk
        Print(
            "   Now attempt to write the maximum number of bytes on this newly plugged device."
        )

        devicename = '/dev/' + session.xenapi.VBD.get_device(vbd_ref)
        XenCertPrint(
            "First finding out the time taken to write 1GB on the device.")
        timeFor512MiBSec = FindTimeToWriteData(devicename, 512)
        timeToWrite = int(
            (float(vdi_size) / (1024 * 1024 * 1024)) * (timeFor512MiBSec * 2))

        if timeToWrite > timeLimitControlInSec:
            raise Exception(
                "Writing through this device will take more than %s hours, please use a source upto %s GiB in size."
                % (timeLimitControlInSec / 3600, timeLimitControlInSec /
                   (timeFor512MiBSec * 2)))
        minutes = 0
        hrs = 0
        if timeToWrite > 60:
            minutes = int(timeToWrite / 60)
            timeToWrite = int(timeToWrite - (minutes * 60))
            if minutes > 60:
                hrs = int(minutes / 60)
                minutes = int(minutes - (hrs * 60))

        Print("   START TIME: %s " % (time.asctime(time.localtime())))

        if hrs > 0:
            Print(
                "   APPROXIMATE RUN TIME: %s hours, %s minutes, %s seconds." %
                (hrs, minutes, timeToWrite))
        elif minutes > 0:
            Print("   APPROXIMATE RUN TIME: %s minutes, %s seconds." %
                  (minutes, timeToWrite))
        elif timeToWrite > 0:
            Print("   APPROXIMATE RUN TIME: %s seconds." % (timeToWrite))

        ddOutFile = 'of=' + devicename
        bytes = 0
        if not util.zeroOut(devicename, 1, int(vdi_size)):
            raise Exception(
                "   - Could not write through the allocated disk space on test disk, please check the log for the exception details."
            )

        Print("   END TIME: %s " % (time.asctime(time.localtime())))
        displayOperationStatus(True)

        checkPoint += 1

    except Exception, e:
        Print(
            "There was an exception performing control path stress tests. Exception: %s"
            % str(e))
        retVal = False
Ejemplo n.º 19
0
def DisplayUsage(storage_type=None):
    DisplayCommonOptions()
    Print("\nStorage specific options:\n")
    DisplayStorageSpecificUsage(storage_type)
    Print("")
    DisplayTestSpecificOptions()