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
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 Documentation Library to deploy and delete NS, and run operations on them.
20 Library OperatingSystem
25 ${SUCCESS_RETURN_CODE} 0
26 ${NS_ACTION_MAX_WAIT_TIME} 1min
27 ${NS_ACTION_POL_TIME} 15sec
28 ${VNF_SCALE_POL_TIME} 15sec
29 ${HEALING_POL_TIME} 15sec
30 ${VIM_TIMEOUT_MULTIPLIER} %{OSM_VIM_MULTIPLIER_TIMEOUT=1.0}
34 Update Network Service
35 [Documentation] Run an update operation over a NS instance, and return the operation id.
36 [Arguments] ${ns_id} ${update_type} ${ns_update_config} ${ns_update_timeout}
37 ${rc} ${stdout}= Run And Return Rc And Output osm ns-update ${ns_id} --updatetype ${update_type} --config ${ns_update_config} --timeout ${ns_update_timeout} --wait
39 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
43 [Documentation] Execute an action over the desired NS.
44 ... Parameters are given to this function in key=value format (one argument per key/value pair).
45 ... Return the ID of the operation associated to the executed action.
46 ... Examples of execution:
47 ... \${ns_op_id}= Execute NS Action \${ns_name} \${ns_action} \${vnf_member_index}
48 ... \${ns_op_id}= Execute NS Action \${ns_name} \${ns_action} \${vnf_member_index} \${param1}=\${value1} \${param2}=\${value2}
50 [Arguments] ${ns_name} ${ns_action} ${vnf_member_index} @{action_params}
51 ${params}= Set Variable ${EMPTY}
52 FOR ${param} IN @{action_params}
53 ${match} ${param_name} ${param_value}= Should Match Regexp ${param} (.+)=(.+) msg=Syntax error in parameters
54 Log ${match},${param_name},${param_value}
55 ${params}= Catenate SEPARATOR= ${params} "${param_name}":"${param_value}",
57 ${osm_ns_action_command}= Set Variable osm ns-action --action_name ${ns_action} --vnf_name ${vnf_member_index}
58 IF '${params}' != '${EMPTY}'
59 ${osm_ns_action_command}= Catenate ${osm_ns_action_command} --params '{${params}}'
61 ${osm_ns_action_command}= Set Variable ${osm_ns_action_command}
63 ${osm_ns_action_command}= Catenate ${osm_ns_action_command} ${ns_name}
64 ${rc} ${stdout}= Run And Return Rc And Output ${osm_ns_action_command}
65 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=${stdout} values=False
66 Wait Until Keyword Succeeds ${NS_ACTION_MAX_WAIT_TIME} ${NS_ACTION_POL_TIME} Check For NS Operation Ended ${stdout}
67 Check For NS Operation Completed ${stdout}
71 [Documentation] Execute an action over the desired K8s NS.
72 ... Parameters are given to this function in key=value format (one argument per key/value pair).
73 ... Return the ID of the operation associated to the executed action.
74 ... Examples of execution:
75 ... \${ns_op_id}= Execute NS Action \${ns_name} \${ns_action} \${vnf_member_index}
76 ... \${ns_op_id}= Execute NS Action \${ns_name} \${ns_action} \${vnf_member_index} \${param1}=\${value1} \${param2}=\${value2}
78 [Arguments] ${ns_name} ${ns_action} ${vnf_member_index} ${kdu_name} @{action_params}
80 ${params}= Set Variable ${EMPTY}
81 FOR ${param} IN @{action_params}
82 ${match} ${param_name} ${param_value}= Should Match Regexp ${param} (.+)=(.+) msg=Syntax error in parameters
83 Log ${match},${param_name},${param_value}
84 ${params}= Catenate SEPARATOR= ${params} "${param_name}":"${param_value}",
86 ${osm_ns_action_command}= Set Variable osm ns-action --action_name ${ns_action} --vnf_name ${vnf_member_index} --kdu_name ${kdu_name}
87 IF '${params}' != '${EMPTY}'
88 ${osm_ns_action_command}= Catenate ${osm_ns_action_command} --params '{${params}}'
90 ${osm_ns_action_command}= Set Variable ${osm_ns_action_command}
92 ${osm_ns_action_command}= Catenate ${osm_ns_action_command} ${ns_name}
93 ${rc} ${stdout}= Run And Return Rc And Output ${osm_ns_action_command}
94 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=${stdout} values=False
95 Wait Until Keyword Succeeds ${NS_ACTION_MAX_WAIT_TIME} ${NS_ACTION_POL_TIME} Check For NS Operation Ended ${stdout}
96 Check For NS Operation Completed ${stdout}
99 Execute Manual VNF Scale
100 [Documentation] Execute a manual VNF Scale action.
101 ... The parameter 'scale_type' must be SCALE_IN or SCALE_OUT.
102 ... Return the ID of the operation associated to the executed scale action.
103 [Arguments] ${ns_name} ${vnf_member_index} ${scaling_group} ${scale_type} ${vnf_scale_max_wait_time}=2min
104 ${vnf_scale_max_wait_time}= Convert Time ${vnf_scale_max_wait_time} result_format=number
105 ${vnf_scale_max_wait_time}= Evaluate ${vnf_scale_max_wait_time} * ${VIM_TIMEOUT_MULTIPLIER}
106 Should Contain Any ${scale_type} SCALE_IN SCALE_OUT msg=Unknown scale type: ${scale_type} values=False
107 ${osm_vnf_scale_command}= Set Variable osm vnf-scale --scaling-group ${scaling_group}
108 IF '${scale_type}'=='SCALE_IN'
109 ${osm_vnf_scale_command}= Catenate ${osm_vnf_scale_command} --scale-in
111 ${osm_vnf_scale_command}= Catenate ${osm_vnf_scale_command} --scale-out
113 ${osm_vnf_scale_command}= Catenate ${osm_vnf_scale_command} ${ns_name} ${vnf_member_index}
114 ${rc} ${stdout}= Run And Return Rc And Output ${osm_vnf_scale_command}
115 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=${stdout} values=False
116 Wait Until Keyword Succeeds ${vnf_scale_max_wait_time} ${VNF_SCALE_POL_TIME} Check For NS Operation Ended ${stdout}
117 Check For NS Operation Completed ${stdout}
121 [Documentation] Execute healing operation over one NS.
122 ... Return the ID of the operation associated to the executed healing action.
123 [Arguments] ${ns_name} ${params} ${healing_max_wait_time}=10m
124 Should Not Be Empty ${ns_name}
125 Should Not Be Empty ${params}
126 ${healing_max_wait_time}= Convert Time ${healing_max_wait_time} result_format=number
127 ${healing_max_wait_time}= Evaluate ${healing_max_wait_time} * ${VIM_TIMEOUT_MULTIPLIER}
128 ${rc} ${stdout}= Run And Return Rc And Output osm ns-heal ${ns_name} ${params}
129 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE} msg=${stdout} values=False
130 Wait Until Keyword Succeeds ${healing_max_wait_time} ${HEALING_POL_TIME} Check For NS Operation Ended ${stdout}
131 Check For NS Operation Completed ${stdout}
135 [Documentation] Get the list of operations of a given NS instance.
136 [Arguments] ${ns_name}
137 Should Not Be Empty ${ns_name}
138 ${rc} ${stdout}= Run And Return Rc And Output osm ns-op-list ${ns_name}
141 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
143 Check For NS Operation Completed
144 [Documentation] Check wheter the status of the desired operation is "COMPLETED" or not.
145 [Arguments] ${ns_operation_id}
146 Should Not Be Empty ${ns_operation_id}
147 ${rc} ${stdout}= Run And Return Rc And Output osm ns-op-show ${ns_operation_id} --literal | yq -r .operationState
149 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
150 Should Contain ${stdout} COMPLETED msg=The ns-action with id ${ns_operation_id} was not completed values=False
152 Check For NS Operation Failed
153 [Documentation] Check wheter the status of the desired operation is "FAILED" or not.
154 [Arguments] ${ns_operation_id}
155 Should Not Be Empty ${ns_operation_id}
156 ${rc} ${stdout}= Run And Return Rc And Output osm ns-op-show ${ns_operation_id} --literal | yq -r .operationState
158 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
159 Should Contain ${stdout} FAILED msg=Timeout waiting for ns-action with id ${ns_operation_id} values=False
161 Check For NS Operation Ended
162 [Documentation] Check wheter the status of the desired operation is "FAILED" or "COMPLETED".
163 [Arguments] ${ns_operation_id}
164 Should Not Be Empty ${ns_operation_id}
165 ${rc} ${stdout}= Run And Return Rc And Output osm ns-op-show ${ns_operation_id} --literal | yq -r .operationState
167 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
168 Should Contain Any ${stdout} FAILED COMPLETED msg=Timeout waiting for ns-action with id ${ns_operation_id} values=False
170 Check For NS Operation Cancelled
171 [Documentation] Check whether the operation was cancelled or not.
172 [Arguments] ${ns_operation_id}
173 Should Not Be Empty ${ns_operation_id}
174 ${rc} ${stdout}= Run And Return Rc And Output osm ns-op-show ${ns_operation_id} --literal | yq -r '.operationState, .isCancelPending'
176 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
177 Should Contain ${stdout} FAILED_TEMP\nfalse msg=Timeout waiting for ns-action with id ${ns_operation_id} values=False
179 Get Operations By Type
180 [Documentation] Keyword to get the operation by type
181 [Arguments] ${ns_id} ${type}
182 Should Not Be Empty ${ns_id}
183 Should Not Be Empty ${type}
184 ${rc} ${stdout}= Run And Return Rc And Output osm ns-op-list ${ns_id} | grep ${type} | awk '{print $2}' 2>&1
186 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
187 Should Not Be Empty ${stdout}
190 Cancel Operation By Id
191 [Documentation] Cancels an ongoing operation by operation ID
192 [Arguments] ${op_id} ${cancel_mode}=GRACEFUL
194 Should Not Be Empty ${op_id}
195 ${rc} ${stdout}= Run And Return RC And Output osm ns-op-cancel ${op_id} --cancel_mode ${cancel_mode} --wait
197 Should Be Equal As Integers ${rc} ${success_return_code}