コード例 #1
0
def get_count_of_SHELL_RICs():
    """Returns a dictionary with Key : Context IDs and Values: the number of SHELL_RICs
    Examples:
    | get_count_of_SHELL_RICs |
    """
    cacheFile = dump_cache()
    fieldDict ={}
    
    # create hash of header values
    cmd = "head -1 %s | tr ',' '\n'" %cacheFile
    stdout, stderr, rc = _exec_command(cmd)
#         print 'DEBUG cmd=%s, rc=%s, stdout=%s stderr=%s' %(cmd,rc,stdout,stderr)
    if rc !=0 or stderr !='':
        raise AssertionError('*ERROR* cmd=%s, rc=%s, %s %s' %(cmd,rc,stdout,stderr))    

    headerList = stdout.strip().split()
    index = 1;
    headerDict = {}
    for fieldName in headerList:
        headerDict[fieldName] = index
        index += 1
    if not headerDict.has_key('HAS_SHELL_DATA'):
        raise AssertionError('*ERROR* Did not find HAS_SHELL_DATA column in cache file')
    
    #Verify if HAS_SHELL_DATA column has 'True' values
    ShellCol = headerDict['HAS_SHELL_DATA']
    contextIdCol = headerDict['CONTEXT_ID'] - 1
    cmd = "grep -v TEST %s | awk -F',' '($%s == \"TRUE\") {print}' " %(cacheFile, ShellCol)
    print '*INFO* cmd=%s' %cmd
    stdout, stderr, rc = _exec_command(cmd)
    if rc == 1:
        print '*INFO* HAS NO SHELL DATA'
        return fieldDict
    if rc > 1 or stderr !='':
        raise AssertionError('*ERROR* cmd=%s, rc=%s, %s %s' %(cmd,rc,stdout,stderr))
    rows = stdout.splitlines()
	 
    # get the requested fields    
    for row in rows:
        values = row.split(',')
        if len(values) != len(headerList):
            raise AssertionError('*ERROR* Number of values (%d) does not match number of headers (%d)' %(len(values), len(headerList)))
        cid = values[contextIdCol]
        fieldDict[cid] = fieldDict.get(cid,0) + 1       
    _delete_file(cacheFile,'',False)
    return fieldDict
コード例 #2
0
    def delete_remote_files(self,*paths):
        """delete one or more files on IP, all files should be provided with fullpath.\n

        Return [0, delete success info, ''] or [1, '', delete error info]

        Examples:
        | ${res} | delete files | /tmp/tmp.exl | /tmp/1.txt |
        | ${res} | delete files | /tmp/tmp.exl | 
        """
        return _delete_file(list(paths), '', False)
コード例 #3
0
    def delete_remote_files_matching_pattern(self, path, name, recurse= False):
        """delete all pattern matching files under desired path on IP.\n
        
        path is the directory.\n
        name support wildcard *, for example GATS*.exl.\n
        recurse default to False, if True, mean recursively find all matching files under all subdirectories.\n
        
        Return [0, delete success info, ''] or [1, '', delete error info]

        Examples:
        | ${res} | delete files matching pattern | /tmp | test* | 
        | ${res} | delete files matching pattern | /tmp | test* | ${True} |
        """
        return _delete_file(name, path, recurse)
コード例 #4
0
def get_ric_fields_from_cache(numrows, domain, contextID):
    """Get the first n rows' ric fields data for the specified domain or/and contextID from MTE cache.
    Ignore RICs that contain 'TEST' and non-publishable RICs.
    Returns an array of dictionary containing all fields for the match.  Returns empty dictionary if match are not found

    Arguments:
        numrows:   number of rows to return
        domain:    RIC must belong to this domain if domain is not NONE
        contextID: RIC must belong to this contextID if contextID is not NONE
                   If domain and contextID are NONE, first PUBLISHABLE=TRUE will be checked
                
    Returns an array of dictionaries containing fields for each RICs.
    E.g. [ {RIC : ric1, SIC sic1, DOMAIN MarketPrice, CONTEXT_ID : 1052 ...}, {RIC : ric2, SIC sic2, DOMAIN MarketPrice, CONTEXT_ID : 1052 ...} ]

    Example:
    | get_ric_fields_from_cache  | 1 | MARKET_PRICE |
    | get_ric_fields_from_cache  | 1 | ${EMPTY} | 1052 |
    | get_ric_fields_from_cache  | 2 | MARKET_PRICE | 1052 |
    | get_ric_fields_from_cache  | 2 |
    """
    if numrows != 'all':
        numrows = int(numrows)
        
    if domain:
        newDomain = _convert_domain_to_cache_format(domain)
        
    cacheFile = dump_cache()
    # create hash of header values
    cmd = "head -1 %s | tr ',' '\n'" %cacheFile
    stdout, stderr, rc = _exec_command(cmd)
#         print 'DEBUG cmd=%s, rc=%s, stdout=%s stderr=%s' %(cmd,rc,stdout,stderr)
    if rc !=0 or stderr !='':
        raise AssertionError('*ERROR* cmd=%s, rc=%s, %s %s' %(cmd,rc,stdout,stderr))
    
    headerList = stdout.strip().split()
    index = 1;
    headerDict = {}
    for fieldName in headerList:
        headerDict[fieldName] = index
        index += 1
    if not headerDict.has_key('DOMAIN') or not headerDict.has_key('PUBLISHABLE') or not headerDict.has_key('CONTEXT_ID'):
        raise AssertionError('*ERROR* Did not find required column names in cache file (DOMAIN, PUBLISHABLE, CONTEXT_ID') 
    
    # get all fields for selected RICs
    domainCol = headerDict['DOMAIN']
    publishableCol = headerDict['PUBLISHABLE']
    contextIDCol = headerDict['CONTEXT_ID']
    
    if contextID and domain:
        if numrows == 'all':
            cmd = "grep -v TEST %s | awk -F',' '$%d == \"%s\" && $%d == \"TRUE\" && $%d == \"%s\" {print}'" %(cacheFile, domainCol, newDomain, publishableCol, contextIDCol, contextID)
        else:
            cmd = "grep -v TEST %s | awk -F',' '$%d == \"%s\" && $%d == \"TRUE\" && $%d == \"%s\" {print}' | head -%d" %(cacheFile, domainCol, newDomain, publishableCol, contextIDCol,contextID, numrows)
            
    elif  domain: 
        if numrows == 'all':
            cmd = "grep -v TEST %s | awk -F',' '$%d == \"%s\" && $%d == \"TRUE\" {print}'" %(cacheFile, domainCol, newDomain, publishableCol)
        else:
            cmd = "grep -v TEST %s | awk -F',' '$%d == \"%s\" && $%d == \"TRUE\" {print}' | head -%d" %(cacheFile, domainCol, newDomain, publishableCol, numrows)
            
    elif  contextID:
        if numrows == 'all':
            cmd = "grep -v TEST %s | awk -F',' '$%d == \"%s\" && $%d == \"TRUE\" {print}'" %(cacheFile, contextIDCol, contextID, publishableCol)
        else:
            cmd = "grep -v TEST %s | awk -F',' '$%d == \"%s\" && $%d == \"TRUE\" {print}' | head -%d" %(cacheFile, contextIDCol, contextID, publishableCol, numrows)
            
    else:
        if numrows == 'all':
            cmd = "grep -v TEST %s | awk -F',' '$%d == \"TRUE\" {print}'" %(cacheFile, publishableCol)
        else:
            cmd = "grep -v TEST %s | awk -F',' '$%d == \"TRUE\" {print}' | head -%d" %(cacheFile, publishableCol, numrows)
            
    print '*INFO* cmd=%s' %cmd
    stdout, stderr, rc = _exec_command(cmd)
#     print 'DEBUG cmd=%s, rc=%s, stdout=%s stderr=%s' %(cmd,rc,stdout,stderr)
    if rc !=0 or stderr !='':
        raise AssertionError('*ERROR* cmd=%s, rc=%s, %s %s' %(cmd,rc,stdout,stderr))
    rows = stdout.splitlines()
    if numrows != 'all' and len(rows) != numrows:
        raise AssertionError('*ERROR* Requested %d rows, Found %d rows' %(numrows,len(rows)))
    
    # get the requested fields
    result = []
    for row in rows:
        values = row.split(',')
        
        if len(values) != len(headerList):
            raise AssertionError('*ERROR* Number of values (%d) does not match number of headers (%d)' %(len(values), len(headerList)))
        
        fieldDict = {}
        for i in range(0, len(values)):
            if headerList[i] == 'DOMAIN':
                newdomain = _convert_cachedomain_to_normal_format(values[i]) 
                fieldDict[headerList[i]] = newdomain
            else:    
                fieldDict[headerList[i]] = values[i]
           
        result.append(fieldDict)
              
    _delete_file(cacheFile,'',False)
    return result 
コード例 #5
0
def get_otf_rics_from_cahce(domain):
    """Checking how many otf item found in MTE cache dump
    
    Returns a list of dictionaries for OTF items (within each dictionary, it has RIC, DOMAIN, PUBLISH_KEY, OTF_STATUS fields)

    Examples:
    | get otf rics from cache  | MARKET_BY_PRICE 
    """

    if domain:
        newDomain = _convert_domain_to_cache_format(domain)
        
    cacheFile = dump_cache()
    # create hash of header values
    cmd = "head -1 %s | tr ',' '\n'" %cacheFile
    stdout, stderr, rc = _exec_command(cmd)
    if rc !=0 or stderr !='':
        raise AssertionError('*ERROR* cmd=%s, rc=%s, %s %s' %(cmd,rc,stdout,stderr))

    headerList = stdout.strip().split()
    index = 1;
    headerDict = {}
    for fieldName in headerList:
        headerDict[fieldName] = index
        index += 1
    if not headerDict.has_key('DOMAIN'):
        raise AssertionError('*ERROR* Did not find required column names in cache file (DOMAIN)')

    # get all fields for selected RICs
    domainCol = headerDict['DOMAIN']
    otfCol = headerDict['OTF_STATUS']
    
    cmd = "grep -v TEST %s | awk -F',' '$%d == \"%s\" && ($%d == \"FULL_OTF\" || $%d == \"PARTIAL_OTF\") {print}' " %(cacheFile, domainCol, newDomain, otfCol, otfCol)
    print '*INFO* cmd=%s' %cmd
    stdout, stderr, rc = _exec_command(cmd)
    if rc !=0 or stderr !='':
        raise AssertionError('*ERROR* cmd=%s, rc=%s, %s %s' %(cmd,rc,stdout,stderr))

    rows = stdout.splitlines()
            
    # get the requested fields
    result = []
    for row in rows:
        values = row.split(',')
        
        if len(values) != len(headerList):
            raise AssertionError('*ERROR* Number of values (%d) does not match number of headers (%d)' %(len(values), len(headerList)))
        
        fieldDict = {}
        for i in range(0, len(values)):
            if headerList[i] == 'DOMAIN':
                newdomain = _convert_cachedomain_to_normal_format(values[i]) 
                fieldDict[headerList[i]] = newdomain
            elif (headerList[i] == 'RIC' or headerList[i] == 'PUBLISH_KEY' or headerList[i] == 'OTF_STATUS'):
                fieldDict[headerList[i]] = values[i]
           
        result.append(fieldDict)
              
    _delete_file(cacheFile,'',False)

    return result       
コード例 #6
0
def get_all_fields_for_ric_from_cache(ric,domain):
    """Get the field values from the MTE cache for the specifed RIC.

    Arguments:
        ric:   RIC name
        domain: domain of RIC
     
    Returns a dictionary containing all fields for the RIC.  Returns empty dictionary if RIC not found.

    Example:
    | get random RICs from cache  | TESTRIC |
    """
    cacheFile = dump_cache()
     
    # create hash of header values
    cmd = "head -1 %s | tr ',' '\n'" %cacheFile
    stdout, stderr, rc = _exec_command(cmd)
#         print 'DEBUG cmd=%s, rc=%s, stdout=%s stderr=%s' %(cmd,rc,stdout,stderr)
    if rc !=0 or stderr !='':
        raise AssertionError('*ERROR* cmd=%s, rc=%s, %s %s' %(cmd,rc,stdout,stderr))
    ricCol      = 0
    domainCol   = 0
    header = stdout.strip().split()
    for i in range(0, len(header)):
        if header[i] == 'RIC':
            ricCol = i+1 # for awk, col numbers start at 1, so add 1 to index
            if (domainCol > 0):
                break
        if header[i] == 'DOMAIN':
            domainCol = i+1 # for awk, col numbers start at 1, so add 1 to index
            if (ricCol > 0):
                break

    if not ricCol:
        raise AssertionError('*ERROR* Did not find required column name in cache file (RIC)')

    if not domainCol:
        raise AssertionError('*ERROR* Did not find required column name in cache file (DOMAIN)')
     
    # get all fields for the RIC
    if (domain == ''):
        cmd = "awk -F',' '$%d == \"%s\" {print}' %s" %(ricCol, ric, cacheFile)
    else:
        domainConverted = _convert_domain_to_cache_format(domain)
        cmd = "awk -F',' '$%d == \"%s\" && $%d == \"%s\" {print}' %s" %(ricCol, ric, domainCol, domainConverted, cacheFile)
    print '*INFO* cmd=%s' %cmd
    stdout, stderr, rc = _exec_command(cmd)
#         print 'DEBUG cmd=%s, rc=%s, stdout=%s stderr=%s' %(cmd,rc,stdout,stderr)
    if rc !=0 or stderr !='':
        raise AssertionError('*ERROR* cmd=%s, rc=%s, %s %s' %(cmd,rc,stdout,stderr))
    rows = stdout.strip().split('\n')
    if len(rows) > 1:
        raise AssertionError('*ERROR* Multiple rows found for RIC %s rows.  %s' %(ric,rows))
    
    # put fields into dictionary
    values = rows[0].split(',')
    if len(values) <= 1:
        return {}
    if len(values) != len(header):
        raise AssertionError('*ERROR* Number of values (%d) does not match number of headers (%d)' %(len(values), len(header)))
    valuesToReturn = {}
    for i in range(0, len(values)):
            valuesToReturn[header[i]] = values[i]
     
    _delete_file(cacheFile,'',False)
    return valuesToReturn