SEBA-178 add renamed field test to migration test
Change-Id: I3a49b3a60bb471da12207c83c57211d94168aac2
diff --git a/src/test/cord-api/Tests/XosScaleValidations/xos-service-migrations.robot b/src/test/cord-api/Tests/XosScaleValidations/xos-service-migrations.robot
index d5c89bd..227703b 100644
--- a/src/test/cord-api/Tests/XosScaleValidations/xos-service-migrations.robot
+++ b/src/test/cord-api/Tests/XosScaleValidations/xos-service-migrations.robot
@@ -1,3 +1,22 @@
+# XOS Migration Tests
+#
+# This test progressively migrates a service through several versions.
+#
+# migration1 - initial version of simpleexampleservice, with 0001 script checked in
+# migration2 - add a "new_field" to the SimpleExampleService model:
+# required string new_field = 3 [
+# help_text = "New field to test data migration",
+# db_index = False,
+# default = "new_stuff"];
+# migration3 - rename "new_field" to "renamed_new_field":
+# required string renamed_new_field = 3 [
+# help_text = "New field to test data migration",
+# db_index = False,
+# default = "renamed_new_stuff"];
+# NOTE: Migration3 generated by xos-migrate has to be manually changed from remove+add to a rename
+# migrations4 - delete "new_field"
+
+
*** Settings ***
Documentation Test migration of a Service in the core
Library RequestsLibrary
@@ -18,6 +37,8 @@
${repository} xosproject/simpleexampleservice-synchronizer
${migration1} migration-test1
${migration2} migration-test2
+${migration3} migration-test3
+${migration4} migration-test4
${helm_chart} ~/cord/helm-charts/xos-services/simpleexampleservice
${cleanup} ${true}
@@ -59,11 +80,13 @@
\ List Should Contain Value ${keys} ${field}
: FOR ${field} IN @{model_B_only_fields}
\ List Should Not Contain Value ${keys} ${field}
+ : FOR ${field} IN @{model_C_only_fields}
+ \ List Should Not Contain Value ${keys} ${field}
Should Be Equal As Strings ${jsondata['name']} ${model_name}
Should Be Equal As Strings ${jsondata['service_message']} initial
-Upgrade Service
- [Documentation] Upgrade the version of the service to version B and wait for completion
+Upgrade Service To Version B
+ [Documentation] Upgrade the version of the service to version B (adds a new field) and wait for completion
[Tags] test5
${rc}= Run And Return RC helm upgrade --set image.repository=${repository} --set image.tag=${migration2} --recreate-pods simpleexampleservice ${helm_chart}
Should Be Equal As Integers ${rc} 0
@@ -81,6 +104,49 @@
Should Be Equal As Strings ${jsondata['service_message']} initial
Should Be Equal As Strings ${jsondata['new_field']} new_stuff
+Upgrade Service To Version C
+ [Documentation] Upgrade the version of the service to version C (renames a field) and wait for completion
+ [Tags] test7
+ ${rc}= Run And Return RC helm upgrade --set image.repository=${repository} --set image.tag=${migration3} --recreate-pods simpleexampleservice ${helm_chart}
+ Should Be Equal As Integers ${rc} 0
+ Wait Until Keyword Succeeds ${timeout} 5s Validate Service Running
+
+Validate Service Version C
+ [Documentation] Validate fields from model in upgraded version B (2.0.0)
+ [Tags] test8
+ ${resp} = CORD Get /xosapi/v1/simpleexampleservice/simpleexampleservices/${model_id}
+ ${jsondata} = To Json ${resp.content}
+ ${keys}= Get Dictionary Keys ${jsondata}
+ : FOR ${field} IN @{model_C_fields}
+ \ List Should Contain Value ${keys} ${field}
+ : FOR ${field} IN @{model_B_only_fields}
+ \ List Should Not Contain Value ${keys} ${field}
+ Should Be Equal As Strings ${jsondata['name']} ${model_name}
+ Should Be Equal As Strings ${jsondata['service_message']} initial
+ Should Be Equal As Strings ${jsondata['renamed_new_field']} new_stuff
+
+Upgrade Service To Version D
+ [Documentation] Upgrade the version of the service to version D (deletes a field) and wait for completion
+ [Tags] test9
+ ${rc}= Run And Return RC helm upgrade --set image.repository=${repository} --set image.tag=${migration4} --recreate-pods simpleexampleservice ${helm_chart}
+ Should Be Equal As Integers ${rc} 0
+ Wait Until Keyword Succeeds ${timeout} 5s Validate Service Running
+
+Validate Service Version D
+ [Documentation] Validate fields from model in version D
+ [Tags] test10
+ ${resp} = CORD Get /xosapi/v1/simpleexampleservice/simpleexampleservices/${model_id}
+ ${jsondata} = To Json ${resp.content}
+ ${keys}= Get Dictionary Keys ${jsondata}
+ : FOR ${field} IN @{model_D_fields}
+ \ List Should Contain Value ${keys} ${field}
+ : FOR ${field} IN @{model_B_only_fields}
+ \ List Should Not Contain Value ${keys} ${field}
+ : FOR ${field} IN @{model_C_only_fields}
+ \ List Should Not Contain Value ${keys} ${field}
+ Should Be Equal As Strings ${jsondata['name']} ${model_name}
+ Should Be Equal As Strings ${jsondata['service_message']} initial
+
*** Keywords ***
Setup
${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
@@ -89,6 +155,9 @@
@{model_A_fields}= Create List service_message service_secret
@{model_B_fields}= Create List service_message service_secret new_field
@{model_B_only_fields}= Create List new_field
+ @{model_C_fields}= Create List service_message service_secret renamed_new_field
+ @{model_C_only_fields}= Create List renamed_new_field
+ @{model_D_fields}= Create List service_message service_secret
Set Suite Variable @{model_A_fields}
@@ -96,6 +165,12 @@
Set Suite Variable @{model_B_only_fields}
+ Set Suite Variable @{model_C_fields}
+
+ Set Suite Variable @{model_C_only_fields}
+
+ Set Suite Variable @{model_D_fields}
+
Teardown
[Documentation] Delete all https sessions
Run Keyword If ${cleanup} == ${true} Ensure Service Deleted