Refactor SFC_FullDeploy tests to not use RSP RPCs
[integration/test.git] / csit / libraries / SFC / SfcKeywords.robot
1 *** Settings ***
2 Documentation     Common Keywords for the SFC Test suites.
3 Library           Collections
4 Resource          ../Utils.robot
5
6 *** Variables ***
7
8 *** Keywords ***
9 Get JSON Elements From URI
10     [Arguments]    ${uri}
11     ${resp} =    RequestsLibrary.Get Request    session    ${uri}
12     [Return]    ${resp.json()}
13
14 Check Classifier Flows
15     ${flowList} =    DockerSfc.Get Flows In Docker Containers
16     BuiltIn.log    ${flowList}
17     BuiltIn.Should Contain    ${flowList}    *actions=pop_nsh*
18     BuiltIn.Should Contain    ${flowList}    *actions=push_nsh*
19
20 Check Service Function Types Added
21     [Arguments]    ${elements}
22     [Documentation]    Check that the service function types are updated with the service function names
23     Utils.Check For Elements At URI    ${SERVICE_FUNCTION_TYPES_URI}    ${elements}
24
25 Check Service Function Types Removed
26     [Arguments]    ${elements}
27     [Documentation]    Check that the service function names are removed from the service function types
28     Utils.Check For Elements Not At URI    ${SERVICE_FUNCTION_TYPES_URI}    ${elements}
29
30 Check Empty Service Function Paths State
31     [Documentation]    Check that the service function paths state is empty after deleting SFPs
32     Utils.Check For Specific Number Of Elements At URI    ${SERVICE_FUNCTION_PATHS_STATE_URI}    service-function-path-state    0
33
34 Check Rendered Service Path Created
35     [Arguments]    ${sfp_name}
36     [Documentation]    Check that the Rendered Service Path is created
37     ${sfp_name_elements_list} =    BuiltIn.Create List    ${sfp_name}
38     Utils.Check For Elements At URI    ${SERVICE_FUNCTION_PATHS_STATE_URI}    ${sfp_name_elements_list}
39
40 Check Rendered Service Path Deleted
41     [Arguments]    ${sfp_name}
42     [Documentation]    Check that the Rendered Service Path is deleted
43     ${sfp_name_elements_list} =    BuiltIn.Create List    ${sfp_name}
44     Utils.Check For Elements Not At URI    ${SERVICE_FUNCTION_PATHS_STATE_URI}    ${sfp_name_elements_list}
45
46 Get Rendered Service Path Name
47     [Arguments]    ${sfp_name}    ${get_reverse}=False
48     [Documentation]    Given an SFP name, do a get on ${SERVICE_FUNCTION_PATH_STATE_URI} to get the RSP name
49     ${resp} =    RequestsLibrary.Get Request    session    ${SERVICE_FUNCTION_PATH_STATE_URI}${sfp_name}
50     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
51     # should be like this: {"service-function-path-state":[{"name":"SFC1-100","sfp-rendered-service-path":[{"name":"SFC1-100-Path-183"}]}]}
52     ${sfp_rendered_service_path_list} =    Collections.Get_From_Dictionary    ${resp.json()}    service-function-path-state
53     ${sfp_rendered_service_path_dict} =    Collections.Get_From_List    ${sfp_rendered_service_path_list}    0
54     ${sfp_state_list} =    Collections.Get_From_Dictionary    ${sfp_rendered_service_path_dict}    sfp-rendered-service-path
55     ${list_length} =    BuiltIn.Get Length    ${sfp_state_list}
56     # The "sfp-rendered-service-path" will only have 1 or 2 entries, depending on chain symmetry config.
57     # The RSP name will be "<SfpName>-Path-<PathId>" and the optional symmetric name will be <SfpName>-Path-<PathId>-Reverse"
58     ${value} =    BuiltIn.Set Variable    None
59     : FOR    ${i}    IN RANGE    ${list_length}
60     \    ${rsp_name_dict} =    Collections.Get From List    ${sfp_state_list}    ${i}
61     \    ${name} =    Collections.Get_From_Dictionary    ${rsp_name_dict}    name
62     \    @{matches} =    String.Get Regexp Matches    ${name}    .*Reverse$
63     \    ${matches_length} =    BuiltIn.Get Length    ${matches}
64     \    ${value} =    BuiltIn.Set Variable If    "${get_reverse}" == "False" and 0 == ${matches_length}    ${name}    "${get_reverse}" == "True" and 0 < ${matches_length}    ${name}
65     \    ...    "${value}" != "None"    ${value}
66     [Return]    ${value}
67
68 Create Sfp And Wait For Rsp Creation
69     [Arguments]    ${sfp_file_name}
70     [Documentation]    Given an SFP name, create it and wait for the associated RSPs to be created
71     Utils.Add Elements To URI From File And Verify    ${SERVICE_FUNCTION_PATHS_URI}    ${sfp_file_name}
72     ${sfp_dict} =    Utils.Json Parse From File    ${sfp_file_name}
73     ${sfps} =    Collections.Get_From_Dictionary    ${sfp_dict}    service-function-paths
74     ${sfp_json_list} =    Collections.Get_From_Dictionary    ${sfps}    service-function-path
75     ${list_length} =    BuiltIn.Get Length    ${sfp_json_list}
76     # Each SFP state entry returned from ODL will have either 2 or 3 name elements, 2 for non-symmetric 3 for symmetric RSP
77     : FOR    ${i}    IN RANGE    ${list_length}
78     \    ${sfp_entry_dict} =    Collections.Get From List    ${sfp_json_list}    ${i}
79     \    ${sfp_name} =    Collections.Get_From_Dictionary    ${sfp_entry_dict}    name
80     \    ${status}    ${symmetric} =    BuiltIn.Run Keyword And Ignore Error    Collections.Get_From_Dictionary    ${sfp_entry_dict}    symmetric
81     \    ${symmetric} =    BuiltIn.Set Variable If    "${status}" == "FAIL"    False    ${symmetric}
82     \    ${num_names} =    BuiltIn.Set Variable If    "${symmetric}" == "False"    2    3
83     \    BuiltIn.Wait Until Keyword Succeeds    60s    2s    Utils.Check For Specific Number Of Elements At URI    ${SERVICE_FUNCTION_PATH_STATE_URI}${sfp_name}    name
84     \    ...    ${num_names}
85
86 Delete Sfp And Wait For Rsps Deletion
87     [Arguments]    ${sfp_name}
88     [Documentation]    Given an SFP name, delete it and wait for the associated SFP state and RSPs to be deleted
89     Utils.Remove All Elements At URI And Verify    ${SERVICE_FUNCTION_PATH_URI}${sfp_name}
90     BuiltIn.Wait Until Keyword Succeeds    60s    2s    Check Rendered Service Path Deleted    ${sfp_name}
91
92 Delete All Sfps And Wait For Rsps Deletion
93     [Documentation]    Delete all SFPs and wait for the RSPs to be deleted
94     Utils.Remove All Elements At URI And Verify    ${SERVICE_FUNCTION_PATHS_URI}
95     BuiltIn.Wait Until Keyword Succeeds    60s    2s    Check Empty Service Function Paths State
96
97 Switch Ips In Json Files
98     [Arguments]    ${json_dir}    ${container_names}
99     ${normalized_dir}=    OperatingSystem.Normalize Path    ${json_dir}/*.json
100     : FOR    ${cont_name}    IN    @{container_names}
101     \    ${cont_ip} =    Get Docker IP    ${cont_name}
102     \    OperatingSystem.Run    sudo sed -i 's/${cont_name}/${cont_ip}/g' ${normalized_dir}