cc252fba71259ff21744a36b0cff177ae435230c
[osm/devops.git] / robot-systest / lib / ns_lib.robot
1 #   Licensed under the Apache License, Version 2.0 (the "License");
2 #   you may not use this file except in compliance with the License.
3 #   You may obtain a copy of the License at
4 #
5 #       http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #   Unless required by applicable law or agreed to in writing, software
8 #   distributed under the License is distributed on an "AS IS" BASIS,
9 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 #   See the License for the specific language governing permissions and
11 #   limitations under the License.
12
13 *** Variables ***
14 ${success_return_code}   0
15 ${ns_launch_max_wait_time}   5min
16 ${ns_launch_pol_time}   30sec
17 ${ns_delete_max_wait_time}   1min
18 ${ns_delete_pol_time}   15sec
19
20 *** Keywords ***
21 Create Network Service
22     [Arguments]   ${nsd}   ${vim_name}   ${ns_name}   ${ns_config}   ${publickey}
23
24     ${config_attr}   Set Variable If   '${ns_config}'!='${EMPTY}'   --config '${ns_config}'   \
25     ${sshkeys_attr}   Set Variable If   '${publickey}'!='${EMPTY}'   --ssh_keys ${publickey}   \
26
27     ${ns_id}=   Instantiate Network Service   ${ns_name}   ${nsd}   ${vim_name}   ${config_attr} ${sshkeys_attr}
28     log   ${ns_id}
29
30     WAIT UNTIL KEYWORD SUCCEEDS   ${ns_launch_max_wait_time}   ${ns_launch_pol_time}   Check For NS Instance To Configured   ${ns_name}
31     Check For NS Instance For Failure   ${ns_name}
32     [Return]  ${ns_id}
33
34 Instantiate Network Service
35     [Arguments]   ${ns_name}   ${nsd}   ${vim_name}   ${ns_extra_args}
36
37     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-create --ns_name ${ns_name} --nsd_name ${nsd} --vim_account ${vim_name} ${ns_extra_args}
38     log   ${stdout}
39     Should Be Equal As Integers   ${rc}   ${success_return_code}
40     [Return]  ${stdout}
41
42 Get Vnf Management Ip Address
43     [Arguments]   ${ns_id}   ${vnf_member_index}
44
45     Should Not Be Empty   ${ns_id}
46     Should Not Be Empty   ${vnf_member_index}
47     ${rc}   ${stdout}=   Run and Return RC and Output   osm vnf-list --filter member-vnf-index-ref=${vnf_member_index} | grep ${ns_id} | awk '{print $14}' 2>&1
48     log   ${stdout}
49     Should Be Equal As Integers   ${rc}   ${success_return_code}
50     [Return]  ${stdout}
51
52 Check For NS Instance To Configured
53     [Arguments]  ${ns_name}
54
55     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-list --filter name="${ns_name}"
56     log   ${stdout}
57     Should Be Equal As Integers   ${rc}   ${success_return_code}
58     Should Contain Any   ${stdout}   READY   BROKEN
59
60 Check For NS Instance For Failure
61     [Arguments]  ${ns_name}
62
63     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-list --filter name="${ns_name}"
64     log   ${stdout}
65     Should Be Equal As Integers   ${rc}   ${success_return_code}
66     Should Not Contain   ${stdout}   BROKEN
67
68 Check For NS Instance To Be Deleted
69     [Arguments]  ${ns}
70
71     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-list | awk '{print $2}' | grep ${ns}
72     Should Not Be Equal As Strings   ${stdout}   ${ns}
73
74 Delete NS
75     [Documentation]  Delete ns
76     [Arguments]  ${ns}
77
78     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-delete ${ns}
79     log   ${stdout}
80     Should Be Equal As Integers   ${rc}   ${success_return_code}
81
82     WAIT UNTIL KEYWORD SUCCEEDS  ${ns_delete_max_wait_time}   ${ns_delete_pol_time}   Check For NS Instance To Be Deleted   ${ns}