Bug 5423: Fix for ERROR messages when intents were deleted.
[integration/test.git] / csit / libraries / CarsAndPeople.robot
1 *** Settings ***
2 Library           Collections
3 Library           CrudLibrary.py
4 Library           SettingsLibrary.py
5 Resource          DatastoreCRUD.robot
6
7 *** Keywords ***
8 Add Cars And Verify
9     [Arguments]    ${controller_ip}    ${num_cars}    ${timeout}=3s
10     [Documentation]    Initializes shard and then adds the specified number of cars and performs a GET as a check.
11     ${resp}    InitCar    ${controller_ip}    ${PORT}
12     Should Be Equal As Strings    ${resp.status_code}    204
13     ${resp}    AddCar    ${controller_ip}    ${RESTCONFPORT}    ${num_cars}    204
14     Should Be Equal As Strings    ${resp.status_code}    204
15     Wait Until Keyword Succeeds    ${timeout}    1s    Get Cars And Verify    ${controller_ip}    ${num_cars}
16
17 Add Cars And Verify Without Init
18     [Arguments]    ${controller_ip}    ${num_cars}    ${timeout}=3s
19     [Documentation]    Adds cars to an initialized cars shard then performs a GET as a check.
20     Comment    First car add may return 409, but subsequent should be 204
21     ${resp}    AddCar    ${controller_ip}    ${RESTCONFPORT}    ${num_cars}    204    409
22     Should Be Equal As Strings    ${resp.status_code}    204
23     Wait Until Keyword Succeeds    ${timeout}    1s    Get Cars And Verify    ${controller_ip}    ${num_cars}
24
25 Get Cars And Verify
26     [Arguments]    ${controller_ip}    ${num_cars}
27     [Documentation]    Gets cars and verifies that the manufacturer is correct.
28     # TODO: Future enhanement: verify all fields.
29     ${resp}    Getcars    ${controller_ip}    ${RESTCONFPORT}    ${0}
30     Should Be Equal As Strings    ${resp.status_code}    200
31     : FOR    ${i}    IN RANGE    1    ${num_cars}+1
32     \    Should Contain    ${resp.content}    manufacturer${i}
33
34 Add People And Verify
35     [Arguments]    ${controller_ip}    ${num_people}    ${timeout}=3s
36     [Documentation]    Note: The first AddPerson call passed with 0 posts directly to the data store to get
37     ...    the people container created so the subsequent AddPerson RPC calls that put to the
38     ...    person list will succeed.
39     ${resp}    AddPerson    ${controller_ip}    ${RESTCONFPORT}    ${0}    204
40     Should Be Equal As Strings    ${resp.status_code}    204
41     Wait Until Keyword Succeeds    ${timeout}    1s    Get One Person And Verify    ${controller_ip}    ${0}
42     ${resp}    AddPerson    ${controller_ip}    ${RESTCONFPORT}    ${num_people}    200
43     Wait Until Keyword Succeeds    ${timeout}    1s    Get People And Verify    ${controller_ip}    ${num_people}
44
45 Add People And Verify Without Init
46     [Arguments]    ${controller_ip}    ${num_people}    ${timeout}=3s
47     [Documentation]    Adds people to an initialized people shard then performs a GET as a check.
48     ${resp}    AddPerson    ${controller_ip}    ${RESTCONFPORT}    ${num_people}    200
49     Should Be Equal As Strings    ${resp.status_code}    200
50     Wait Until Keyword Succeeds    ${timeout}    1s    Get People And Verify    ${controller_ip}    ${num_people}
51
52 Get One Person And Verify
53     [Arguments]    ${controller_ip}    ${number}
54     [Documentation]    Gets a person and verifies that the user ID is correct.
55     # TODO: Future enhanement: verify all fields.
56     ${resp}    GetPersons    ${controller_ip}    ${RESTCONFPORT}    ${0}
57     Should Be Equal As Strings    ${resp.status_code}    200
58     Should Contain    ${resp.content}    user${number}
59
60 Get People And Verify
61     [Arguments]    ${controller_ip}    ${num_people}
62     [Documentation]    Gets multiple people and verifies that the user IDs are correct.
63     # TODO: Future enhanement: verify all fields.
64     ${resp}    GetPersons    ${controller_ip}    ${RESTCONFPORT}    ${0}
65     Should Be Equal As Strings    ${resp.status_code}    200
66     : FOR    ${i}    IN RANGE    1    ${num_people}+1
67     \    Should Contain    ${resp.content}    user${i}
68
69 Add Car Person And Verify
70     [Arguments]    ${controller_ip}    ${timeout}=3s
71     [Documentation]    Add a car-person via the data store and get the car-person from Leader.
72     ...    Note: This is done to get the car-people container created so subsequent
73     ...    BuyCar RPC puts to the car-person list will succeed.
74     AddCarPerson    ${controller_ip}    ${RESTCONFPORT}    ${0}
75     Wait Until Keyword Succeeds    ${timeout}    1s    Get One Car-Person Mapping And Verify    ${controller_ip}    ${0}
76
77 Get One Car-Person Mapping And Verify
78     [Arguments]    ${controller_ip}    ${number}
79     [Documentation]    Gets a car person mapping and verifies that the user ID is correct.
80     ${resp}    GetCarPersonMappings    ${controller_ip}    ${RESTCONFPORT}    ${0}
81     Should Be Equal As Strings    ${resp.status_code}    200
82     Should Contain    ${resp.content}    user${number}
83
84 Get Car-Person Mappings And Verify
85     [Arguments]    ${controller_ip}    ${num_entries}
86     ${resp}    GetCarPersonMappings    ${controller_ip}    ${RESTCONFPORT}    ${0}
87     Should Be Equal As Strings    ${resp.status_code}    200
88     : FOR    ${i}    IN RANGE    1    ${num_entries}+1
89     \    Should Contain    ${resp.content}    user${i}
90
91 Buy Cars And Verify
92     [Arguments]    ${controller_ip}    ${num_entries}    ${start}=${0}    ${timeout}=3s
93     BuyCar    ${controller_ip}    ${RESTCONFPORT}    ${num_entries}    ${start}
94     ${total_entries}    Evaluate    ${start}+${num_entries}
95     Wait Until Keyword Succeeds    ${timeout}    1s    Get Car-Person Mappings And Verify    ${controller_ip}    ${total_entries}
96
97 Check Cars Deleted
98     [Arguments]    ${controller_ip}
99     ${resp}    Getcars    ${controller_ip}    ${RESTCONFPORT}    ${0}
100     Should Be Equal As Strings    ${resp.status_code}    404
101
102 Delete All Cars And Verify
103     [Arguments]    ${controller_ip}    ${timeout}=3s
104     DeleteAllCars    ${controller_ip}    ${RESTCONFPORT}    ${0}
105     Wait Until Keyword Succeeds    ${timeout}    1s    Check Cars Deleted    ${controller_ip}
106
107 Check People Deleted
108     [Arguments]    ${controller_ip}
109     ${resp}    GetPersons    ${controller_ip}    ${RESTCONFPORT}    ${0}
110     Should Be Equal As Strings    ${resp.status_code}    404
111
112 Delete All People And Verify
113     [Arguments]    ${controller_ip}    ${timeout}=3s
114     DeleteAllPersons    ${controller_ip}    ${RESTCONFPORT}    ${0}
115     Wait Until Keyword Succeeds    ${timeout}    1s    Check People Deleted    ${controller_ip}
116
117 Check Cars-Persons Deleted
118     [Arguments]    ${controller_ip}
119     ${resp}    GetCarPersonMappings    ${controller_ip}    ${RESTCONFPORT}    ${0}
120     Should Be Equal As Strings    ${resp.status_code}    404
121
122 Delete All Cars-Persons And Verify
123     [Arguments]    ${controller_ip}    ${timeout}=3s
124     DeleteAllCarsPersons    ${controller_ip}    ${RESTCONFPORT}    ${0}
125     Wait Until Keyword Succeeds    ${timeout}    1s    Check Cars-Persons Deleted    ${controller_ip}
126
127 Delete All Entries From Shards
128     [Arguments]    @{controllers}
129     [Documentation]    Delete All Shards.
130     : FOR    ${ip}    IN    @{controllers}
131     \    Delete All Cars And Verify    ${ip}
132     : FOR    ${ip}    IN    @{controllers}
133     \    Delete All People And Verify    ${ip}
134     : FOR    ${ip}    IN    @{controllers}
135     \    Delete All Cars-Persons And Verify    ${ip}
136
137 Check Cars
138     [Arguments]    ${controller_ip}    ${nth_car}
139     [Documentation]    Verifies that the first through nth car is present.
140     ${resp}    Getcars    ${controller_ip}    ${RESTCONFPORT}    ${0}
141     Should Be Equal As Strings    ${resp.status_code}    200
142     : FOR    ${INDEX}    IN RANGE    1    ${nth_car}
143     \    ${counter}=    Convert to String    ${INDEX}
144     \    Log    manufacturer${counter}
145     \    Should Contain    ${resp.content}    manufacturer${counter}
146
147 Check People
148     [Arguments]    ${controller_ip}    ${nth_person}
149     [Documentation]    Verifies that the first through nth person is present.
150     ${resp}    GetPersons    ${controller_ip}    ${RESTCONFPORT}    ${0}
151     Should Be Equal As Strings    ${resp.status_code}    200
152     : FOR    ${INDEX}    IN RANGE    1    ${nth_person}
153     \    ${counter}=    Convert to String    ${INDEX}
154     \    Log    user${counter}
155     \    Should Contain    ${resp.content}    user${counter}
156
157 Check CarPeople
158     [Arguments]    ${controller_ip}    ${nth_carperson}
159     [Documentation]    Verifies that the first through nth car-person is present.
160     ${resp}    GetCarPersonMappings    ${controller_ip}    ${RESTCONFPORT}    ${0}
161     Should Be Equal As Strings    ${resp.status_code}    200
162     : FOR    ${INDEX}    IN RANGE    1    ${nth_carperson}
163     \    ${counter}=    Convert to String    ${INDEX}
164     \    Log    user${counter}
165     \    Should Contain    ${resp.content}    user${counter}
166
167 Check Elements In Shards
168     [Arguments]    ${controller_ip}    ${nth}
169     [Documentation]    Check all shards for nth elements
170     wait until keyword succeeds    3    1    Check Cars    ${controller_ip}    ${nth}
171     wait until keyword succeeds    3    1    Check People    ${controller_ip}    ${nth}
172     wait until keyword succeeds    3    1    Check CarPeople    ${controller_ip}    ${nth}
173
174 Initialize Cars
175     [Arguments]    ${controller_ip}    ${field bases}
176     [Documentation]    Initializes the cars shard by creating a 0th car with POST then deleting it.
177     ...    Field bases are a dictionary of datastore record field values onto which is appended
178     ...    an incremental value to uniquely identify the record from which it came.
179     ...    Typically, you will use the Create Dictionary keyword on arguments which look like this:
180     ...    id=${EMPTY} category=coupe model=model manufacturer=mfg year=2
181     ${node}=    Set Variable    ${EMPTY}
182     ${prefix}=    Set Variable    {"car:cars":{"car-entry":[{
183     ${postfix}=    Set Variable    }]}}
184     Create Records    ${controller_ip}    ${node}    ${0}    ${0}    ${prefix}    ${field bases}
185     ...    ${postfix}
186     ${node}=    Set Variable    car:cars/car-entry
187     Delete Records    ${controller_ip}    ${node}    ${0}    ${0}
188
189 Create Cars
190     [Arguments]    ${controller_ip}    ${first}    ${last}    ${field bases}
191     [Documentation]    Creates cars with record IDs of specified range using POST.
192     ...    If first and last are equal, only one record is updated.
193     ...    Field bases are a dictionary of datastore record field values onto which is appended
194     ...    an incremental value to uniquely identify the record from which it came.
195     ...    Typically, you will use the Create Dictionary keyword on an argument which looks like this:
196     ...    id=${EMPTY} category=coupe model=model manufacturer=mfg year=2
197     ${node}=    Set Variable    car:cars
198     ${prefix}=    Set Variable    {"car-entry":[{
199     ${postfix}=    Set Variable    }]}
200     Create Records    ${controller_ip}    ${node}    ${first}    ${last}    ${prefix}    ${field bases}
201     ...    ${postfix}
202
203 Update Cars
204     [Arguments]    ${controller_ip}    ${first}    ${last}    ${field bases}
205     [Documentation]    Updates cars with record IDs of the specified using PUT.
206     ...    If first and last are equal, only one record is updated.
207     ...    Field bases are a dictionary of datastore record field values onto which is appended
208     ...    an incremental value to uniquely identify the record from which it came.
209     ...    Typically, you will use the Create Dictionary keyword on arguments which look like this:
210     ...    id=${EMPTY} category=coupe model=model manufacturer=mfg year=2
211     ${node}=    Set Variable    car:cars/car-entry
212     ${prefix}=    Set Variable    {"car-entry":[{
213     ${postfix}=    Set Variable    }]}
214     Update Records    ${controller_ip}    ${node}    ${first}    ${last}    ${prefix}    ${field bases}
215     ...    ${postfix}
216
217 Read All Cars
218     [Arguments]    ${controller_ip}
219     [Documentation]    Returns all records from the cars shard in JSON format.
220     ${node}=    Set Variable    car:cars
221     ${result}=    Read Records    ${controller_ip}    ${node}
222     [Return]    ${result}
223
224 Read One Car
225     [Arguments]    ${controller_ip}    ${id}
226     [Documentation]    Returns the specified record from the cars shard in JSON format.
227     ${node}=    Set Variable    car:cars/car-entry/${id}
228     ${result}=    Read Records    ${controller_ip}    ${node}
229     [Return]    ${result}
230
231 Remove All Cars
232     [Arguments]    ${controller_ip}
233     [Documentation]    Deletes all records from the cars shard.
234     ${node}=    Set Variable    car:cars
235     Delete All Records    ${controller_ip}    ${node}
236
237 Remove Cars
238     [Arguments]    ${controller_ip}    ${first}    ${last}
239     [Documentation]    Deletes the specified range of records from the cars shard.
240     ${node}=    Set Variable    car:cars/car-entry
241     Delete Records    ${controller_ip}    ${node}    ${first}    ${last}