blob: e2031df2855e51a2625e7d614f79cc7f5da07709 [file] [log] [blame]
Scott Baker7651bfc2019-02-11 13:20:21 -08001*** Settings ***
2Documentation Test migration of a Service in the core
3Library RequestsLibrary
4Library HttpLibrary.HTTP
5Library Collections
6Library String
7Library OperatingSystem
8Library DateTime
9Library ../../Framework/utils/utils.py
10Resource ../../Framework/utils/utils.robot
11Library ../../Framework/restApi.py
12Variables ../../Properties/RestApiProperties.py
13Suite Setup Setup
14Suite Teardown Teardown
15
16*** Variables ***
17${timeout} 300s
18${repository} xosproject/simpleexampleservice-synchronizer
19${migration1} migration-test1
20${migration2} migration-test2
21${helm_chart} ~/cord/helm-charts/xos-services/simpleexampleservice
22${cleanup} ${true}
23
24*** Test Cases ***
25Ensure Clean Environment
26 [Documentation] Ensure the service is not installed and its endpoint is not being served
27 [Tags] test1
28 ${output}= Run helm ls | grep simpleexampleservice | wc -l
29 Should Be Equal As Integers ${output} 0
30 ${resp} = Get Request ${SERVER_IP} uri=/xosapi/v1/simpleexampleservice/simpleexampleservices
Scott Bakerbd429142019-02-20 14:59:48 -080031 Log ${resp.content}
Scott Baker7651bfc2019-02-11 13:20:21 -080032 Should Be Equal As Strings ${resp.status_code} 404
33
34Install initial version
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
40Create Model
41 [Documentation] Create a service model
42 [Tags] test3
43 ${model_name}= Generate Random Value string
44 ${data}= Create Dictionary name=${model_name} service_message=initial
45 ${data}= Evaluate json.dumps(${data}) json
46 ${resp}= CORD Post /xosapi/v1/simpleexampleservice/simpleexampleservices ${data}
47 ${json_content}= Evaluate json.loads('''${resp.content}''') json
48 ${model_id}= Get From Dictionary ${json_content} id
49 Set Suite Variable ${model_id}
50 Set Suite Variable ${model_name}
51
52Validate Service Version A
53 [Documentation] Validate fields from model in version A
54 [Tags] test4
55 ${resp} = CORD Get /xosapi/v1/simpleexampleservice/simpleexampleservices/${model_id}
56 ${jsondata} = To Json ${resp.content}
57 ${keys}= Get Dictionary Keys ${jsondata}
58 : FOR ${field} IN @{model_A_fields}
59 \ List Should Contain Value ${keys} ${field}
60 : FOR ${field} IN @{model_B_only_fields}
61 \ List Should Not Contain Value ${keys} ${field}
62 Should Be Equal As Strings ${jsondata['name']} ${model_name}
63 Should Be Equal As Strings ${jsondata['service_message']} initial
64
65Upgrade Service
66 [Documentation] Upgrade the version of the service to version B and wait for completion
67 [Tags] test5
68 ${rc}= Run And Return RC helm upgrade --set image.repository=${repository} --set image.tag=${migration2} --recreate-pods simpleexampleservice ${helm_chart}
69 Should Be Equal As Integers ${rc} 0
70 Wait Until Keyword Succeeds ${timeout} 5s Validate Service Running
71
72Validate Service Version B
73 [Documentation] Validate fields from model in upgraded version B (2.0.0)
74 [Tags] test6
75 ${resp} = CORD Get /xosapi/v1/simpleexampleservice/simpleexampleservices/${model_id}
76 ${jsondata} = To Json ${resp.content}
77 ${keys}= Get Dictionary Keys ${jsondata}
78 : FOR ${field} IN @{model_B_fields}
79 \ List Should Contain Value ${keys} ${field}
80 Should Be Equal As Strings ${jsondata['name']} ${model_name}
81 Should Be Equal As Strings ${jsondata['service_message']} initial
82 Should Be Equal As Strings ${jsondata['new_field']} new_stuff
83
84*** Keywords ***
85Setup
86 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
87 ${HEADERS} Create Dictionary Content-Type=application/json allow_modify_feedback=True
88 Create Session ${server_ip} http://${server_ip}:${server_port} auth=${AUTH} headers=${HEADERS}
89 @{model_A_fields}= Create List service_message service_secret
90 @{model_B_fields}= Create List service_message service_secret new_field
91 @{model_B_only_fields}= Create List new_field
92
93 Set Suite Variable @{model_A_fields}
94
95 Set Suite Variable @{model_B_fields}
96
97 Set Suite Variable @{model_B_only_fields}
98
99Teardown
100 [Documentation] Delete all https sessions
101 Run Keyword If ${cleanup} == ${true} Ensure Service Deleted
102 Run Keyword If ${cleanup} == ${true} Ensure Service Unloaded
103 Delete All Sessions
104
105Validate Service Running
106 # wait for helm chart to be deployed
107 ${output}= Run helm ls | grep simpleexampleservice | grep -i deployed | wc -l
108 Should Be Equal As Integers ${output} 1
109 # wait for the synchronizer pod to be running
110 ${output}= Run kubectl get pods | grep simpleexampleservice | grep -i running | grep 1/1 | wc -l
111 Should Be Equal As Integers ${output} 1
112 # wait for no other synchronizer pods to be terminating
113 ${output}= Run kubectl get pods | grep simpleexampleservice | grep -i terminating | wc -l
114 Should Be Equal As Integers ${output} 0
115 # wait for the endpoint to exist
116 ${resp} = CORD Get /xosapi/v1/simpleexampleservice/simpleexampleservices
117
118Ensure Service Deleted
119 ${output}= Run helm ls | grep simpleexampleservice | grep -i deployed | wc -l
120 Run Keyword If ${output} == 1 Delete Service
121
122Delete Service
123 Log Deleating Service Helm Chart
124 ${rc}= Run And Return RC helm del --purge simpleexampleservice
125 Should Be Equal As Integers ${rc} 0
126 Log Deleted Service Helm Chart
127
128Ensure Service Unloaded
129 [Documentation] Unload the service if it is loaded.
130 Wait Until Keyword Succeeds 200s 2s CORD Get /xosapi/v1/core/users
131 ${resp}= Get Request ${SERVER_IP} uri=/xosapi/v1/dynamicload/load_status
Scott Bakerbd429142019-02-20 14:59:48 -0800132 Log ${resp.content}
Scott Baker7651bfc2019-02-11 13:20:21 -0800133 Should Be Equal As Strings ${resp.status_code} 200
134 ${jsondata}= To Json ${resp.content}
135 ${length}= Get Length ${jsondata['services']}
136 : FOR ${INDEX} IN RANGE 0 ${length}
137 \ ${dict}= Get From List ${jsondata['services']} ${INDEX}
138 \ Run Keyword If "${dict['name']}" == "simpleexampleservice" and "${dict['state']}" == "present" Unload Service
139
140Unload Service
141 [Documentation] Unload the service
Scott Baker7b7a2dd2019-02-14 16:25:59 -0800142 Log Unloading Service, with table purge
143 ${data}= Create Dictionary name=simpleexampleservice version=1.1.7 cleanup_behavior=2
Scott Baker7651bfc2019-02-11 13:20:21 -0800144 ${data}= Evaluate json.dumps(${data}) json
Scott Bakerbd429142019-02-20 14:59:48 -0800145 Log ${data}
Scott Baker7651bfc2019-02-11 13:20:21 -0800146 ${resp}= Post Request ${SERVER_IP} uri=/xosapi/v1/dynamicload/unload_models data=${data}
Scott Bakerbd429142019-02-20 14:59:48 -0800147 Log ${resp.content}
Scott Baker7651bfc2019-02-11 13:20:21 -0800148 Should Be Equal As Strings ${resp.status_code} 200
149 Log Successfully Unloaded