Robot fix for Autohealing tests
[osm/tests.git] / robot-systest / testsuite / heal_04-autohealing.robot
1 #   Licensed under the Apache License, Version 2.0 (the "License");\r
2 #   you may not use this file except in compliance with the License.\r
3 #   You may obtain a copy of the License at\r
4 #\r
5 #       http://www.apache.org/licenses/LICENSE-2.0\r
6 #\r
7 #   Unless required by applicable law or agreed to in writing, software\r
8 #   distributed under the License is distributed on an "AS IS" BASIS,\r
9 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
10 #   See the License for the specific language governing permissions and\r
11 #   limitations under the License.\r
12 \r
13 *** Settings ***\r
14 Documentation     [HEAL-04] Autohealing of NS\r
15 Suite Teardown    Run Keyword And Ignore Error    Suite Cleanup\r
16 Force Tags        heal_04   cluster_main   daily   regression\r
17 Library           OperatingSystem\r
18 Library           String\r
19 Library           Collections\r
20 Library           Process\r
21 Library           SSHLibrary\r
22 Resource          %{ROBOT_DEVOPS_FOLDER}/lib/vnfd_lib.robot\r
23 Resource          %{ROBOT_DEVOPS_FOLDER}/lib/vnf_lib.robot\r
24 Resource          %{ROBOT_DEVOPS_FOLDER}/lib/nsd_lib.robot\r
25 Resource          %{ROBOT_DEVOPS_FOLDER}/lib/ns_lib.robot\r
26 Resource          %{ROBOT_DEVOPS_FOLDER}/lib/ssh_lib.robot\r
27 Resource          %{ROBOT_DEVOPS_FOLDER}/lib/openstack_lib.robot\r
28 \r
29 *** Variables ***\r
30 # NS and VNF descriptor package folder and ids\r
31 ${vnfd_pkg}   autoheal_vnf\r
32 ${vnfd_name}   autoheal_vnfd\r
33 ${vdu_name}   autoheal_vnfd-VM\r
34 ${vnf_index}   autoheal-basic-1\r
35 ${nsd_pkg}   autoheal_ns\r
36 ${nsd_name}  autoheal_nsd\r
37 # NS instance name and configuration\r
38 ${ns_name}    heal_04\r
39 ${ns_config}   {vld: [ {name: mgmt, vim-network-name: %{VIM_MGMT_NET}} ] }\r
40 \r
41 # SSH keys and username to be used\r
42 ${publickey}   %{HOME}/.ssh/id_rsa.pub\r
43 ${privatekey}   %{HOME}/.ssh/id_rsa\r
44 ${username}   ubuntu\r
45 ${password}   ${EMPTY}\r
46 \r
47 ${success_return_code}   0\r
48 \r
49 #Healing wait time\r
50 ${healing_pol_time}   15sec\r
51 ${healing_max_wait_time}   10m\r
52 \r
53 *** Test Cases ***\r
54 Create VNF Descriptors\r
55     Create VNFD   '%{PACKAGES_FOLDER}/${vnfd_pkg}'\r
56 \r
57 \r
58 Create NS Descriptor\r
59     Create NSD   '%{PACKAGES_FOLDER}/${nsd_pkg}'\r
60 \r
61 \r
62 Network Service Instance Test\r
63     ${id}=   Create Network Service   ${nsd_name}   %{VIM_TARGET}   ${ns_name}   ${ns_config}   ${publickey}\r
64     Set Suite Variable   ${ns_id}   ${id}\r
65 \r
66 \r
67 Get NS Id\r
68     [Tags]   cleanup\r
69     ${variables}   Get Variables\r
70     IF   not "\${ns_id}" in "${variables}"\r
71         ${id}=   Get Ns Id   ${ns_name}\r
72         Set Suite Variable   ${ns_id}   ${id}\r
73     END\r
74 \r
75 \r
76 Get VNF Info\r
77     Variable Should Exist  ${ns_id}  msg=NS is not available\r
78     ${ip_addr}=  Get Vnf Management Ip Address   ${ns_id}   ${vnf_index}\r
79     log   ${ip_addr}\r
80     Set Suite Variable   ${vnf_ip_addr}   ${ip_addr}\r
81 \r
82     ${vnf_id}=  Get Vnf Id   ${ns_id}   ${vnf_index}\r
83     Set Suite Variable   ${vnf_autoheal_id}   ${vnf_id}\r
84     ${id}=  Get VNF VIM ID   ${vnf_id}\r
85     Set Suite Variable   ${vdu_autoheal_id}   ${id}\r
86     log   ${vdu_autoheal_id}\r
87 \r
88     @{autoheal_ip_list}=  Get Vnf Vdur IPs   ${vnf_autoheal_id}\r
89     Set Suite Variable   @{autoheal_ip_list}   @{autoheal_ip_list}\r
90     log   @{autoheal_ip_list}\r
91 \r
92 \r
93 Stop Autoheal VDU\r
94     Variable Should Exist  ${vdu_autoheal_id}  msg=VDU is not available\r
95     Halt Server   ${vdu_autoheal_id}\r
96     Sleep   20\r
97 \r
98 \r
99 Wait For Autohealing To Be Completed\r
100     FOR    ${Index}    IN RANGE    0    15\r
101         ${status}=    Run Keyword And Return Status    Get Operations By Type    ${ns_id}    heal\r
102         Run Keyword If  ${status}    Exit For Loop\r
103     ...  ELSE  Sleep    10\r
104     END\r
105     ${stdout}=    Get Operations By Type    ${ns_id}    heal\r
106     ${healing_max_wait_time}=   Convert Time   ${healing_max_wait_time}   result_format=number\r
107     ${healing_max_wait_time}=   Evaluate   ${healing_max_wait_time} * ${vim_timeout_multiplier}\r
108     Wait Until Keyword Succeeds  ${healing_max_wait_time}  ${healing_pol_time}  Check For NS Operation Ended  ${stdout}\r
109     Check For NS Operation Completed  ${stdout}\r
110 \r
111 \r
112 Check VNF After Healing\r
113     Variable Should Exist  ${vnf_autoheal_id}  msg=VNF is not available\r
114 \r
115     @{ip_list}=  Get Vnf Vdur IPs   ${vnf_autoheal_id}\r
116     log   @{ip_list}\r
117     Should Be Equal   ${ip_list}   ${autoheal_ip_list}   IP addresses have changed after healing\r
118 \r
119     ${id}=  Get VNF VIM ID   ${vnf_autoheal_id}\r
120     log   ${id}\r
121     Should Not Be Equal   ${id}   ${vdu_autoheal_id}   VDU id has not changed after healing\r
122 \r
123 \r
124 Delete NS Instance\r
125     [Tags]   cleanup\r
126     Delete NS   ${ns_name}\r
127 \r
128 \r
129 Delete NS Descriptor\r
130     [Tags]   cleanup\r
131     Delete NSD   ${nsd_name}\r
132 \r
133 \r
134 Delete VNF Descriptors\r
135     [Tags]   cleanup\r
136     Delete VNFD   ${vnfd_name}\r
137 \r
138 *** Keywords ***\r
139 Suite Cleanup\r
140     [Documentation]  Test Suit Cleanup: Deleting Descriptor, instance and vim\r
141 \r
142     Run Keyword If Any Tests Failed  Delete NS   ${ns_name}\r
143     Run Keyword If Any Tests Failed  Delete NSD   ${nsd_name}\r
144     Run Keyword If Any Tests Failed  Delete VNFD   ${vnfd_name}\r