blob: 0d042ca4e9b4ae9722bc362aecaf1b12433e5c11 [file] [log] [blame]
Scott Baker358b8282019-02-21 15:11:51 -08001# XOS Migration Tests
2#
3# This test progressively migrates a service through several versions.
4#
5# migration1 - initial version of simpleexampleservice, with 0001 script checked in
6# migration2 - add a "new_field" to the SimpleExampleService model:
7# required string new_field = 3 [
8# help_text = "New field to test data migration",
9# db_index = False,
10# default = "new_stuff"];
11# migration3 - rename "new_field" to "renamed_new_field":
12# required string renamed_new_field = 3 [
13# help_text = "New field to test data migration",
14# db_index = False,
15# default = "renamed_new_stuff"];
16# NOTE: Migration3 generated by xos-migrate has to be manually changed from remove+add to a rename
17# migrations4 - delete "new_field"
18
19
Scott Baker7651bfc2019-02-11 13:20:21 -080020*** Settings ***
21Documentation Test migration of a Service in the core
22Library RequestsLibrary
23Library HttpLibrary.HTTP
24Library Collections
25Library String
26Library OperatingSystem
27Library DateTime
28Library ../../Framework/utils/utils.py
29Resource ../../Framework/utils/utils.robot
30Library ../../Framework/restApi.py
31Variables ../../Properties/RestApiProperties.py
32Suite Setup Setup
33Suite Teardown Teardown
34
35*** Variables ***
36${timeout} 300s
37${repository} xosproject/simpleexampleservice-synchronizer
38${migration1} migration-test1
39${migration2} migration-test2
Scott Baker358b8282019-02-21 15:11:51 -080040${migration3} migration-test3
41${migration4} migration-test4
Scott Baker7651bfc2019-02-11 13:20:21 -080042${helm_chart} ~/cord/helm-charts/xos-services/simpleexampleservice
43${cleanup} ${true}
44
45*** Test Cases ***
46Ensure Clean Environment
47 [Documentation] Ensure the service is not installed and its endpoint is not being served
48 [Tags] test1
49 ${output}= Run helm ls | grep simpleexampleservice | wc -l
50 Should Be Equal As Integers ${output} 0
51 ${resp} = Get Request ${SERVER_IP} uri=/xosapi/v1/simpleexampleservice/simpleexampleservices
Scott Bakerbd429142019-02-20 14:59:48 -080052 Log ${resp.content}
Scott Baker7651bfc2019-02-11 13:20:21 -080053 Should Be Equal As Strings ${resp.status_code} 404
54
55Install initial version
56 [Documentation] Install version A of the service and wait for completion
57 [Tags] test2
58 Run helm install -n simpleexampleservice --set image.repository=${repository} --set image.tag=${migration1} ${helm_chart}
59 Wait Until Keyword Succeeds ${timeout} 5s Validate Service Running
60
61Create Model
62 [Documentation] Create a service model
63 [Tags] test3
64 ${model_name}= Generate Random Value string
65 ${data}= Create Dictionary name=${model_name} service_message=initial
66 ${data}= Evaluate json.dumps(${data}) json
67 ${resp}= CORD Post /xosapi/v1/simpleexampleservice/simpleexampleservices ${data}
Scott Baker014b4452019-02-21 08:36:38 -080068 ${json_content}= To Json ${resp.content}
Scott Baker7651bfc2019-02-11 13:20:21 -080069 ${model_id}= Get From Dictionary ${json_content} id
70 Set Suite Variable ${model_id}
71 Set Suite Variable ${model_name}
72
73Validate Service Version A
74 [Documentation] Validate fields from model in version A
75 [Tags] test4
76 ${resp} = CORD Get /xosapi/v1/simpleexampleservice/simpleexampleservices/${model_id}
77 ${jsondata} = To Json ${resp.content}
78 ${keys}= Get Dictionary Keys ${jsondata}
79 : FOR ${field} IN @{model_A_fields}
80 \ List Should Contain Value ${keys} ${field}
81 : FOR ${field} IN @{model_B_only_fields}
82 \ List Should Not Contain Value ${keys} ${field}
Scott Baker358b8282019-02-21 15:11:51 -080083 : FOR ${field} IN @{model_C_only_fields}
84 \ List Should Not Contain Value ${keys} ${field}
Scott Baker7651bfc2019-02-11 13:20:21 -080085 Should Be Equal As Strings ${jsondata['name']} ${model_name}
86 Should Be Equal As Strings ${jsondata['service_message']} initial
87
Scott Baker358b8282019-02-21 15:11:51 -080088Upgrade Service To Version B
89 [Documentation] Upgrade the version of the service to version B (adds a new field) and wait for completion
Scott Baker7651bfc2019-02-11 13:20:21 -080090 [Tags] test5
91 ${rc}= Run And Return RC helm upgrade --set image.repository=${repository} --set image.tag=${migration2} --recreate-pods simpleexampleservice ${helm_chart}
92 Should Be Equal As Integers ${rc} 0
93 Wait Until Keyword Succeeds ${timeout} 5s Validate Service Running
94
95Validate Service Version B
96 [Documentation] Validate fields from model in upgraded version B (2.0.0)
97 [Tags] test6
98 ${resp} = CORD Get /xosapi/v1/simpleexampleservice/simpleexampleservices/${model_id}
99 ${jsondata} = To Json ${resp.content}
100 ${keys}= Get Dictionary Keys ${jsondata}
101 : FOR ${field} IN @{model_B_fields}
102 \ List Should Contain Value ${keys} ${field}
103 Should Be Equal As Strings ${jsondata['name']} ${model_name}
104 Should Be Equal As Strings ${jsondata['service_message']} initial
105 Should Be Equal As Strings ${jsondata['new_field']} new_stuff
106
Scott Baker358b8282019-02-21 15:11:51 -0800107Upgrade Service To Version C
108 [Documentation] Upgrade the version of the service to version C (renames a field) and wait for completion
109 [Tags] test7
110 ${rc}= Run And Return RC helm upgrade --set image.repository=${repository} --set image.tag=${migration3} --recreate-pods simpleexampleservice ${helm_chart}
111 Should Be Equal As Integers ${rc} 0
112 Wait Until Keyword Succeeds ${timeout} 5s Validate Service Running
113
114Validate Service Version C
115 [Documentation] Validate fields from model in upgraded version B (2.0.0)
116 [Tags] test8
117 ${resp} = CORD Get /xosapi/v1/simpleexampleservice/simpleexampleservices/${model_id}
118 ${jsondata} = To Json ${resp.content}
119 ${keys}= Get Dictionary Keys ${jsondata}
120 : FOR ${field} IN @{model_C_fields}
121 \ List Should Contain Value ${keys} ${field}
122 : FOR ${field} IN @{model_B_only_fields}
123 \ List Should Not Contain Value ${keys} ${field}
124 Should Be Equal As Strings ${jsondata['name']} ${model_name}
125 Should Be Equal As Strings ${jsondata['service_message']} initial
126 Should Be Equal As Strings ${jsondata['renamed_new_field']} new_stuff
127
128Upgrade Service To Version D
129 [Documentation] Upgrade the version of the service to version D (deletes a field) and wait for completion
130 [Tags] test9
131 ${rc}= Run And Return RC helm upgrade --set image.repository=${repository} --set image.tag=${migration4} --recreate-pods simpleexampleservice ${helm_chart}
132 Should Be Equal As Integers ${rc} 0
133 Wait Until Keyword Succeeds ${timeout} 5s Validate Service Running
134
135Validate Service Version D
136 [Documentation] Validate fields from model in version D
137 [Tags] test10
138 ${resp} = CORD Get /xosapi/v1/simpleexampleservice/simpleexampleservices/${model_id}
139 ${jsondata} = To Json ${resp.content}
140 ${keys}= Get Dictionary Keys ${jsondata}
141 : FOR ${field} IN @{model_D_fields}
142 \ List Should Contain Value ${keys} ${field}
143 : FOR ${field} IN @{model_B_only_fields}
144 \ List Should Not Contain Value ${keys} ${field}
145 : FOR ${field} IN @{model_C_only_fields}
146 \ List Should Not Contain Value ${keys} ${field}
147 Should Be Equal As Strings ${jsondata['name']} ${model_name}
148 Should Be Equal As Strings ${jsondata['service_message']} initial
149
Scott Baker7651bfc2019-02-11 13:20:21 -0800150*** Keywords ***
151Setup
152 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
153 ${HEADERS} Create Dictionary Content-Type=application/json allow_modify_feedback=True
154 Create Session ${server_ip} http://${server_ip}:${server_port} auth=${AUTH} headers=${HEADERS}
Scott Baker222955a2019-03-29 09:56:59 -0700155 @{model_A_fields}= Create List service_message
156 @{model_B_fields}= Create List service_message new_field
Scott Baker7651bfc2019-02-11 13:20:21 -0800157 @{model_B_only_fields}= Create List new_field
Scott Baker222955a2019-03-29 09:56:59 -0700158 @{model_C_fields}= Create List service_message renamed_new_field
Scott Baker358b8282019-02-21 15:11:51 -0800159 @{model_C_only_fields}= Create List renamed_new_field
Scott Baker222955a2019-03-29 09:56:59 -0700160 @{model_D_fields}= Create List service_message
Scott Baker7651bfc2019-02-11 13:20:21 -0800161
162 Set Suite Variable @{model_A_fields}
163
164 Set Suite Variable @{model_B_fields}
165
166 Set Suite Variable @{model_B_only_fields}
167
Scott Baker358b8282019-02-21 15:11:51 -0800168 Set Suite Variable @{model_C_fields}
169
170 Set Suite Variable @{model_C_only_fields}
171
172 Set Suite Variable @{model_D_fields}
173
Scott Baker7651bfc2019-02-11 13:20:21 -0800174Teardown
175 [Documentation] Delete all https sessions
176 Run Keyword If ${cleanup} == ${true} Ensure Service Deleted
177 Run Keyword If ${cleanup} == ${true} Ensure Service Unloaded
178 Delete All Sessions
179
180Validate Service Running
181 # wait for helm chart to be deployed
182 ${output}= Run helm ls | grep simpleexampleservice | grep -i deployed | wc -l
183 Should Be Equal As Integers ${output} 1
184 # wait for the synchronizer pod to be running
185 ${output}= Run kubectl get pods | grep simpleexampleservice | grep -i running | grep 1/1 | wc -l
186 Should Be Equal As Integers ${output} 1
187 # wait for no other synchronizer pods to be terminating
188 ${output}= Run kubectl get pods | grep simpleexampleservice | grep -i terminating | wc -l
189 Should Be Equal As Integers ${output} 0
190 # wait for the endpoint to exist
191 ${resp} = CORD Get /xosapi/v1/simpleexampleservice/simpleexampleservices
192
193Ensure Service Deleted
194 ${output}= Run helm ls | grep simpleexampleservice | grep -i deployed | wc -l
195 Run Keyword If ${output} == 1 Delete Service
196
197Delete Service
198 Log Deleating Service Helm Chart
199 ${rc}= Run And Return RC helm del --purge simpleexampleservice
200 Should Be Equal As Integers ${rc} 0
201 Log Deleted Service Helm Chart
202
203Ensure Service Unloaded
204 [Documentation] Unload the service if it is loaded.
205 Wait Until Keyword Succeeds 200s 2s CORD Get /xosapi/v1/core/users
206 ${resp}= Get Request ${SERVER_IP} uri=/xosapi/v1/dynamicload/load_status
Scott Bakerbd429142019-02-20 14:59:48 -0800207 Log ${resp.content}
Scott Baker7651bfc2019-02-11 13:20:21 -0800208 Should Be Equal As Strings ${resp.status_code} 200
209 ${jsondata}= To Json ${resp.content}
210 ${length}= Get Length ${jsondata['services']}
211 : FOR ${INDEX} IN RANGE 0 ${length}
212 \ ${dict}= Get From List ${jsondata['services']} ${INDEX}
213 \ Run Keyword If "${dict['name']}" == "simpleexampleservice" and "${dict['state']}" == "present" Unload Service
214
215Unload Service
216 [Documentation] Unload the service
Scott Baker7b7a2dd2019-02-14 16:25:59 -0800217 Log Unloading Service, with table purge
218 ${data}= Create Dictionary name=simpleexampleservice version=1.1.7 cleanup_behavior=2
Scott Baker7651bfc2019-02-11 13:20:21 -0800219 ${data}= Evaluate json.dumps(${data}) json
Scott Bakerbd429142019-02-20 14:59:48 -0800220 Log ${data}
Scott Baker7651bfc2019-02-11 13:20:21 -0800221 ${resp}= Post Request ${SERVER_IP} uri=/xosapi/v1/dynamicload/unload_models data=${data}
Scott Bakerbd429142019-02-20 14:59:48 -0800222 Log ${resp.content}
Scott Baker7651bfc2019-02-11 13:20:21 -0800223 Should Be Equal As Strings ${resp.status_code} 200
224 Log Successfully Unloaded