How to use log_abort method in autotest

Best Python code snippet using autotest_python

ovfUtils.py

Source:ovfUtils.py Github

copy

Full Screen

...30 pass31pass32 33def joinPathComponents(*path_comp_list):34 outx.log_abort("Enter ovfUtils.joinPathComponents\n\n -- Path Component List: %s" %(list(path_comp_list)))35 ##accum_path = os.path.join(*path_comp_list)36 accum_path = ""37 for px in path_comp_list:38 outx.log_abort("ovfUtils.joinPathComponents\n\n -- Accum Path: \"%s\" Px: \"%s\"" %(accum_path, px))39 accum_path = os.path.join(accum_path, px)40 pass41 outx.log_abort("Exit ovfUtils.joinPathComponents\n\n -- Returning: \"%s\"" %(accum_path))42 return(accum_path)43pass44def getMatchingFilesFromPathGlob(pathglob):45 outx.log_debug("Enter ovfUtils.getMatchingFilesFromPathGlob\n\n -- Path Glob: \"%s\"" %(pathglob))46##47## path_re = cvtGlobToREPatt(pathglob)48## outx.log_abort("Enter ovfUtils.getMatchingFilesFromPathGlob\n\n -- Path Glob: \"%s\" Path RE: \"%s\"" %(pathglob, path_re))49## matching_files = glob.glob(path_re)50## outx.log_abort("Enter ovfUtils.getMatchingFilesFromPathGlob\n\n -- Path Glob: \"%s\"" %(pathglob))51##52 matching_files = glob.glob(pathglob)53 outx.log_debug("Exit ovfUtils.getMatchingFilesFromPathGlob\n\n -- Returning Matching Files: \"%s\"" %(matching_files))54 return(matching_files)55pass56# return the lexicographic bigger name which will work for us57def getNewerFile(files):58 bigger = files[0]59 for i in range(1, len(files)):60 if bigger < files[i]:61 bigger = files[i]62 return bigger63pass64def getMatchingFiles(filepfx, filesfx):65 outx.log_debug("Enter getMatchingFiles\n\n -- FilePfx: \"%s\"\n\n -- FileSfx: \"%s\"" %(filepfx, filesfx))66 matching_files = getMatchingFilesFromPathGlob(filepfx + '//*//*' + filesfx)67 outx.log_info("Exit getMatchingFiles\n\n -- FilePfx: \"%s\"\n\n -- FileSfx: \"%s\"\n\n -- Returning:\n%s" %(filepfx, filesfx, matching_files))68 return(matching_files)69pass70def getMatchingFile(filepfx, filesfx):71 matching_files = getMatchingFiles(filepfx=filepfx, filesfx=filesfx)72 if matching_files:73 mfile = getNewerFile(matching_files)74 outx.log_info("Exit getMatchingFils\n\n -- FilePfx: \"%s\"\n\n -- FileSfx: \"%s\"\n\n -- Matching Files:\n%s\n\n -- Returning: \"%s\"" %(filepfx, filesfx, matching_files, mfile))75 return(mfile)76 else:77 outx.log_debug("Exit getMatchingFils\n\n -- FilePfx: \"%s\"\n\n -- FileSfx: \"%s\"\n\n -- No Matching Files -- Returning None" %(filepfx, filesfx))78 return(None)79 pass80pass81def getMatchingFilesFromPathGlobList(*path_glob_list):82 outx.log_abort("Enter ovfUtils.getMatchingFilesFromPathGlobList\n\n -- Path Glob List: %s" %(list(path_glob_list)))83 full_path_glob = joinPathComponents(path_glob_list)84 matching_files = getMatchingFilesFromPathGlob(full_path_glob)85 outx.log_abort("Exit ovfUtils.getMatchingFilesFromPathGlobList\n\n -- Returning Path List: \"%s\"" %(matching_files))86 return(matching_files)87pass88def getMatchingFilesFromPathCompList(*path_comp_list):89 outx.log_abort("Enter ovfUtils.getMatchingFilesFromPathCompList\n\n -- Path Comp List: %s" %(list(path_comp_list)))90 dir_list = path_comp_list[:-1]91 if isinstance(dir_list, tuple):92 outx.log_abort("1. Dir List(%s): %s" %(type(dir_list), dir_list))93 dir_list = list(dir_list)94 outx.log_abort("2. Dir List(%s): %s" %(type(dir_list), dir_list))95 elif isinstance(dir_list, str):96 outx.log_abort("3. Dir List(%s): %s" %(type(dir_list), dir_list))97 dir_list = [ dir_list ]98 outx.log_abort("4. Dir List(%s): %s" %(type(dir_list), dir_list))99 pass100 outx.log_abort("5. Dir List(%s): %s" %(type(dir_list), dir_list))101 basename = path_comp_list[-1]102 outx.log_abort("ovfUtils.getMatchingFilesFromPathCompList\n\n -- Dir List: %s Basename: \"%s\"" %(dir_list, basename))103 outx.log_abort("6. Dir List(%s): %s" %(type(dir_list), dir_list))104 dir_path = joinPathComponents(*dir_list)105 outx.log_abort("7. Dir List: %s Dir Path: \"%s\"" %(dir_list, dir_path))106 ## sleep(4)107 ##if dir_path and (dir_path[-1] == os.sep):108 glob_matches = getMatchingFilesFromPathGlob(filepfx)109 if glob_matches:110 matching_files += glob_matches111 pass112 if filepfx and filesfx:113 for strx in [ "", "\\", "/", "." ]:114 concatfile = (filepfx + strx + filesfx)115 if os.path.exists(concatfile) and os.path.isfile(concatfile):116 matching_files.append(concatfile)117 pass118 pass119 pass120def getMatchingFilesFromPathGlobList(*path_glob_list):121 outx.log_abort("Enter ovfUtils.getMatchingFilesFromPathGlobList\n\n -- Path Glob List: %s" %(list(path_glob_list)))122 full_path_glob = joinPathComponents(path_glob_list)123 matching_files = getMatchingFilesFromPathGlob(full_path_glob)124 outx.log_abort("Exit ovfUtils.getMatchingFilesFromPathGlobList\n\n -- Returning Path List: \"%s\"" %(matching_files))125 return(matching_files)126pass127def getMatchingFilesFromPathCompList(*path_comp_list):128 outx.log_abort("Enter ovfUtils.getMatchingFilesFromPathCompList\n\n -- Path Comp List: %s" %(list(path_comp_list)))129 dir_list = path_comp_list[:-1]130 if isinstance(dir_list, tuple):131 outx.log_abort("1. Dir List(%s): %s" %(type(dir_list), dir_list))132 dir_list = list(dir_list)133 outx.log_abort("2. Dir List(%s): %s" %(type(dir_list), dir_list))134 elif isinstance(dir_list, str):135 outx.log_abort("3. Dir List(%s): %s" %(type(dir_list), dir_list))136 dir_list = [ dir_list ]137 outx.log_abort("4. Dir List(%s): %s" %(type(dir_list), dir_list))138 pass139 outx.log_abort("5. Dir List(%s): %s" %(type(dir_list), dir_list))140 basename = path_comp_list[-1]141 outx.log_abort("ovfUtils.getMatchingFilesFromPathCompList\n\n -- Dir List: %s Basename: \"%s\"" %(dir_list, basename))142 outx.log_abort("6. Dir List(%s): %s" %(type(dir_list), dir_list))143 dir_path = joinPathComponents(*dir_list)144 outx.log_abort("7. Dir List: %s Dir Path: \"%s\"" %(dir_list, dir_path))145 ## sleep(4)146 ##if dir_path and (dir_path[-1] == os.sep):147 if dir_path and (dir_path[-1] == os_sep()):148 dir_path = dir_path[:-1]149 pass150 path_glob = None151 if dir_path:152 ##path_glob = (dir_path + os.sep + basename)153 path_glob = (dir_path + os_sep() + basename)154 else:155 path_glob = basename156 pass157 matching_files = getMatchingFilesFromPathGlob(path_glob)158 outx.log_abort("Exit ovfUtils.getMatchingFilesFromPathCompList\n\n -- Returning Path List: \"%s\"" %(matching_files))159 return(matching_files)160pass161def cvtGlobToREPatt(inglob):162 repatt = ""163 prev_cx = None164 ##outx.log_abort("cvtGlobToREPatt -- Inglob: \"%s\" Len(inglob): %d" %(inglob, len(inglob)))165 for cx in inglob:166 if cx == r"*":167 ##outx.log_abort("1. Cx: \"%s\" Prev_Cx: \"%s\"" %(cx, prev_cx))168 if (prev_cx == r"."):169 repatt += r"*"170 ##outx.log_abort("2. Cx: \"%s\" Prev_Cx: \"%s\" RE Patt: \"%s\" " %(cx, prev_cx, repatt))171 else:172 ##outx.log_abort("3. Cx: \"%s\" Prev_Cx: \"%s\"" %(cx, prev_cx))173 ##repatt += re.escape(".")174 repatt += "."175 repatt += r"*"176 ##outx.log_abort("4. Cx: \"%s\" Prev_Cx: \"%s\" RE Patt: \"%s\" " %(cx, prev_cx, repatt))177 pass178 else:179 repatt += re.escape(cx)180 ##outx.log_abort("5. Cx: \"%s\" Prev_Cx: \"%s\" RE Patt: \"%s\" " %(cx, prev_cx, repatt))181 pass182 prev_cx = cx183 pass184 repatt += r"$"185 ##outx.log_abort("cvtGlobToREPatt -- InGlob: \"%s\" RE Patt: \"%s\"" %(inglob, repatt))186 return(repatt)187pass188def getDirTreeMatchingFiles(root_path, filename_patt, patt_is_re=False):189 accum_path_list = []190 patt_re = None191 if patt_is_re:192 patt_re = filename_patt193 else:194 patt_re = cvtGlobToREPatt(filename_patt)195 pass196 outx.log_abort("getDirTreeMatchingFiles Filename Patt: \"%s\" Patt Is RE: \"%s\" Patt RE: \"%s\"" %(filename_patt, patt_is_re, patt_re))197 ###for rootx,dirsx,filesx in os.walk(root_path):198 rootx = ""199 dirsx = []200 for filesx in [1]:201 outx.log_abort("ovfUtils.getDirTreeMatchingFiles\n\n -- Root: \"%s\"\n\n -- All Files:\n%s" %(rootx, outx.pformat(filesx)))202 ###for filex in filesx:203 for filex in [ "osc.py" ]:204 outx.log_abort("ovfUtils.getDirTreeMatchingFiles -- FileX: \"%s\"" %(filex))205 ##regex = re.compile(patt_re, re.IGNORECASE)206 ##match = regex.search(filex)207 ##208 ##match = re.search(patt_re, filex, re.IGNORECASE)209 match = re.match(patt_re, filex, re.IGNORECASE)210 if match:211 outx.log_abort("ovfUtils.getDirTreeMatchingFiles -- Comparing Patt RE: \"%s\" FileX: \"%s\" Match: %s" %(patt_re, filex, (match and True)))212 pathx = os.path.join(rootx, filex)213 ###outx.log_abort("ovfUtils.getDirTreeMatchingFiles -- FileX: \"%s\" Matches PattX: \"%s\"\n\n -- File Path: \"%s\"\n\n -- Match:\n%s" %(filex, patt_re, pathx, str(match.group())))214 accum_path_list.append(pathx)215 break216 else:217 outx.log_abort("ovfUtils.getDirTreeMatchingFiles -- Comparing Patt RE: \"%s\" FileX: \"%s\" Match: %s" %(patt_re, filex, (match and True)))218 pass219 ## sleep(4)220 pass221 pass222 outx.log_abort("Exit ovfUtils.getDirTreeMatchingFiles\n\n -- Returning:\n%s" %(outx.pformat(accum_path_list)))223 return(accum_path_list)224pass225# 226# ##getMatchingFilesFromPathGlobList(".", "*.cfg")227# getMatchingFilesFromPathCompList("TEMP", "*.py")228# ## sleep(100)229# getMatchingFilesFromPathCompList(".", "*.cfg")230# getMatchingFilesFromPathCompList("foo", "bar", "baz", "*.cfg")231# getMatchingFilesFromPathCompList(".", "*.cfg")232# 233# ##accumMatchingFilesFromPathGlobList("*.py", ".*SAVE.*", ".*ORIG.*", "*.xml")234# ##getDirTreeMatchingFiles(r".", r".*.py", r".*.xml", r".*.cfg")235# getDirTreeMatchingFiles(r".", r"*.p*")236# ## sleep(100)237# getDirTreeMatchingFiles(r".", r".*.py")238# getDirTreeMatchingFiles(r".", r"*.xml")239# getDirTreeMatchingFiles(r".", r"*.*f*")240# getDirTreeMatchingFiles(r".", ".*SAVE.*")241# getDirTreeMatchingFiles(r".", ".*ORIG.*")242# ## sleep(100)243# 244#######################################################################245##246## ==============================================================================247## INFO - treeData:248## { 'ovf': { 'datacenter': 'Physical Datacenter',249## 'datastore': 'datastore1 (9)',250## 'gateway': '10.71.118.252',251## 'host': '10.71.117.243',252## 'netmask': '255.255.255.128',253## 'network': 'dvPortGroup-118',254## 'nscpluginfilename': 'NscSdnControllerPlugin.zip',255## 'nsmpluginfilename': 'NsmMgrPlugin.zip',256## 'oscbuild': '3774',257## 'oscbuildhomedir': '/home/mounts/builds_host',258## 'oscrelease': '2_5',259## 'sourceovf': '/home/mounts/builds_host/2_5/Build3850/OSC-3850.ovf',260## 'vcenterip': '10.71.117.200',261## 'vcenterpass': 'admin123',262## 'vcenteruser': 'root'}}263## ==============================================================================264##265#######################################################################266class Ovf():267#######################################################################268## 269##270## -- Old OVF Class Init (including 'ovfElementXml')271## class Ovf():272## #ip, sourceOVF, vmName, gateway, netmask, dnslist, ntplist, network, vcIp, vcuser, vcpass, datastore, datacenter, cluster, enableSSH273## 274## def __init__(self, GlobalData=None, sourceOVF=None, vmName=None, vmType=None, vmIp=None, ovftool=None, ovfElementXml=None, vmNameSuffix=None):275## _funcargs = { 'vmType':vmType, 'sourceOVF':sourceOVF, 'vmIp':vmIp, 'ovftool':ovftool, 'ovfElementXml':ovfElementXml, 'vmNameSuffix':vmNameSuffix }276## ##outx.log_info("Enter Ovf Class Constructor -- _funcargs:\n%s" %(outx.pformat(_funcargs)))277## self.vmType = vmType278## self.vmIp = vmIp279## self.vmName = vmName280## self.vmNameSuffix = vmNameSuffix281## self.ovftool = (ovftool or GlobalData['ovfToolExe'])282## self.ovfElementXml = ovfElementXml283## tree = xml.etree.ElementTree.fromstring(ovfElementXml)284## treeData = etToDatastruct(tree)285## outx.log_info("treeData:\n%s" %(outx.pformat(treeData)))286## if tree.tag == 'OVF':287## if not vmType:288## vmType = getText(tree, "vmType")289## if not vmIp:290## vmIp = getText(tree, "vmIp")291## if not vmName:292## vmName = getText(tree, "vmName")293## if not sourceOVF:294## sourceOVF = getText(tree, "sourceOVF")295## pass296## self.sourceovf = sourceOVF297## self.vmName = vmName298## self.vmIp = vmIp299## self.vmType = vmType300## if vmNameSuffix != None:301## self.vmName = self.vmName + '-' + vmNameSuffix302## pass303## 304## #if type == "ISC" : 305## self.enableSSH = getText( tree, "enableSSH")306## self.respool = getText( tree, "respool")307## self.gateway = getText( tree, "gateway")308## self.netmask = getText( tree, "netmask")309## self.dnslist = getText( tree, "dnslist")310## self.ntplist = getText( tree, "ntplist")311## self.host = getText( tree, "host")312## self.network = getText( tree, "network")313## self.vcIp = getText( tree, "vcenterIP")314## vcuser = getText( tree, "vcenterUser")315## vcuser = vcuser.replace('@', " ")316## vcuser = vcuser.replace('.', " ")317## vcuser = vcuser.replace(':', " ")318## vcuserx = vcuser.split(" ")319## vcuser = vcuserx[0]320## self.vcuser = vcuser321## self.vcuser = "root"322## self.vcpass = getText( tree, "vcenterPass")323## self.datastore = getText( tree, "datastore")324## self.datacenter = getText( tree, "datacenter")325## self.cluster = getText( tree, "cluster") 326## defaultvcuser = GlobalData['defaultVcUser']327## defaultvcpass = GlobalData['defaultVcPasswd']328## self.vcuser = (self.vcuser or defaultvcuser)329## self.vcpass = (self.vcpass or defaultvcpass)330## else : 331## outx.exitFailure( "OVF tag is missing - exiting") 332## pass333## ## outx.log_info("Ovf Class Constructor -- Args:\n%s" %(outx.pformat(_funcargs)))334## self_attrs = self.__dir__()335## self_dir = {}336## for atx in self_attrs:337## if '__' not in atx:338## self_dir[atx] = getattr(self, atx)339## pass340## pass341## self.self_dir = self_dir342## outx.log_info("Ovf Class Constructor -- Self:\n%s" %(outx.pformat(self_dir)))343## ## sleep(5)344## if not os.path.exists(self.sourceovf):345## outx.log_abort("Ovf Class Constructor -- sourceOVF: \"%s\" not found" %(self.sourceovf))346## pass347## pass348## 349#######################################################################350 def __init__(self, GlobalData=None, sourceOVF=None, vmName=None, vmType=None, vmIp=None, ovftool=None, ovfElementXml=None, ovfDatastruct=None, ovfElement=None, overwriteExistingVm=False, vmNameSuffix=None, powerOnVm=True):351 if vmType is not None:352 vmType = vmType.lower()353 pass354 _funcargs = { 'sourceOVF':sourceOVF, 'vmName':vmName, 'vmType':vmType, 'vmIp':vmIp, 'ovftool':ovftool, 'ovfElementXml':ovfElementXml, 'ovfDatastruct':ovfDatastruct, 'ovfElement':ovfElement, 'overwriteExistingVm':overwriteExistingVm, 'vmNameSuffix':vmNameSuffix, 'powerOnVm':powerOnVm }355 ##_funcargs['GlobalData'] = GlobalData356 outx.log_info("Enter Ovf Class Constructor -- _funcargs(1):\n%s" %(outx.pformat(_funcargs)))357 ## sleep(30)358 ovftool = (ovftool or (GlobalData and GlobalData['ovfToolExe']))359 if ovftool:360 self.ovftool = ovftool361 else:362 outx.log_abort("Ovf Class Constructor -- No value for 'ovftool' found")363 pass364 outx.log_info("overwriteExistingVm(1): \"%s\"" %(overwriteExistingVm))365 if ovfDatastruct:366 pass367 elif ovfElement:368 ovfDatastruct = etToDatastruct(ovfElement)369 _funcargs['tree'] = ovfElement370 _funcargs['ovfElement'] = ovfElement371 elif tree:372 ovfDatastruct = etToDatastruct(tree)373 _funcargs['tree'] = tree374 _funcargs['ovfElement'] = tree375 elif ovfElementXml:376 tree = xml.etree.ElementTree.fromstring(ovfElementXml)377 ovfDatastruct = etToDatastruct(tree)378 _funcargs['tree'] = tree379 _funcargs['ovfElement'] = tree380 _funcargs['ovfElementXml'] = ovfElementXml381 else:382 outx.log_abort("Ovf Class Constructor -- Expected one of 'ovfDatastruct', 'ovfElement', 'tree', or 'ovfElementXml' options for initialization parameters\n\n -- Func. Args.:\n%s" %(outx.pformat(_funcargs)))383 pass384 outx.log_info("overwriteExistingVm(2): \"%s\"" %(overwriteExistingVm))385 _funcargs['ovfDatastruct'] = ovfDatastruct386 if vmName is not None:387 #self.vmname = vmName388 self.name = vmName389 pass390 if vmType is not None:391 #self.vmtype = vmType392 self.type = vmType393 pass394 if vmIp is not None:395 #self.vmip = vmIp396 self.ip = vmIp397 pass398 if sourceOVF is not None:399 #self.sourceOVF = sourceOVF400 self.sourceovf = sourceOVF401 pass402 if ovftool is not None:403 self.ovftool = ovftool404 pass405 if vmNameSuffix is not None:406 #self.vmNameSuffix = vmNameSuffix407 self.namesuffix = vmNameSuffix408 pass409 if overwriteExistingVm is not None:410 #self.overwriteExistingVm = overwriteExistingVm411 self.overwriteexistingVm = overwriteExistingVm412 pass413 if powerOnVm is not None:414 #self.powerOnVm = powerOnVm415 self.poweronvm = powerOnVm416 pass417 outx.log_debug("OVF Class Init -- Self:\n%s\n\n -- Ovf Datastruct:\n%s" %(outx.objformat(self), outx.pformat(ovfDatastruct)))418 for k,v in ovfDatastruct.items():419 ##if not hasattr(self, k):420 if not (hasattr(self, k) and getattr(self, k) is not None):421 setattr(self, k, v)422 pass423 pass424 outx.log_debug("OVF Class Init --\n\n -- OVF Instance -- Self:\n%s" %(outx.objformat(self)))425 outx.log_debug("Ovf Class Constructor -- _funcargs(2):\n%s" %(outx.pformat(_funcargs)))426 self.ovftool = (ovftool or GlobalData['ovfToolExe'])427 outx.log_debug("Ovf Class Constructor -- OvfToolExe: \"%s\"" %(self.ovftool))428## { 'ovf': { 'datacenter': 'Physical Datacenter',429## 'datastore': 'datastore1 (9)',430## 'gateway': '10.71.118.252',431## 'host': '10.71.117.243',432## 'netmask': '255.255.255.128',433## 'network': 'dvPortGroup-118',434## 'nscpluginfilename': 'NscSdnControllerPlugin.zip',435## 'nsmpluginfilename': 'NsmMgrPlugin.zip',436 outx.log_debug("OVF Class Init --\n\n -- OVF Instance -- Self:\n%s" %(outx.objformat(self)))437 if vmNameSuffix is not None:438 #self.vmName = self.vmName + '-' + vmNameSuffix439 self.name = self.name + '-' + vmNameSuffix440 pass441 outx.log_debug("OVF Class Init --\n\n -- OVF Instance -- Self:\n%s" %(outx.objformat(self)))442 ##self.vmName = (vmName or dictLookup(ovfDatastruct, ['vmName', 'name'], ignoreCase=True)443 if (hasattr(self, 'name') and getattr(self, 'name') is not None):444 outx.log_info("Name: \"%s\"" %(self.name))445 pass446 elif (hasattr(self, 'vmname') and getattr(self, 'vmname') is not None):447 self.name = self.vmname448 outx.log_info("Name: \"%s\"" %(self.name))449 else:450 self.name = dictLookup(ovfDatastruct, ['vmName', 'name', 'targetName'], ignoreCase=True)451 pass452 if not getattr(self, 'name', None):453 outx.log_abort("OVF Class Init -- No 'name', 'vmname', or 'targetname' given")454 pass455 outx.log_debug("OVF Class Init --\n\n -- OVF Instance -- Self:\n%s" %(outx.objformat(self)))456 self.vmname = self.name457 self.targetName = self.name458 outx.log_info("Name: \"%s\"" %(self.name))459 if (hasattr(self, 'type') and getattr(self, 'type') is not None):460 pass461 elif (hasattr(self, 'vmtype') and getattr(self, 'vmtype') is not None):462 self.type = self.vmtype463 else:464 self.type = dictLookup(ovfDatastruct, ['vmType', 'type'], ignoreCase=True)465 if self.type:466 self.type = self.type.lower()467 pass468 pass469 outx.log_debug("OVF Class Init --\n\n -- OVF Instance -- Self:\n%s" %(outx.objformat(self)))470 if (hasattr(self, 'ip') and getattr(self, 'ip') is not None):471 pass472 elif (hasattr(self, 'vmip') and getattr(self, 'vmip') is not None):473 self.ip = self.ip474 else:475 self.ip = dictLookup(ovfDatastruct, ['vmIp', 'ip'], ignoreCase=True)476 pass477 outx.log_debug("OVF Class Init --\n\n -- OVF Instance -- Self:\n%s" %(outx.objformat(self)))478 if not getattr(self, 'name', None):479 outx.log_abort("OVF Class Init -- No 'ip', or 'vmip' given")480 pass481 self.vmIsOscType = (getattr(self, 'type', None) == 'osc')482 outx.log_debug("OVF Class Init --\n\n -- OVF Instance -- Self:\n%s" %(outx.objformat(self)))483 if hasattr(self, 'oscVctrUser'):484 self.vcuser = self.oscVctrUser485 if hasattr(self, 'oscVctrPass'):486 self.vcpass = self.oscVctrPass487 if hasattr(self, 'oscVctrIp'):488 self.vcip = self.oscVctrIp489 pass490 491 ##vcuser = self.vcUser492 vcuser = self.vcuser493 vcuser = vcuser.replace('@', " ")494 vcuser = vcuser.replace('.', " ")495 vcuser = vcuser.replace(':', " ")496 vcuserx = vcuser.split(" ")497 vcuser = vcuserx[0]498 self.vcuser = vcuser499 defaultVcUser = None500 if (GlobalData and ('defaultVcUser' in GlobalData)):501 defaultVcUser = GlobalData['defaultVcUser']502 defaultVcPass = None503 if (GlobalData and ('defaultVcPass' in GlobalData)):504 defaultVcPass = GlobalData['defaultVcPass']505 pass506 self.vcuser = (self.vcuser or defaultVcUser)507 self.vcpass = (self.vcpass or defaultVcPass)508 outx.log_debug("OVF Class Init --\n\n -- OVF Instance -- Self:\n%s" %(outx.objformat(self)))509 ##if not self.name:510 if not self.name:511 outx.log_abort("Ovf Class Constructor -- No 'name' Given:\n\n -- Func Args:\n%s\n\n -- Self:\n%s" %(outx.pformat(_funcargs), outx.pformat(get_obj_dict(self))))512 pass513 outx.log_info("Ovf Class Constructor -- VM Name: \"%s\"" %(self.name))514 _funcargs['self_dict'] = get_obj_dict(self)515 outx.log_debug("OVF Class Init --\n\n -- OVF Instance -- Self:\n%s" %(outx.objformat(self)))516 outx.log_debug("Ovf Class Constructor -- Args:\n%s" %(outx.pformat(_funcargs)))517 outx.log_debug("Ovf Class Constructor -- Self:\n%s" %(outx.objformat(self)))518 ##if not getattr(self, 'sourceOVF', None):519 if not getattr(self, 'sourceovf', None):520 outx.log_abort("Ovf Class Constructor -- No 'sourceOVF' spefified")521 elif not os.path.exists(self.sourceovf):522 outx.log_abort("Ovf Class Constructor -- sourceOVF: \"%s\" not found" %(self.sourceovf))523 pass524 if not os.path.exists(self.ovftool):525 outx.log_error("Ovf Class Constructor -- Ovf Tool: \"%s\" not found" %(self.ovftool))526 pass527 outx.log_debug("Exit OVF Class Init --\n\n -- OVF Instance -- Self:\n%s" %(outx.objformat(self)))528 pass529 def getVmName(self):530 outx.log_info("getVmName -- Returning: \"%s\"" %(self.name))531 ## sleep(10)532 return(self.name)533 pass534 def getVmIp(self):535 return(self.ip)536 pass537 def getVmOvf(self):538 return(self.sourceovf)539 pass540 def deploy(self, synchronic=True, overwriteExistingVm=False, powerOnVm=True):541 if overwriteExistingVm is None:542 if hasattr(self, 'overwriteExistingVm') and (self.overwriteExistingVm is not None):543 overwriteExistingVm = self.overwriteExistingVm544 else:545 overwriteExisting = False546 overwriteExistingVm = False547 pass548 pass549 overwriteOpt = ""550 poweroffOpt = ""551 if overwriteExistingVm:552 overwriteOpt = "--overwrite"553 poweroffOpt = "--powerOffTarget"554 pass555 outx.log_info("Enter ovf.deploy()\n\n -- Self:\n%s" %(outx.pformat(get_obj_dict(self))))556 ##self.ovftool = getMatchingFile(self.ovftool, "ovftool.exe")557 self.sourceovf = getMatchingFile(self.sourceovf, ".ovf")558 outx.log_info("ovf.deploy -- sourceOVF: \"%s\"" %(self.sourceovf))559 if self.vmIsOscType:560 outx.log_info("ovf.deploy --\n\n -- Self:\n%s" %(outx.pformat(self.__dict__)))561 # start program562#######################################################################################563## 564## p = Popen([self.ovftool , "--powerOn" , "--noSSLVerify", "--acceptAllEulas", 565## "-ds=%s" % self.datastore, "-n=%s" % self.name, "--network=%s" % self.network, "--prop:sbm_ip_0=%s" % self.vmIp, 566## "--prop:sbm_netmask_0=%s" % self.netmask, "--prop:sbm_dns1_0=%s" % self.dnslist, "--prop:sbm_ntp_0=%s" % self.ntplist, 567## "--prop:sbm_gateway_0=%s" % self.gateway, "--diskMode=thin", "--prop:sbm_isSSHEnabled=%s" % self.enablessh, self.sourceovf, 568## "vi://%s:%s@%s/%s/host/%s" %(self.vcuser, self.vcpass, self.vcip, self.datacenter.replace(' ','%20'), self.cluster.replace(' ','%20'))])569##570#######################################################################################571 vm_inv_url = "vi://%s:%s@%s/%s/host/%s" %(self.vcuser, self.vcpass, self.vcip,572 self.datacenter.replace(' ','%20'),573 ##self.cluster.replace(' ','%20'),574 self.host.replace(' ','%20'),575 )576 outx.log_info("ovf.deploy -- self.vcuser: \"%s\"" %(self.vcuser))577 outx.log_info("ovf.deploy -- vm_inv_url: \"%s\"" %(vm_inv_url))578 self.vm_inv_url = vm_inv_url579 ovftool_arglist = [580 "--powerOn",581 "--noSSLVerify",582 "--hideEula",583 "--acceptAllEulas", 584 poweroffOpt,585 overwriteOpt,586 "-ds=%s" %(self.datastore),587 "-n=%s" %(self.name),588 "--network=%s" %(self.network),589 "--prop:sbm_ip_0=%s" %(self.ip),590 "--prop:sbm_netmask_0=%s" %(self.netmask),591 "--prop:sbm_dns1_0=%s" %(self.dnslist),592 "--prop:sbm_ntp_0=%s" %(self.ntplist), 593 "--prop:sbm_gateway_0=%s" %(self.gateway),594 "--diskMode=thin",595 "--prop:sbm_isSSHEnabled=%s" %(self.enablessh),596 self.sourceovf,597 vm_inv_url,598 ]599 ovftool_arglist = [ x for x in ovftool_arglist if x ]600 ##outx.log_info("ovfTool started at: %s" % currentTime())601 ovftool_exec_argv = [ self.ovftool ] + ovftool_arglist602 outx.log_info("ovf.deploy -- Ovf Tool:\"%s\"\n-- Ovftool Arglist:\n%s" %(self.ovftool, outx.pformat(ovftool_arglist)))603 outx.log_info("ovf.deploy -- ovfTool 'deploy' starting ...\n -- Ovftool Args:\n%s" %(outx.pformat(ovftool_exec_argv)))604 ##p = Popen( ovftool_exec_argv )605 else:606#######################################################################################607## 608## p = Popen([self.ovftool , "--powerOn" , "--noSSLVerify", "--acceptAllEulas", 609## "-ds=%s" % self.datastore, "-n=%s" % self.name, "--network=%s" % self.network, 610## "--diskMode=thin", self.sourceovf, 611## "vi://%s:%s@%s/%s/host/%s" %(self.vcuser, self.vcpass, self.vcip, self.datacenter.replace(' ','%20'), self.cluster.replace(' ','%20'))]) 612## outx.log_info("ovfTool started at: %s" % currentTime())613##614#######################################################################################615 vm_inv_url = "vi://%s:%s@%s/%s/host/%s" %(self.vcuser, self.vcpass, self.vcip,616 self.datacenter.replace(' ','%20'),617 ##self.cluster.replace(' ','%20'),618 self.host.replace(' ','%20'),619 )620 outx.log_info("ovf.deploy -- self.vcuser: \"%s\"" %(self.vcuser))621 outx.log_info("ovf.deploy -- vm_inv_url: \"%s\"" %(vm_inv_url))622 self.vm_inv_url = vm_inv_url623 ovftool_arglist = [624 "--powerOn",625 "--noSSLVerify",626 "--hideEula",627 "--acceptAllEulas", 628 "-ds=%s" %(self.datastore),629 "-n=%s" %(self.name),630 "--network=%s" %(self.network),631 "--diskMode=thin",632 self.sourceovf, 633 vm_inv_url,634 ]635 outx.log_info("ovf.deploy -- Ovftool Arglist:\n%s" %(outx.pformat(ovftool_arglist)))636 ##outx.log_info("ovfTool started at: %s" % currentTime())637 ovftool_exec_argv = [ self.ovftool ] + ovftool_arglist638 outx.log_info("ovf.deploy -- Ovf Tool:\"%s\"\n-- Ovftool Arglist:\n%s" %(self.ovftool, outx.pformat(ovftool_arglist)))639 outx.log_info("ovf.deploy -- ovfTool 'deploy' starting ...\n -- Ovftool Args:\n%s" %(outx.pformat(ovftool_exec_argv)))640 ##p = Popen( ovftool_exec_argv, stdout=PIPE, stderr=PIPE )641 pass642 p = Popen( ovftool_exec_argv, stdout=PIPE, stderr=PIPE )643 if synchronic:644 ##returncode = p.wait()645 ##p.wait()646 (stdout_data, stderr_data) = p.communicate()647 #stdout_str = str(stdout_data)648 stdout_str = stdout_data.decode('ascii')649 #stderr_str = str(stderr_data)650 stderr_str = stderr_data.decode('ascii')651 outx.log_info("ovf.deploy -- ovfTool 'deploy' completed\n -- Return Code: \"%s\"\n\n -- STDOUT: \"%s\"\n\n -- STDERR: \"%s\"" %(p.returncode, stdout_str, stderr_str))652 ## sleep(10)653 else :654 outx.log_info("ovf.deploy -- Exiting before waiting to ovfTool to finish deployment")655 656 outx.log_info("ovf.deploy -- ovfTool 'probe' completed -- Return Code: \"%s\"" %(p.returncode))657 return(p)658 pass659 def probe(self):660 outx.log_debug("Enter ovf.probe()\n\n -- Self:\n%s" %(outx.pformat(get_obj_dict(self))))661 ##self.ovftool = getMatchingFile(self.ovftool, "ovftool.exe")662 outx.log_debug("ovf.probe --\n\n -- Self:\n%s" %(outx.pformat(self.__dict__)))663 # start program664 vm_inv_url = "vi://%s:%s@%s/%s/host/%s" %(self.vcuser, self.vcpass, self.vcip,665 self.datacenter.replace(' ','%20'),666 ##self.cluster.replace(' ','%20'),667 self.host.replace(' ','%20'),668 )669 outx.log_debug("ovf.probe -- self.vcuser: \"%s\"" %(self.vcuser))670 outx.log_debug("ovf.probe -- vm_inv_url: \"%s\"" %(vm_inv_url))671 self.vm_inv_url = vm_inv_url672 self.vm_probe_url = (self.vm_inv_url + "/Resources/" + self.name)673 ## Power-Off VM Options: "--powerOffSource", "--powerOffTarget" ##674 ovftool_arglist = [675 "--noSSLVerify",676 "--hideEula",677 "--acceptAllEulas", 678## "--powerOffSource",679 self.vm_probe_url,680 ]681 ##outx.log_debug("ovfTool started at: %s" % currentTime())682 ovftool_exec_argv = [ self.ovftool ] + ovftool_arglist683 outx.log_debug("ovf.probe -- Ovf Tool:\"%s\"\n-- Ovftool Arglist:\n%s" %(self.ovftool, outx.pformat(ovftool_arglist)))684 outx.log_info("ovf.probe -- ovfTool 'probe' starting ...\n -- Ovftool Args:\n%s" %(outx.pformat(ovftool_exec_argv)))685 ## sleep(5)686 p = Popen( ovftool_exec_argv, stdout=PIPE, stderr=PIPE )687 ##returncode = p.wait()688 ##p.wait()689 (stdout_data, stderr_data) = p.communicate()690 #stdout_str = str(stdout_data)691 stdout_str = stdout_data.decode('ascii')692 #stderr_str = str(stderr_data)693 stderr_str = stderr_data.decode('ascii')694 rtncode = p.returncode695 outx.log_info("ovf.probe -- ovfTool 'probe' completed\n -- Return Code: \"%s\"\n\n -- STDOUT: \"%s\"\n\n -- STDERR: \"%s\"" %(rtncode, stdout_str, stderr_str))696 errmsg1 = "The attempted operation cannot be performed in the current state (Powered on)".lower()697 errmsg2 = "Locator does not refer to an object".lower()698 stdout_lower = stdout_str.lower()699 stderr_lower = stderr_str.lower()700 if rtncode == 0:701 outx.log_info("ovf.probe -- ovfTool 'probe' Returning 'True' -- VM was found on ESX/VCenter (1)")702 return(True) ## -- VM was found on ESX/VCenter703 elif (errmsg1 in stdout_lower) or (errmsg1 in stderr_lower):704 outx.log_info("ovf.probe -- ovfTool 'probe' Returning 'True' -- VM was found on ESX/VCenter (2)")705 return(True) ## -- VM was found on ESX/VCenter706 elif (errmsg2 in stdout_lower) or (errmsg2 in stderr_lower):707 outx.log_info("ovf.probe -- ovfTool 'probe' Returning 'False' -- VM was NOT found on ESX/VCenter (3)")708 return(False) ## -- VM was NOT found on ESX/VCenter709 else:710 outx.log_abort("ovf.probe -- Unexpected Output from OvfTool 'probe' for Error-Code: \"%s\" -- \n\n -- STDOUT: \"%s\"\n\n -- STDERR: \"%s\"" %(rtncode, stdout_str, stderr_str))711 pass712pass713def mainPgm():714 getMatchingFile('I:\\0.6', '.ovf')715pass716if __name__ == "__main__":717 mainPgm()718 exit()...

Full Screen

Full Screen

operations.py

Source:operations.py Github

copy

Full Screen

...30 # Все операции упорядочены по времени в обратном31 # порядке. Для каждой задачи выполняется только последняя32 # по времени операция.33 operation.success = False34 log_abort(operation, u"new pending operations present")35 else:36 seen_jobs.add(operation.job_id)37 if operation.op == u"start":38 st = try_start(operation)39 elif operation.op == u"pause":40 st = try_pause(operation)41 elif operation.op == u"abort":42 st = try_abort(operation)43 else:44 operation.success = False45 log_abort(operation, u"unknown operation")46 if st is not None:47 Session.add(st)48 Session.add(operation)49 Session.flush()50 if job.state.s != old_state:51 log.debug(u"%s: changed state to %s", job.logname(), job.state.s)52 53 heartbeat.debug("end")54 try:55 queues.operation.get(True, config["operation_loop"])56 while not queues.operation.empty():57 queues.operation.get()58 except eventlet.queue.Empty:59 pass60def trigger(environ, start_response): 61 method = environ.get('REQUEST_METHOD', '')62 if method != 'POST':63 start_response('405 Method Not Allowed', [('Content-type', 'text/plain')])64 return '405 Method Not Allowed\n'65 log.debug("got operation trigger notification")66 queues.operation.put(None)67 start_response('204 No Content', [])68 return ''69def log_abort(operation, reason):70 log.debug(u"%s: aborted operation %s: %s",71 operation.job.logname(), operation.op, reason)72def try_start(operation):73 """74 Отправить задачу из операции на запуск, если это возможно75 """76 job_state = operation.job.state.s77 if job_state in (u"new", u"paused"):78 st = operation.job.add_state(u"starting")79 queues.run.put(operation.job)80 return st81 operation.success = False82 log_abort(operation, u"job cannot be started from state %s" % job_state)83 return None84def try_pause(operation):85 """86 Отправить задачу из операции на остановку, если это возможно87 """88 job_state = operation.job.state.s89 if job_state in (u"running",):90 st = operation.job.add_state(u"pausing")91 queues.pause.put(operation.job)92 return st93 operation.success = False94 log_abort(operation, u"job cannot be paused from state %s" % job_state)95 return None96def try_abort(operation):97 """98 Отправить задачу из операции на отмену выполнения, если это возможно99 """100 job_state = operation.job.state.s101 if job_state in (u"running", u"paused"):102 st = operation.job.add_state(u"aborting")103 queues.abort.put(operation.job)104 return st105 operation.success = False106 log_abort(operation, u"job cannot be aborted from state %s" % job_state)...

Full Screen

Full Screen

SmachEx.py

Source:SmachEx.py Github

copy

Full Screen

1from smach import StateMachine2from smach_ros import SimpleActionState3from hobbit_msgs.msg import ArmServerGoal, ArmServerAction4from rospy import loginfo5# Instance of SMACH state machine6sm = StateMachine(['finished','aborted','preempted'])7with sm:8 # Definition of action goals9 goal_floor = ArmServerGoal(data='MoveToPreGraspFloor', velocity=0.0, joints=[])10 goal_table = ArmServerGoal(data='MoveToPreGraspTable', velocity=0.0, joints=[])11 goal_OpGrip = ArmServerGoal(data='OpenGripper', velocity=0.0, joints=[])12 goal_ClGrip = ArmServerGoal(data='CloseGripper', velocity=0.0, joints=[])13 # Assambly of the full state machine14 StateMachine.add('INITIAL_POS', SimpleActionState('hobbit_arm',ArmServerAction,goal=goal_OpGrip),transitions={'succeeded':'FLOOR_POS','aborted':'LOG_ABORT', 'preempted':'LOG_ABORT'})15 StateMachine.add('FLOOR_POS', SimpleActionState('hobbit_arm',ArmServerAction,goal=goal_floor),transitions={'succeeded':'CLOSE_GRIPPER','aborted':'LOG_ABORT', 'preempted':'LOG_ABORT'})16 StateMachine.add('GRIPPER_CLOSED', SimpleActionState('hobbit_arm',ArmServerAction,goal=goal_ClGrip),transitions={'succeeded':'TABLE_POS','aborted':'LOG_ABORT', 'preempted':'LOG_ABORT'})17 StateMachine.add('TABLE_POS', SimpleActionState('hobbit_arm',ArmServerAction,goal=goal_table),transitions={'succeeded':'OPEN_GRIPPER','aborted':'LOG_ABORT', 'preempted':'LOG_ABORT'})18 StateMachine.add('GRIPPER_OPEN', SimpleActionState('hobbit_arm',ArmServerAction,goal=goal_OpGrip),transitions={'succeeded':'finished','aborted':'LOG_ABORT', 'preempted':'LOG_ABORT'})...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful