X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=test%2Ftools%2Fodl-mdsal-clustering-tests%2Fclustering-functional-test%2Fcrud.py;fp=test%2Ftools%2Fodl-mdsal-clustering-tests%2Fclustering-functional-test%2Fcrud.py;h=84baac7fadef3ed2ee89b1247fc706df150858ad;hb=4fb2fbc9331a59cee6e9d0c5d7da88045eaec5df;hp=08f0d421ab54521cb6c406cf1053923bd3e34543;hpb=8f11e2fa8f466cd642484f232fa751028fc69890;p=integration%2Ftest.git diff --git a/test/tools/odl-mdsal-clustering-tests/clustering-functional-test/crud.py b/test/tools/odl-mdsal-clustering-tests/clustering-functional-test/crud.py index 08f0d421ab..84baac7fad 100644 --- a/test/tools/odl-mdsal-clustering-tests/clustering-functional-test/crud.py +++ b/test/tools/odl-mdsal-clustering-tests/clustering-functional-test/crud.py @@ -7,22 +7,18 @@ import util import settings -# -#Creates the specified number of cars based on Cars yang model -# using RESTCONF -# - def addCar(numberOfCars): - + """Creates the specified number of cars based on Cars yang model using RESTCONF""" for x in range(1, numberOfCars+1): strId = str(x) - payload = settings.add_car_payload_template.substitute(id=strId,category="category"+strId,model="model"+strId, - manufacturer="manufacturer"+strId, - year=(2000+x%100)) + payload = settings.add_car_payload_template.substitute( + id=strId, category="category" + strId, model="model" + strId, + manufacturer="manufacturer" + strId, + year=(2000 + x % 100)) print("payload formed after template substitution=") print(payload) # Send the POST request - resp = util.post(settings.getAddCarUrl(),"admin", "admin",payload) + resp = util.post(settings.getAddCarUrl(), "admin", "admin", payload) print("the response of the POST to add car=") print(resp) @@ -30,25 +26,25 @@ def addCar(numberOfCars): print("getting the cars in store ") resp = getCars(0) - #TBD: Detailed validation + # TBD: Detailed validation -# -#Creates the specified number of persons based on People yang model -# using main RPC -# -# To enable RPC a non-user input person entry is created with personId=user0 -# -# def addPerson(numberOfPersons): - #FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF - if(numberOfPersons==0): - strId =str(numberOfPersons) - payload = settings.add_person_payload_template.substitute(personId="user"+strId,gender="unknown",age=0, - address=strId + "Way, Some Country, Some Zip "+strId, - contactNo= "some number"+strId) + """Creates the specified number of persons based on People yang model using main RPC + + + To enable RPC a non-user input person entry is created with personId=user0 + + """ + # FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF + if numberOfPersons == 0: + strId = str(numberOfPersons) + payload = settings.add_person_payload_template.substitute( + personId="user" + strId, gender="unknown", age=0, + address=strId + "Way, Some Country, Some Zip " + strId, + contactNo="some number" + strId) # Send the POST request using RESTCONF - resp = util.nonprintpost(settings.getAddPersonUrl(),"admin", "admin",payload) + resp = util.nonprintpost(settings.getAddPersonUrl(), "admin", "admin", payload) return genderToggle = "Male" @@ -60,11 +56,12 @@ def addPerson(numberOfPersons): strId = str(x) - payload = settings.add_person_rpc_payload_template.substitute(personId="user"+strId,gender=genderToggle,age=(20+x%100), - address=strId + "Way, Some Country, Some Zip "+str(x%1000), - contactNo= "some number"+strId) + payload = settings.add_person_rpc_payload_template.substitute( + personId="user" + strId, gender=genderToggle, age=(20 + x % 100), + address=strId + "Way, Some Country, Some Zip " + str(x % 1000), + contactNo="some number" + strId) # Send the POST request using RPC - resp = util.post(settings.getAddPersonRpcUrl(),"admin", "admin",payload) + resp = util.post(settings.getAddPersonRpcUrl(), "admin", "admin", payload) print("payload formed after template substitution=") print(payload) @@ -72,33 +69,36 @@ def addPerson(numberOfPersons): print(resp) print("getting the persons for verification") - resp=getPersons(0) + resp = getPersons(0) - #TBD: Detailed validation + # TBD: Detailed validation -#This method is not exposed via commands as only getCarPersons is of interest -#addCarPerson entry happens when buyCar is called -# -# To enable RPC a non-user input car-person entry is created with personId=user0 -# -# -def addCarPerson(numberOfCarPersons): - #FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF - if(numberOfCarPersons==0): - payload = settings.add_car_person_template.substitute(Id=str(numberOfCarPersons),personId="user"+str(numberOfCarPersons)) +def addCarPerson(numberOfCarPersons): + """This method is not exposed via commands as only getCarPersons is of interest + + addCarPerson entry happens when buyCar is called + + + To enable RPC a non-user input car-person entry is created with personId=user0 + + """ + # FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF + if numberOfCarPersons == 0: + payload = settings.add_car_person_template.substitute( + Id=str(numberOfCarPersons), personId="user" + str(numberOfCarPersons)) # Send the POST request REST CONF - resp = util.nonprintpost(settings.getAddCarPersonUrl(),"admin", "admin",payload) + resp = util.nonprintpost(settings.getAddCarPersonUrl(), "admin", "admin", payload) return - for x in range(1, numberOfCarPersons+1): + for x in range(1, numberOfCarPersons + 1): strId = str(x) - payload = settings.add_car_person_template.substitute(Id=strId,personId="user"+strId) + payload = settings.add_car_person_template.substitute(Id=strId, personId="user" + strId) # Send the POST request REST CONF - resp = util.post(settings.getAddCarPersonUrl(),"admin", "admin",payload) + resp = util.post(settings.getAddCarPersonUrl(), "admin", "admin", payload) print("payload formed after template substitution=") print(payload) @@ -107,26 +107,26 @@ def addCarPerson(numberOfCarPersons): print(resp) print("getting the car_persons for verification") - resp=getCarPersonMappings(0) + resp = getCarPersonMappings(0) - #TBD detailed validation + # TBD detailed validation -# -# Invokes an RPC REST call that does a car purchase by a person id -# -# It is expected that the Car and Person entries are already created -# before invoking this method -# -# def buyCar(numberOfCarBuyers): - for x in range(1, numberOfCarBuyers+1): + """Invokes an RPC REST call that does a car purchase by a person id + + + It is expected that the Car and Person entries are already created + before invoking this method + + """ + for x in range(1, numberOfCarBuyers + 1): strId = str(x) - payload = settings.buy_car_rpc_template.substitute(personId="user"+strId,carId=strId) + payload = settings.buy_car_rpc_template.substitute(personId="user" + strId, carId=strId) # Send the POST request using RPC - resp = util.post(settings.getBuyCarRpcUrl(),"admin", "admin",payload) + resp = util.post(settings.getBuyCarRpcUrl(), "admin", "admin", payload) print("payload formed after template substitution=") print(payload) @@ -135,63 +135,55 @@ def buyCar(numberOfCarBuyers): print(resp) print("getting the car_persons for verification") - resp=getCarPersonMappings(0) + resp = getCarPersonMappings(0) -# -# Uses the GET on car:cars resource -# to get all cars in the store using RESTCONF -# -# def getCars(ignore): - resp = util.get(settings.getCarsUrl(),"admin", "admin") - print (resp) + """Uses the GET on car:cars resource to get all cars in the store using RESTCONF""" + resp = util.get(settings.getCarsUrl(), "admin", "admin") + print(resp) return resp -# -# Uses the GET on people:people resource -# to get all persons in the store using RESTCONF -# -#This also returns the dummy entry created for routed RPC -# with personId being user0 -# -# -# + def getPersons(ignore): - resp = util.get(settings.getPersonsUrl(),"admin","admin") - print (resp) + """Uses the GET on people:people resource to get all persons in the store using RESTCONF + + + This also returns the dummy entry created for routed RPC + with personId being user0 + + """ + resp = util.get(settings.getPersonsUrl(), "admin", "admin") + print(resp) return resp -# -# Uses the GET on car-people:car-people resource -# to get all car-persons entry in the store using RESTCONF -# -#This also returns the dummy entry created for routed RPC -# with personId being user0 -# -# + def getCarPersonMappings(ignore): - resp = util.get(settings.getCarPersonUrl(),"admin","admin") - print (resp) + """Uses the GET on car-people:car-people resource to get all car-persons entry in the store using RESTCONF + + + This also returns the dummy entry created for routed RPC + with personId being user0 + + """ + resp = util.get(settings.getCarPersonUrl(), "admin", "admin") + print(resp) return resp -# -#delete all cars in the store using RESTCONF -# -# + def deleteAllCars(ignore): - util.delete(settings.getCarsUrl(),"admin","admin") + """delete all cars in the store using RESTCONF""" + util.delete(settings.getCarsUrl(), "admin", "admin") resp = getCars(ignore) - print("Cars in store after deletion:"+ str(resp)) + print("Cars in store after deletion:" + str(resp)) + -# -#delete all persons in the store using RESTCONF -# -# def deleteAllPersons(ignore): - util.delete(settings.getPersonsUrl(),"admin","admin") + """delete all persons in the store using RESTCONF""" + util.delete(settings.getPersonsUrl(), "admin", "admin") resp = getPersons(ignore) - print("Persons in store after deletion:"+ str(resp)) + print("Persons in store after deletion:" + str(resp)) + # # Usage message shown to user @@ -202,17 +194,16 @@ def options(): command = 'ac=Add Car\n\t\tap=Add Person \n\t\tbc=Buy Car\n\t\tgc=Get Cars\n\t\tgp=Get Persons\n\t\t' \ 'gcp=Get Car-Person Mappings\n\t\tdc=Delete All Cars\n\t\tdp=Delete All Persons)' - param = '\n\t is\n\t\t' \ - 'number of cars to be added if =ac\n\t\t' \ - 'number of persons to be added if =ap\n\t\t' \ - 'number of car buyers if =bc\n\t\t'\ - 'pass 0 if =gc or gp or gcp or dc or dp'\ - + param = '\n\t is\n\t\t' \ + 'number of cars to be added if =ac\n\t\t' \ + 'number of persons to be added if =ap\n\t\t' \ + 'number of car buyers if =bc\n\t\t'\ + 'pass 0 if =gc or gp or gcp or dc or dp'\ usageString = 'usage: python crud \nwhere\n\t = ODL server ip address' \ '\n\t = any of the following commands \n\t\t' - usageString = usageString + command +param + usageString = usageString + command + param print (usageString) @@ -228,15 +219,14 @@ def main(): settings.hostname = sys.argv[1] settings.port = '8080' call = dict(ac=addCar, ap=addPerson, bc=buyCar, - gc=getCars, gp=getPersons, gcp=getCarPersonMappings,dc=deleteAllCars,dp=deleteAllPersons) + gc=getCars, gp=getPersons, gcp=getCarPersonMappings, dc=deleteAllCars, dp=deleteAllPersons) - #FOR RPC TO WORK PROPERLY THE FIRST PERSON SHOULD BE ADDED VIA RESTCONF + # FOR RPC TO WORK PROPERLY THE FIRST PERSON SHOULD BE ADDED VIA RESTCONF addPerson(0) - #FOR RPC TO WORK PROPERLY THE FIRST PERSON SHOULD BE ADDED VIA RESTCONF + # FOR RPC TO WORK PROPERLY THE FIRST PERSON SHOULD BE ADDED VIA RESTCONF addCarPerson(0) - call[sys.argv[2]](int(sys.argv[3])) #