2 # Copyright 2020 Canonical Ltd.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 Documentation Library providing keywords for CRUD operations over Kubernetes clusters with OSM client.
19 Library OperatingSystem
23 ${SUCCESS_RETURN_CODE} 0
24 ${K8SCLUSTER_LAUNCH_MAX_WAIT_TIME} 6min
25 ${K8SCLUSTER_LAUNCH_POL_TIME} 30sec
26 ${K8SCLUSTER_DELETE_MAX_WAIT_TIME} 2min
27 ${K8SCLUSTER_DELETE_POL_TIME} 15sec
32 [Documentation] Register a Kubernetes cluster in OSM using the name, version and credentials passed as arguments.
33 [Arguments] ${k8scluster_creds} ${k8scluster_version} ${k8scluster_vim} ${k8scluster_net} ${k8scluster_name}
34 ${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"
36 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
37 Wait Until Keyword Succeeds ${K8SCLUSTER_LAUNCH_MAX_WAIT_TIME} ${K8SCLUSTER_LAUNCH_POL_TIME} Check For K8s Cluster To Be Ready ${k8scluster_name}
38 Check For K8s Cluster To Be Enabled ${k8scluster_name}
42 [Documentation] Unregister/delete a Kubernetes cluster from OSM.
43 [Arguments] ${k8scluster_name}
44 ${rc} ${stdout}= Run And Return Rc And Output osm k8scluster-delete ${k8scluster_name}
46 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
47 Wait Until Keyword Succeeds ${K8SCLUSTER_DELETE_MAX_WAIT_TIME} ${K8SCLUSTER_DELETE_POL_TIME} Check For K8s Cluster To Be Deleted ${k8scluster_name}
50 [Documentation] Get the list of Kubernetes clusters in OSM, and return it.
51 ${rc} ${stdout}= Run And Return Rc And Output osm k8scluster-list
52 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
57 [Documentation] Check if a Kubernetes cluster identified by name exists in OSM, and return it.
58 [Arguments] ${k8scluster_name}
59 ${rc} ${stdout}= Run And Return Rc And Output osm k8scluster-list --filter name="${k8scluster_name}"
60 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
63 Check For K8s Cluster To Be Deleted
64 [Documentation] Check if a Kubernetes cluster identified by name is not present in OSM.
65 [Arguments] ${k8scluster_name}
66 ${rc} ${stdout}= Run And Return Rc And Output osm k8scluster-list --filter name="${k8scluster_name}" | awk '{print $2}' | grep ${k8scluster_name}
68 Should Be Empty ${stdout}
70 Check For K8s Cluster To Be Ready
71 [Documentation] Check if a Kubernetes cluster registered in OSM is ready (the state must be ENABLED or DEGRADED).
72 [Arguments] ${k8scluster_name}
73 ${rc} ${stdout}= Run And Return Rc And Output osm k8scluster-list --filter name="${k8scluster_name}" --filter _admin.operationalState="ENABLED,DEGRADED"
75 ${rc} ${stdout}= Run And Return Rc And Output echo "${stdout}" | awk '{print $2}' | grep ${k8scluster_name}
77 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
78 Should Be Equal As Strings ${stdout} ${k8scluster_name}
80 Check For K8s Cluster To Be Enabled
81 [Documentation] Check if the state of Kubernetes cluster registered in OSM is ENABLED.
82 [Arguments] ${k8scluster_name}
83 ${rc} ${stdout}= Run And Return Rc And Output osm k8scluster-show ${k8scluster_name}
85 ${rc} ${stdout}= Run And Return Rc And Output osm k8scluster-list --filter name="${k8scluster_name}" --filter _admin.operationalState="ENABLED"
87 ${rc} ${stdout}= Run And Return Rc And Output echo "${stdout}" | awk '{print $2}' | grep ${k8scluster_name}
89 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
90 Should Be Equal As Strings ${stdout} ${k8scluster_name}