Beispiel #1
0
 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 verifyCreate(goldenFilePath, currentFilePath):
     goldenStr  = Util.readFile(goldenFilePath)
     currentStr = Util.readFile(currentFilePath)
     
     goldenStr  = ResponseVerification.formalize(goldenStr)
     currentStr = ResponseVerification.formalize(currentStr)
     
     if goldenStr == currentStr:
         ResponseVerification.__logger.info('Response Verification test result: PASSED')
         return True
     else:
         ResponseVerification.__logger.info('golden:  ' + goldenStr)
         ResponseVerification.__logger.info('current: ' + currentStr)
         ResponseVerification.__logger.info('Response Verification test result: FAILED')
         return False
Beispiel #3
0
    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
Beispiel #4
0
 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 validateByFile(xsdFilePaths, xmlFilePath):
    xsdStreamSources = []
    for xsdFilePath in xsdFilePaths:
        xsdStreamSource = StreamSource(FileReader(xsdFilePath))
        xsdStreamSources.append(xsdStreamSource)
    xmlStreamSource = StreamSource(StringReader(Util.readFile(xmlFilePath)))
    return validate(xsdStreamSources, xmlStreamSource)
Beispiel #6
0
 def populateCreateDescription(self, description):
     if not description:
         try:
             self.createDescription = self.requestParams['description']
         except KeyError:
             self.createDescription = Util.getXpathValue(Util.readFile(self.requestBodyFilePath), XPath._RequestBodyDescription)
             if (self.createDescription.startswith('$')):
                 raise ValueError('request body description [' + self.createDescription + '] is not defined in file ' + self.requestBodyFilePath)
Beispiel #7
0
 def populateCreateName(self, name):
     if not name:
         try:
             self.createName = self.requestParams['name']
         except KeyError:
             self.createName = Util.getXpathValue(Util.readFile(self.requestBodyFilePath), XPath._RequestBodyName)
             if (self.createName.startswith('$')):
                 raise ValueError('request body name [' + self.createName + '] is not defined in file ' + self.requestBodyFilePath)
     self.logger.info('-----------> element object name or create name: ' + self.createName)
Beispiel #8
0
    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
Beispiel #9
0
 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
Beispiel #10
0
 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
Beispiel #11
0
 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
Beispiel #12
0
 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
Beispiel #13
0
 def updateByTemplate(self, objectClassName, updateRequestBodyParams, category, testCaseId):
     
     NsmUtil.printHeadLine2('update by template test case ' + testCaseId)
     
     self.updateUrl = self.uid + '/put'
     paramKeys = updateRequestBodyParams.keys()
     
     # priority: updateRequestBodyParams, update-tenant-all.xml
     requestBodyFileName = None
     if 'request.body.file' in paramKeys:
         requestBodyFileName = updateRequestBodyParams['request.body.file']
     requestBodyFilePath = Define._PathReqeustBodyUpdate + '/' + objectClassName + '/' + requestBodyFileName
     requestBody = Util.readFile(requestBodyFilePath)
     
     # priority: built-in request body file, updateRequestBodyParams, self.createName
     name = self.createName + ' Update ' + category + ' ' + str(testCaseId) 
     if 'name' in paramKeys:
         name = updateRequestBodyParams['name']
         
     description = self.createDescription.replace('Default', 'Default Update')
     if 'description' in paramKeys:
         description = updateRequestBodyParams['description']
             
     requestBody = requestBody.replace('${uid}', self.uid)
     requestBody = requestBody.replace('${name}', name)
     requestBody = requestBody.replace('${description}', description)
     for key, value in updateRequestBodyParams.items():
         if key == 'uid':
             for uidKey, uidValue in value.items():
                 keyStr = '${' + uidKey + '}'
                 main_module = __import__("__main__")
                 varObj = getattr(main_module, uidValue)
                 requestBody = requestBody.replace(keyStr, varObj.uid)                 
         else:   
             keyStr = '${' + key + '}'
             requestBody = requestBody.replace(keyStr, value)
     self.update(objectClassName, requestBody, category, testCaseId)
Beispiel #14
0
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)
        
        
        
Beispiel #15
0
from isp.layer3PrivateAccessVlan import Layer3PrivateAccessVlan
from isp.privateMplsConnection import PrivateMplsConnection
from isp.securedPrivateEdgeZone import SecuredPrivateEdgeZone
from isp.ipAddressPool import IpAddressPool
from isp.ipReservation import IpReservation
from isp.loadBalancerService import LoadBalancerService
from isp.dynamicPatService import DynamicPatService
from isp.staticNatService import StaticNatService
from isp.staticNatPortRedirectionService import StaticNatPortRedirectionService

if __name__ == '__main__':
 
    logger = Util.getLogger(__file__)
    
    fakeCatalogXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><root/>'
    content = Util.readFile(Define._PathUidDefault)
    lineList = content.split("\n")
    #print lineList
    for line in reversed(lineList):
        if line:
            items = line.split(';')
            print items
            objectUid   = items[0]
            objectClass = items[1]
            objectName  = items[2]
            ### will do these three afterwards
            if objectClass != 'Top' and objectClass != 'Provider' and objectClass != 'Pod':
                myObject = eval(objectClass)(fakeCatalogXml, objectName, None, None, None)
                myObject.setUid(objectUid)
                myObject.setOnLine()
                result = myObject.delete('888')
Beispiel #16
0
'''


from lib import HttpUtil, Util
from isp import Define, XPath
from isp.nsmUtil import NsmUtil
from pprint import pprint
from isp.responseVerification import ResponseVerification

import simplexml


if __name__ == '__main__':
    
    person = {'person':{'name':'joaquim','age':15,'cars':[{'id':1},{'id':2}]}}
    print simplexml.dumps(person)
    
    person = simplexml.loads('<?xml version="1.0" ?><person><cars><car><id>1</id></car><car><id>2</id></car></cars><age>15</age><name>joaquim</name></person>')
    print person['person']['name']
    print person
    
    filePath = '/Users/huhe/Install/workspace/NSM-NBAPI-Jython/response/create/response-create-default/My-Default-Internet-Edge-Zone-Layer-3-VLAN-create-001.xml'
    result = simplexml.loads(Util.readFile(filePath))
    print result
    
    print result['task']['result']['name']
    
    print result['task']['result']['properties']