def addCarPerson(hostname,port,numberOfCarPersons):

    #FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF
    if(numberOfCarPersons==0):
        payload = SettingsLibrary.add_car_person_template.substitute(Id=str(numberOfCarPersons),personId="user"+str(numberOfCarPersons))
        # Send the POST request REST CONF
        resp = UtilLibrary.nonprintpost(SettingsLibrary.getAddCarPersonUrl(hostname,port),"admin", "admin",payload)

        return

    for x in range(1, numberOfCarPersons+1):
        strId = str(x)

        payload = SettingsLibrary.add_car_person_template.substitute(Id=strId,personId="user"+strId)

        # Send the POST request REST CONF
        resp = UtilLibrary.post(SettingsLibrary.getAddCarPersonUrl(hostname,port),"admin", "admin",payload)

        print("payload formed after template substitution=")
        print(payload)

        print("the response of the POST to add car_person=")
        print(resp)

    print("getting the car_persons for verification")
    resp=getCarPersonMappings(hostname,port,0)
Ejemplo n.º 2
0
def buyCar(hostname, port, numberOfCarBuyers, start=0):
    """Invokes an RPC REST call that does a car purchase by a person id

    <note>
        It is expected that the Car and Person entries are already created
        before invoking this method
    </note>
    """

    print("Buying " + str(numberOfCarBuyers) + " Cars")
    for x in range(start, start + numberOfCarBuyers):
        strId = str(x + 1)

        payload = SettingsLibrary.buy_car_rpc_template.substitute(
            personId="user" + strId, carId=strId)

        # Send the POST request using RPC
        resp = UtilLibrary.post(
            SettingsLibrary.getBuyCarRpcUrl(hostname, port), "admin", "admin",
            payload)

        print(resp)
        print(resp.text)

        if resp.status_code != 200:
            raise RuntimeError(
                "Buy car failed for {}:{} with status {}".format(
                    hostname, port, resp.status_code))
def addCarPerson(hostname, port, numberOfCarPersons):
    """This method is not exposed via commands as only getCarPersons is of interest

    addCarPerson entry happens when buyCar is called
    <note>
        To enable RPC a non-user input car-person entry is created with personId=user0
    </note>
    """
    # FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF
    if (numberOfCarPersons == 0):
        payload = SettingsLibrary.add_car_person_template.substitute(
            Id=str(numberOfCarPersons), personId="user" + str(numberOfCarPersons))
        # Send the POST request REST CONF
        resp = UtilLibrary.nonprintpost(SettingsLibrary.getAddCarPersonUrl(hostname, port), "admin", "admin", payload)

        return resp

    for x in range(1, numberOfCarPersons + 1):
        strId = str(x)

        payload = SettingsLibrary.add_car_person_template.substitute(Id=strId, personId="user" + strId)

        # Send the POST request REST CONF
        resp = UtilLibrary.post(SettingsLibrary.getAddCarPersonUrl(hostname, port), "admin", "admin", payload)

        print("payload formed after template substitution=")
        print(payload)

        print("the response of the POST to add car_person=")
        print(resp)

    print("getting the car_persons for verification")
    resp = getCarPersonMappings(hostname, port, 0)
    # TBD detailed validation
    return resp
Ejemplo n.º 4
0
def addCar(hostname, port, numberOfCars, *expected):
    """Creates the specified number of cars based on Cars yang model using RESTCONF"""
    for x in range(1, numberOfCars + 1):
        strId = str(x)
        payload = SettingsLibrary.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 = UtilLibrary.post(SettingsLibrary.getAddCarUrl(hostname, port),
                                "admin", "admin", payload)

        print("the response of the POST to add car=")
        print(resp)
        if expected and str(resp.status_code) not in expected:
            raise RuntimeError(
                "Add car failed for {}:{} with status {}".format(
                    hostname, port, resp.status_code))

    return resp
Ejemplo n.º 5
0
def addCarPerson(hostname,port,numberOfCarPersons):

    #FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF
    if(numberOfCarPersons==0):
        payload = SettingsLibrary.add_car_person_template.substitute(Id=str(numberOfCarPersons),personId="user"+str(numberOfCarPersons))
        # Send the POST request REST CONF
        resp = UtilLibrary.nonprintpost(SettingsLibrary.getAddCarPersonUrl(hostname,port),"admin", "admin",payload)

        return

    for x in range(1, numberOfCarPersons+1):
        strId = str(x)

        payload = SettingsLibrary.add_car_person_template.substitute(Id=strId,personId="user"+strId)

        # Send the POST request REST CONF
        resp = UtilLibrary.post(SettingsLibrary.getAddCarPersonUrl(hostname,port),"admin", "admin",payload)

        print("payload formed after template substitution=")
        print(payload)

        print("the response of the POST to add car_person=")
        print(resp)

    print("getting the car_persons for verification")
    resp=getCarPersonMappings(hostname,port,0)
Ejemplo n.º 6
0
def addPerson(hostname,port,numberOfPersons):
    #FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF
    if(numberOfPersons==0):
        strId =str(numberOfPersons)
        payload = SettingsLibrary.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 = UtilLibrary.nonprintpost(SettingsLibrary.getAddPersonUrl(hostname,port),"admin", "admin",payload)
        return resp

    genderToggle = "Male"
    for x in range(1, numberOfPersons+1):
        if(genderToggle == "Male"):
            genderToggle = "Female"
        else:
            genderToggle = "Male"

        strId = str(x)

        payload = SettingsLibrary.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 = UtilLibrary.post(SettingsLibrary.getAddPersonRpcUrl(hostname,port),"admin", "admin",payload)

        print("payload formed after template substitution=")
        print(payload)
        print("the response of the POST to add person=")
        print(resp)

    return resp
def addPerson(hostname,port,numberOfPersons):
    #FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF
    if(numberOfPersons==0):
        strId =str(numberOfPersons)
        payload = SettingsLibrary.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 = UtilLibrary.nonprintpost(SettingsLibrary.getAddPersonUrl(hostname,port),"admin", "admin",payload)
        return resp

    genderToggle = "Male"
    for x in range(1, numberOfPersons+1):
        if(genderToggle == "Male"):
            genderToggle = "Female"
        else:
            genderToggle = "Male"

        strId = str(x)

        payload = SettingsLibrary.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 = UtilLibrary.post(SettingsLibrary.getAddPersonRpcUrl(hostname,port),"admin", "admin",payload)

        print("payload formed after template substitution=")
        print(payload)
        print("the response of the POST to add person=")
        print(resp)

    return resp
Ejemplo n.º 8
0
def addCarPerson(hostname, port, numberOfCarPersons):
    """This method is not exposed via commands as only getCarPersons is of interest

    addCarPerson entry happens when buyCar is called
    <note>
        To enable RPC a non-user input car-person entry is created with personId=user0
    </note>
    """
    # FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF
    if (numberOfCarPersons == 0):
        payload = SettingsLibrary.add_car_person_template.substitute(
            Id=str(numberOfCarPersons), personId="user" + str(numberOfCarPersons))
        # Send the POST request REST CONF
        resp = UtilLibrary.nonprintpost(SettingsLibrary.getAddCarPersonUrl(hostname, port), "admin", "admin", payload)

        return resp

    for x in range(1, numberOfCarPersons + 1):
        strId = str(x)

        payload = SettingsLibrary.add_car_person_template.substitute(Id=strId, personId="user" + strId)

        # Send the POST request REST CONF
        resp = UtilLibrary.post(SettingsLibrary.getAddCarPersonUrl(hostname, port), "admin", "admin", payload)

        print("payload formed after template substitution=")
        print(payload)

        print("the response of the POST to add car_person=")
        print(resp)

    print("getting the car_persons for verification")
    resp = getCarPersonMappings(hostname, port, 0)
    # TBD detailed validation
    return resp
Ejemplo n.º 9
0
def addPerson(hostname, port, numberOfPersons, *expected):
    """Creates the specified number of persons based on People yang model using main RPC
    <note>
        To enable RPC a non-user input person entry is created with personId=user0
    </note>
    """
    # FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF
    if numberOfPersons == 0:
        strId = str(numberOfPersons)
        payload = SettingsLibrary.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 = UtilLibrary.nonprintpost(
            SettingsLibrary.getAddPersonUrl(hostname, port), "admin", "admin",
            payload)
        return resp

    genderToggle = "Male"
    for x in range(1, numberOfPersons + 1):
        if genderToggle == "Male":
            genderToggle = "Female"
        else:
            genderToggle = "Male"

        strId = str(x)

        payload = SettingsLibrary.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 = UtilLibrary.post(
            SettingsLibrary.getAddPersonRpcUrl(hostname, port),
            "admin",
            "admin",
            payload,
        )

        print("payload formed after template substitution=")
        print(payload)
        print("the response of the POST to add person=")
        print(resp)
        if expected and str(resp.status_code) not in expected:
            raise RuntimeError(
                "Add person failed for {}:{} with status {}".format(
                    hostname, port, resp.status_code))

    return resp
Ejemplo n.º 10
0
def initCar(hostname, port):
    """Initiales the car shard"""
    x = 0
    strId = str(x)
    payload = SettingsLibrary.add_car_init_payload_template.substitute(
        id=strId, category="category" + strId, model="model" + strId,
        manufacturer="manufacturer" + strId,
        year=(2000 + x % 100))
    print("Initialization payload=")
    print(payload)
    resp = UtilLibrary.post(SettingsLibrary.getAddCarInitUrl(hostname, port), "admin", "admin", payload)
    print("the response of the POST to add car=")
    print(resp)
    return resp
Ejemplo n.º 11
0
def initCar(hostname, port):
    """Initiales the car shard"""
    x = 0
    strId = str(x)
    payload = SettingsLibrary.add_car_init_payload_template.substitute(
        id=strId, category="category" + strId, model="model" + strId,
        manufacturer="manufacturer" + strId,
        year=(2000 + x % 100))
    print("Initialization payload=")
    print(payload)
    resp = UtilLibrary.post(SettingsLibrary.getAddCarInitUrl(hostname, port), "admin", "admin", payload)
    print("the response of the POST to add car=")
    print(resp)
    return resp
def addCar(hostname,port,numberOfCars):

    for x in range(1, numberOfCars+1):
        strId = str(x)
        payload = SettingsLibrary.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 = UtilLibrary.post(SettingsLibrary.getAddCarUrl(hostname,port),"admin", "admin",payload)

        print("the response of the POST to add car=")
        print(resp)

    return resp
Ejemplo n.º 13
0
def addCar(hostname,port,numberOfCars):

    for x in range(1, numberOfCars+1):
        strId = str(x)
        payload = SettingsLibrary.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 = UtilLibrary.post(SettingsLibrary.getAddCarUrl(hostname,port),"admin", "admin",payload)

        print("the response of the POST to add car=")
        print(resp)

    return resp
Ejemplo n.º 14
0
def buyCar(hostname,port,numberOfCarBuyers):
    for x in range(1, numberOfCarBuyers+1):
        strId = str(x)

        payload = SettingsLibrary.buy_car_rpc_template.substitute(personId="user"+strId,carId=strId)

        # Send the POST request using RPC
        resp = UtilLibrary.post(SettingsLibrary.getBuyCarRpcUrl(hostname,port),"admin", "admin",payload)

        print("payload formed after template substitution=")
        print(payload)

        print("the response of the POST to buycar=")
        print(resp)

    print("getting the car_persons for verification")
    resp=getCarPersonMappings(hostname,port,0)
def buyCar(hostname,port,numberOfCarBuyers):
    for x in range(1, numberOfCarBuyers+1):
        strId = str(x)

        payload = SettingsLibrary.buy_car_rpc_template.substitute(personId="user"+strId,carId=strId)

        # Send the POST request using RPC
        resp = UtilLibrary.post(SettingsLibrary.getBuyCarRpcUrl(hostname,port),"admin", "admin",payload)

        print("payload formed after template substitution=")
        print(payload)

        print("the response of the POST to buycar=")
        print(resp)

    print("getting the car_persons for verification")
    resp=getCarPersonMappings(hostname,port,0)
Ejemplo n.º 16
0
def addCar(hostname, port, 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 = SettingsLibrary.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 = UtilLibrary.post(SettingsLibrary.getAddCarUrl(hostname, port), "admin", "admin", payload)

        print("the response of the POST to add car=")
        print(resp)

    time.sleep(5)  # Let the add finish
    return resp
Ejemplo n.º 17
0
def addPerson(hostname, port, numberOfPersons, *expected):
    """Creates the specified number of persons based on People yang model using main RPC
    <note>
        To enable RPC a non-user input person entry is created with personId=user0
    </note>
    """
    # FOR RPC TO WORK PROPERLY THE FIRST ENTRY SHOULD BE VIA RESTCONF
    if (numberOfPersons == 0):
        strId = str(numberOfPersons)
        payload = SettingsLibrary.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 = UtilLibrary.nonprintpost(SettingsLibrary.getAddPersonUrl(hostname, port), "admin", "admin", payload)
        return resp

    genderToggle = "Male"
    for x in range(1, numberOfPersons + 1):
        if(genderToggle == "Male"):
            genderToggle = "Female"
        else:
            genderToggle = "Male"

        strId = str(x)

        payload = SettingsLibrary.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 = UtilLibrary.post(SettingsLibrary.getAddPersonRpcUrl(hostname, port), "admin", "admin", payload)

        print("payload formed after template substitution=")
        print(payload)
        print("the response of the POST to add person=")
        print(resp)
        if expected and str(resp.status_code) not in expected:
            raise RuntimeError('Add person failed for {}:{} with status {}'.
                               format(hostname, port, resp.status_code))

    return resp
Ejemplo n.º 18
0
def addCar(hostname, port, numberOfCars, *expected):
    """Creates the specified number of cars based on Cars yang model using RESTCONF"""
    for x in range(1, numberOfCars + 1):
        strId = str(x)
        payload = SettingsLibrary.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 = UtilLibrary.post(SettingsLibrary.getAddCarUrl(hostname, port), "admin", "admin", payload)

        print("the response of the POST to add car=")
        print(resp)
        if expected and str(resp.status_code) not in expected:
            raise RuntimeError('Add car failed for {}:{} with status {}'.
                               format(hostname, port, resp.status_code))

    return resp
Ejemplo n.º 19
0
def buyCar(hostname, port, numberOfCarBuyers, start=0):
    """Invokes an RPC REST call that does a car purchase by a person id

    <note>
        It is expected that the Car and Person entries are already created
        before invoking this method
    </note>
    """
    for x in range(start, start+numberOfCarBuyers):
        strId = str(x+1)

        payload = SettingsLibrary.buy_car_rpc_template.substitute(personId="user" + strId, carId=strId)

        # Send the POST request using RPC
        resp = UtilLibrary.post(SettingsLibrary.getBuyCarRpcUrl(hostname, port), "admin", "admin", payload)

        print(resp)
        print(resp.text)

        if (resp.status_code != 204):
            return False

    return True