def generate_run_job(scr, testbed_name, job_type, topology_name, unique_id): global rprt mail_recipient = topology_name.split("_")[1] + "@cisco.com" script = re.findall(r'.*/(\w+).py', scr)[0] #job_name=tm+"_"+"job_"+script+".job" #jb=tm+"_"+"job_"+script job_name = topology_name + ".job" jb = topology_name yaml_path = dr + "/" + testbed_name + "/" + testbed_name + ".yaml" drp = dr + "/" + testbed_name drp_tmp = "/storage/users/dich/tcl_script/PI_pfrv3/logs/" print(banner(drp)) os.chdir(drp) make_job.job_make(job_name, scr, yaml_path, 'csr_image', job_type) print(banner("Sleeping for 15 minutes for testbed to come up....")) time.sleep(300) #nmap2yaml.bootstrap_config(topology_name) #dich modify # time.sleep(120) # ylm=test_path+"/"+dd+"/"+testbed_name+".yaml" # print(banner(ylm)) # start_dev.devices_bringup(ylm) ret_code = os.system( "easypy -mailto %s -archive_dir %s %s -xunit -xunit_dir /storage/users/dich/report/PI_regression/" % (mail_recipient, drp_tmp, job_name))
def gen_run_job(scr): script = re.findall(r'.*/(\w+).py', scr)[0] job_name = tm + "_" + "job_" + script + ".py" jb = tm + "_" + "job_" + script make_job.job_make(job_name, scr, pyml, "dummy", cfg_location=fll) os.system("easypy -archive_dir %s %s " % (fll, job_name)) fl = os.listdir() print(banner("fl=%s" % fl)) zp_fldr = str('{:%y-%m}'.format(datetime.datetime.now())) for it in fl: if zp_fldr == it: os.chdir(zp_fldr) fil = os.listdir() print(banner("fil=%s" % fil)) for itm in fil: if ".zip" in itm: if jb in itm: os.system("unzip %s" % itm) fl_unpck = os.listdir() for ti in fl_unpck: if ".report" in ti: if jb in ti: report = open(ti) report = report.read() web_lnk = re.findall( r'^\s*(.+resultsviewer.+\.zip)', report, re.MULTILINE)[0] passed = re.findall( r'^\s*(Passed\s*: \d+)', report, re.MULTILINE)[0] passx = re.findall( r'^\s*(Passx\s*: \d+)', report, re.MULTILINE)[0] failed = re.findall( r'^\s*(Failed\s*: \d+)', report, re.MULTILINE)[0] aborted = re.findall( r'^\s*(Aborted\s*: \d+)', report, re.MULTILINE)[0] blocked = re.findall( r'^\s*(Blocked\s*: \d+)', report, re.MULTILINE)[0] skipped = re.findall( r'^\s*(Skipped\s*: \d+)', report, re.MULTILINE)[0] errored = re.findall( r'^\s*(Errored\s*: \d+)', report, re.MULTILINE)[0] sucess = re.findall( r'^\s*(Success Rate\s*: [0-9.]+ %)', report, re.MULTILINE)[0] rt = re.findall( r'^\s*Success Rate\s*: ([0-9.]+) %', report, re.MULTILINE)[0] mail_rprt = report_mail_standard % ( script, passed, passx, failed, aborted, blocked, skipped, errored, sucess, web_lnk) return (mail_rprt)
def connect_to_Fretta(self): """ common setup subsection: connecting devices """ global g_topo_data log.info(banner("Common Setup: Connection to devices")) #self.script_args['testStep'] = 1 get_test_topo(self.script_args) rtr1_name = g_topo_data['R1'] rtr1 = routers[rtr1_name] rtr2_name = g_topo_data['R2'] rtr2 = routers[rtr2_name] # Step 1 self.script_args['testStep'] = 1 log.info( banner("STEP %s: Device Connection" % (self.script_args['testStep']))) # Create instance of device R1 device_uut = self.script_args['R1'] self.script_args['uut'] = self.script_args['testbed'].devices[ device_uut] tcl.eval('set csccon_default(clear_config_inconsistancy) 0') self.script_args['uut'].connect() log.info("STEP %s: Device Connection Passed" % (self.script_args['testStep'])) rtr1.execute("terminal length 500") rtr1.execute("terminal width 500") response[ "Clear logging buffer \[confirm\] \[y\/n\] \:"] = "econ_sendline y;exp_continue" rtr1.execute("clear logging", reply=response) rtr1.execute("clear context", reply=response) #pdb.set_trace() #rtr1.admin("show platform") self.script_args['testStep'] = 2 log.info( banner("STEP %s: Device Connection" % (self.script_args['testStep']))) device_uut_r2 = self.script_args['R2'] self.script_args['uut_r2'] = self.script_args['testbed'].devices[ device_uut_r2] tcl.eval('set csccon_default(clear_config_inconsistancy) 0') self.script_args['uut_r2'].connect() log.info("STEP %s: Device Connection Passed" % (self.script_args['testStep'])) rtr2.execute("terminal length 500") rtr2.execute("terminal width 500") response[ "Clear logging buffer \[confirm\] \[y\/n\] \:"] = "econ_sendline y;exp_continue" rtr2.execute("clear logging", reply=response) rtr2.execute("clear context", reply=response)
def bringup_testbed(testbed): global pyml, fll, tid tb_fl=dr+"/"+testbed os.mkdir(tb_fl) os.chdir(tb_fl) phy_yml=tb_fl+"/"+testbed+".yaml" pyml=test_path+"/"+phy_yml fll=test_path+"/"+tb_fl lgyml=standard_topologies_defn.topology[testbed]+testbed+"_logical.yaml" print(banner(fll)) print(banner(pyml)) os.system("python /nobackup/jayshar/py/regression/pyats_labmon/labmon_plugin.py --logical-yaml=%s --labmon-host=cent-labmon01 --physical-yaml=%s"%(lgyml, pyml)) tid=housekeeping.create_cfg_files(pyml, fll, standard_topologies_defn.topology[testbed])
def generate_run_job(scr, testbed_name, job_type, topology_name, unique_id): global rprt, dd dd = dr + "/" + testbed_name mail_recipient = topology_name.split("_")[1] + "@cisco.com" script = re.findall(r'.*/(\w+).py', scr)[0] #job_name=tm+"_"+"job_"+script+"_"+job_type+".job" #jb=tm+"_"+"job_"+script job_name = topology_name + ".job" jb = topology_name yaml_path = test_path + "/" + dr + "/" + testbed_name + "/" + testbed_name + ".yaml" drp = test_path + "/" + dr + "/" + testbed_name print(banner(drp)) os.chdir(drp) print('dichhhhh:' + scr) make_tcl_job.job_make(job_name, scr, yaml_path, 'csr_image', job_type) job_location = test_path + "/" + autoeasy_config print(banner("Sleeping for 15 minutes for testbed to come up....")) time.sleep(300) #qiangwa comment #nmap2conf.bootstrap_config(topology_name) #time.sleep(120) # '''ylm=test_path+"/"+dd+"/"+testbed_name+".yaml" # print(banner(ylm)) # start_dev.devices_bringup(ylm)''' #config_terminal.set_config_terminal(top_nmap, server_ip, testbed_name, user_name, passwrd, dd, topology_name) #print("autoeasy -ni %s -cf %s -mailto %s -mailfrom '*****@*****.**'" %(job_name, job_location, mail_recipient)) os.environ.clear() os.environ["TESTBED"] = "cent-mdc-csr" os.environ["AUTOTEST"] = "/opt/ats5.3.0" os.environ["ATS_EASY"] = "/opt/ats5.3.0/ats_easy" os.environ[ "PATH"] = "/opt/ats5.3.0/bin:/opt/ats5.3.0/etc:/opt/ats5.3.0/ats_easy/bin:/opt/ats5.3.0/ats_easy/etc:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/qiangwa/bin" os.environ[ "LD_LIBRARY_PATH"] = "/opt/ats5.3.0/lib:/opt/ats5.3.0/ats_lib" os.environ["SHELL"] = "/bin/bash" os.environ["expect_library"] = "/opt/ats5.3.0/regression/lib" os.environ["EXPECT_LIBRARY"] = "/opt/ats5.3.0/regression/lib" os.environ["IXIA_HOME"] = "/opt/ats5.3.0/lib" os.environ["TAS_PATH"] = "/opt/ats5.3.0/lib/tas" os.environ["TCLLIBPATH"] = "/opt/ats5.3.0/lib" # os.environ['TESTBED_MAP_FILE'] = "/storage/users/dich/tcl_script/cent/cent_feature/etc/pi25-csr.MAP" os.environ[ 'TESTBED_MAP_FILE'] = "/storage/users/dich/tcl_script/0326_PI_cent/cent_feature/etc/pi25-csr.MAP" #qiangwa modi #os.system("autoeasy -user %s -mailto %s -ni %s -cf %s -t %s" %(mail_recipient, mail_recipient, job_name, job_location, job_type)) os.system( "autoeasy -mailto %s %s -cf %s -ad /storage/users/dich/report/PI_regression" % (mail_recipient, job_name, job_location)) '''fl=os.listdir()
def generate_run_job(scr, testbed_name, job_type, topology_name, unique_id, job_params, mail): global rprt, yaml_file mail_recipient = mail + "@cisco.com" script = re.findall(r'.*/(\w+).py', scr)[0] #job_name=tm+"_"+"job_"+script+".job" #jb=tm+"_"+"job_"+script job_name = topology_name + ".job" jb = topology_name #yaml_path=test_path+"/"+dr+"/"+testbed_name+"/"+testbed_name+".yaml" drp = dr + "/" + testbed_name print(banner(drp)) os.chdir(drp) print("job_make arg:") print(job_name, scr, yaml_file, 'csr_image', job_type) make_job.job_make(job_name, scr, yaml_file, 'csr_image', job_type, job_params=job_params) #nmap2yaml.bootstrap_config(topology_name) #dich modify # time.sleep(120) # ylm=test_path+"/"+dd+"/"+testbed_name+".yaml" # print(banner(ylm)) # start_dev.devices_bringup(ylm) time.sleep(20) print("easypy %s -mailto %s -archive_dir %s" % (job_name, mail_recipient, drp)) ret_code = os.system( "easypy %s -xunit -xunit_dir /storage/users/dich/report/PI_regression/%s -mailto %s -archive_dir %s" % (job_name, job_type, mail_recipient, drp))
def generate_run_job(scr, testbed_name, job_type, topology_name, unique_id): global rprt, dd dd = dr + "/" + testbed_name mail_recipient = topology_name.split("_")[1] + "@cisco.com" script = re.findall(r'.*/(\w+).py', scr)[0] #job_name=tm+"_"+"job_"+script+"_"+job_type+".job" #jb=tm+"_"+"job_"+script job_name = topology_name + ".job" jb = topology_name yaml_path = test_path + "/" + dr + "/" + testbed_name + "/" + testbed_name + ".yaml" drp = test_path + "/" + dr + "/" + testbed_name print(banner(drp)) os.chdir(drp) make_tcl_job.job_make(job_name, scr, yaml_path, 'csr_image', job_type) #job_location = test_path + "/" + autoeasy_config #print(banner("Sleeping for 15 minutes for testbed to come up....")) #time.sleep(900) #nmap2conf.bootstrap_config(topology_name) #time.sleep(120) '''ylm=test_path+"/"+dd+"/"+testbed_name+".yaml" print(banner(ylm)) start_dev.devices_bringup(ylm)''' #config_terminal.set_config_terminal(top_nmap, server_ip, testbed_name, user_name, passwrd, dd, topology_name) #print("autoeasy -ni %s -cf %s -mailto %s" %(job_name, job_location, mail_recipient)) #os.environ["TESTBED"] = "cent-mdc-csr" #os.system("autoeasy -user %s -mailto %s -ni %s -cf %s -t %s" %(mail_recipient, mail_recipient, job_name, job_location, job_type)) '''fl=os.listdir()
def prepare_for_subtest(self): """ Testcase Setup section """ log.info(banner(" Aetest Testcase Execution "))
def create_custom_image(topo): global new_name, name_for_server, imageDict imageDir = "/home/cisco/image" #new_name=re.findall(r'.*/([A-Za-z0-9_.-]+)\.ova', csr_image)[0] tb_fl = dr + "/" + topo os.mkdir(tb_fl) rply = OrderedDict() rp = r'uc_send "%s\r"' pr = r'\[sudo\] password for %s:' rply[pr % user_name] = rp % passwrd rply[r'This is your AD password:'******'This is your UNIX password:'******'cd %s'" % imageDir) testbed.devices[server_ip].execute("cd %s" % imageDir) #create a set of images imageList = [] imageList.append(transitHubImage) imageList.append(branch1Image) imageList.append(branch2Image) imageList.append(hubImage) imageSet = set(imageList) print(imageSet) imageDict = {} image_name_list = [] for image in imageSet: new_name = re.findall(r'.*/([A-Za-z0-9_.-]+)\.ova', image)[0] name_for_server = new_name + "_10nic.ova" targetDST = imageDir + "/" + name_for_server if new_name not in image_name_list: image_name_list.append(new_name) new_name = targetDST k = [ 'cot', '-f', 'edit-hardware', 'aa', '-o', 'bb', '-c', '2', '-m', '4GB', '-n', '10', '--nic-types', 'virtio' ] for i in range(0, len(k)): if k[i] == "aa": k[i] = image if k[i] == "bb": k[i] = new_name cot_cmd = '' for cmd in k: cot_cmd = cot_cmd + cmd + ' ' print("Executing command '%s'" % cot_cmd) op = testbed.devices[server_ip].execute(cot_cmd) # print(op) if str(op) != "": print(banner("image %s with 10 NICS built" % image)) else: print( banner( "Error in building a 10 NIC image from source image. Exiting proc!!!!" )) if image == hubImage: imageDict['hub'] = targetDST if image == transitHubImage: imageDict['transit'] = targetDST if image == branch1Image: imageDict['branch1'] = targetDST if image == branch2Image: imageDict['branch2'] = targetDST
for testbed in fnl['test']: virtual_harness.create_server_connect_yaml() virtual_harness.create_custom_image(testbed) print("Start Proc:copy_files_to_dir") virtual_harness.copy_files_to_dir(testbed, pi25) #yaml_file=tb_fl+'/CSR1Kv.virl' print("Start Proc:modify_virl_image") virtual_harness.modify_virl_image(virl_file, imageDict) if tbCreateFlag == "true": print("Start Proc:tb_kickoff") virtual_harness.tb_kickoff(topology_name, virl_file) print( banner( "Sleeping for 5 minutes for testbed to come up....")) for i in range(300): print('sleep %ds of %ds.' % (i + 1, 300), end='\r') time.sleep(1) print("Start Proc:modify_testbed_yaml") virtual_harness.modify_testbed_yaml(testbed, topology_name, subject) for script in fnl['test'][testbed]['scripts']: print("Start Proc:generate_run_job arg:") print( "script: %s\n testbed: %s\n job_type: %s\n topology_name: %s\n unique_id: %s\n job_params: %s\n " % (fnl['test'][testbed]['scripts'][script], testbed, job_type, topology_name, unique_id, job_params)) rp = virtual_harness.generate_run_job( fnl['test'][testbed]['scripts'][script], testbed, job_type,
def create_custom_image(topo): global new_name, name_for_server, imageDict #new_name=re.findall(r'.*/([A-Za-z0-9_.-]+)\.ova', csr_image)[0] tb_fl = dr + "/" + topo os.mkdir(tb_fl) #create a set of images imageList = [] #imageList.append(hubImage) = imageList + hubImage + transitHubImage + branch1Image + branch2Image imageList.append(transitHubImage) imageList.append(branch1Image) imageList.append(branch2Image) imageList.append(hubImage) imageSet = set(imageList) #qiangwa add name_for_server = hubImage print(imageSet) imageDict = {} #qiangwa add imageDict['hub'] = hubImage imageDict['transit'] = transitHubImage imageDict['branch1'] = branch1Image imageDict['branch2'] = branch2Image for image in imageSet: #qiangwa add break new_name = re.findall(r'.*/([A-Za-z0-9_.-]+)\.ova', image)[0] name_for_server = new_name + "_10nic.ova" #name_for_server=new_name+"_10nic.ova" targetDST = destn + "/" + new_name + "_10nic.ova" new_name = test_path + "/" + tb_fl + "/" + new_name + "_10nic.ova" k = [ '/auto/nsstg-tools/bin/cot', 'edit-hardware', 'aa', '-o', 'bb', '-c', '2', '-m', '8GB', '-n', '10', '--nic-types', 'virtio' ] for i in range(0, len(k)): if k[i] == "aa": k[i] = image if k[i] == "bb": k[i] = new_name print(k) p = subprocess.Popen(k, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, errors = p.communicate() if str(output) == "b''": print(banner("image %s with 10 NICS built" % image)) src = "/ws/krannara-sjc/iwan2x/test_harness_interop/" + new_name if image == hubImage: imageDict['hub'] = targetDST if image == transitHubImage: imageDict['transit'] = targetDST if image == branch1Image: imageDict['branch1'] = targetDST if image == branch2Image: imageDict['branch2'] = targetDST #os.move(src, dstn) else: print( banner( "Error in building a 10 NIC image from source image. Exiting proc!!!!" )) exit()