blob: 62fcaccbd9986ba4b233a515b88cfda3a3f6a7aa [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
32 Should Be Equal As Strings ${resp.status_code} 404
33
34Install SimpleExampleService
35 [Documentation] Install version A of the service and wait for completion
36 [Tags] test2
37 Run helm install -n simpleexampleservice --set image.repository=${repository} --set image.tag=${migration1} ${helm_chart}
38 Wait Until Keyword Succeeds ${timeout} 5s Validate Service Running
39
40Verify Tables Present
41 [Documentation] Verify the tables are present
42 [Tags] test3
43 Table Must Exist simpleexampleservice_simpleexampleservice
44 Table Must Exist simpleexampleservice_simpleexampleserviceinstance
45 Table Must Exist simpleexampleservice_serviceinstancewithcompute2
46 Table Must Exist simpleexampleservice_embeddedimagenew
47 Table Must Exist simpleexampleservice_colornew
48
49Verify Migrations Present
50 [Documentation] Verify Migrations are Present
51 [Tags] test4
52 Row Count is Greater Than X SELECT * FROM django_migrations where app='simpleexampleservice' 0
53
54Create Model
55 [Documentation] Create a service model
56 [Tags] test5
57 ${model_name}= Generate Random Value string
58 ${data}= Create Dictionary name=${model_name} service_message=initial
59 ${data}= Evaluate json.dumps(${data}) json
60 ${resp}= CORD Post /xosapi/v1/simpleexampleservice/simpleexampleservices ${data}
61 ${json_content}= Evaluate json.loads('''${resp.content}''') json
62 ${model_id}= Get From Dictionary ${json_content} id
63 Set Suite Variable ${model_id}
64 Set Suite Variable ${model_name}
65
66Delete Service Synchronizer
67 [Documentation] Delete the service synchronizer
68 [Tags] test6
69 Delete Service
70 Wait Until Keyword Succeeds ${timeout} 5s Validate Service Not Running
71
72Unload Service While Dirty
73 [Documentation] Unload the service
74 [Tags] test7
75 ${data}= Create Dictionary name=simpleexampleservice version=1.1.7
76 ${data}= Evaluate json.dumps(${data}) json
77 ${resp}= Post Request ${SERVER_IP} uri=/xosapi/v1/dynamicload/unload_models data=${data}
78 Should Be Equal As Strings ${resp.status_code} 409
79
80Unload Service Automatic Cleanup
81 [Documentation] Unload the service
82 [Tags] test8
83 ${data}= Create Dictionary name=simpleexampleservice version=1.1.7 cleanup_behavior=1
84 ${data}= Evaluate json.dumps(${data}) json
85 # The first time it should delete the model, and may return a TRYAGAIN
86 ${resp}= Post Request ${SERVER_IP} uri=/xosapi/v1/dynamicload/unload_models data=${data}
87 Should Be Equal As Strings ${resp.status_code} 200
88 # Try it a second time, just in case deletion was in progress, should succeed this time
89 ${resp}= Post Request ${SERVER_IP} uri=/xosapi/v1/dynamicload/unload_models data=${data}
90 Should Be Equal As Strings ${resp.status_code} 200
91
92Verify Service Stopped
93 [Documentation] Make sure the core has stopped serving the service
94 [Tags] test9
95 Wait Until Keyword Succeeds ${timeout} 5s Validate Service Not Served
96
97Verify Tables Removed
98 [Documentation] Verify the tables have been removed
99 [Tags] test10
100 Run Keyword And Expect Error Table 'simpleexampleservice_simpleexampleservice' does not exist in the db Table Must Exist simpleexampleservice_simpleexampleservice
101 Run Keyword And Expect Error Table 'simpleexampleservice_simpleexampleserviceinstance' does not exist in the db Table Must Exist simpleexampleservice_simpleexampleserviceinstance
102 Run Keyword And Expect Error Table 'simpleexampleservice_serviceinstancewithcompute2' does not exist in the db Table Must Exist simpleexampleservice_serviceinstancewithcompute2
103 Run Keyword And Expect Error Table 'simpleexampleservice_embeddedimagenew' does not exist in the db Table Must Exist simpleexampleservice_embeddedimagenew
104 Run Keyword And Expect Error Table 'simpleexampleservice_colornew' does not exist in the db Table Must Exist simpleexampleservice_colornew
105
106Verify Migrations Removed
107 [Documentation] Verify Migrations Removed
108 [Tags] test11
109 Row Count is 0 SELECT * FROM django_migrations where app='simpleexampleservice'
110
111
112*** Keywords ***
113Setup
114 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
115 ${HEADERS} Create Dictionary Content-Type=application/json allow_modify_feedback=True
116 Create Session ${server_ip} http://${server_ip}:${server_port} auth=${AUTH} headers=${HEADERS}
117 @{model_A_fields}= Create List service_message service_secret
118 @{model_B_fields}= Create List service_message service_secret new_field
119 @{model_B_only_fields}= Create List new_field
120
121 ${db_addr}= Run kubectl get services | grep -i xos-db | awk '{print $3}'
122 Connect To Database psycopg2 xos postgres password ${db_addr} 5432
123
124 Set Suite Variable @{model_A_fields}
125
126 Set Suite Variable @{model_B_fields}
127
128 Set Suite Variable @{model_B_only_fields}
129
130Teardown
131 [Documentation] Delete all https sessions
132 Run Keyword If ${cleanup} == ${true} Ensure Service Deleted
133 Run Keyword If ${cleanup} == ${true} Ensure Service Unloaded
134 Disconnect From Database
135 Delete All Sessions
136
137Validate Service Running
138 # wait for helm chart to be deployed
139 ${output}= Run helm ls | grep simpleexampleservice | grep -i deployed | wc -l
140 Should Be Equal As Integers ${output} 1
141 # wait for the synchronizer pod to be running
142 ${output}= Run kubectl get pods | grep simpleexampleservice | grep -i running | grep 1/1 | wc -l
143 Should Be Equal As Integers ${output} 1
144 # wait for no other synchronizer pods to be terminating
145 ${output}= Run kubectl get pods | grep simpleexampleservice | grep -i terminating | wc -l
146 Should Be Equal As Integers ${output} 0
147 # wait for the endpoint to exist
148 ${resp} = CORD Get /xosapi/v1/simpleexampleservice/simpleexampleservices
149
150Validate Service Not Running
151 # wait for helm chart to be deployed
152 ${output}= Run helm ls | grep simpleexampleservice | grep -i deployed | wc -l
153 Should Be Equal As Integers ${output} 0
154 # wait for the synchronizer pod to be not running
155 ${output}= Run kubectl get pods | grep simpleexampleservice | grep -i running | grep 1/1 | wc -l
156 # wait for no other synchronizer pods to finish terminating
157 ${output}= Run kubectl get pods | grep simpleexampleservice | grep -i terminating | wc -l
158 Should Be Equal As Integers ${output} 0
159
160Validate Service Not Served
161 # endpoint should not be served
162 ${resp} = Get Request ${SERVER_IP} uri=/xosapi/v1/simpleexampleservice/simpleexampleservices
163 Should Be Equal As Strings ${resp.status_code} 404
164 # wait for the core to be up
165 ${resp} = CORD Get /xosapi/v1/core/users
166
167Ensure Service Deleted
168 ${output}= Run helm ls | grep simpleexampleservice | grep -i deployed | wc -l
169 Run Keyword If ${output} == 1 Delete Service
170
171Delete Service
172 Log Deleating Service Helm Chart
173 ${rc}= Run And Return RC helm del --purge simpleexampleservice
174 Should Be Equal As Integers ${rc} 0
175 Log Deleted Service Helm Chart
176
177Ensure Service Unloaded
178 [Documentation] Unload the service if it is loaded.
179 Wait Until Keyword Succeeds 200s 2s CORD Get /xosapi/v1/core/users
180 ${resp}= Get Request ${SERVER_IP} uri=/xosapi/v1/dynamicload/load_status
181 Should Be Equal As Strings ${resp.status_code} 200
182 ${jsondata}= To Json ${resp.content}
183 ${length}= Get Length ${jsondata['services']}
184 : FOR ${INDEX} IN RANGE 0 ${length}
185 \ ${dict}= Get From List ${jsondata['services']} ${INDEX}
186 \ Run Keyword If "${dict['name']}" == "simpleexampleservice" and "${dict['state']}" == "present" Unload Service
187
188Unload Service
189 [Documentation] Unload the service
190 Log Unloading Service, with table purge
191 ${data}= Create Dictionary name=simpleexampleservice version=1.1.7 cleanup_behavior=2
192 ${data}= Evaluate json.dumps(${data}) json
193 ${resp}= Post Request ${SERVER_IP} uri=/xosapi/v1/dynamicload/unload_models data=${data}
194 Should Be Equal As Strings ${resp.status_code} 200
195 Log Successfully Unloaded