Exemple #1
0
    def _create_test_case(self):

        """ Create Test case if testopia test case doesn't exist"""
        path = self._namespace.suite.source

        fn=open(self._namespace.suite.source)
        items=fn.read()

        regex = re.compile("Case.*\d{1,10}|\s.*:(?P<name>.*)(((?:\n|\r\n?).+)+)")

        find = regex.findall(items)
        tp = Testopia("*****@*****.**","password",'http://bugzilla/xmlrpc.cgi')

        plan_id = 1253
        author_id = 1
        isautomated = True
        category_id = 931
        #tp.testcase_create('testing',plan_id,author_id,isautomated,category_id,1)
        for i in range(0,len(find)):
            alias= str(sys.argv[1].split('.')[0]) + " plan:"+str(plan_id)+" case: "+str(i)
        try:
            create_case=tp.testcase_create(find[i][0],int(plan_id),int(8),False,int(931),int(2),alias,'None',1,1)
        except:
            print "error\n"
            create_case=tp.testcase_create(find[i][0].split('(')[0],int(plan_id),int(8),False,int(931),int(2),alias,'None',1,1)
        try:
            store_case=tp.testcase_store_text(create_case['case_id'],1,"automation","*****@*****.**",find[i][1].replace('\n','<br>'), "Ensure it pass")
        except:
                pass
Exemple #2
0
    def __init__(self,username,password,host,ssl,testrunid):
        Testopia.__init__(self,username=username,password=password,host=host,ssl=ssl)
        self.testrunid = testrunid
        self.testcaseids = None
        self.failed_testcaseids = None
        self.testrun = None

        self.canConnect = False
        self.apicalls = 0
        self.threadlist = []
Exemple #3
0
 def end_test(self, name, attrs):
     """Updates test case status in testopia to 'PASS' / 'FAIL' as matched.
     """
     if attrs['status'] == 'PASS':
         self.outfile.write('PASS\n')
         tcmscon = Testopia.from_config('/var/dt/tf/etc/testopia.cfg')
         tcmscon.testcaserun_update(run_id=self.run_id,\
         case_id=self.case_id, build_id=self.build_id,\
         environment_id=self.environment_id, case_run_status_id=2)
         #self.writemsg()
     else:
         self.outfile.write('FAIL: %s\n' % attrs['message'])
         tcmscon = Testopia.from_config('/var/dt/tf/etc/testopia.cfg')
         tcmscon.testcaserun_update(run_id=self.run_id,\
         case_id=self.case_id, build_id=self.build_id, \
         environment_id=self.environment_id, case_run_status_id=3)
Exemple #4
0
	def create_test_run(self, build_version):
	# Function to create new test run for BVT 
	# Assumptions:
	#	product_id for SPOI : 2
	#	BVT test_plan id : 3

		tcmscon = Testopia.from_config('/var/dt/tf/etc/testopia.cfg')
		build_id = 0
                product_version = ''

		try:
			build_details = tcmscon.build_check_by_name( build_version , 2)
			build_id = build_details['build_id']
		except Exception:
			new_created_build_id = tcmscon.build_create( name=build_version, product_id=2 )
			build_id = new_created_build_id['build_id']
			
		env_details = tcmscon.environment_check_by_name('bvt',2)
		env_id = env_details['environment_id']
		print " Test run parameter details : %d %d " %  (build_id, env_id)
                db = MySQLdb.connect("localhost","bugzilla","bugzpass","bugzilla" )
                cursor = db.cursor()
                mystr = build_version
                sql = "SELECT id FROM versions WHERE product_id = '%d' and value like '%s'" %(2,mystr)
                cursor.execute(sql)
                results = cursor.fetchone()
                row_count = cursor.rowcount
                print("number of affected rows: {}".format(row_count))
                if row_count == 0:
                    print("This product version does not exist: {}".format(mystr))
                    print("Going to add this version {}".format(mystr))
                    sql = "INSERT INTO versions (value,product_id,isactive) VALUES ('%s',2,1)" %(mystr,)
                    try:
                        cursor.execute(sql)
                        db.commit()
                        sql = "SELECT id FROM versions WHERE product_id = '%d' and value like '%s'" %(2,mystr)
                        cursor.execute(sql)
                        results = cursor.fetchone()

                    except:
                        db.rollback()
                db.close()
                product_versionid = results[0]
	
		#Create new testrun for BVT
		from time import gmtime, strftime
		showtime = strftime("%Y-%m-%d_%H:%M:%S", gmtime())
		testrun_details = tcmscon.testrun_create(build_id=build_id, environment_id=env_id, plan_id=3, summary=("Build_Verification_Tests_%d_%s" % (build_id,showtime)) , product_version=mystr, manager_id=1)

		#Add test cases from BVT test plan to created test cases
		tlist = tcmscon.testplan_get_test_cases(3)
		for i in range (0, len(tlist)):
			tcmscon.testcaserun_create(case_id=tlist[i]['case_id'], assignee=1, build_id=build_id, environment_id=env_id, run_id=testrun_details['run_id'])
		#tcmscon.testcaserun_create(case_id=1049, assignee=1, build_id=9, environment_id=17, run_id=187)
		tcmscon = None
		print testrun_details['run_id']
		return testrun_details['run_id']
Exemple #5
0
    def start_test(self, name, attrs):
        """Updates test case status in testopia to be running on start of
        execution"""

        #self.outfile = open(outpath, 'w')
        tags = ' '.join(attrs['tags'])
        self.outfile.write("- %s '%s' [ %s ] :: " % (name, attrs['doc'], tags))
        tcmscon = Testopia.from_config('/var/dt/tf/etc/testopia.cfg')
        tcmscon.testcaserun_update(run_id=self.run_id, case_id=self.case_id,\
        build_id=self.build_id, environment_id=self.environment_id,\
        case_run_status_id=4)
Exemple #6
0
    def update_tests_run_status(self):
        # Function uploads the protractor tests result to Bugzilla against created test run
        self.no_of_tests = len(self.tests_result)
        if self.no_of_tests is not 0:
            tcmscon = Testopia.from_config('/var/dt/tf/etc/testopia.cfg')
            #Get Test run details : build_id, environment_id
            testrun_detail_list = tcmscon.testrun_get(self.run_id)
            build_id = testrun_detail_list['build_id']
            env_id = testrun_detail_list['environment_id']
            print "Test run details : %s %s " % (build_id, env_id)

            for i in range(self.no_of_tests):
                test_summary = str(self.tests_result[i]['description'])
                testrun_result = str(
                    self.tests_result[i]['assertions'][0]['passed'])

                test_detail_list = tcmscon.testrun_list(run_id=self.run_id,
                                                        summary=test_summary)
                case_id = test_detail_list[0]['case_id']

                print "Result : %s %s " % (test_summary, testrun_result)
                if testrun_result is "True":
                    tcmscon.testcaserun_update(run_id=self.run_id,\
                                 case_id=case_id, build_id=build_id, \
                                            environment_id=env_id, case_run_status_id=2)
                else:
                    tcmscon.testcaserun_update(run_id=self.run_id,\
                                 case_id=case_id, build_id=build_id, \
                                            environment_id=env_id, case_run_status_id=3)

                test_summary = ""
                testrun_result = ""
                test_detail_list = ""
                case_id = ""
            tcmscon = None
        else:
            print >> sys.stderr, "No test results found in %s" % (
                self.protractor_report_json)
def main(argv=None):
    if argv is None:
        argv = sys.argv

    print "Command Line : %s" % argv

    try:
        try:
            opts, args = getopt.getopt(argv[1:], "ho:v", ["help", "output=", "mode=", "build_number="])
        except getopt.error, msg:
            raise Usage(msg)
            
        #default values, this will be overwritten by command line args or envronment vars
        #command line args > envronment vars > default values

        #mode can be add_build, write_results, update_test_cases
        mode = "write_result"
        testopia_url = "http://11.22.33.44/"
        testopia_xmlrpc_url = None
        testopia_id = "*****@*****.**"
        testopia_password = "******"
        product_name = "PI_SampleProduct"
        environment = "xxxxxxxx"
        build_number = "0000"      
            
        #replace default value by envronment vars
        logger.info("-------------Environment Variables-------------")
        for (k,v) in os.environ.items():
            logger.info("%-20s : %s" % (k, v))
        logger.info("-----------------------------------------------") 
            
        if (os.environ.get("BUILD_NUMBER", None) != None):
            build_number = os.environ["BUILD_NUMBER"]
        if (os.environ.get("TESTOPIA_URL", None) != None):
            testopia_url = os.environ["TESTOPIA_URL"]            
        if (os.environ.get("TESTOPIA_ID", None) != None):
            testopia_id = os.environ["TESTOPIA_ID"]          
        if (os.environ.get("TESTOPIA_PASSWORD", None) != None):
            testopia_password = os.environ["TESTOPIA_PASSWORD"]          
        if (os.environ.get("PRODUCT_NAME", None) != None):
            product_name = os.environ["PRODUCT_NAME"]        
        if (os.environ.get("ENVIRONMENT", None) != None):
            environment = os.environ["ENVIRONMENT"]              
                    
        #replace default value by command line args
        for option, value in opts:
            if option == "-v":
                verbose = True
            if option in ("-h", "--help"):
                raise Usage(help_message)
            if option in ("-o", "--output"):
                output = value
            if option in ("--build_number"):
                build_number = value                
            if option in ("--mode"):
                mode = value  
                
        logger.info("-------------All Variables After Replace-------------")
        logger.info("%-20s : %s" % ("mode", mode))

        logger.info("%-20s : %s" % ("testopia_url", testopia_url))
        #testopia_xmlrpc_url = testopia_url + "bugzilla/xmlrpc.cgi"
        #logger.info(check_url(testopia_xmlrpc_url))
        testopia_xmlrpc_url = testopia_url + "xmlrpc.cgi"
        logger.info("%-20s : %s" % ("testopia_xmlrpc_url", testopia_xmlrpc_url))
        logger.info("%-20s : %s" % ("testopia_id", testopia_id))        
        logger.info("%-20s : %s" % ("testopia_password", testopia_password)) 
            
        #if the build number get from jenkins it will looks like "job/deploy%20build/3/"
        build_number = "PI%s" % (build_number.strip('/').split('/')[-1].zfill(4))
        logger.info("%-20s : %s" % ("build_number", build_number))
        
        logger.info("%-20s : %s" % ("product_name", product_name))
        logger.info("%-20s : %s" % ("environment", environment))
        
        logger.info("%-20s : %s" % ("test_cases_result_path", test_cases_result_path))
                
        logger.info("-------------Start Processing-------------")        
        tp = Testopia(testopia_id, testopia_password, testopia_xmlrpc_url)   
        
        author_id = get_testopia_author_id(tp, testopia_id)
        logger.info("author '%s' id is %d" % (testopia_id, author_id)) 

        if (product_name == "PI_SampleProduct"):
            product_id = 12
        else:    
            product_id = get_testopia_product_id(tp, product_name)
        logger.info("product '%s' id is %d" % (product_name, product_id)) 

        if (mode == "add_build") :            
            build_description = "%s auto create this build" % str(datetime.now())
            logger.info("create a build") 
            build = tp.build_create(build_number, product_id, description=build_description)
            logger.info("build : %s" % (build))
        elif (mode == "write_result") :
            build_id = get_testopia_build_id(tp, product_id, build_number)
            logger.info("build '%s' id is %d" % (build_number, build_id)) 
            
            plan_id = get_testopia_testplan_id(tp, product_id, default_testplan_name)   
            logger.info("testplan '%s' id is %d" % (default_testplan_name, plan_id))         
            
            environment_id = get_testopia_environment_id(tp, product_id, environment)   
            logger.info("environment '%s' id is %d" % (environment, environment_id))                     
            
            #create a test run
            test_run_summary = "auto create test run"
            test_run_notes = "%s auto create this run" % str(datetime.now())
            logger.info("create a test run") 
            testrun = tp.testrun_create(build_id, environment_id, plan_id, test_run_summary, author_id, plan_text_version=0, notes=test_run_notes, product_version='unspecified')
            logger.info("testrun : %s" % testrun) 
            
            csv_reader = csv.reader(open(test_cases_result_path, 'rb'), delimiter=',', quotechar='"')
            for row in csv_reader:
                tc_alias = row[0]
                tc_summary = row[1]
                tc_result = row[2]
                
                #get test case id from alias
                case_id = get_testopia_testcase_id(tp, tc_alias)
                                
                if (case_id != None):             
                    logger.info("test case '%s' id is %d" % (tc_alias, case_id))    
                             
                    #add test case to test run
                    tp.testrun_add_cases(testrun['run_id'], case_id)
                
                    #update test case result in this run
                    case_run_status_id = get_testopia_caserun_status_id(tp, tc_result)
                    #logger.info("case result '%s' id is %d" % (tc_result, case_run_status_id))   
                    update_case_run = tp.testcaserun_update(testrun['run_id'], case_id, build_id, environment_id, case_run_status_id=case_run_status_id)
                    logger.info("update case result %s(case_run_status_id :%s)" % (tc_result, update_case_run['case_run_status_id']))   
                else:
                    logger.error("fail to get test case '%s' id" % tc_alias)                
        elif (mode == "update_test_cases") :                     
            type_id = get_testopia_type_id(tp, "Unit")
            
            #check is testplan exist
            logger.info("check is testplan '%s' exist" % default_testplan_name)   
            if (tp.testplan_is_exist(product_id, default_testplan_name)):
                logger.info("testplan '%s' is exist" % default_testplan_name) 
            else:
                logger.info("testplan '%s' is not exist so create it" % default_testplan_name) 
                tp.testplan_create(default_testplan_name, product_id, author_id, type_id, 'unspecified')
            plan_id = get_testopia_testplan_id(tp, product_id, default_testplan_name)    
            logger.info("testplan '%s' id is %d" % (default_testplan_name, plan_id)) 
            
            #update test cases to testplan              
            csv_reader = csv.reader(open(test_cases_result_path, 'rb'), delimiter=',', quotechar='"')
            for row in csv_reader:
                tc_alias = row[0]
                tc_summary = row[1]
                
                if (tp.testcase_is_exist(tc_alias)) :
                    logger.info("testcase '%s' is exist so update it" % tc_alias) 
                    testcase = tp.testcase_update(tc_alias, tc_summary, isautomated=True, case_status_id=2, priority_id=1)
                    logger.debug("testcase : %s" % testcase) 
                else :
                    logger.info("testcase '%s' is not exist so create it" % tc_alias) 
                    testcase = tp.testcase_create(summary=tc_summary, plan_id=plan_id, author_id=author_id, isautomated=True, category_id=1, case_status_id=2, alias=tc_alias, priority_id=1)
                    logger.debug("testcase : %s" % testcase) 
Exemple #8
0
	def start_bvt_run(self, run_id):
		tcmscon = Testopia.from_config('/var/dt/tf/etc/testopia.cfg')
		# Retrieve test cases list from given test run 
		test_cases_list = tcmscon.testrun_get_test_cases( run_id )
		print test_cases_list
		
		test_run_details = tcmscon.testrun_get( run_id )
		yaml_deploy_data = {}
		yaml_deploy_data['test_run'] = {}
		yaml_deploy_data['test_run']['cases'] = {}
		yaml_data = {}
		yaml_data['test_run'] = {}
		yaml_data['test_run']['cases'] = {}
		
		#Run deployment test first
		for i in range (0, len(test_cases_list)):
			if test_cases_list[i]['summary'] == "1_DT_Installation_Configuration":
				case_id = test_cases_list[i]['case_id']
				yaml_deploy_data['test_run']['cases'][case_id] = {}
	                        yaml_deploy_data['test_run']['cases'][case_id]['summary'] = test_cases_list[i]['summary']
        	                yaml_deploy_data['test_run']['cases'][case_id]['case_id'] = case_id
                	        yaml_deploy_data['test_run']['cases'][case_id]['isautomated'] = test_cases_list[i]['isautomated']
		                yaml_deploy_data['test_run']['plan_id'] = test_run_details['plan_id']
		yaml_deploy_data['test_run']['plan_id'] = test_run_details['plan_id']
		yaml_deploy_data['test_run']['run_id'] = run_id
		yaml_deploy_data['test_run']['environment_id'] = test_run_details['environment_id']
		yaml_deploy_data['test_run']['summary'] = test_run_details['summary']

		#Create run file for DT installation and configuration test
		import yaml
		fileName = "/var/dt/tf/tmp/bugzilla/%s" % (run_id)
		print "BVT installation test starts ...."
		
		with open(fileName, 'w') as yaml_file:
                        yaml.dump(yaml_deploy_data, yaml_file, default_flow_style=False, explicit_start=True)
		print "yaml file created"
		
		self._wait_for_test_run_execution(str(run_id))
		print "End of Deployment test execution \n"
		

		#Prepare dict to dump in yaml from test_cases_list
		for i in range (0, len(test_cases_list)):
			if test_cases_list[i]['summary'] != "1_DT_Installation_Configuration":
				case_id = test_cases_list[i]['case_id']			
				yaml_data['test_run']['cases'][case_id] = {}
				yaml_data['test_run']['cases'][case_id]['summary'] = test_cases_list[i]['summary']
				yaml_data['test_run']['cases'][case_id]['case_id'] = case_id
				yaml_data['test_run']['cases'][case_id]['isautomated'] = test_cases_list[i]['isautomated']
		yaml_data['test_run']['plan_id'] = test_run_details['plan_id']
		yaml_data['test_run']['run_id'] = run_id
		yaml_data['test_run']['environment_id'] = test_run_details['environment_id']
		yaml_data['test_run']['summary'] = test_run_details['summary']

		#Delete and create run file to trigger the BVT run
		import os
		os.remove(fileName)	
		print "BVT run starts ...."
		with open(fileName, 'w') as yaml_file:
			yaml.dump(yaml_data, yaml_file, default_flow_style=False, explicit_start=True)
		
		#self._wait_for_test_run_execution(str(run_id))
		#Wait for all tests to get executed; check for file timestamp   
		ts1 = os.stat("/var/dt/tf/logs/" + str(run_id) + "/index.html").st_mtime
                import time
		while True:
			time.sleep(2700) #Explicit wait to get execution completed 
			if ts1 != os.stat("/var/dt/tf/logs/" + str(run_id) + "/index.html").st_mtime :
				break	
		
		print "End of BVT execution \n"
		tcmscon = None
Exemple #9
0
from testopia import Testopia
t2 = Testopia.from_config('/var/dt/tf/etc/testopia.cfg')
t2.testrun_get(63)
t2.environment_get(4)
Exemple #10
0
def processfile(runfile):
    """Function to process testopia run yaml file and create workflows, add them 
    to run in fireworks"""
    with open(runfile, 'r') as f:
        run_details = yaml.load(f)
    testcases = run_details['test_run']['cases']
    print 'testcases:\n'
    print testcases
    testcasetype = type(testcases)
    print testcasetype
    run_id = int(run_details['test_run']['run_id'])
    print run_id
    environment_id = int(run_details['test_run']['environment_id'])
    print environment_id
    tcms = Testopia.from_config('/var/dt/tf/etc/testopia.cfg')
    environment_details = tcms.environment_get(environment_id)
    print environment_details
    rundetailsfromtcms = tcms.testrun_get(run_id)
    product_version = rundetailsfromtcms['product_version']
    build_id = rundetailsfromtcms['build_id']
    buildinfo = tcms.build_get(build_id)
    print buildinfo
    build_name = buildinfo['name']
    print "build name: " + build_name
    print "product_version " + product_version
    environment_name = environment_details['name']
    print environment_name
    environment_file = '/var/dt/tf/etc/environments/' + environment_name + '.py'
    environment_filepyc = environment_file + 'c'
    if os.path.isfile(environment_filepyc):
        print "environment pyc file is present, deleting it"
        os.remove(environment_filepyc)
    else:
        print "No cached environment pyc file found"
    print environment_file
    testsonfire = []
    fwsequence = {}
    fwkey = ''
    fwvalue = ''
    for testcase in testcases.keys():
        case_id = int(testcase)
        testcase_name = run_details['test_run']['cases'][testcase]['summary']
        argsf = [
            run_id, case_id, build_id, environment_id, environment_name,
            environment_file, testcase_name, product_version, build_name
        ]
        fw_test = Firework(PyTask(func='HookFW.runCase', args=argsf))
        print "argsf are:"
        print argsf
        testsonfire.append(fw_test)
        if fwvalue:
            fwsequence[fwvalue] = fw_test
            fwvalue = fw_test
        else:
            fwvalue = fw_test

    #To be run as last firework in the workflow, to compile logs for the entire set of testcases

    rebotcmd = "cd /var/dt/tf/logs/" + str(
        run_id
    ) + '; rebot -N "DTTF" -R */*.xml; ln -s report.html index.html; echo ok '
    fw_test = Firework(ScriptTask.from_str(rebotcmd))
    testsonfire.append(fw_test)
    fwsequence[fwvalue] = fw_test
    print "tests on fire:"
    print testsonfire
    print "test sequence:"
    print fwsequence
    workflow = Workflow(testsonfire, fwsequence)
    launchpad = LaunchPad()
    launchpad.add_wf(workflow)