def deployBuild():
    getLogger().info('Deploy the latest build on BSM Server')
    try:
        #1. Stop BSM Service
        getLogger().info('Stop BSM Service.')
        cmd = "su -c '$JBOSS_HOME/bin/bsmsrv abort' - bsm"
        runSSHCommand(cmd)

        #2. Uninstall previous deployed build
        getLogger().info('Uninstall previous build.')
        cmd = 'rm -rf /soft/bsmsoft/bsm1/bsm'
        runSSHCommand(cmd)

        #3. Install BSM component
        build = re.search('_(.*)_', BSMCONFIG['artifact']).group(1)
        getLogger().info('Install BSM package')
        cmd = './nagra_install_3.11.4 bsmsoft bsm1 bsm bsm %s -link yes -peek_tar yes -install yes -overwrite yes -create_dir yes' % (
            build)
        runSSHCommand(cmd)

        #4. Start BSM Service
        getLogger().info('Launch the BSM Service.')
        cmd = "su -c '$HOME/bin/bsmsrv_bsm1 start' - bsm"
        runSSHCommand(cmd)

    except Exception:
        raise
    finally:
        SSH.close()
Example #2
0
def drawChartForAutoFailureByPriority():
    import pylab as p
    results = {'P0': 0, 'P1': 0, 'P2': 0, 'P3': 0, 'P4': 0, 'P5': 0}
    getLogger().info('Draw Automation failures by priorities chart')
    failedCaseDict = retrieveFailedTestCases()
    for key in failedCaseDict:
        priority = failedCaseDict[key][1]
        results[priority] = results[priority] + 1
    #Start to draw bar chart
    fig = p.figure(figsize=(5, 5))
    ax = fig.add_subplot(1, 1, 1)
    y = [
        results['P0'], results['P1'], results['P2'], results['P3'],
        results['P4'], results['P5']
    ]
    n = len(y)
    ind = range(n)
    ax.bar(ind, y, facecolor='yellow', align='center', ecolor='black')
    ax.set_ylabel('Number of Failures')
    # Create a title, in italics
    ax.set_title('Automation Failures By Priorities', fontstyle='italic')
    ax.set_xticks(ind)
    group_labels = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5']
    ax.set_xticklabels(group_labels)
    fig.autofmt_xdate()
    plt.savefig(os.path.join(sys.path[0], 'FailureByPriority.png'))
Example #3
0
def loadRptTemplate():
    try:
        getLogger().info('Load BSM report template.')
        fileHandler = open(os.path.join(sys.path[0], 'rpt.tpl'))
        return fileHandler.read()
    except Exception, e:
        getLogger().error('Exception happened: %s' % e)
        raise
def runCommand(cmd):
    getLogger().info('Run command %s' % (cmd))
    p = subprocess.Popen(cmd,
                         shell=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.STDOUT)
    stdoutput, erroutput = p.communicate()
    return stdoutput, erroutput
def getConfigData():
    results = {}
    from xml.etree import ElementTree as ET
    str = os.path.join(os.getcwd(), 'config', 'BSMConfig.xml')
    getLogger().info('Result from Ant command: %s' % (str))
    config = ET.parse(os.path.join(os.getcwd(), 'config', 'BSMConfig.xml'))
    entries = config.findall('./entry')
    for entry in entries:
        results[entry.attrib['key']] = entry.text
    return results
Example #6
0
def drawChartForAutoFailureDistribution():
    getLogger().info('Draw Automation failure distribution chart')
    try:
        table_content = getDetailTableContent()
        testDataParser = TestDataParser()
        testDataParser.feed(table_content.strip())
        getLogger().info('Retrieved Suite Name info from Junit report: %s ' %
                         str(testDataParser.getSuiteNameList()))
        getLogger().info(
            'Retrieved Total number List info from Junit report: %s ' %
            str(testDataParser.getTotalCaseNumList()))
        getLogger().info(
            'Retrieved Failure number List info from Junit report: %s ' %
            str(testDataParser.getFailureNumList()))
        font = {'family': 'Calibri', 'weight': 'normal', 'size': 9}
        plt.rc('font', **font)
        plt.figure(figsize=(5, 5))
        plt.pie(x=testDataParser.getFailureNumList(),
                labels=testDataParser.getSuiteNameList(),
                autopct='%1.1f%%',
                shadow=True)
        plt.title("Automation Failures Distribution",
                  bbox={
                      'facecolor': '0.8',
                      'pad': 5
                  })
        plt.savefig(os.path.join(sys.path[0], 'Failure.png'))
    except Exception:
        raise
Example #7
0
def setTestSummaryData(template):
    try:
        getLogger().info(
            'Retrieve test summary data from JUnit report and set it to template'
        )
        fileHandler = open(
            os.path.join(sys.path[0], '..', 'junit', 'overview-summary.html'))
        content = fileHandler.read()
        i = content.index("<h2>Summary</h2>")
        start = content.index("<table", i)
        end = content.index("table>", start) + OFFSET
        table_content = removeLinks(content[start:end])
        return template.replace('#SUMMARY#', table_content)
    except Exception, e:
        getLogger().error('Exception happened: %s' % e)
        raise
def runSSHCommand(command):
    getLogger().info('Run ssh command: %s' % (command))
    try:
        stdin, stdout, stderr = SSH.exec_command(command)
        getLogger().info('Std output: %s' % (stdout.read()))
        getLogger().info('Std err: %s' % (stderr.read()))
    except paramiko.SSHException:
        getLogger().error("Error running command: " + command)
        raise
def getBuildInfo():
    import re
    buildnum = ''
    url = ''
    try:
        #Get build num
        html = getHttpResponse(BSMCONFIG['buildbranch'])
        patt = re.compile(r'Last successful build \(#(\d+)\)')
        matcher = patt.search(html)
        if matcher is not None:
            buildnum = matcher.group(1)
        #Compose build download address
        url = BSMCONFIG[
            'buildbranch'] + buildnum + '/artifact/bsmapp/target/' + BSMCONFIG[
                'artifact']
        getLogger().info('Latest successful build num is %s and url %s' %
                         (buildnum, url))
        return buildnum, url
    except Exception:
        raise
def checkUrl():
    #Sleep for 3 mins and check whether the bsm server is launched.
    getLogger().info('Check whether the build %s is ready for test' %
                     (BUILD_NUM))
    import time, re
    patt = re.compile(r'Login')
    testurl = 'http://' + BSMCONFIG['host_name'] + ':8080/bsm/'
    count = 1
    while (count <= 10):
        getLogger().info('Sleep for 10 secs')
        time.sleep(10)
        getLogger().info('Try to access test url: %s' % (testurl))
        html = getHttpResponse(testurl)
        matcher = patt.search(html)
        if matcher is None:
            count += 1
            continue
        else:
            getLogger().info('The build %s is ready for test' % (BUILD_NUM))
            return True
    return False
def downloadBuild():
    #1. Remove previous installation package
    getLogger().info('Remove previous package')
    build = re.search('-(.*)_', BSMCONFIG['artifact']).group(1)
    cmd = 'rm -f *%s*' % build
    runSSHCommand(cmd)
    #2. Retrive and download the latest build info
    getLogger().info(
        'Retrieve the latest successful build from Jeakins CI Server')
    BUILD_NUM, BUILD_URL = getBuildInfo()
    getLogger().info('Downloading the latest successful build from %s' %
                     (BUILD_URL))
    cmd = 'wget -q -T300 ' + BUILD_URL
    runSSHCommand(cmd)
Example #12
0
def retrieveFailedTestCases():
    from BsmCaseRetriever import BsmCaseRetriever

    def getSuiteFailureTableContent(fileName):
        fileHandler = open(fileName)
        content = fileHandler.read()
        i = -99
        try:
            i = content.index("<h2>Errors</h2>")
        except:
            i = content.index("<h2>Failures</h2>")
        start = content.index("<table", i)
        end = content.index("table>", start) + OFFSET
        return content[start:end]

    getLogger().info('Draw Automation Failure chart by prority')
    basePath = os.path.join(sys.path[0], '..', 'junit', 'com', 'nagra', 'bsm',
                            'tests')
    htmlFileList = os.listdir(basePath)
    bsmCaseRetriever = BsmCaseRetriever(
        os.path.join(sys.path[0], '.\..\..\Fitnesse'))
    try:
        table_content = getDetailTableContent()
        testDataParser = TestDataParser()
        testDataParser.feed(table_content.strip())
        suiteNameLst = testDataParser.getSuiteNameList()
        getLogger().info(suiteNameLst)
        failureNumLst = testDataParser.getFailureNumList()
        getLogger().info(failureNumLst)
        i = 0
        results = {}
        while (i < len(suiteNameLst)):
            if failureNumLst[i] != 0:
                for fileItem in htmlFileList:
                    pattern = '\d+_%s-errors.html|\d+_%s-fails.html' % (
                        suiteNameLst[i], suiteNameLst[i])
                    if re.match(pattern, fileItem) is not None:
                        failureCaseParser = FailureCaseParser()
                        failureCaseParser.feed(
                            getSuiteFailureTableContent(
                                os.path.join(basePath, fileItem)))
                        for caseId in failureCaseParser.getFailureCaseList():
                            results[
                                caseId] = bsmCaseRetriever.retrieveCaseTitleAndPriority(
                                    suiteNameLst[i], caseId)
            i = i + 1
        return results
    except Exception:
        raise
def uploadTestData(localpath, remotepath):
    from os import listdir
    from os.path import join
    try:
        getLogger().info('Create SFTP Connection.')
        t = paramiko.Transport((BSMCONFIG['host_name'], 22))
        t.connect(username=BSMCONFIG['host_username'],
                  password=BSMCONFIG['host_password'])
        sftp = paramiko.SFTPClient.from_transport(t)
        getLogger().info('Change working directory to %s' % (remotepath))
        sftp.chdir(remotepath)
        for file in listdir(localpath):
            src = join(localpath, file)
            des = join(remotepath, file)
            sftp.put(src, des)
            getLogger().info('Uploaded file from %s to %s' % (src, des))
        t.close()
    except Exception:
        raise
def runCommand(cmd):
    getLogger().info('Run command %s' % (cmd))
    p = subprocess.Popen(cmd,
                         shell=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.STDOUT)
    stdoutput, erroutput = p.communicate()
    return stdoutput, erroutput


if __name__ == '__main__':
    global SSH, SSHAS
    global BUILD_NUM, BUILD_URL
    import re, os.path, sys, subprocess
    os.chdir(os.path.abspath(sys.path[0]))
    os.chdir("..")
    BSMCONFIG = getConfigData()
    SSH = getSSHConn()
    BUILD_NUM = ''
    BUILD_URL = ''
    updateBranch()
    downloadBuild()
    deployBuild()
    if checkUrl():
        runAutoTest()
        generateReport()
        sendReport()
    else:
        getLogger().info('Test url is not avaiable.')
def updateBranch():
    getLogger().info('Sync with P4 Server to update test branch')
    cmd = 'p4 sync'
    (stdoutput, erroutput) = runCommand(cmd)
    getLogger().info('Result from command: %s' % (stdoutput))
    return stdoutput
def generateReport():
    from genReport import generateRpt
    getLogger().info('Generate Test report')
    generateRpt(BUILD_NUM, BUILD_URL)
def runAutoTest():
    getLogger().info('Call Ant Command to run BSM Automation.')
    cmd = 'ant.bat runalltests'
    (stdoutput, erroutput) = runCommand(cmd)
    getLogger().info('Result from Ant command: %s' % (stdoutput))
    return stdoutput
def sendReport():
    from autoReportSender import sendReport
    getLogger().info('Send out Automation test report')
    sendReport()
    getLogger().info('Finished Automation test on build %s' % (BUILD_NUM))