blob: fcb61ee60e7e3e24060c0ffcb7bdfe622bb79a84 [file] [log] [blame]
Scott Baker7b7a2dd2019-02-14 16:25:59 -08001*** Settings ***
2Documentation Test remove of a service
3Library RequestsLibrary
Scott Baker7b7a2dd2019-02-14 16:25:59 -08004Library Collections
5Library String
6Library OperatingSystem
7Library DateTime
Scott Baker7b7a2dd2019-02-14 16:25:59 -08008Library DatabaseLibrary
Zack Williams821c5022020-01-15 15:11:46 -07009Library CORDRobot
10Library ImportResource resources=CORDRobot
Scott Baker7b7a2dd2019-02-14 16:25:59 -080011Variables ../../Properties/RestApiProperties.py
12Suite Setup Setup
13Suite Teardown Teardown
14
15*** Variables ***
16${timeout} 300s
17${repository} xosproject/simpleexampleservice-synchronizer
18${migration1} migration-test1
19${migration2} migration-test2
20${helm_chart} ~/cord/helm-charts/xos-services/simpleexampleservice
21${cleanup} ${true}
22
23*** Test Cases ***
24Ensure Clean Environment
25 [Documentation] Ensure the service is not installed and its endpoint is not being served
26 [Tags] test1
27 ${output}= Run helm ls | grep simpleexampleservice | wc -l
28 Should Be Equal As Integers ${output} 0
29 ${resp} = Get Request ${SERVER_IP} uri=/xosapi/v1/simpleexampleservice/simpleexampleservices
Scott Bakerbd429142019-02-20 14:59:48 -080030 Log ${resp.content}
Scott Baker7b7a2dd2019-02-14 16:25:59 -080031 Should Be Equal As Strings ${resp.status_code} 404
32
33Install SimpleExampleService
34 [Documentation] Install version A of the service and wait for completion
35 [Tags] test2
36 Run helm install -n simpleexampleservice --set image.repository=${repository} --set image.tag=${migration1} ${helm_chart}
37 Wait Until Keyword Succeeds ${timeout} 5s Validate Service Running
38
39Verify Tables Present
40 [Documentation] Verify the tables are present
41 [Tags] test3
42 Table Must Exist simpleexampleservice_simpleexampleservice
43 Table Must Exist simpleexampleservice_simpleexampleserviceinstance
44 Table Must Exist simpleexampleservice_serviceinstancewithcompute2
45 Table Must Exist simpleexampleservice_embeddedimagenew
46 Table Must Exist simpleexampleservice_colornew
47
48Verify Migrations Present
49 [Documentation] Verify Migrations are Present
50 [Tags] test4
51 Row Count is Greater Than X SELECT * FROM django_migrations where app='simpleexampleservice' 0
52
53Create Model
54 [Documentation] Create a service model
55 [Tags] test5
56 ${model_name}= Generate Random Value string
57 ${data}= Create Dictionary name=${model_name} service_message=initial
58 ${data}= Evaluate json.dumps(${data}) json
59 ${resp}= CORD Post /xosapi/v1/simpleexampleservice/simpleexampleservices ${data}
Scott Baker014b4452019-02-21 08:36:38 -080060 ${json_content}= To Json ${resp.content}
Scott Baker7b7a2dd2019-02-14 16:25:59 -080061 ${model_id}= Get From Dictionary ${json_content} id
62 Set Suite Variable ${model_id}
63 Set Suite Variable ${model_name}
64
65Delete Service Synchronizer
66 [Documentation] Delete the service synchronizer
67 [Tags] test6
68 Delete Service
69 Wait Until Keyword Succeeds ${timeout} 5s Validate Service Not Running
70
71Unload Service While Dirty
72 [Documentation] Unload the service
73 [Tags] test7
74 ${data}= Create Dictionary name=simpleexampleservice version=1.1.7
75 ${data}= Evaluate json.dumps(${data}) json
76 ${resp}= Post Request ${SERVER_IP} uri=/xosapi/v1/dynamicload/unload_models data=${data}
Scott Bakerbd429142019-02-20 14:59:48 -080077 Log ${resp.content}
Scott Baker7b7a2dd2019-02-14 16:25:59 -080078 Should Be Equal As Strings ${resp.status_code} 409
79
80Unload Service Automatic Cleanup
81 [Documentation] Unload the service
82 [Tags] test8
Scott Baker5f443f22019-02-20 19:33:32 -080083 # May have to do this multiple times to wait for cleanup to complete
84 Wait Until Keyword Succeeds ${timeout} 5s Unload With Automatic Cleanup
Scott Baker7b7a2dd2019-02-14 16:25:59 -080085
86Verify Service Stopped
87 [Documentation] Make sure the core has stopped serving the service
88 [Tags] test9
89 Wait Until Keyword Succeeds ${timeout} 5s Validate Service Not Served
90
91Verify Tables Removed
92 [Documentation] Verify the tables have been removed
93 [Tags] test10
94 Run Keyword And Expect Error Table 'simpleexampleservice_simpleexampleservice' does not exist in the db Table Must Exist simpleexampleservice_simpleexampleservice
95 Run Keyword And Expect Error Table 'simpleexampleservice_simpleexampleserviceinstance' does not exist in the db Table Must Exist simpleexampleservice_simpleexampleserviceinstance
96 Run Keyword And Expect Error Table 'simpleexampleservice_serviceinstancewithcompute2' does not exist in the db Table Must Exist simpleexampleservice_serviceinstancewithcompute2
97 Run Keyword And Expect Error Table 'simpleexampleservice_embeddedimagenew' does not exist in the db Table Must Exist simpleexampleservice_embeddedimagenew
98 Run Keyword And Expect Error Table 'simpleexampleservice_colornew' does not exist in the db Table Must Exist simpleexampleservice_colornew
99
100Verify Migrations Removed
101 [Documentation] Verify Migrations Removed
102 [Tags] test11
103 Row Count is 0 SELECT * FROM django_migrations where app='simpleexampleservice'
104
105
106*** Keywords ***
107Setup
108 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
109 ${HEADERS} Create Dictionary Content-Type=application/json allow_modify_feedback=True
110 Create Session ${server_ip} http://${server_ip}:${server_port} auth=${AUTH} headers=${HEADERS}
Scott Baker222955a2019-03-29 09:56:59 -0700111 @{model_A_fields}= Create List service_message
112 @{model_B_fields}= Create List service_message new_field
Scott Baker7b7a2dd2019-02-14 16:25:59 -0800113 @{model_B_only_fields}= Create List new_field
114
115 ${db_addr}= Run kubectl get services | grep -i xos-db | awk '{print $3}'
116 Connect To Database psycopg2 xos postgres password ${db_addr} 5432
117
118 Set Suite Variable @{model_A_fields}
119
120 Set Suite Variable @{model_B_fields}
121
122 Set Suite Variable @{model_B_only_fields}
123
124Teardown
125 [Documentation] Delete all https sessions
126 Run Keyword If ${cleanup} == ${true} Ensure Service Deleted
127 Run Keyword If ${cleanup} == ${true} Ensure Service Unloaded
128 Disconnect From Database
129 Delete All Sessions
130
131Validate Service Running
132 # wait for helm chart to be deployed
133 ${output}= Run helm ls | grep simpleexampleservice | grep -i deployed | wc -l
134 Should Be Equal As Integers ${output} 1
135 # wait for the synchronizer pod to be running
136 ${output}= Run kubectl get pods | grep simpleexampleservice | grep -i running | grep 1/1 | wc -l
137 Should Be Equal As Integers ${output} 1
138 # wait for no other synchronizer pods to be terminating
139 ${output}= Run kubectl get pods | grep simpleexampleservice | grep -i terminating | wc -l
140 Should Be Equal As Integers ${output} 0
141 # wait for the endpoint to exist
142 ${resp} = CORD Get /xosapi/v1/simpleexampleservice/simpleexampleservices
143
144Validate Service Not Running
145 # wait for helm chart to be deployed
146 ${output}= Run helm ls | grep simpleexampleservice | grep -i deployed | wc -l
147 Should Be Equal As Integers ${output} 0
148 # wait for the synchronizer pod to be not running
149 ${output}= Run kubectl get pods | grep simpleexampleservice | grep -i running | grep 1/1 | wc -l
150 # wait for no other synchronizer pods to finish terminating
151 ${output}= Run kubectl get pods | grep simpleexampleservice | grep -i terminating | wc -l
152 Should Be Equal As Integers ${output} 0
153
154Validate Service Not Served
155 # endpoint should not be served
156 ${resp} = Get Request ${SERVER_IP} uri=/xosapi/v1/simpleexampleservice/simpleexampleservices
Scott Bakerbd429142019-02-20 14:59:48 -0800157 Log ${resp.content}
Scott Baker7b7a2dd2019-02-14 16:25:59 -0800158 Should Be Equal As Strings ${resp.status_code} 404
159 # wait for the core to be up
160 ${resp} = CORD Get /xosapi/v1/core/users
161
162Ensure Service Deleted
163 ${output}= Run helm ls | grep simpleexampleservice | grep -i deployed | wc -l
164 Run Keyword If ${output} == 1 Delete Service
165
166Delete Service
167 Log Deleating Service Helm Chart
168 ${rc}= Run And Return RC helm del --purge simpleexampleservice
169 Should Be Equal As Integers ${rc} 0
170 Log Deleted Service Helm Chart
171
172Ensure Service Unloaded
173 [Documentation] Unload the service if it is loaded.
174 Wait Until Keyword Succeeds 200s 2s CORD Get /xosapi/v1/core/users
175 ${resp}= Get Request ${SERVER_IP} uri=/xosapi/v1/dynamicload/load_status
Scott Bakerbd429142019-02-20 14:59:48 -0800176 Log ${resp.content}
Scott Baker7b7a2dd2019-02-14 16:25:59 -0800177 Should Be Equal As Strings ${resp.status_code} 200
178 ${jsondata}= To Json ${resp.content}
179 ${length}= Get Length ${jsondata['services']}
180 : FOR ${INDEX} IN RANGE 0 ${length}
181 \ ${dict}= Get From List ${jsondata['services']} ${INDEX}
182 \ Run Keyword If "${dict['name']}" == "simpleexampleservice" and "${dict['state']}" == "present" Unload Service
183
184Unload Service
185 [Documentation] Unload the service
186 Log Unloading Service, with table purge
187 ${data}= Create Dictionary name=simpleexampleservice version=1.1.7 cleanup_behavior=2
188 ${data}= Evaluate json.dumps(${data}) json
189 ${resp}= Post Request ${SERVER_IP} uri=/xosapi/v1/dynamicload/unload_models data=${data}
Scott Bakerbd429142019-02-20 14:59:48 -0800190 Log ${resp.content}
Scott Baker7b7a2dd2019-02-14 16:25:59 -0800191 Should Be Equal As Strings ${resp.status_code} 200
192 Log Successfully Unloaded
Scott Baker5f443f22019-02-20 19:33:32 -0800193
194Unload With Automatic Cleanup
195 ${data}= Create Dictionary name=simpleexampleservice version=1.1.7 cleanup_behavior=1
196 ${data}= Evaluate json.dumps(${data}) json
197 ${resp}= Post Request ${SERVER_IP} uri=/xosapi/v1/dynamicload/unload_models data=${data}
198 Log ${resp.content}
199 Should Be Equal As Strings ${resp.status_code} 200
200 ${jsondata}= To Json ${resp.content}
201 # Verify it is in SUCCESS_NOTHING_CHANGED state
Scott Baker014b4452019-02-21 08:36:38 -0800202 Should Be Equal As Strings ${jsondata["status"]} SUCCESS_NOTHING_CHANGED