Feature 11001: Robot framework linting for E2E tests
[osm/tests.git] / robot-systest / testsuite / basic_21-support_of_volumes.robot
1 *** Comments ***
2 #   Licensed under the Apache License, Version 2.0 (the "License");
3 #   you may not use this file except in compliance with the License.
4 #   You may obtain a copy of the License at
5 #
6 #       http://www.apache.org/licenses/LICENSE-2.0
7 #
8 #   Unless required by applicable law or agreed to in writing, software
9 #   distributed under the License is distributed on an "AS IS" BASIS,
10 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 #   See the License for the specific language governing permissions and
12 #   limitations under the License.
13
14
15 *** Settings ***
16 Documentation   [BASIC-21] NS with only one VDU and several volumes
17
18 Library   OperatingSystem
19 Library   String
20 Library   Collections
21 Library   Process
22 Library   SSHLibrary
23
24 Resource   ../lib/vnfd_lib.resource
25 Resource   ../lib/vnf_lib.resource
26 Resource   ../lib/nsd_lib.resource
27 Resource   ../lib/ns_lib.resource
28 Resource   ../lib/ssh_lib.resource
29 Resource   ../lib/openstack_lib.resource
30
31 Test Tags   basic_21   cluster_main   daily   regression
32
33 Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
34
35
36 *** Variables ***
37 # NS and VNF descriptor package folder and ids
38 ${VNFD_PKG}   several_volumes_vnf
39 ${VNFD_NAME}   several_volumes-vnf
40 ${NSD_PKG}   several_volumes_ns
41 ${NSD_NAME}   several_volumes-ns
42
43 # NS instance name and configuration
44 ${NS_NAME}   basic_21
45 ${NS_CONFIG}   {vld: [ {name: mgmtnet, vim-network-name: %{VIM_MGMT_NET}} ] }
46
47 # SSH keys and username to be used
48 ${PUBLICKEY}   %{HOME}/.ssh/id_rsa.pub
49 ${PRIVATEKEY}   %{HOME}/.ssh/id_rsa
50 ${USERNAME}   ubuntu
51 ${PASSWORD}   ${EMPTY}
52
53 ${VNF_MEMBER_INDEX}   vnf-several-volumes
54 ${SUCCESS_RETURN_CODE}   0
55
56
57 *** Test Cases ***
58 Create VNF Descriptor
59     [Documentation]   Upload VNF package for the testsuite.
60     [Tags]   prepare
61     Create VNFD   '%{PACKAGES_FOLDER}/${VNFD_PKG}'
62
63 Create NS Descriptor
64     [Documentation]   Upload NS package for the testsuite.
65     [Tags]   prepare
66     Create NSD   '%{PACKAGES_FOLDER}/${NSD_PKG}'
67
68 Network Service Instance Test
69     [Documentation]   Instantiate NS for the testsuite.
70     [Tags]   prepare
71     ${id}=   Create Network Service   ${NSD_NAME}   %{VIM_TARGET}   ${NS_NAME}   ${NS_CONFIG}   ${PUBLICKEY}
72     Set Suite Variable   ${NS_ID}   ${id}
73
74 Get NS Id
75     [Documentation]   Get NS identifier and stores as suite variable to be used later on.
76     [Tags]   verify   cleanup
77     ${variables}=   Get Variables
78     IF   not "\${ns_id}" in "${variables}"
79         ${id}=   Get Ns Id   ${NS_NAME}
80         Set Suite Variable   ${NS_ID}   ${id}
81     END
82
83 Get Volumes From VNFD
84     [Documentation]   Get from VNF descriptor the expected number of volumes in the VNF.
85     [Tags]   verify
86     ${rc}   ${stdout}=   Run And Return RC And Output   osm vnfpkg-show ${VNFD_NAME} --literal | yq '.vdu[0]."virtual-storage-desc" | length'
87     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}   msg=${stdout}   values=False
88     ${num_virtual_storage}=   Convert To Integer   ${stdout}
89     Set Suite Variable   ${VNF_NUM_VOLUMES}   ${num_virtual_storage}
90     Log   ${VNF_NUM_VOLUMES}
91
92 Get VNF IP Address
93     [Documentation]   Get the mgmt IP address of the VNF.
94     [Tags]   verify
95     Variable Should Exist   ${NS_ID}   msg=NS is not available
96     ${ip_addr}=   Get Vnf Management Ip Address   ${NS_ID}   ${VNF_MEMBER_INDEX}
97     Log   ${ip_addr}
98     Set Suite Variable   ${VNF_IP_ADDR}   ${ip_addr}
99
100 # Get Persistent Volume Id
101 #     [Documentation]   Get VIM volume identifier of the persistent volume of the VNF.
102 #     [Tags]   cleanup
103 #     Variable Should Exist   ${ns_id}   msg=NS is not available
104 #     ${vnfs_list}=   Get Ns Vnf List   ${ns_id}
105 #     ${vim_id}=   Get VNF VIM ID   ${vnfs_list}[0]
106 #     ${volumes_attached}=   Get Server Property   ${vim_id}   volumes_attached
107 #     ${match}=   Get Regexp Matches   ${volumes_attached}   '([0-9a-f\-]+)'   1
108 #     Set Suite Variable   ${PERSISTENT_VOLUME_ID}   ${match}[0]
109
110 Check VDU disks
111     [Documentation]   Check that the number of volumes is the expected one.
112     [Tags]   verify
113     Variable Should Exist   ${VNF_IP_ADDR}   msg=VNF is not available
114     Sleep   30 seconds   Wait for SSH daemon to be up
115     ${stdout}=   Execute Remote Command Check Rc Return Output   ${VNF_IP_ADDR}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}   sudo lsblk -l
116     Log   ${stdout}
117     ${lines}=   Get Lines Containing String   ${stdout}   disk
118     ${num_lines}=   Get Line Count   ${lines}
119     IF   ${num_lines} < ${VNF_NUM_VOLUMES}   Fail   msg=Number of disks (${num_lines}) is less than specified in VDU (${VNF_NUM_VOLUMES})
120
121 Delete NS Instance Test
122     [Documentation]   Delete NS instance.
123     [Tags]   cleanup
124     Delete NS   ${NS_NAME}
125
126 # Check Persistent Volume Was Deleted
127 #     [Documentation]   Check that the persistent volume was deleted.
128 #     [Tags]   cleanup
129 #     Variable Should Exist   ${PERSISTENT_VOLUME_ID}   msg=Volume is not available
130 #     ${exists}=   Check If Volume Exists   ${PERSISTENT_VOLUME_ID}
131 #     Log   ${exists}
132 #     IF   ${exists}==0
133 #         Fail   msg=Persistent volume was deleted
134 #         Set Suite Variable   ${PERSISTENT_VOLUME_ID}   ${EMPTY}}
135 #     ELSE
136 #         Log   Persistent volume still exists, deleting...
137 #         Delete Volume   ${PERSISTENT_VOLUME_ID}
138 #         Set Suite Variable   ${PERSISTENT_VOLUME_ID}   ${EMPTY}}
139 #     END
140
141 Delete NS Descriptor Test
142     [Documentation]   Delete NS package from OSM.
143     [Tags]   cleanup
144     Delete NSD   ${NSD_NAME}
145
146 Delete VNF Descriptor Test
147     [Documentation]   Delete VNF package from OSM.
148     [Tags]   cleanup
149     Delete VNFD   ${VNFD_NAME}
150
151
152 *** Keywords ***
153 Suite Cleanup
154     [Documentation]   Test Suit Cleanup: Deleting Descriptor, instance and vim
155     Run Keyword If Any Tests Failed   Delete NS   ${NS_NAME}
156     Run Keyword If Any Tests Failed   Delete NSD   ${NSD_NAME}
157     Run Keyword If Any Tests Failed   Delete VNFD   ${VNFD_NAME}
158 #    Run Keyword If Any Tests Failed   Check Volume Was Deleted