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