Bug 2327 fix to verify ipaddress in sol003_02 testsuite
[osm/tests.git] / robot-systest / testsuite / k8s_01-create_k8s_cluster.robot
1 *** Comments ***
2 #   Copyright 2020 Canonical Ltd.
3 #
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
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16
17 *** Settings ***
18 Documentation   [K8s-01] Create K8s cluster.
19
20 Library   OperatingSystem
21 Library   String
22 Library   Collections
23 Library   Process
24 Library   SSHLibrary
25 Library   ../lib/renderTemplate.py
26
27 Resource   ../lib/vnfd_lib.resource
28 Resource   ../lib/nsd_lib.resource
29 Resource   ../lib/ns_lib.resource
30 Resource   ../lib/ssh_lib.resource
31
32 Test Tags   k8s_01   cluster_k8s
33
34 Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
35
36
37 *** Variables ***
38 # NS and VNF descriptor package files
39 ${VNFD_PKG1}   k8s_jujucontroller_vnf.tar.gz
40 ${VNFD_PKG2}   k8s_jujumachine_vnf.tar.gz
41 ${NSD_PKG}   k8s_juju_ns.tar.gz
42 ${VNFD_NAME1}   k8s_jujucontroller_vnf
43 ${VNFD_NAME2}   k8s_jujumachine_vnf
44 ${NSD_NAME}   k8s_juju
45
46 # VNF Member indexes
47 ${VNF_MEMBER_INDEX_1}   k8s_vnf1
48 ${VNF_MEMBER_INDEX_2}   k8s_vnf2
49 ${VNF_MEMBER_INDEX_3}   k8s_vnf3
50 ${VNF_MEMBER_INDEX_4}   k8s_vnf4
51 ${VNF_MEMBER_INDEX_5}   k8s_juju
52
53 # Kubeconfig file
54 ${KUBECONFIG_FILE}   /home/ubuntu/.kube/config
55
56 # NS instance name
57 ${NS_NAME}   k8s-cluster
58
59 # SSH keys and username to be used
60 ${PUBLICKEY}   %{HOME}/.ssh/id_rsa.pub
61 ${PRIVATEKEY}   %{HOME}/.ssh/id_rsa
62 ${USERNAME}   ubuntu
63 ${PASSWORD}   ${EMPTY}
64
65 # Template and config file to use
66 ${TEMPLATE}   k8s_juju_template.yaml
67 ${CONFIG_FILE}   config.yaml
68
69
70 *** Test Cases ***
71 Render a template
72     [Documentation]   Generate from a template the instantiation parameters that will be used for the NS instance.
73     ${stdout}=   Render Template   ../resources/${TEMPLATE}   ../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}
74     Log To Console   \n${stdout}
75
76 Create Controller VNF Descriptor
77     [Documentation]   Upload first VNF package for the testsuite.
78     Create VNFD   '%{PACKAGES_FOLDER}/${VNFD_PKG1}'
79
80 Create Machines VNF Descriptor
81     [Documentation]   Upload second VNF package for the testsuite.
82     Create VNFD   '%{PACKAGES_FOLDER}/${VNFD_PKG2}'
83
84 Create K8s Cluster NS Descriptor
85     [Documentation]   Upload NS package for the testsuite.
86     Create NSD   '%{PACKAGES_FOLDER}/${NSD_PKG}'
87
88 Instantiate K8s Cluster Network Service
89     [Documentation]   Instantiate NS for the testsuite.
90     ${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}
91     Set Suite Variable   ${NS_ID}   ${id}
92
93 Get Management Ip Addresses
94     [Documentation]   Get the mgmt IP addresses of the five VNF of the NS.
95     ${ip_addr_1}=   Get Vnf Management Ip Address   ${NS_ID}   ${VNF_MEMBER_INDEX_1}
96     Log   ${ip_addr_1}
97     Set Suite Variable   ${VNF_1_IP_ADDR}   ${ip_addr_1}
98     ${ip_addr_2}=   Get Vnf Management Ip Address   ${NS_ID}   ${VNF_MEMBER_INDEX_2}
99     Log   ${ip_addr_2}
100     Set Suite Variable   ${VNF_2_IP_ADDR}   ${ip_addr_2}
101     ${ip_addr_3}=   Get Vnf Management Ip Address   ${NS_ID}   ${VNF_MEMBER_INDEX_3}
102     Log   ${ip_addr_3}
103     Set Suite Variable   ${VNF_3_IP_ADDR}   ${ip_addr_3}
104     ${ip_addr_4}=   Get Vnf Management Ip Address   ${NS_ID}   ${VNF_MEMBER_INDEX_4}
105     Log   ${ip_addr_4}
106     Set Suite Variable   ${VNF_4_IP_ADDR}   ${ip_addr_4}
107     ${ip_addr_5}=   Get Vnf Management Ip Address   ${NS_ID}   ${VNF_MEMBER_INDEX_5}
108     Log   ${ip_addr_5}
109     Set Suite Variable   ${VNF_5_IP_ADDR}   ${ip_addr_5}
110
111 Test SSH Access
112     [Documentation]   Check that the five VNF are accessible via SSH in their respective mgmt IP address.
113     Variable Should Exist   ${VNF_1_IP_ADDR}   msg=IP address of the management VNF '${VNF_MEMBER_INDEX_1}' is not available
114     Variable Should Exist   ${VNF_2_IP_ADDR}   msg=IP address of the management VNF '${VNF_MEMBER_INDEX_2}' is not available
115     Variable Should Exist   ${VNF_3_IP_ADDR}   msg=IP address of the management VNF '${VNF_MEMBER_INDEX_3}' is not available
116     Variable Should Exist   ${VNF_4_IP_ADDR}   msg=IP address of the management VNF '${VNF_MEMBER_INDEX_4}' is not available
117     Variable Should Exist   ${VNF_5_IP_ADDR}   msg=IP address of the management VNF '${VNF_MEMBER_INDEX_5}' is not available
118     Sleep   30s   Waiting ssh daemon to be up
119     Test SSH Connection   ${VNF_1_IP_ADDR}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}
120     Test SSH Connection   ${VNF_2_IP_ADDR}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}
121     Test SSH Connection   ${VNF_3_IP_ADDR}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}
122     Test SSH Connection   ${VNF_4_IP_ADDR}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}
123     Test SSH Connection   ${VNF_5_IP_ADDR}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}
124
125 Check Kubeconfig File
126     [Documentation]   Check that the Kubeconfig file of the provisioned cluster is present in the VNF.
127     Check If Remote File Exists   ${VNF_5_IP_ADDR}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}   ${KUBECONFIG_FILE}
128
129 Delete NS Instance
130     [Documentation]   Delete NS instance.
131     [Tags]   cleanup
132     Delete NS   ${NS_NAME}
133
134 Delete NS Descriptor
135     [Documentation]   Delete NS package from OSM.
136     [Tags]   cleanup
137     Delete NSD   ${NSD_NAME}
138
139 Delete Controller VNF Descriptor
140     [Documentation]   Delete first VNF package from OSM.
141     [Tags]   cleanup
142     Delete VNFD   ${VNFD_NAME1}
143
144 Delete Machines VNF Descriptor
145     [Documentation]   Delete second VNF package from OSM.
146     [Tags]   cleanup
147     Delete VNFD   ${VNFD_NAME2}
148
149
150 *** Keywords ***
151 Suite Cleanup
152     [Documentation]   Test Suite Cleanup: Deleting descriptors and NS instance
153     Run Keyword If Any Tests Failed   Delete NS   ${NS_NAME}
154     Run Keyword If Any Tests Failed   Delete NSD   ${NSD_NAME}
155     Run Keyword If Any Tests Failed   Delete VNFD   ${VNFD_NAME1}
156     Run Keyword If Any Tests Failed   Delete VNFD   ${VNFD_NAME2}