2 Documentation Common Keywords for the SFC Test suites.
4 Resource ../CompareStream.robot
5 Resource ../Utils.robot
10 Get JSON Elements From URI
12 ${resp} = RequestsLibrary.Get Request session ${uri}
13 [Return] ${resp.json()}
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 [Arguments] ${elements}
25 [Documentation] Check that the service function types are updated with the service function names
26 Utils.Check For Elements At URI ${SERVICE_FUNCTION_TYPES_URI} ${elements}
28 Check Service Function Types Removed
29 [Arguments] ${elements}
30 [Documentation] Check that the service function names are removed from the service function types
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 [Arguments] ${sfp_name}
39 [Documentation] Check that the Rendered Service Path is created
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 [Arguments] ${sfp_name}
45 [Documentation] Check that the Rendered Service Path is deleted
46 Utils.No Content From URI session ${SERVICE_FUNCTION_PATH_STATE_URI}/${sfp_name}
48 Get Rendered Service Path Name
49 [Arguments] ${sfp_name} ${get_reverse}=False
50 [Documentation] Given an SFP name, do a get on ${SERVICE_FUNCTION_PATH_STATE_URI} to get the RSP name
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 ${resp.json()} service-function-path-state
55 ${sfp_rendered_service_path_dict} = Collections.Get_From_List ${sfp_rendered_service_path_list} 0
56 ${sfp_state_list} = Collections.Get_From_Dictionary ${sfp_rendered_service_path_dict} sfp-rendered-service-path
57 ${list_length} = BuiltIn.Get Length ${sfp_state_list}
58 # The "sfp-rendered-service-path" will only have 1 or 2 entries, depending on chain symmetry config.
59 # The RSP name will be "<SfpName>-Path-<PathId>" and the optional symmetric name will be <SfpName>-Path-<PathId>-Reverse"
60 ${value} = BuiltIn.Set Variable None
61 : FOR ${i} IN RANGE ${list_length}
62 \ ${rsp_name_dict} = Collections.Get From List ${sfp_state_list} ${i}
63 \ ${name} = Collections.Get_From_Dictionary ${rsp_name_dict} name
64 \ @{matches} = String.Get Regexp Matches ${name} .*Reverse$
65 \ ${matches_length} = BuiltIn.Get Length ${matches}
66 \ ${value} = BuiltIn.Set Variable If "${get_reverse}" == "False" and 0 == ${matches_length} ${name} "${get_reverse}" == "True" and 0 < ${matches_length} ${name}
67 \ ... "${value}" != "None" ${value}
70 Create Sfp And Wait For Rsp Creation
71 [Arguments] ${sfp_file_name}
72 [Documentation] Given an SFP name, create it and wait for the associated RSPs to be created
73 Utils.Add Elements To URI From File And Verify ${SERVICE_FUNCTION_PATHS_URI} ${sfp_file_name}
74 ${sfp_dict} = Utils.Json Parse From File ${sfp_file_name}
75 ${sfps} = Collections.Get_From_Dictionary ${sfp_dict} service-function-paths
76 ${sfp_json_list} = Collections.Get_From_Dictionary ${sfps} service-function-path
77 ${list_length} = BuiltIn.Get Length ${sfp_json_list}
78 # Each SFP state entry returned from ODL will have either 2 or 3 name elements, 2 for non-symmetric 3 for symmetric RSP
79 : FOR ${i} IN RANGE ${list_length}
80 \ ${sfp_entry_dict} = Collections.Get From List ${sfp_json_list} ${i}
81 \ ${sfp_name} = Collections.Get_From_Dictionary ${sfp_entry_dict} name
82 \ ${status} ${symmetric} = BuiltIn.Run Keyword And Ignore Error Collections.Get_From_Dictionary ${sfp_entry_dict} symmetric
83 \ ${symmetric} = BuiltIn.Set Variable If "${status}" == "FAIL" False ${symmetric}
84 \ ${num_names} = BuiltIn.Set Variable If "${symmetric}" == "False" 2 3
85 \ BuiltIn.Wait Until Keyword Succeeds 60s 2s Utils.Check For Specific Number Of Elements At URI ${SERVICE_FUNCTION_PATH_STATE_URI}/${sfp_name} name
88 Delete Sfp And Wait For Rsps Deletion
89 [Arguments] ${sfp_name}
90 [Documentation] Given an SFP name, delete it and wait for the associated SFP state and RSPs to be deleted
91 Utils.Remove All Elements At URI And Verify ${SERVICE_FUNCTION_PATH_URI}/${sfp_name}
92 BuiltIn.Wait Until Keyword Succeeds 60s 2s Check Rendered Service Path Deleted ${sfp_name}
94 Delete All Sfps And Wait For Rsps Deletion
95 [Documentation] Delete all SFPs and wait for the RSPs to be deleted
96 Utils.Remove All Elements At URI And Verify ${SERVICE_FUNCTION_PATHS_URI}
97 BuiltIn.Wait Until Keyword Succeeds 60s 2s Check Empty Service Function Paths State
99 Switch Ips In Json Files
100 [Arguments] ${json_dir} ${container_names}
101 ${normalized_dir}= OperatingSystem.Normalize Path ${json_dir}/*.json
102 : FOR ${cont_name} IN @{container_names}
103 \ ${cont_ip} = Get Docker IP ${cont_name}
104 \ OperatingSystem.Run sudo sed -i 's/${cont_name}/${cont_ip}/g' ${normalized_dir}