KUBERNETES K8s-02 Robot Test
Change-Id: Ib5ad818386c5c63daada979785b07ce3f0eeb63e
Signed-off-by: calvinosanc1 <guillermo.calvino@canonical.com>
diff --git a/robot-systest/environment.rc b/robot-systest/environment.rc
index a459e47..80673a8 100644
--- a/robot-systest/environment.rc
+++ b/robot-systest/environment.rc
@@ -18,3 +18,4 @@
# export PACKAGES_FOLDER=<PACKAGES_FOLDER=>
# export ROBOT_DEVOPS_FOLDER=<ROBOT_DEVOPS_FOLDER>
# export ROBOT_REPORT_FOLDER=<ROBOT_REPORT_FOLDER>
+# export K8S_CREDENTIALS=<KUBECONFIG.yaml>
diff --git a/robot-systest/lib/k8scluster_lib.robot b/robot-systest/lib/k8scluster_lib.robot
new file mode 100644
index 0000000..3896941
--- /dev/null
+++ b/robot-systest/lib/k8scluster_lib.robot
@@ -0,0 +1,58 @@
+# Copyright 2020 Canonical Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+*** Variables ***
+${success_return_code} 0
+${k8scluster_launch_max_wait_time} 2min
+${k8scluster_launch_pol_time} 30sec
+${k8scluster_delete_max_wait_time} 2min
+${k8scluster_delete_pol_time} 15sec
+
+*** Keywords ***
+Create K8s Cluster
+ [Arguments] ${k8scluster_creds} ${k8scluster_version} ${k8scluster_vim} ${k8scluster_net} ${k8scluster_name}
+ ${rc} ${stdout}= Run and Return RC and Output osm k8scluster-add --creds ${k8scluster_creds} --version ${k8scluster_version} --vim ${k8scluster_vim} --k8s-nets '{"net1": "${k8scluster_net}"}' ${k8scluster_name} --description "Robot cluster"
+ log ${stdout}
+ Should Be Equal As Integers ${rc} ${success_return_code}
+ WAIT UNTIL KEYWORD SUCCEEDS ${k8scluster_launch_max_wait_time} ${k8scluster_launch_pol_time} Check For K8s Cluster To Be Ready ${k8scluster_name}
+ [Return] ${stdout}
+
+Delete K8s Cluster
+ [Arguments] ${k8scluster_name}
+ ${rc} ${stdout}= Run and Return RC and Output osm k8scluster-delete ${k8scluster_name}
+ Should Be Equal As Integers ${rc} ${success_return_code}
+ WAIT UNTIL KEYWORD SUCCEEDS ${k8scluster_delete_max_wait_time} ${k8scluster_delete_pol_time} Check For K8s Cluster To Be Deleted ${k8scluster_name}
+
+Get K8s Cluster
+ ${rc} ${stdout}= Run and Return RC and Output osm k8scluster-list
+ Should Be Equal As Integers ${rc} ${success_return_code}
+ log ${stdout}
+ [Return] ${stdout}
+
+Check for K8s Cluster
+ [Arguments] ${k8scluster_name}
+ ${rc} ${stdout}= Run and Return RC and Output osm k8scluster-list --filter name="${k8scluster_name}"
+ Should Be Equal As Integers ${rc} ${success_return_code}
+ [Return] ${stdout}
+
+Check For K8s Cluster To Be Deleted
+ [Arguments] ${k8scluster_name}
+ ${rc} ${stdout}= Run and Return RC and Output osm k8scluster-list --filter name="${k8scluster_name}" | awk '{print $2}' | grep ${k8scluster_name}
+ Should Be Empty ${stdout}
+
+Check For K8s Cluster To Be Ready
+ [Arguments] ${k8scluster_name}
+ ${rc} ${stdout}= Run and Return RC and Output osm k8scluster-list --filter name="${k8scluster_name}" --filter _admin.operationalState="ENABLED" | awk '{print $2}' | grep ${k8scluster_name}
+ Should Be Equal As Integers ${rc} ${success_return_code}
+ Should Be Equal As Strings ${stdout} ${k8scluster_name}
diff --git a/robot-systest/resources/k8s_02-k8scluster_creation_data.py b/robot-systest/resources/k8s_02-k8scluster_creation_data.py
new file mode 100644
index 0000000..8a816ab
--- /dev/null
+++ b/robot-systest/resources/k8s_02-k8scluster_creation_data.py
@@ -0,0 +1,24 @@
+# Copyright 2020 Canonical Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from pathlib import Path
+
+# Get ${HOME} from local machine
+home = str(Path.home())
+# K8s cluster name
+k8scluster_name = 'k8s-test'
+k8scluster_version = 'v1'
+# SSH keys to be used
+publickey = home + '/.ssh/id_rsa.pub'
+privatekey = home + '/.ssh/id_rsa'
diff --git a/robot-systest/testsuite/k8s_02-k8scluster_creation.robot b/robot-systest/testsuite/k8s_02-k8scluster_creation.robot
new file mode 100644
index 0000000..5f3dfad
--- /dev/null
+++ b/robot-systest/testsuite/k8s_02-k8scluster_creation.robot
@@ -0,0 +1,44 @@
+# Copyright 2020 Canonical Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+*** Settings ***
+Library OperatingSystem
+Library String
+Library Collections
+Library Process
+
+Resource %{ROBOT_DEVOPS_FOLDER}/lib/k8scluster_lib.robot
+
+Variables %{ROBOT_DEVOPS_FOLDER}/resources/k8s_02-k8scluster_creation_data.py
+
+Suite Teardown Run Keyword And Ignore Error Test Cleanup
+
+*** Test Cases ***
+Add K8s Cluster To OSM
+ [Tags] k8scluster
+ Create K8s Cluster %{K8S_CREDENTIALS} ${k8scluster_version} %{VIM_TARGET} %{VIM_MGMT_NET} ${k8scluster_name}
+
+List K8s Clusters
+ [Tags] k8scluster
+ ${stdout}= Get K8s Cluster
+ Log To Console \n${stdout}
+
+Remove K8s Cluster from OSM
+ [Tags] k8scluster
+ Delete K8s Cluster ${k8scluster_name}
+
+*** Keywords ***
+Test Cleanup
+ [Documentation] Test Suit Cleanup: Deleting K8s Cluster
+ Run Keyword If Test Failed Delete K8s Cluster ${k8scluster_name}