VOL-2499 Robot testing framework for alarms
Change-Id: If8e66344f5bb84c242a3e16fe6b162c44f7d02f2
diff --git a/libraries/k8s.robot b/libraries/k8s.robot
index c3b67fe..24a1ca6 100644
--- a/libraries/k8s.robot
+++ b/libraries/k8s.robot
@@ -51,6 +51,41 @@
... kubectl delete pod ${restart_pod_name} -n ${namespace} --grace-period=0 --force
Log ${output}
+Exec Pod
+ [Arguments] ${namespace} ${name} ${command}
+ [Documentation] Uses kubectl to execute a command in the pod and return the output
+ ${rc} ${exec_pod_name}= Run and Return Rc and Output
+ ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}'
+ Log ${exec_pod_name}
+ Should Not Be Empty ${exec_pod_name} Unable to parse pod name
+ ${rc} ${output}= Run and Return Rc and Output
+ ... kubectl exec -i ${exec_pod_name} -n ${namespace} -- ${command}
+ Log ${output}
+ [return] ${output}
+
+Exec Pod Separate Stderr
+ [Arguments] ${namespace} ${name} ${command}
+ [Documentation] Uses kubectl to execute a command in the pod and return the stderr and stdout
+ ${rc} ${exec_pod_name}= Run and Return Rc and Output
+ ... kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}'
+ Log ${exec_pod_name}
+ Should Not Be Empty ${exec_pod_name} Unable to parse pod name
+ @{args}= Split String ${command}
+ ${result}= Run Process
+ ... kubectl exec -i ${exec_pod_name} -n ${namespace} -- @{args}
+ ${stdout}= Set Variable ${result.stdout}
+ ${stderr}= Set Variable ${result.stderr}
+ Log ${stdout}
+ Log ${stderr}
+ [return] ${stdout} ${stderr}
+
+Apply Kubernetes Resources
+ [Arguments] ${resource_yaml} ${namespace}
+ [Documentation] Use kubectl to create resources given a yaml file
+ ${rc} Run and Return Rc
+ ... kubectl apply -n ${namespace} -f ${resource_yaml}
+ Should Be Equal as Integers ${rc} 0
+
Validate Pod Status
[Arguments] ${pod_name} ${namespace} ${expectedStatus}
[Documentation] To run the kubectl command and check the status of the given pod matches the expected status
diff --git a/libraries/utils.robot b/libraries/utils.robot
index fed2694..779d987 100644
--- a/libraries/utils.robot
+++ b/libraries/utils.robot
@@ -320,3 +320,20 @@
... ${dst['dp_iface_name']}.${src['s_tag']} ${dst['ip']} ${dst['user']} ${dst['pass']}
... ${dst['container_type']} ${dst['container_name']}
END
+
+Should Be Larger Than
+ [Documentation] Verify that value_1 is > value_2
+ [Arguments] ${value_1} ${value_2}
+ Run Keyword If ${value_1} <= ${value_2}
+ ... Fail The value ${value_1} is not larger than ${value_2}
+
+Should Be Float
+ [Documentation] Verify that value is a floating point number type
+ [Arguments] ${value}
+ ${type} Evaluate type(${value}).__name__
+ Should Be Equal ${type} float
+
+Get Current Time
+ [Documentation] Return the current time in RFC3339 format
+ ${output}= Run date -u +"%FT%T%:z"
+ [return] ${output}
diff --git a/libraries/voltctl.robot b/libraries/voltctl.robot
index 87ec701..6c942db 100644
--- a/libraries/voltctl.robot
+++ b/libraries/voltctl.robot
@@ -384,6 +384,15 @@
Log ${sn}
[Return] ${sn}
+Get Parent ID From Device ID
+ [Arguments] ${device_id}
+ [Documentation] Gets the device id by matching for ${device_id}
+ ${rc} ${pid}= Run and Return Rc and Output
+ ... ${VOLTCTL_CONFIG}; voltctl device list --filter=Id=${device_id} --format='{{.ParentId}}'
+ Should Be Equal As Integers ${rc} 0
+ Log ${pid}
+ [Return] ${pid}
+
Validate Device Removed
[Arguments] ${id}
[Documentation] Verifys that device, ${serial_number}, has been removed