Updated k8s04: new test to upgrade KDU with new keyword in ns_lib
[osm/tests.git] / robot-systest / lib / ns_lib.robot
index b1db909..148e381 100644 (file)
 *** Variables ***
 ${success_return_code}   0
 ${ns_launch_pol_time}   30sec
-${ns_delete_max_wait_time}   3min
+${ns_delete_max_wait_time}   4min
 ${ns_delete_pol_time}   15sec
 ${ns_action_max_wait_time}   1min
 ${ns_action_pol_time}   15sec
-${vnf_scale_max_wait_time}   5min
-${vnf_scale_pol_time}   30sec
+${vnf_scale_max_wait_time}   2min
+${vnf_scale_pol_time}   15sec
 
 
 *** Keywords ***
@@ -57,6 +57,17 @@ Get Vnf Management Ip Address
     [Return]  ${stdout}
 
 
+Get Vnf Id
+    [Arguments]   ${ns_id}   ${vnf_member_index}
+
+    Should Not Be Empty   ${ns_id}
+    Should Not Be Empty   ${vnf_member_index}
+    ${rc}   ${stdout}=   Run and Return RC and Output   osm vnf-list --filter member-vnf-index-ref=${vnf_member_index} | grep ${ns_id} | awk '{print $2}' 2>&1
+    log   ${stdout}
+    Should Be Equal As Integers   ${rc}   ${success_return_code}
+    [Return]  ${stdout}
+
+
 Get Ns Vnf List
     [Arguments]   ${ns_id}
 
@@ -86,7 +97,7 @@ Get Vnf Ip List
     [arguments]   ${vnf_id}
 
     should not be empty   ${vnf_id}
-    @{vnf_ip_list_string}=   run and return rc and output   osm vnf-show ${vnf_id} --filter vdur --literal | grep -o '[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}' | sort -t: -u -k1,1 2>&1
+    @{vnf_ip_list_string}=   run and return rc and output   osm vnf-list --filter id=${vnf_id} | grep -o '[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}' | sort -t: -u -k1,1 2>&1
     # returns a string of ip addresses and needs to be converted into a list
     should not be empty   ${vnf_ip_list_string}[1]
     @{vnf_ip_list} =  split string    ${vnf_ip_list_string}[1]
@@ -152,6 +163,31 @@ Execute NS Action
     [Return]  ${stdout}
 
 
+Execute NS K8s Action
+    [Documentation]     Execute an action over the desired K8s NS.
+    ...                 Parameters are given to this function in key=value format (one argument per key/value pair).
+    ...                 Return the ID of the operation associated to the executed action.
+    ...                 Examples of execution:
+    ...                     \${ns_op_id}=  Execute NS Action  \${ns_name}  \${ns_action}  \${vnf_member_index}
+    ...                     \${ns_op_id}=  Execute NS Action  \${ns_name}  \${ns_action}  \${vnf_member_index}  \${param1}=\${value1}  \${param2}=\${value2}
+
+    [Arguments]  ${ns_name}  ${ns_action}  ${vnf_member_index}  ${kdu_name}  @{action_params}
+
+    ${params}=  Set Variable  ${EMPTY}
+    FOR  ${param}  IN  @{action_params}
+        ${match}  ${param_name}  ${param_value} =  Should Match Regexp  ${param}  (.+)=(.+)  msg=Syntax error in parameters
+        ${params}=  Catenate  SEPARATOR=  ${params}  "${param_name}":"${param_value}",
+    END
+    ${osm_ns_action_command}=  Set Variable  osm ns-action --action_name ${ns_action} --vnf_name ${vnf_member_index} --kdu_name ${kdu_name}
+    ${osm_ns_action_command}=  Run Keyword If  '${params}'!='${EMPTY}'  Catenate  ${osm_ns_action_command}  --params '{${params}}'
+    ...  ELSE  Set Variable  ${osm_ns_action_command}
+    ${osm_ns_action_command}=  Catenate  ${osm_ns_action_command}  ${ns_name}
+    ${rc}  ${stdout}=  Run and Return RC and Output  ${osm_ns_action_command}
+    Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
+    Wait Until Keyword Succeeds  ${ns_action_max_wait_time}  ${ns_action_pol_time}  Check For NS Operation Completed  ${stdout}
+    [Return]  ${stdout}
+
+
 Execute Manual VNF Scale
     [Documentation]     Execute a manual VNF Scale action.
     ...                 The parameter 'scale_type' must be SCALE_IN or SCALE_OUT.
@@ -166,7 +202,7 @@ Execute Manual VNF Scale
     ${osm_vnf_scale_command}=  Catenate  ${osm_vnf_scale_command}  ${ns_name}  ${vnf_member_index}
     ${rc}  ${stdout}=  Run and Return RC and Output  ${osm_vnf_scale_command}
     Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
-    Wait Until Keyword Succeeds  ${ns_action_max_wait_time}  ${ns_action_pol_time}  Check For NS Operation Completed  ${stdout}
+    Wait Until Keyword Succeeds  ${vnf_scale_max_wait_time}  ${vnf_scale_pol_time}  Check For NS Operation Completed  ${stdout}
     [Return]  ${stdout}
 
 
@@ -211,3 +247,13 @@ Get Vnf Vdur Names
     @{vdur} =  Split String  ${stdout}
     [Return]  @{vdur}
 
+
+Get Vnf Kdu Replica Count
+    [Documentation]     Return the number of KDU replicas (empty if none) of a VNF instance.
+
+    [Arguments]   ${vnf_id}   ${kdu_name}
+
+    ${rc}  ${stdout}=  Run and Return RC and Output  osm vnf-show ${vnf_id} --kdu ${kdu_name} | yq r - config.replicaCount
+    Should Be Equal As Integers  ${rc}  ${success_return_code}  msg=${stdout}  values=False
+    [Return]  ${stdout}
+