Scott Baker | 358b828 | 2019-02-21 15:11:51 -0800 | [diff] [blame] | 1 | # 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 Baker | 7651bfc | 2019-02-11 13:20:21 -0800 | [diff] [blame] | 20 | *** Settings *** |
| 21 | Documentation Test migration of a Service in the core |
| 22 | Library RequestsLibrary |
| 23 | Library HttpLibrary.HTTP |
| 24 | Library Collections |
| 25 | Library String |
| 26 | Library OperatingSystem |
| 27 | Library DateTime |
| 28 | Library ../../Framework/utils/utils.py |
| 29 | Resource ../../Framework/utils/utils.robot |
| 30 | Library ../../Framework/restApi.py |
| 31 | Variables ../../Properties/RestApiProperties.py |
| 32 | Suite Setup Setup |
| 33 | Suite Teardown Teardown |
| 34 | |
| 35 | *** Variables *** |
| 36 | ${timeout} 300s |
| 37 | ${repository} xosproject/simpleexampleservice-synchronizer |
| 38 | ${migration1} migration-test1 |
| 39 | ${migration2} migration-test2 |
Scott Baker | 358b828 | 2019-02-21 15:11:51 -0800 | [diff] [blame] | 40 | ${migration3} migration-test3 |
| 41 | ${migration4} migration-test4 |
Scott Baker | 7651bfc | 2019-02-11 13:20:21 -0800 | [diff] [blame] | 42 | ${helm_chart} ~/cord/helm-charts/xos-services/simpleexampleservice |
| 43 | ${cleanup} ${true} |
| 44 | |
| 45 | *** Test Cases *** |
| 46 | Ensure 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 Baker | bd42914 | 2019-02-20 14:59:48 -0800 | [diff] [blame] | 52 | Log ${resp.content} |
Scott Baker | 7651bfc | 2019-02-11 13:20:21 -0800 | [diff] [blame] | 53 | Should Be Equal As Strings ${resp.status_code} 404 |
| 54 | |
| 55 | Install 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 | |
| 61 | Create 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 Baker | 014b445 | 2019-02-21 08:36:38 -0800 | [diff] [blame] | 68 | ${json_content}= To Json ${resp.content} |
Scott Baker | 7651bfc | 2019-02-11 13:20:21 -0800 | [diff] [blame] | 69 | ${model_id}= Get From Dictionary ${json_content} id |
| 70 | Set Suite Variable ${model_id} |
| 71 | Set Suite Variable ${model_name} |
| 72 | |
| 73 | Validate 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 Baker | 358b828 | 2019-02-21 15:11:51 -0800 | [diff] [blame] | 83 | : FOR ${field} IN @{model_C_only_fields} |
| 84 | \ List Should Not Contain Value ${keys} ${field} |
Scott Baker | 7651bfc | 2019-02-11 13:20:21 -0800 | [diff] [blame] | 85 | Should Be Equal As Strings ${jsondata['name']} ${model_name} |
| 86 | Should Be Equal As Strings ${jsondata['service_message']} initial |
| 87 | |
Scott Baker | 358b828 | 2019-02-21 15:11:51 -0800 | [diff] [blame] | 88 | Upgrade Service To Version B |
| 89 | [Documentation] Upgrade the version of the service to version B (adds a new field) and wait for completion |
Scott Baker | 7651bfc | 2019-02-11 13:20:21 -0800 | [diff] [blame] | 90 | [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 | |
| 95 | Validate 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 Baker | 358b828 | 2019-02-21 15:11:51 -0800 | [diff] [blame] | 107 | Upgrade 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 | |
| 114 | Validate 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 | |
| 128 | Upgrade 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 | |
| 135 | Validate 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 Baker | 7651bfc | 2019-02-11 13:20:21 -0800 | [diff] [blame] | 150 | *** Keywords *** |
| 151 | Setup |
| 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 Baker | 222955a | 2019-03-29 09:56:59 -0700 | [diff] [blame] | 155 | @{model_A_fields}= Create List service_message |
| 156 | @{model_B_fields}= Create List service_message new_field |
Scott Baker | 7651bfc | 2019-02-11 13:20:21 -0800 | [diff] [blame] | 157 | @{model_B_only_fields}= Create List new_field |
Scott Baker | 222955a | 2019-03-29 09:56:59 -0700 | [diff] [blame] | 158 | @{model_C_fields}= Create List service_message renamed_new_field |
Scott Baker | 358b828 | 2019-02-21 15:11:51 -0800 | [diff] [blame] | 159 | @{model_C_only_fields}= Create List renamed_new_field |
Scott Baker | 222955a | 2019-03-29 09:56:59 -0700 | [diff] [blame] | 160 | @{model_D_fields}= Create List service_message |
Scott Baker | 7651bfc | 2019-02-11 13:20:21 -0800 | [diff] [blame] | 161 | |
| 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 Baker | 358b828 | 2019-02-21 15:11:51 -0800 | [diff] [blame] | 168 | 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 Baker | 7651bfc | 2019-02-11 13:20:21 -0800 | [diff] [blame] | 174 | Teardown |
| 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 | |
| 180 | Validate 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 | |
| 193 | Ensure Service Deleted |
| 194 | ${output}= Run helm ls | grep simpleexampleservice | grep -i deployed | wc -l |
| 195 | Run Keyword If ${output} == 1 Delete Service |
| 196 | |
| 197 | Delete 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 | |
| 203 | Ensure 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 Baker | bd42914 | 2019-02-20 14:59:48 -0800 | [diff] [blame] | 207 | Log ${resp.content} |
Scott Baker | 7651bfc | 2019-02-11 13:20:21 -0800 | [diff] [blame] | 208 | 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 | |
| 215 | Unload Service |
| 216 | [Documentation] Unload the service |
Scott Baker | 7b7a2dd | 2019-02-14 16:25:59 -0800 | [diff] [blame] | 217 | Log Unloading Service, with table purge |
| 218 | ${data}= Create Dictionary name=simpleexampleservice version=1.1.7 cleanup_behavior=2 |
Scott Baker | 7651bfc | 2019-02-11 13:20:21 -0800 | [diff] [blame] | 219 | ${data}= Evaluate json.dumps(${data}) json |
Scott Baker | bd42914 | 2019-02-20 14:59:48 -0800 | [diff] [blame] | 220 | Log ${data} |
Scott Baker | 7651bfc | 2019-02-11 13:20:21 -0800 | [diff] [blame] | 221 | ${resp}= Post Request ${SERVER_IP} uri=/xosapi/v1/dynamicload/unload_models data=${data} |
Scott Baker | bd42914 | 2019-02-20 14:59:48 -0800 | [diff] [blame] | 222 | Log ${resp.content} |
Scott Baker | 7651bfc | 2019-02-11 13:20:21 -0800 | [diff] [blame] | 223 | Should Be Equal As Strings ${resp.status_code} 200 |
| 224 | Log Successfully Unloaded |