Fix k8scluster_lib keywords to log output of k8scluster-list
[osm/tests.git] / robot-systest / lib / k8scluster_lib.robot
1 # Copyright 2020 Canonical Ltd.
2 #
3 #   Licensed under the Apache License, Version 2.0 (the "License");
4 #   you may not use this file except in compliance with the License.
5 #   You may obtain a copy of the License at
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #   Unless required by applicable law or agreed to in writing, software
10 #   distributed under the License is distributed on an "AS IS" BASIS,
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 #   See the License for the specific language governing permissions and
13 #   limitations under the License.
14
15 *** Variables ***
16 ${success_return_code}   0
17 ${k8scluster_launch_max_wait_time}   6min
18 ${k8scluster_launch_pol_time}   30sec
19 ${k8scluster_delete_max_wait_time}   2min
20 ${k8scluster_delete_pol_time}   15sec
21
22 *** Keywords ***
23 Create K8s Cluster
24     [Arguments]   ${k8scluster_creds}   ${k8scluster_version}   ${k8scluster_vim}   ${k8scluster_net}   ${k8scluster_name}
25     ${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"
26     log   ${stdout}
27     Should Be Equal As Integers   ${rc}   ${success_return_code}
28     WAIT UNTIL KEYWORD SUCCEEDS  ${k8scluster_launch_max_wait_time}  ${k8scluster_launch_pol_time}   Check For K8s Cluster To Be Ready  ${k8scluster_name}
29     Check For K8s Cluster To Be Enabled  ${k8scluster_name}
30     [Return]  ${stdout}
31
32 Delete K8s Cluster
33     [Arguments]   ${k8scluster_name}
34     ${rc}   ${stdout}=   Run and Return RC and Output   osm k8scluster-delete ${k8scluster_name}
35     Should Be Equal As Integers   ${rc}   ${success_return_code}
36     WAIT UNTIL KEYWORD SUCCEEDS  ${k8scluster_delete_max_wait_time}   ${k8scluster_delete_pol_time}   Check For K8s Cluster To Be Deleted   ${k8scluster_name}
37
38 Get K8s Cluster
39     ${rc}   ${stdout}=   Run and Return RC and Output   osm k8scluster-list
40     Should Be Equal As Integers   ${rc}   ${success_return_code}
41     log   ${stdout}
42     [Return]  ${stdout}
43
44 Check for K8s Cluster
45     [Arguments]   ${k8scluster_name}
46     ${rc}   ${stdout}=   Run and Return RC and Output   osm k8scluster-list --filter name="${k8scluster_name}"
47     Should Be Equal As Integers   ${rc}   ${success_return_code}
48     [Return]  ${stdout}
49
50 Check For K8s Cluster To Be Deleted
51     [Arguments]   ${k8scluster_name}
52     ${rc}   ${stdout}=   Run and Return RC and Output   osm k8scluster-list --filter name="${k8scluster_name}" | awk '{print $2}' | grep ${k8scluster_name}
53     Should Be Empty   ${stdout}
54
55 Check For K8s Cluster To Be Ready
56     [Arguments]   ${k8scluster_name}
57     ${rc}   ${stdout}=   Run and Return RC and Output   osm k8scluster-list --filter name="${k8scluster_name}" --filter _admin.operationalState="ENABLED,DEGRADED"
58     log   ${stdout}
59     ${rc}   ${stdout}=   Run and Return RC and Output   echo "${stdout}" | awk '{print $2}' | grep ${k8scluster_name}
60     Should Be Equal As Integers   ${rc}   ${success_return_code}
61     Should Be Equal As Strings   ${stdout}   ${k8scluster_name}
62
63 Check For K8s Cluster To Be Enabled
64     [Arguments]   ${k8scluster_name}
65     ${rc}   ${stdout}=   Run and Return RC and Output   osm k8scluster-list --filter name="${k8scluster_name}" --filter _admin.operationalState="ENABLED"
66     log   ${stdout}
67     ${rc}   ${stdout}=   Run and Return RC and Output   echo "${stdout}" | awk '{print $2}' | grep ${k8scluster_name}
68     Should Be Equal As Integers   ${rc}   ${success_return_code}
69     Should Be Equal As Strings   ${stdout}   ${k8scluster_name}