本文整理汇总了Python中isp.nsmUtil.NsmUtil类的典型用法代码示例。如果您正苦于以下问题:Python NsmUtil类的具体用法?Python NsmUtil怎么用?Python NsmUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NsmUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: processCmdList
def processCmdList(self, cmdList):
status = True
for oneCmdSet in cmdList:
cmdStr = oneCmdSet['cmd']
expectPattern = oneCmdSet['expect'] if 'expect' in oneCmdSet.keys() else None
sleep = oneCmdSet['sleep'] if 'sleep' in oneCmdSet.keys() else None
self._expect.sendIt(cmdStr)
'''
if sleep:
self._logger.info('sleep: ' + sleep + ' seconds ...')
time.sleep(int(sleep))
'''
if sleep:
self._expect.setDefaultTimeout(int(sleep)*1000)
self._logger.info('timeout is set to ' + sleep + ' seconds')
if expectPattern:
self._expect.expectIt(expectPattern)
self._output = self._expect._output
if re.search(expectPattern, self._output):
NsmUtil.printStatusHeadLine('Passed: pattern found: ' + expectPattern)
else:
NsmUtil.printStatusHeadLine('Failed: pattern not found: ' + expectPattern)
status = False
else:
self._expect.expectAll()
if sleep: self._expect.setDefaultTimeout(30*1000)
return status
示例2: getDetail
def getDetail(self, testCaseId):
NsmUtil.printHeadLine2('START: get detail test case ' + testCaseId)
nameDash = self.createName.replace(' ', '-')
debugDetailFilePath = Define._PathResponseCreateDefault + '/' + nameDash + '-detail-' + testCaseId + '.xml'
if (self.isOffLine):
self.logger.debug('get detail from file: ' + debugDetailFilePath)
self.detailXml = Util.readFile(debugDetailFilePath)
else:
try:
self.getDetailUrl = Util.getXpathValue(self.createTaskXml, XPath._TaskElementUid)
except:
self.getDetailUrl = self.uid
self.logger.info('get detail url: ' + self.getDetailUrl)
self.detailXml = HttpUtil.doGet(self.getDetailUrl, Define._credential) if self.getDetailUrl and self.getDetailUrl != '' else None
if self.detailXml:
self.logger.debug('write detail to file: ' + debugDetailFilePath)
Util.writeFile(debugDetailFilePath, self.detailXml)
if self.detailXml:
self.uid = Util.getXpathValue(self.detailXml, XPath._DetailUid)
self.logger.info('uid for ' + self.createName + ': ' + self.uid)
self.getCatalogUrl = Util.getXpathValue(self.detailXml, XPath._DetailLinkCatalog)
Element._uidList.append([self.uid, self.mySubClassName, self.createName])
NsmUtil.printHeadLine2('END: get detail test case ' + testCaseId)
return self.detailXml
示例3: delete
def delete(self, testCaseId):
NsmUtil.printHeadLine2('START: delete test case ' + testCaseId)
self.deleteUrl = self.uid + '/delete'
nameDash = self.createName.replace(' ', '-')
debugDeleteFilePath = Define._PathResponseDelete + '/' + nameDash + '-delete-' + testCaseId + '.xml'
self.logger.info('delete url: ' + self.deleteUrl)
status = None
if (self.isOffLine):
self.logger.debug('get delete task from file: ' + debugDeleteFilePath)
self.deleteTaskXml = Util.readFile(debugDeleteFilePath)
myTask = Task(self.deleteTaskXml)
status = myTask.checkResult()
self.deleteTaskXml = myTask.taskXml
else:
self.deleteTaskXml = HttpUtil.doPost(self.deleteUrl, Define._credential)
self.logger.debug('write pending delete task to file: ' + debugDeleteFilePath + '-pending.xml')
Util.writeFile(debugDeleteFilePath+'-pending.xml', self.deleteTaskXml)
myTask = Task(self.deleteTaskXml)
status = myTask.checkResult()
self.deleteTaskXml = myTask.taskXml
self.logger.info('write to file ' + debugDeleteFilePath)
#self.logger.info(self.deleteTaskXml)
Util.writeFile(debugDeleteFilePath, self.deleteTaskXml)
NsmUtil.printHeadLine2('END: delete test case ' + testCaseId)
return status
示例4: create
def create(self, testCaseId):
NsmUtil.printHeadLine2('START: create test case ' + testCaseId)
Element.populateCreateParameter(self)
requestBody = Util.readFile(self.requestBodyFilePath)
requestBody = requestBody.replace('${uid}', self.createUid)
requestBody = requestBody.replace('${name}', self.createName)
requestBody = requestBody.replace('${description}', self.createDescription)
for key, value in self.requestParams.items():
keyStr = '${' + key + '}'
requestBody = requestBody.replace(keyStr, value)
self.logger.info('create request: ' + self.catalogCreateUrl)
# pod creation request body is too huge, skip it
if self.mySubClassName != 'Pod':
self.logger.info('request body: ' + "\n\n" + requestBody +"\n")
nameDash = self.createName.replace(' ', '-')
debugCreateFilePath = Define._PathResponseCreateDefault + '/' + nameDash + '-create-' + testCaseId + '.xml'
status = None
if (self.isOffLine):
timeStart = datetime.now()
self.logger.debug('get create task from file: ' + debugCreateFilePath)
self.createTaskXml = Util.readFile(debugCreateFilePath)
myTask = Task(self.createTaskXml)
status = myTask.checkResult()
self.createTaskXml = myTask.taskXml
if Define._Performance and Define._CurrentPerfAction:
timeEnd = datetime.now()
Define._PerformanceData.setCurrentTenantClassLog(Define._CurrentPerfClassName, Define._CurrentPerfObjectName, Define._CurrentPerfAction, timeStart, timeEnd)
else:
timeStart = datetime.now()
self.createTaskXml = HttpUtil.doPost(self.catalogCreateUrl, Define._credential, requestBody)
self.logger.debug('write pending create task to file: ' + debugCreateFilePath + '-pending.xml')
Util.writeFile(debugCreateFilePath+'-pending.xml', self.createTaskXml)
myTask = Task(self.createTaskXml)
status = myTask.checkResult()
self.createTaskXml = myTask.taskXml
if Define._Performance and Define._CurrentPerfAction:
timeEnd = datetime.now()
Define._PerformanceData.setCurrentTenantClassLog(Define._CurrentPerfClassName, Define._CurrentPerfObjectName, Define._CurrentPerfAction, timeStart, timeEnd)
self.logger.info('write final create task to file ' + debugCreateFilePath)
#self.logger.info(self.createTaskXml)
Util.writeFile(debugCreateFilePath, self.createTaskXml)
NsmUtil.printHeadLine2('END: create test case ' + testCaseId)
return status
示例5: reset
def reset(self):
evalMap = {
'${tftp-server-host}': DeviceDefine._TFTPHost,
}
resetCmdList = self._cmdMap['reset']
resetCmdList = DeviceElement.evaluate(resetCmdList, evalMap)
NsmUtil.printHeadLine2('reset device to base line config')
return self.processCmdList(resetCmdList)
示例6: copy
def copy(self):
evalMap = {
'${tftp-server-host}': DeviceDefine._TFTPHost,
'${host-name}': self._host,
}
copyCmdList = self._cmdMap['copy']
copyCmdList = DeviceElement.evaluate(copyCmdList, evalMap)
NsmUtil.printHeadLine2('copy running config to tftp server')
return self.processCmdList(copyCmdList)
示例7: getReservations
def getReservations(self, testCaseId):
NsmUtil.printHeadLine2('START: get ip reservation test case ' + str(testCaseId))
allocatedUrl = self.relLinkDictionary['nsmr:ipreservations']
responseFileName = self.createName + '-reservations-' + testCaseId + '.xml'
responseFilePath = Define._PathResponseCreateDefault + '/' + responseFileName
responseFilePath = responseFilePath.replace(' ', '-')
responseXml = Element.getRequest(self, allocatedUrl, responseFilePath)
NsmUtil.printHeadLine2('END: get ip reservation test case ' + str(testCaseId))
return responseXml
示例8: start2
def start2():
test = TestSimple()
test.start()
NsmUtil.saveUid(test._uidList)
NsmUtil.saveResult(test._resultList)
NsmUtil.printHeadLine2('total test case: ' + str(test._totalTestCase))
NsmUtil.printHeadLine1('test completed')
示例9: verifyCreate
def verifyCreate(self):
if self.mySubClassName != 'Pod' and self.isOffLine and self.createTaskXml: self.logger.info(Util.prettfyXmlByString(self.createTaskXml))
NsmUtil.printHeadLine2('START: create response verification: parameters from request body')
status = True
for key, value in self.requestParams.items():
keyItems = key.split('.')
pattern = None
if key.endswith('.ipv4.start'):
pattern = '<ipv4Start>' + value + '</ipv4Start>'
elif key.endswith('.ipv4.end'):
pattern = '<ipv4End>' + value + '</ipv4End>'
elif key.endswith('.ipv4') or key.endswith('.mask') or key.endswith('.protocol') or key.endswith('.start') or key.endswith('.end') or key.endswith('.ASNumber') or key.endswith('.uid') or key == 'name' or key == 'description':
pattern = '<' + keyItems[-1] + '>' + value + '</' + keyItems[-1] + '>'
elif key.endswith('.netmask'):
pattern = '<integer>' + value + '</integer>'
elif key.startswith('serverfarm.probe.') or key == 'lb.algorithm':
pattern = '<string>' + value + '</string>'
elif key.endswith('redirect.port'):
pattern = '<redirectPort>' + value + '</redirectPort>'
if pattern:
if self.createTaskXml.find(pattern) < 0:
status = False
NsmUtil.printStatusHeadLine2('Failed: pattern not found: ' + pattern)
else:
NsmUtil.printStatusHeadLine2('Passed: pattern found: ' + pattern)
NsmUtil.printHeadLine2('END: create response verification: parameters from request body')
return status
示例10: testIpAddressPool
def testIpAddressPool(self, provider, poolType, online):
NsmUtil.printHeadLine2('IpAddressPool' + ' [' + poolType + '] - ' + 'detail' + ' - ' + 'positive' + ' - test case ' + str(1))
self._totalTestCase += 1
ipAddressPoolUid = None
if poolType == 'Global': ipAddressPoolUid = provider.getGlobalIpAddressPoolUid()
else: ipAddressPoolUid = provider.getInfrastructureIpAddressPoolUid()
ipAddressPool = IpAddressPool(ipAddressPoolUid, 'Provider', poolType)
if not online: ipAddressPool.setOffLine()
ipAddressPoolDetail = ipAddressPool.getDetail()
assert ipAddressPoolDetail
result = NsmUtil.printResult(ipAddressPoolDetail, 'positive')
self._resultList.append(['IpAddressPool', poolType, 'detail', 'positive', str(1), str(result)])
return ipAddressPool
示例11: reserveIpAddress
def reserveIpAddress(self, internetEdgeZoneLayer3Vlan, parentName, count, reservationIndex, online):
name = 'My Default IP Address Pool of ' + parentName + ' ' + str(reservationIndex)
myInternetZoneL3VlanSubPoolUid = internetEdgeZoneLayer3Vlan.getSubPoolUid()
myInternetZoneL3VlanSubPool = IpAddressPool(myInternetZoneL3VlanSubPoolUid, name, parentName, 'SubPool')
if online: myInternetZoneL3VlanSubPool.setOnLine()
elif not online: myInternetZoneL3VlanSubPool.setOffLine()
myInternetZoneL3VlanSubPoolDetail = myInternetZoneL3VlanSubPool.getDetail('101')
name = 'My Default IP Address Reservation of ' + parentName + ' ' + str(reservationIndex)
owner = name + ' owner'
description = TestSimple.__descriptionPrefix + name
requestParams = {
'owner': owner,
'count': str(count),
}
myInternetZoneIpReservationCount = IpReservation(myInternetZoneL3VlanSubPoolDetail, name, description, 'default-ip-reservation-count.xml', requestParams)
if online: myInternetZoneIpReservationCount.setOnLine()
elif not online: myInternetZoneIpReservationCount.setOffLine()
myInternetZoneIpReservationCount.create('011')
myInternetZoneIpReservationCount.getDetail('111')
reservationXml = myInternetZoneIpReservationCount.getReservations('111')
return NsmUtil.getIpAddressListByReservation(reservationXml, count)
示例12: update
def update(self, objectClassName, requestBody, category, testCaseId):
NsmUtil.printHeadLine2('START: update test case ' + str(testCaseId))
self.updateUrl = self.uid + '/put'
self.logger.info('update request url: ' + self.updateUrl)
if self.mySubClassName != 'Pod':
self.logger.info('request body: ' + "\n\n" + requestBody +"\n")
else:
podRequestFilePath = Define._PathLog + '/pod-request-body.xml'
Util.writeFile(podRequestFilePath, requestBody)
name = self.createName + ' Update ' + category + ' ' + str(testCaseId)
nameDash = name.replace(' ', '-')
debugUpdateClassPath = Define._PathResponseUpdate + '/' + objectClassName
Util.mkdir(debugUpdateClassPath)
debugUpdateFilePath = debugUpdateClassPath + '/' + nameDash + '.xml'
status = None
if (self.isOffLine):
self.logger.debug('get update task from file: ' + debugUpdateFilePath)
self.updateTaskXml = Util.readFile(debugUpdateFilePath)
myTask = Task(self.updateTaskXml)
status = myTask.checkResult()
self.updateTaskXml = myTask.taskXml
else:
self.updateTaskXml = HttpUtil.doPost(self.updateUrl, Define._credential, requestBody)
if not self.updateTaskXml:
return False
self.logger.debug('write pending update task to file: ' + debugUpdateFilePath + '-pending.xml')
Util.writeFile(debugUpdateFilePath+'-pending.xml', self.updateTaskXml)
myTask = Task(self.updateTaskXml)
status = myTask.checkResult()
self.updateTaskXml = myTask.taskXml
self.logger.info('write final update task to file ' + debugUpdateFilePath)
#self.logger.info(self.updateTaskXml)
Util.writeFile(debugUpdateFilePath, self.updateTaskXml)
NsmUtil.printHeadLine2('END: update test case ' + str(testCaseId))
return status
示例13: verifyUpdate
def verifyUpdate(self, updateVerificationPatternList, storage):
NsmUtil.printHeadLine2('START: update response verification')
vrfDeviceName1 = 'l3.aggregation.switch.1.mgmt.addr'
vrfDeviceName2 = 'l3.aggregation.switch.2.mgmt.addr'
vrfDeviceIP1 = self.pod.getParameterStringValueByName(vrfDeviceName1)
vrfDeviceIP2 = self.pod.getParameterStringValueByName(vrfDeviceName2)
param1 = '<ipv4>' + vrfDeviceIP1 + '</ipv4>'
param2 = '<ipv4>' + vrfDeviceIP2 + '</ipv4>'
params = [param1, param2]
status = Element.verifyParamemtersExist(self, params, self.updateTaskXml)
NsmUtil.printHeadLine2('END: update response verification')
if status:
return True
else:
return False
示例14: testUpdateVerification
def testUpdateVerification(self, result, thisObject, pod, updateVerificationPatternList, className, name, category, testCaseId,storage):
if result and Define._Verfiy and Define._VerifyUpdate:
thisObject.setPod(pod)
result = thisObject.verifyUpdate(updateVerificationPatternList, storage)
result = NsmUtil.printResult(result, category)
self._resultList.append([className, name, 'update-verify', category, str(testCaseId), str(result)])
return result
else:
return None
示例15: getCatalog
def getCatalog(self, testCaseId='000'):
NsmUtil.printHeadLine2('START: get catalog test case ' + testCaseId)
self.logger.debug('get catalog request: ' + self.getCatalogUrl)
nameDash = self.createName.replace(' ', '-')
debugCatalogFilePath = Define._PathResponseCreateDefault + '/' + nameDash + '-catalog-' + testCaseId + '.xml'
if (self.isOffLine):
self.logger.debug('get catalog from file: ' + debugCatalogFilePath)
self.catalogXml = Util.readFile(debugCatalogFilePath)
else:
self.catalogXml = HttpUtil.doGet(self.getCatalogUrl, Define._credential) if self.getCatalogUrl and self.getCatalogUrl != '' else None
if self.catalogXml:
self.logger.debug('catalog output file: ' + debugCatalogFilePath)
Util.writeFile(debugCatalogFilePath, self.catalogXml)
NsmUtil.printHeadLine2('END: get catalog test case ' + testCaseId)
return self.catalogXml