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