Fix netconf entity name creation during lookup
[integration/test.git] / csit / libraries / SFC / SfcKeywords.robot
index 2dafb53d85f5ce895da6be8c33be2f070267dc45..5ebe41449a370bac0e1f3ba9f84226e08b131504 100644 (file)
@@ -1,16 +1,12 @@
 *** Settings ***
 Documentation     Common Keywords for the SFC Test suites.
 Library           Collections
-Resource          ../../../libraries/Utils.robot
+Resource          ../CompareStream.robot
+Resource          ../Utils.robot
 
 *** Variables ***
 
 *** Keywords ***
-Post Elements To URI As JSON
-    [Arguments]    ${uri}    ${data}
-    ${resp} =    RequestsLibrary.Post Request    session    ${uri}    data=${data}    headers=${headers}
-    BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
-
 Get JSON Elements From URI
     [Arguments]    ${uri}
     ${resp} =    RequestsLibrary.Get Request    session    ${uri}
@@ -19,8 +15,10 @@ Get JSON Elements From URI
 Check Classifier Flows
     ${flowList} =    DockerSfc.Get Flows In Docker Containers
     BuiltIn.log    ${flowList}
-    BuiltIn.Should Contain Match    ${flowList}    *actions=pop_nsh*
-    BuiltIn.Should Contain Match    ${flowList}    *actions=push_nsh*
+    ${expected_nsh_pop}=    Set_Variable_If_At_Most    oxygen    *actions=pop_nsh*    *actions=decap(),decap(),*
+    ${expected_nsh_push}=    Set_Variable_If_At_Most    oxygen    *actions=push_nsh*    *actions=encap(nsh*
+    Collections.Should Contain Match    ${flowList}    ${expected_nsh_pop}
+    Collections.Should Contain Match    ${flowList}    ${expected_nsh_push}
 
 Check Service Function Types Added
     [Arguments]    ${elements}
@@ -34,7 +32,7 @@ Check Service Function Types Removed
 
 Check Empty Service Function Paths State
     [Documentation]    Check that the service function paths state is empty after deleting SFPs
-    Utils.Check For Specific Number Of Elements At URI    ${SERVICE_FUNCTION_PATHS_STATE_URI}    service-function-path-state    0
+    Utils.No Content From URI    session    ${SERVICE_FUNCTION_PATH_STATE_URI}
 
 Check Rendered Service Path Created
     [Arguments]    ${sfp_name}
@@ -45,13 +43,12 @@ Check Rendered Service Path Created
 Check Rendered Service Path Deleted
     [Arguments]    ${sfp_name}
     [Documentation]    Check that the Rendered Service Path is deleted
-    ${sfp_name_elements_list} =    BuiltIn.Create List    ${sfp_name}
-    Utils.Check For Elements Not At URI    ${SERVICE_FUNCTION_PATHS_STATE_URI}    ${sfp_name_elements_list}
+    Utils.No Content From URI    session    ${SERVICE_FUNCTION_PATH_STATE_URI}/${sfp_name}
 
 Get Rendered Service Path Name
     [Arguments]    ${sfp_name}    ${get_reverse}=False
     [Documentation]    Given an SFP name, do a get on ${SERVICE_FUNCTION_PATH_STATE_URI} to get the RSP name
-    ${resp} =    RequestsLibrary.Get Request    session    ${SERVICE_FUNCTION_PATH_STATE_URI}${sfp_name}
+    ${resp} =    RequestsLibrary.Get Request    session    ${SERVICE_FUNCTION_PATH_STATE_URI}/${sfp_name}
     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
     # should be like this: {"service-function-path-state":[{"name":"SFC1-100","sfp-rendered-service-path":[{"name":"SFC1-100-Path-183"}]}]}
     ${sfp_rendered_service_path_list} =    Collections.Get_From_Dictionary    ${resp.json()}    service-function-path-state
@@ -61,26 +58,39 @@ Get Rendered Service Path Name
     # The "sfp-rendered-service-path" will only have 1 or 2 entries, depending on chain symmetry config.
     # The RSP name will be "<SfpName>-Path-<PathId>" and the optional symmetric name will be <SfpName>-Path-<PathId>-Reverse"
     ${value} =    BuiltIn.Set Variable    None
-    : FOR    ${i}    IN RANGE    ${list_length}
-    \    ${rsp_name_dict} =    Collections.Get From List    ${sfp_state_list}    ${i}
-    \    ${name} =    Collections.Get_From_Dictionary    ${rsp_name_dict}    name
-    \    @{matches} =    String.Get Regexp Matches    ${name}    .*Reverse$
-    \    ${matches_length} =    BuiltIn.Get Length    ${matches}
-    \    ${value} =    BuiltIn.Set Variable If    "${get_reverse}" == "False" and 0 == ${matches_length}    ${name}    "${get_reverse}" == "True" and 0 < ${matches_length}    ${name}
-    \    ...    "${value}" != "None"    ${value}
+    FOR    ${i}    IN RANGE    ${list_length}
+        ${rsp_name_dict} =    Collections.Get From List    ${sfp_state_list}    ${i}
+        ${name} =    Collections.Get_From_Dictionary    ${rsp_name_dict}    name
+        @{matches} =    String.Get Regexp Matches    ${name}    .*Reverse$
+        ${matches_length} =    BuiltIn.Get Length    ${matches}
+        ${value} =    BuiltIn.Set Variable If    "${get_reverse}" == "False" and 0 == ${matches_length}    ${name}    "${get_reverse}" == "True" and 0 < ${matches_length}    ${name}
+        ...    "${value}" != "None"    ${value}
+    END
     [Return]    ${value}
 
 Create Sfp And Wait For Rsp Creation
-    [Arguments]    ${sfp_file_name}    ${created_sfps}
+    [Arguments]    ${sfp_file_name}
     [Documentation]    Given an SFP name, create it and wait for the associated RSPs to be created
     Utils.Add Elements To URI From File And Verify    ${SERVICE_FUNCTION_PATHS_URI}    ${sfp_file_name}
-    BuiltIn.Run Keyword If    len(${created_sfps}) > 0    BuiltIn.Wait Until Keyword Succeeds    60s    2s    Utils.Check For Elements At URI    ${SERVICE_FUNCTION_PATHS_STATE_URI}
-    ...    ${created_sfps}
+    ${sfp_dict} =    Utils.Json Parse From File    ${sfp_file_name}
+    ${sfps} =    Collections.Get_From_Dictionary    ${sfp_dict}    service-function-paths
+    ${sfp_json_list} =    Collections.Get_From_Dictionary    ${sfps}    service-function-path
+    ${list_length} =    BuiltIn.Get Length    ${sfp_json_list}
+    # Each SFP state entry returned from ODL will have either 2 or 3 name elements, 2 for non-symmetric 3 for symmetric RSP
+    FOR    ${i}    IN RANGE    ${list_length}
+        ${sfp_entry_dict} =    Collections.Get From List    ${sfp_json_list}    ${i}
+        ${sfp_name} =    Collections.Get_From_Dictionary    ${sfp_entry_dict}    name
+        ${status}    ${symmetric} =    BuiltIn.Run Keyword And Ignore Error    Collections.Get_From_Dictionary    ${sfp_entry_dict}    symmetric
+        ${symmetric} =    BuiltIn.Set Variable If    "${status}" == "FAIL"    False    ${symmetric}
+        ${num_names} =    BuiltIn.Set Variable If    "${symmetric}" == "False"    2    3
+        BuiltIn.Wait Until Keyword Succeeds    60s    2s    Utils.Check For Specific Number Of Elements At URI    ${SERVICE_FUNCTION_PATH_STATE_URI}/${sfp_name}    name
+        ...    ${num_names}
+    END
 
 Delete Sfp And Wait For Rsps Deletion
     [Arguments]    ${sfp_name}
     [Documentation]    Given an SFP name, delete it and wait for the associated SFP state and RSPs to be deleted
-    Utils.Remove All Elements At URI And Verify    ${SERVICE_FUNCTION_PATH_URI}${sfp_name}
+    Utils.Remove All Elements At URI And Verify    ${SERVICE_FUNCTION_PATH_URI}/${sfp_name}
     BuiltIn.Wait Until Keyword Succeeds    60s    2s    Check Rendered Service Path Deleted    ${sfp_name}
 
 Delete All Sfps And Wait For Rsps Deletion
@@ -91,6 +101,7 @@ Delete All Sfps And Wait For Rsps Deletion
 Switch Ips In Json Files
     [Arguments]    ${json_dir}    ${container_names}
     ${normalized_dir}=    OperatingSystem.Normalize Path    ${json_dir}/*.json
-    : FOR    ${cont_name}    IN    @{container_names}
-    \    ${cont_ip} =    Get Docker IP    ${cont_name}
-    \    OperatingSystem.Run    sudo sed -i 's/${cont_name}/${cont_ip}/g' ${normalized_dir}
+    FOR    ${cont_name}    IN    @{container_names}
+        ${cont_ip} =    Get Docker IP    ${cont_name}
+        OperatingSystem.Run    sudo sed -i 's/${cont_name}/${cont_ip}/g' ${normalized_dir}
+    END