Robot libraries for Prometheus, VIM and NS instances.
[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 ${ns_action_max_wait_time}   1min
20 ${ns_action_pol_time}   15sec
21 ${vnf_scale_max_wait_time}   5min
22 ${vnf_scale_pol_time}   30sec
23
24
25 *** Keywords ***
26 Create Network Service
27     [Arguments]   ${nsd}   ${vim_name}   ${ns_name}   ${ns_config}   ${publickey}
28
29     ${config_attr}   Set Variable If   '${ns_config}'!='${EMPTY}'   --config '${ns_config}'   \
30     ${sshkeys_attr}   Set Variable If   '${publickey}'!='${EMPTY}'   --ssh_keys ${publickey}   \
31
32     ${ns_id}=   Instantiate Network Service   ${ns_name}   ${nsd}   ${vim_name}   ${config_attr} ${sshkeys_attr}
33     log   ${ns_id}
34
35     WAIT UNTIL KEYWORD SUCCEEDS   ${ns_launch_max_wait_time}   ${ns_launch_pol_time}   Check For NS Instance To Configured   ${ns_name}
36     Check For NS Instance For Failure   ${ns_name}
37     [Return]  ${ns_id}
38
39 Instantiate Network Service
40     [Arguments]   ${ns_name}   ${nsd}   ${vim_name}   ${ns_extra_args}
41
42     ${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}
43     log   ${stdout}
44     Should Be Equal As Integers   ${rc}   ${success_return_code}
45     [Return]  ${stdout}
46
47 Get Vnf Management Ip Address
48     [Arguments]   ${ns_id}   ${vnf_member_index}
49
50     Should Not Be Empty   ${ns_id}
51     Should Not Be Empty   ${vnf_member_index}
52     ${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
53     log   ${stdout}
54     Should Be Equal As Integers   ${rc}   ${success_return_code}
55     [Return]  ${stdout}
56
57 Check For NS Instance To Configured
58     [Arguments]  ${ns_name}
59
60     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-list --filter name="${ns_name}"
61     log   ${stdout}
62     Should Be Equal As Integers   ${rc}   ${success_return_code}
63     Should Contain Any   ${stdout}   READY   BROKEN
64
65 Check For NS Instance For Failure
66     [Arguments]  ${ns_name}
67
68     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-list --filter name="${ns_name}"
69     log   ${stdout}
70     Should Be Equal As Integers   ${rc}   ${success_return_code}
71     Should Not Contain   ${stdout}   BROKEN
72
73 Check For NS Instance To Be Deleted
74     [Arguments]  ${ns}
75
76     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-list | awk '{print $2}' | grep ${ns}
77     Should Not Be Equal As Strings   ${stdout}   ${ns}
78
79 Delete NS
80     [Documentation]  Delete ns
81     [Arguments]  ${ns}
82
83     ${rc}   ${stdout}=   Run and Return RC and Output   osm ns-delete ${ns}
84     log   ${stdout}
85     Should Be Equal As Integers   ${rc}   ${success_return_code}
86
87     WAIT UNTIL KEYWORD SUCCEEDS  ${ns_delete_max_wait_time}   ${ns_delete_pol_time}   Check For NS Instance To Be Deleted   ${ns}
88
89 Execute NS Action
90     [Documentation]     Execute an action over the desired NS.
91     ...                 Parameters are given to this function in key=value format (one argument per key/value pair).
92     ...                 Return the ID of the operation associated to the executed action.
93     ...                 Examples of execution:
94     ...                     \${ns_op_id}=  Execute NS Action  \${ns_name}  \${ns_action}  \${vnf_member_index}
95     ...                     \${ns_op_id}=  Execute NS Action  \${ns_name}  \${ns_action}  \${vnf_member_index}  \${param1}=\${value1}  \${param2}=\${value2}
96
97     [Arguments]  ${ns_name}  ${ns_action}  ${vnf_member_index}  @{action_params}
98
99     ${params}=  Set Variable  ${EMPTY}
100     FOR  ${param}  IN  @{action_params}
101         ${match}  ${param_name}  ${param_value} =  Should Match Regexp  ${param}  (.+)=(.+)  msg=Syntax error in parameters
102         ${params}=  Catenate  SEPARATOR=  ${params}  "${param_name}":"${param_value}",
103     END
104     ${osm_ns_action_command}=  Set Variable  osm ns-action --action_name ${ns_action} --vnf_name ${vnf_member_index}
105     ${osm_ns_action_command}=  Run Keyword If  '${params}'!='${EMPTY}'  Catenate  ${osm_ns_action_command}  --params '{${params}}'
106     ...  ELSE  Set Variable  ${osm_ns_action_command}
107     ${osm_ns_action_command}=  Catenate  ${osm_ns_action_command}  ${ns_name}
108     ${rc}  ${stdout}=  Run and Return RC and Output  ${osm_ns_action_command}
109     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
110     Wait Until Keyword Succeeds  ${ns_action_max_wait_time}  ${ns_action_pol_time}  Check For NS Operation Completed  ${stdout}
111     [Return]  ${stdout}
112
113
114 Execute Manual VNF Scale
115     [Documentation]     Execute a manual VNF Scale action.
116     ...                 The parameter 'scale_type' must be SCALE_IN or SCALE_OUT.
117     ...                 Return the ID of the operation associated to the executed scale action.
118
119     [Arguments]  ${ns_name}  ${vnf_member_index}  ${scaling_group}  ${scale_type}
120
121     Should Contain Any  ${scale_type}  SCALE_IN  SCALE_OUT  msg=Unknown scale type: ${scale_type}  values=False
122     ${osm_vnf_scale_command}=  Set Variable  osm vnf-scale --scaling-group ${scaling_group}
123     ${osm_vnf_scale_command}=  Run Keyword If  '${scale_type}'=='SCALE_IN'  Catenate  ${osm_vnf_scale_command}  --scale-in
124     ...  ELSE  Catenate  ${osm_vnf_scale_command}  --scale-out
125     ${osm_vnf_scale_command}=  Catenate  ${osm_vnf_scale_command}  ${ns_name}  ${vnf_member_index}
126     ${rc}  ${stdout}=  Run and Return RC and Output  ${osm_vnf_scale_command}
127     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
128     Wait Until Keyword Succeeds  ${ns_action_max_wait_time}  ${ns_action_pol_time}  Check For NS Operation Completed  ${stdout}
129     [Return]  ${stdout}
130
131
132 Get Operations List
133     [Arguments]  ${ns_name}
134
135     ${rc}  ${stdout}=  Run and Return RC and Output  osm ns-op-list ${ns_name}
136     log  ${stdout}
137     log  ${rc}
138     Should Be Equal As Integers  ${rc}  ${success_return_code}
139
140
141 Check For NS Operation Completed
142     [Documentation]     Check wheter the status of the desired operation is "COMPLETED" or not.
143
144     [Arguments]  ${ns_operation_id}
145
146     ${rc}  ${stdout}=  Run and Return RC and Output  osm ns-op-show ${ns_operation_id} --literal | yq r - operationState
147     log  ${stdout}
148     Should Be Equal As Integers  ${rc}  ${success_return_code}
149     Should Contain  ${stdout}  COMPLETED  msg=Timeout waiting for ns-action with id ${ns_operation_id}  values=False
150
151
152 Get Ns Vnfr Ids
153     [Documentation]     Return a list with the IDs of the VNF records of a NS instance.
154
155     [Arguments]  ${ns_id}
156
157     ${rc}  ${stdout}=  Run and Return RC and Output  osm vnf-list | grep ${ns_id} | awk '{print $2}' 2>&1
158     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
159     @{vdur} =  Split String  ${stdout}
160     [Return]  @{vdur}
161
162
163 Get Vnf Vdur Names
164     [Documentation]     Return a list with the names of the VDU records of a VNF instance.
165
166     [Arguments]  ${vnf_id}
167
168     ${rc}  ${stdout}=  Run and Return RC and Output  osm vnf-show ${vnf_id} --literal | yq r - vdur.*.name
169     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
170     @{vdur} =  Split String  ${stdout}
171     [Return]  @{vdur}
172