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