Example #1
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)
Example #2
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']
Example #3
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)
Example #4
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)
Example #5
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
Example #6
0
from testopia import Testopia
t2 = Testopia.from_config('/var/dt/tf/etc/testopia.cfg')
t2.testrun_get(63)
t2.environment_get(4)
Example #7
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)