Scott Baker | 7b7a2dd | 2019-02-14 16:25:59 -0800 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation Test remove of a service |
| 3 | Library RequestsLibrary |
| 4 | Library HttpLibrary.HTTP |
| 5 | Library Collections |
| 6 | Library String |
| 7 | Library OperatingSystem |
| 8 | Library DateTime |
| 9 | Library ../../Framework/utils/utils.py |
| 10 | Library DatabaseLibrary |
| 11 | Resource ../../Framework/utils/utils.robot |
| 12 | Library ../../Framework/restApi.py |
| 13 | Variables ../../Properties/RestApiProperties.py |
| 14 | Suite Setup Setup |
| 15 | Suite 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 *** |
| 26 | Ensure 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 Baker | bd42914 | 2019-02-20 14:59:48 -0800 | [diff] [blame] | 32 | Log ${resp.content} |
Scott Baker | 7b7a2dd | 2019-02-14 16:25:59 -0800 | [diff] [blame] | 33 | Should Be Equal As Strings ${resp.status_code} 404 |
| 34 | |
| 35 | Install 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 | |
| 41 | Verify 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 | |
| 50 | Verify 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 | |
| 55 | Create 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 Baker | 014b445 | 2019-02-21 08:36:38 -0800 | [diff] [blame] | 62 | ${json_content}= To Json ${resp.content} |
Scott Baker | 7b7a2dd | 2019-02-14 16:25:59 -0800 | [diff] [blame] | 63 | ${model_id}= Get From Dictionary ${json_content} id |
| 64 | Set Suite Variable ${model_id} |
| 65 | Set Suite Variable ${model_name} |
| 66 | |
| 67 | Delete 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 | |
| 73 | Unload 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 Baker | bd42914 | 2019-02-20 14:59:48 -0800 | [diff] [blame] | 79 | Log ${resp.content} |
Scott Baker | 7b7a2dd | 2019-02-14 16:25:59 -0800 | [diff] [blame] | 80 | Should Be Equal As Strings ${resp.status_code} 409 |
| 81 | |
| 82 | Unload Service Automatic Cleanup |
| 83 | [Documentation] Unload the service |
| 84 | [Tags] test8 |
Scott Baker | 5f443f2 | 2019-02-20 19:33:32 -0800 | [diff] [blame] | 85 | # 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 Baker | 7b7a2dd | 2019-02-14 16:25:59 -0800 | [diff] [blame] | 87 | |
| 88 | Verify 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 | |
| 93 | Verify 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 | |
| 102 | Verify 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 *** |
| 109 | Setup |
| 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 Baker | 222955a | 2019-03-29 09:56:59 -0700 | [diff] [blame] | 113 | @{model_A_fields}= Create List service_message |
| 114 | @{model_B_fields}= Create List service_message new_field |
Scott Baker | 7b7a2dd | 2019-02-14 16:25:59 -0800 | [diff] [blame] | 115 | @{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 | |
| 126 | Teardown |
| 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 | |
| 133 | Validate 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 | |
| 146 | Validate 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 | |
| 156 | Validate Service Not Served |
| 157 | # endpoint should not be served |
| 158 | ${resp} = Get Request ${SERVER_IP} uri=/xosapi/v1/simpleexampleservice/simpleexampleservices |
Scott Baker | bd42914 | 2019-02-20 14:59:48 -0800 | [diff] [blame] | 159 | Log ${resp.content} |
Scott Baker | 7b7a2dd | 2019-02-14 16:25:59 -0800 | [diff] [blame] | 160 | 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 | |
| 164 | Ensure Service Deleted |
| 165 | ${output}= Run helm ls | grep simpleexampleservice | grep -i deployed | wc -l |
| 166 | Run Keyword If ${output} == 1 Delete Service |
| 167 | |
| 168 | Delete 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 | |
| 174 | Ensure 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 Baker | bd42914 | 2019-02-20 14:59:48 -0800 | [diff] [blame] | 178 | Log ${resp.content} |
Scott Baker | 7b7a2dd | 2019-02-14 16:25:59 -0800 | [diff] [blame] | 179 | 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 | |
| 186 | Unload 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 Baker | bd42914 | 2019-02-20 14:59:48 -0800 | [diff] [blame] | 192 | Log ${resp.content} |
Scott Baker | 7b7a2dd | 2019-02-14 16:25:59 -0800 | [diff] [blame] | 193 | Should Be Equal As Strings ${resp.status_code} 200 |
| 194 | Log Successfully Unloaded |
Scott Baker | 5f443f2 | 2019-02-20 19:33:32 -0800 | [diff] [blame] | 195 | |
| 196 | Unload 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 Baker | 014b445 | 2019-02-21 08:36:38 -0800 | [diff] [blame] | 204 | Should Be Equal As Strings ${jsondata["status"]} SUCCESS_NOTHING_CHANGED |