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
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
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
def saveUid(uidList): line = '' NsmUtil.__logger.debug('') for pair in uidList: objectUid = pair[0] objectClass = pair[1] objectName = pair[2] NsmUtil.__logger.debug('uid: ' + objectUid + ' ------> ' + objectClass + ' [' + objectName + ']') line += objectUid + ';' + objectClass + ';' + objectName + "\n" Util.writeFile(Define._PathUidDefault, line) NsmUtil.__logger.debug('')
def getList(self, getUrl, listClassName, testCaseId): NsmUtil.printHeadLine2('START: get ' + listClassName + ' list test case ' + testCaseId) nameDash = self.createName.replace(' ', '-') debugDetailFilePath = Define._PathResponseCreateDefault + '/' + nameDash + '-' + listClassName + '-list-' + testCaseId + '.xml' getResponseXml = None self.logger.info('get list url: ' + getUrl) if (self.isOffLine): self.logger.debug('get ' + listClassName + ' list response from file: ' + debugDetailFilePath) getResponseXml = Util.readFile(debugDetailFilePath) else: getResponseXml = HttpUtil.doGet(getUrl, Define._credential) self.logger.debug('write ' + listClassName + ' list response to file: ' + debugDetailFilePath) Util.writeFile(debugDetailFilePath, getResponseXml) NsmUtil.printHeadLine2('END: get ' + listClassName + ' list test case ' + testCaseId) return getResponseXml
def getRequest(self, getUrl, debugDetailFilePath): getResponseXml = None self.logger.info('get request url: ' + getUrl) if (self.isOffLine): self.logger.debug('get response from file: ' + debugDetailFilePath) getResponseXml = Util.readFile(debugDetailFilePath) else: getResponseXml = HttpUtil.doGet(getUrl, Define._credential) self.logger.debug('write response to file: ' + debugDetailFilePath) Util.writeFile(debugDetailFilePath, getResponseXml) ''' uid = Util.getXpathValue(getResponseXml, XPath._DetailUid) self.logger.info('uid: ' + uid) getCatalogUrl = Util.getXpathValue(getResponseXml, XPath._DetailLinkCatalog) return getCatalogUrl ''' return getResponseXml
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
def getDetail(self, testCaseId): NsmUtil.printHeadLine2('START: get detail test case ' + testCaseId) fileName = 'My Default IP Address Pool ' + self.parentName + ' ' + self.category nameDash = fileName.replace(' ', '-') debugGatalogFilePath = Define._PathResponseCreateDefault + '/' + nameDash + '-detail-' + testCaseId + '.xml' if (self.isOffLine): self.logger.debug('get detail from file: ' + debugGatalogFilePath) self.catalogXml = Util.readFile(debugGatalogFilePath) else: self.catalogXml = HttpUtil.doGet(self.ipAddressPoolUid, Define._credential) self.logger.debug('write detail to file: ' + debugGatalogFilePath) Util.writeFile(debugGatalogFilePath, self.catalogXml) self.parseCatalog() NsmUtil.printHeadLine2('END: get detail test case ' + testCaseId) return self.catalogXml
def saveResult(resultList): index = 0 passedTotal = 0 failedTotal = 0 skippedTotal = 0 line = '' lineHtml = '<table border="0" cellspacing="0" cellpadding="2" style="font-size:14px">' lineHtml += '<tr><th align="left" width="210">API</th><th align="left" width="100">CRUD</th><th align="left" width="100">Result</th></tr>' NsmUtil.__logger.info('') for oneResult in resultList: index += 1 oneLine = ' - '.join(oneResult) NsmUtil.__logger.info(str(index) + ' - ' + oneLine) line += oneLine + "\n" resultHtml = None if oneResult[-1] == 'True': passedTotal += 1 resultHtml = '<font color="green">Passed</font>' elif oneResult[-1] == 'skipped': skippedTotal += 1 resultHtml = '<font color="red">Failed</font>' elif oneResult[-1] == 'False': failedTotal += 1 resultHtml = 'Skipped' lineHtml += '<tr>' lineHtml += '<td>' + oneResult[0] + '</td><td>' + oneResult[2] + '</td><td>' + resultHtml + '</td>' lineHtml += '</tr>' Util.writeFile(Define._PathResultDefault, line) NsmUtil.__logger.info('') NsmUtil.printHeadLine2(str(passedTotal) + ' test cases passed, ' + str(failedTotal) + ' test cases failed, ' + str(skippedTotal) + ' test cases skipped') lineHtml += '</table>' Util.writeFile(Define._PathResultDefault+'.html', lineHtml)
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
'traffic.src.filter.1.uid': myPrivateExternalNetwork.uid, 'traffic.dst.filter.1.uid': mySecuredPrivateZoneL3Vlan.uid, 'fw.service.1.protocol': 'tcp', 'fw.service.1.port.start': '80', 'fw.service.1.port.end': '80', } myFirewallService4 = FirewallService(myTenantCatalogXml, name, description) myFirewallService4.setRequestBodyParams(requestParams) myFirewallService4.setOffLine() myFirewallService4.create('001') myFirewallServiceDetailXml4 = myFirewallService4.getDetail('101') FirewallServiceCatalogXml4 = myFirewallService4.getCatalog('201') logger.info('') line = '' for pair in Element._uidList: objectUid = pair[0] objectClass = pair[1] objectName = pair[2] logger.debug('uid: ' + objectUid + ' for class ' + objectClass + " and object " + objectName) line += objectUid + ';' + objectClass + ';' + objectName + "\n" Util.writeFile(Define._PathUidDefault, line) logger.info('') logger.info('================= creation complete successfully ==================') logger.info('')
from java.io import FileReader from lib import Util, HttpUtil from lib import XmlSchemaValidator from isp import Define from isp.nsmUtil import NsmUtil if __name__ == '__main__': #skippedXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><serviceOfferings xmlns="http://www.cisco.com/NetworkServicesManager/1.1" xmlns:ns2="http://www.w3.org/2005/Atom"/>' if False: xsdString1 = HttpUtil.doGet(Define._UrlSchemaNSM, Define._credential) Util.writeFile(Define._PathSchemaNsm, xsdString1) xsdString2 = HttpUtil.doGet(Define._UrlSchemaAtom, Define._credential) Util.writeFile(Define._PathSchemaAtom, xsdString2) xsdString3 = HttpUtil.doGet(Define._UrlSchemaNameSpace, Define._credential) Util.writeFile(Define._PathSchemaNameSpace, xsdString3) xdsFilePaths = [Define._PathSchemaNsm, Define._PathSchemaAtom, Define._PathSchemaNameSpace] files = Util.getAllFiles(Define._PathResponse, '*.xml') for file in files: print '\n' print file xmlString = Util.readFile(file) XmlSchemaValidator.validateByFile(xdsFilePaths, file)
index = 0 newLines = '' for line in lineList: if line: index += 1 if index == inputIndex: items = line.split(';') objectUid = items[0] objectClass = items[1] objectName = '[' + items[2] + ']' print (str(index) + ': \t' + objectClass.ljust(28, ' ') + objectName.ljust(80, ' ') + objectUid) inputYes = raw_input('\npress y to confirm ... ') if inputYes == 'y' or inputYes == 'Y': myObject = eval(objectClass)(fakeCatalogXml, objectName, None, None, None) myObject.setUid(objectUid) myObject.setOnLine() result = myObject.delete('999') if result: lineList.remove(line) logger.info('-------------------> Delete Result: PASSED') else: logger.info('-------------------> Delete Result: FAILED') break else: print 'input is not confirmed, skip ...' newLines += line + '\n' Util.writeFile(Define._PathUidDefault, newLines)
NsmUtil.mkPresetDir() jsonFileName = Define._SetupJsonFileName logger = Util.getLogger(__file__) Define._PathRequestBodyCreateDefault = Define._PathRequestBodyCreateSetup Define._PathResponseCreateDefault = Define._PathResponseCreateSetup Define._PathUidDefault = Define._PathUidSetup json_data = open(Define._SetupJsonFileName) logger.debug('json setup file name: ' + jsonFileName) data = json.load(json_data) ### pprint(data) json_data.close() requestBodyParameter = None uidDictionary = {} setup('Top', data['Top'], requestBodyParameter, uidDictionary) line = '' for objectName, uid in uidDictionary.items(): line += uid + ';' + objectName + '\n' logger.debug('\n\n' + line) Util.writeFile(Define._PathUidSetup, line) print '\n\n================== setup completed ====================\n'