341237c00efd864bf0c334733f1fac1194da3c1f
[osm/tests.git] / robot-systest / testsuite / k8s_01-create_k8s_cluster.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 *** Settings ***
16 Documentation   [K8s-01] Create K8s cluster.
17
18 Library   OperatingSystem
19 Library   String
20 Library   Collections
21 Library   Process
22 Library   SSHLibrary
23 Library   %{ROBOT_DEVOPS_FOLDER}/lib/renderTemplate.py
24
25 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/vnfd_lib.robot
26 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/nsd_lib.robot
27 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/ns_lib.robot
28 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/ssh_lib.robot
29
30 Force Tags   k8s_01   cluster_k8s
31
32 Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
33
34
35 *** Variables ***
36 # NS and VNF descriptor package files
37 ${vnfd_pkg1}   k8s_jujucontroller_vnf.tar.gz
38 ${vnfd_pkg2}   k8s_jujumachine_vnf.tar.gz
39 ${nsd_pkg}   k8s_juju_ns.tar.gz
40 ${vnfd_name1}   k8s_jujucontroller_vnf
41 ${vnfd_name2}   k8s_jujumachine_vnf
42 ${nsd_name}   k8s_juju
43
44 # VNF Member indexes
45 ${vnf_member_index_1}   k8s_vnf1
46 ${vnf_member_index_2}   k8s_vnf2
47 ${vnf_member_index_3}   k8s_vnf3
48 ${vnf_member_index_4}   k8s_vnf4
49 ${vnf_member_index_5}   k8s_juju
50
51 # Username
52 ${username}   ubuntu
53
54 # Kubeconfig file
55 ${kubeconfig_file}   /home/ubuntu/.kube/config
56
57 # NS instance name
58 ${ns_name}   k8s-cluster
59
60 # SSH keys and username to be used
61 ${publickey}   %{HOME}/.ssh/id_rsa.pub
62 ${privatekey}   %{HOME}/.ssh/id_rsa
63 ${username}   ubuntu
64 ${password}   ${EMPTY}
65
66 # Template and config file to use
67 ${template}   k8s_juju_template.yaml
68 ${config_file}   config.yaml
69
70
71 *** Test Cases ***
72 Render a template
73
74     ${stdout}=   Render template   %{ROBOT_DEVOPS_FOLDER}/resources/${template}   %{ROBOT_DEVOPS_FOLDER}/resources/${config_file}   IP_VM1=%{IP_VM1}   IP_VM2=%{IP_VM2}   IP_VM3=%{IP_VM3}   IP_VM4=%{IP_VM4}   IP_JUJU=%{IP_JUJU}   NETWORK=%{VIM_MGMT_NET}
75     Log To Console   \n${stdout}
76
77
78 Create Controller VNF Descriptor
79
80     Create VNFD   '%{PACKAGES_FOLDER}/${vnfd_pkg1}'
81
82
83 Create Machines VNF Descriptor
84
85     Create VNFD   '%{PACKAGES_FOLDER}/${vnfd_pkg2}'
86
87
88 Create K8s Cluster NS Descriptor
89
90     Create NSD   '%{PACKAGES_FOLDER}/${nsd_pkg}'
91
92
93 Instantiate K8s Cluster Network Service
94
95     ${id}=   Create Network Service   ${nsd_name}   %{VIM_TARGET}   ${ns_name}   ns_config=${EMPTY}   publickey=${publickey}   ns_launch_max_wait_time=70min   config_file=%{ROBOT_DEVOPS_FOLDER}/resources/${config_file}
96     Set Suite Variable   ${ns_id}   ${id}
97
98
99 Get Management Ip Addresses
100
101     ${ip_addr_1}   Get Vnf Management Ip Address   ${ns_id}   ${vnf_member_index_1}
102     log   ${ip_addr_1}
103     Set Suite Variable   ${vnf_1_ip_addr}   ${ip_addr_1}
104     ${ip_addr_2}   Get Vnf Management Ip Address   ${ns_id}   ${vnf_member_index_2}
105     log   ${ip_addr_2}
106     Set Suite Variable   ${vnf_2_ip_addr}   ${ip_addr_2}
107     ${ip_addr_3}   Get Vnf Management Ip Address   ${ns_id}   ${vnf_member_index_3}
108     log   ${ip_addr_3}
109     Set Suite Variable   ${vnf_3_ip_addr}   ${ip_addr_3}
110     ${ip_addr_4}   Get Vnf Management Ip Address   ${ns_id}   ${vnf_member_index_4}
111     log   ${ip_addr_4}
112     Set Suite Variable   ${vnf_4_ip_addr}   ${ip_addr_4}
113     ${ip_addr_5}   Get Vnf Management Ip Address   ${ns_id}   ${vnf_member_index_5}
114     log   ${ip_addr_5}
115     Set Suite Variable   ${vnf_5_ip_addr}   ${ip_addr_5}
116
117
118 Test SSH Access
119
120     Variable Should Exist   ${vnf_1_ip_addr}   msg=IP address of the management VNF '${vnf_member_index_1}' is not available
121     Variable Should Exist   ${vnf_2_ip_addr}   msg=IP address of the management VNF '${vnf_member_index_2}' is not available
122     Variable Should Exist   ${vnf_3_ip_addr}   msg=IP address of the management VNF '${vnf_member_index_3}' is not available
123     Variable Should Exist   ${vnf_4_ip_addr}   msg=IP address of the management VNF '${vnf_member_index_4}' is not available
124     Variable Should Exist   ${vnf_5_ip_addr}   msg=IP address of the management VNF '${vnf_member_index_5}' is not available
125     Sleep   30s   Waiting ssh daemon to be up
126     Test SSH Connection   ${vnf_1_ip_addr}   ${username}   ${password}   ${privatekey}
127     Test SSH Connection   ${vnf_2_ip_addr}   ${username}   ${password}   ${privatekey}
128     Test SSH Connection   ${vnf_3_ip_addr}   ${username}   ${password}   ${privatekey}
129     Test SSH Connection   ${vnf_4_ip_addr}   ${username}   ${password}   ${privatekey}
130     Test SSH Connection   ${vnf_5_ip_addr}   ${username}   ${password}   ${privatekey}
131
132
133 Check kubeconfig file
134
135     Check If remote File Exists   ${vnf_5_ip_addr}   ${username}   ${password}   ${privatekey}   ${kubeconfig_file}
136
137
138 Delete NS Instance
139     [Tags]   cleanup
140
141     Delete NS   ${ns_name}
142
143
144 Delete NS Descriptor
145     [Tags]   cleanup
146
147     Delete NSD   ${nsd_name}
148
149
150 Delete Controller VNF Descriptor
151     [Tags]   cleanup
152
153     Delete VNFD   ${vnfd_name1}
154
155 Delete Machines VNF Descriptor
156     [Tags]   cleanup
157
158     Delete VNFD   ${vnfd_name2}
159
160
161 *** Keywords ***
162 Suite Cleanup
163     [Documentation]   Test Suite Cleanup: Deleting descriptors and NS instance
164
165     Run Keyword If Any Tests Failed   Delete NS   ${ns_name}
166     Run Keyword If Any Tests Failed   Delete NSD   ${nsd_name}
167     Run Keyword If Any Tests Failed   Delete VNFD   ${vnfd_name}