[VOL-3844] Test for ONOS apps minor version upgrade
[VOL-3843] Test for Voltha components minor version upgrade
Change-Id: Iae981056d92c461d67419ef3a1107c86a5aa231b
diff --git a/libraries/k8s.robot b/libraries/k8s.robot
index 63b9efe..a8312e6 100755
--- a/libraries/k8s.robot
+++ b/libraries/k8s.robot
@@ -351,7 +351,7 @@
[Arguments] ${namespace} ${key} ${value}
[Documentation] Uses kubectl to scale a deployment given the app name of the pod
${rc} ${name} Run And Return Rc And Output
- ... kubectl describe rs -n ${namespace} -l ${key}=${value} | grep "Controlled By" | awk -F'/' '{print $2}'
+ ... kubectl describe rs -n ${namespace} -l ${key}=${value} | grep "Controlled By" | awk -F'/' '{print $2}' | awk 'FNR == 1'
Should Be Equal as Integers ${rc} 0
[Return] ${name}
@@ -461,3 +461,38 @@
${rc} ${count} Run and Return Rc and Output
... kubectl -n ${namespace} get pods -l ${key}=${value} -o name | wc -l
[Return] ${count}
+
+Get Pod Restart Count
+ [Arguments] ${namespace} ${name}
+ [Documentation] Returns the restart count for the given Pod
+ ${rc} ${count}= Run and Return Rc and Output
+ ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $4}'
+ [Return] ${count}
+
+Verify ONOS Pod Restart
+ [Arguments] ${restarted}=True
+ [Documentation] Verifies if any of the given ONOS instances restarted
+ ${num_onos}= Wait Until Keyword Succeeds 20s 5s Get Number of Running Pods Number By Label default
+ ... app onos-onos-classic
+ FOR ${I} IN RANGE 0 ${num_onos}
+ ${onos_pod}= Catenate SEPARATOR=- onos-onos-classic ${I}
+ ${count}= Get Pod Restart Count default ${onos_pod}
+ Run Keyword If ${restarted}
+ ... Should Not Be Equal As Integers ${count} 0 ONOS Pod ${onos_pod} Not Restarted
+ ... ELSE
+ ... Should Be Equal As Integers ${count} 0 ONOS Pod ${onos_pod} Restarted
+ END
+
+Deploy Pod New Image
+ [Arguments] ${namespace} ${deployment} ${container} ${image}
+ [Documentation] Deploys the Pod given image
+ ${rc} Run and Return Rc
+ ... kubectl -n ${namespace} set image deployment/${deployment} ${container}=${image}
+ Should Be Equal as Integers ${rc} 0
+
+Verify Pod Image
+ [Arguments] ${namespace} ${key} ${value} ${image}
+ [Documentation] Verifies the Pod Image
+ ${output}= Run
+ ... kubectl -n ${namespace} get pods -l ${key}=${value} -o=jsonpath="{.items[].status.containerStatuses[].image}"
+ Should Be Equal '${output}' 'docker.io/${image}'
diff --git a/libraries/onos.robot b/libraries/onos.robot
index e0288b3..3225d5f 100755
--- a/libraries/onos.robot
+++ b/libraries/onos.robot
@@ -720,3 +720,33 @@
Should Be Equal As Integers ${dhcp_count} 0
# Close ONOS SSH Connection
Close ONOS SSH Connection ${onos_ssh_connection}
+
+Delete ONOS App
+ [Arguments] ${url} ${app_name}
+ [Documentation] This keyword deactivates and uninstalls the given ONOS App
+ ${rc}= Run And Return Rc curl --fail -sSL -X DELETE ${url}/onos/v1/applications/${app_name}
+ Should Be Equal As Integers ${rc} 0
+
+Verify ONOS App Active
+ [Arguments] ${url} ${app_name} ${app_version}=${EMPTY}
+ [Documentation] This keyword verifies that the given ONOS App status is Active
+ ${rc} ${output} Run And Return Rc And Output
+ ... curl --fail -sSL ${url}/onos/v1/applications/${app_name} | jq -r .state
+ Should Be Equal As Integers ${rc} 0
+ Should Be Equal '${output}' 'ACTIVE'
+ ${rc1} ${output1} Run And Return Rc And Output
+ ... curl --fail -sSL ${url}/onos/v1/applications/${app_name} | jq -r .version
+ Run Keyword If '${app_version}'!='${EMPTY}'
+ ... Run Keywords
+ ... Should Be Equal As Integers ${rc1} 0
+ ... AND Should Be Equal '${output1}' '${app_version}'
+
+Install And Activate ONOS App
+ [Arguments] ${url} ${app_oar_file}
+ [Documentation] This keyword installs and activates the given ONOS App
+ ${cmd}= Catenate SEPARATOR=
+ ... curl --fail -sSL -H Content-Type:application/octet-stream -
+ ... X POST ${url}/onos/v1/applications?activate=true --data-binary \@${app_oar_file}
+ ${rc} ${output} Run And Return Rc And Output ${cmd}
+ Should Be Equal As Integers ${rc} 0
+ Log ${output}