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}
41 [Documentation] Unregister/delete a Kubernetes cluster from OSM.
42 [Arguments] ${k8scluster_name}
43 ${rc} ${stdout}= Run And Return Rc And Output osm k8scluster-delete ${k8scluster_name}
45 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
46 Wait Until Keyword Succeeds ${K8SCLUSTER_DELETE_MAX_WAIT_TIME} ${K8SCLUSTER_DELETE_POL_TIME} Check For K8s Cluster To Be Deleted ${k8scluster_name}
49 [Documentation] Get the list of Kubernetes clusters in OSM, and return it.
50 ${rc} ${stdout}= Run And Return Rc And Output osm k8scluster-list
51 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
56 [Documentation] Check if a Kubernetes cluster identified by name exists in OSM, and return it.
57 [Arguments] ${k8scluster_name}
58 ${rc} ${stdout}= Run And Return Rc And Output osm k8scluster-list --filter name="${k8scluster_name}"
59 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
62 Check For K8s Cluster To Be Deleted
63 [Documentation] Check if a Kubernetes cluster identified by name is not present in OSM.
64 [Arguments] ${k8scluster_name}
65 ${rc} ${stdout}= Run And Return Rc And Output osm k8scluster-list --filter name="${k8scluster_name}" | awk '{print $2}' | grep ${k8scluster_name}
67 Should Be Empty ${stdout}
69 Check For K8s Cluster To Be Ready
70 [Documentation] Check if a Kubernetes cluster registered in OSM is ready (the state must be ENABLED or DEGRADED).
71 [Arguments] ${k8scluster_name}
72 ${rc} ${stdout}= Run And Return Rc And Output osm k8scluster-list --filter name="${k8scluster_name}" --filter _admin.operationalState="ENABLED,DEGRADED"
74 ${rc} ${stdout}= Run And Return Rc And Output echo "${stdout}" | awk '{print $2}' | grep ${k8scluster_name}
76 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
77 Should Be Equal As Strings ${stdout} ${k8scluster_name}
79 Check For K8s Cluster To Be Enabled
80 [Documentation] Check if the state of Kubernetes cluster registered in OSM is ENABLED.
81 [Arguments] ${k8scluster_name}
82 ${rc} ${stdout}= Run And Return Rc And Output osm k8scluster-show ${k8scluster_name}
84 ${rc} ${stdout}= Run And Return Rc And Output osm k8scluster-list --filter name="${k8scluster_name}" --filter _admin.operationalState="ENABLED"
86 ${rc} ${stdout}= Run And Return Rc And Output echo "${stdout}" | awk '{print $2}' | grep ${k8scluster_name}
88 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
89 Should Be Equal As Strings ${stdout} ${k8scluster_name}