2 Documentation GbpSxp library covering common tasks of gbp-sxp test cases.
4 Library OperatingSystem WITH NAME os
6 Library RequestsLibrary
8 Library ./GbpSxp.py WITH NAME gbpsxp
9 Resource ../variables/Variables.robot
10 Resource ./Utils.robot
11 Resource ./SSHKeywords.robot
15 ${ISE_API_DIR} ${CURDIR}/../variables/gbp/ise-mock-server-api
17 ${GBP_ENDPOINTS_URI} /restconf/operational/base-endpoint:endpoints
18 ${GBP_EP_TEMPLATES_CONFIG_URI} /restconf/config/sxp-ep-provider-model:sxp-ep-mapper
19 ${GBP_RENDERER_CONFIG_URI} /restconf/config/renderer:renderers/renderer/ios-xe-renderer
20 ${GBP_RENDERER_POLICY_OPERATIONAL_URI}
21 ... /restconf/operational/renderer:renderers/renderer/ios-xe-renderer/renderer-policy
22 ${GBP_RENDERER_POLICY_STATUS_OPERATIONAL_URI} ${GBP_RENDERER_POLICY_OPERATIONAL_URI}/status
23 ${GBP_RPC_UNREGISTER_ENDPOINT_URI} /restconf/operations/base-endpoint:unregister-endpoint
24 ${GBP_TENANT_CONFIG_URI} /restconf/config/policy:tenants/tenant/tenant-red
25 ${MOUNTPOINT_IOSXE_SUFFIX} yang-ext:mount/ned:native
27 ... /restconf/config/network-topology:network-topology/topology/topology-netconf
28 ${NETCONF_OPERATIONAL_URI}
29 ... /restconf/operational/network-topology:network-topology/topology/topology-netconf
30 ${SXP_EP_PROVIDER_CONFIG_URI} /restconf/config/sxp-ep-provider-model:sxp-ep-mapper
31 ${SXP_ISE_ADAPTER_CONFIG_URI} /restconf/config/sxp-ise-adapter-model:gbp-sxp-ise-adapter
32 ${SXP_ISE_ADAPTER_OPERATIONAL_URI} /restconf/operational/sxp-ise-adapter-model:gbp-sxp-ise-adapter
33 ${SXP_NODE_RPC_ADD_ENTRY_URI} /restconf/operations/sxp-controller:add-entry
34 ${SXP_TOPOLOGY_NODE_CONFIG_URI} /restconf/config/network-topology:network-topology/topology/sxp
35 ${SXP_TOPOLOGY_NODE_OPERATIONAL_URI}
36 ... /restconf/operational/network-topology:network-topology/topology/sxp
41 [Documentation] Setup ssh session to tools system
42 [Arguments] ${ip_address}=${TOOLS_SYSTEM_IP}
43 ${tools_connection} SSHKeywords.Open_Connection_To_Tools_System ${ip_address}
44 SSHKeywords.Virtual_Env_Create
45 SSHKeywords.Virtual_Env_Install_Package mock-server tornado==4.2
46 ${sed_output} SSHKeywords.Execute_Command_At_Path_Should_Pass
47 ... sed -r -i 's/^(DEFAULT_FORMAT = ).+$/\\1XML/' lib/python2.7/site-packages/mock_server/data.py
48 ... path=${SSHKeywords__current_venv_path}
49 SSHKeywords.Virtual_Env_Freeze
50 RETURN ${tools_connection}
52 Deploy_Ise_Mock_Server
53 [Documentation] Deploy and start ise mock-server
54 [Arguments] ${ise_mock_server_api_folder} ${ise_rest_port}
55 # deploy ise mock-server
56 SSHLibrary.Put_Directory ${ISE_API_DIR}/${ise_mock_server_api_folder} destination=. recursive=True
57 # start ise mock-server
58 SSHKeywords.Virtual_Env_Activate_On_Current_Session
60 ... mock-server --dir=${ise_mock_server_api_folder} --port=${ise_rest_port} --address=${TOOLS_SYSTEM_IP} --debug
61 BuiltIn.Wait_Until_Keyword_Succeeds 5 1 gbpsxp.Check_Ise_Mock_Server_Is_Online ${ise_rest_port}
62 ${mock_server_pid} SSHKeywords.Execute_Command_Should_Pass pgrep -f mock-server
63 SSHKeywords.Execute_Command_Should_Pass lsof -p ${mock_server_pid}
65 Teardown_Ise_Mock_Server
66 [Documentation] Stop and wipe clean ise mock-server
67 [Arguments] ${ise_mock_server_api_folder}
68 # stop ise mock-server
69 SSHLibrary.Execute_command pkill -f mock-server return_stderr=True return_rc=False
70 SSHKeywords.Execute_Command_Should_Pass
71 ... ls -la ${ise_mock_server_api_folder}; cat ${ise_mock_server_api_folder}/access-*.log
72 # wipe ise mock-server deployment
73 SSHLibrary.Execute_command rm -rf ${ise_mock_server_api_folder} return_stderr=True return_rc=False
76 [Documentation] Deactivate virtualenv and close ssh session on tools system
77 [Arguments] ${session_list}=@{EMPTY}
78 FOR ${ssh_session} IN @{session_list}
79 BuiltIn.Log ${ssh_session}
80 SSHKeywords.Restore_Current_Ssh_Connection_From_Index ${ssh_session}
81 SSHKeywords.Virtual_Env_Deactivate_On_Current_Session
82 SSHKeywords.Virtual_Env_Delete
83 # fallback to single session
85 ${session_list_size} get length ${session_list}
86 BuiltIn.Log ${session_list_size}
87 IF ${session_list_size} == 0
88 SSHKeywords.Virtual_Env_Deactivate_On_Current_Session
90 IF ${session_list_size} == 0 SSHKeywords.Virtual_Env_Delete
91 SSHLibrary.Close_All_Connections
93 Configure_Ise_Source_And_Gain_Harvest_Status
94 [Documentation] Post ise-source configuration and wait for ise harvest status
95 [Arguments] ${session_arg} ${configure_ise_source_file} ${ise_rest_uri}
96 # post ise-source configuration and wait for status
97 ${sxp_source_config_json} Utils.Json_Parse_From_File ${configure_ise_source_file}
98 gbpsxp.Replace_Ise_Source_Address ${sxp_source_config_json} ${ise_rest_uri}
99 BuiltIn.Log ${sxp_source_config_json}
100 ${now} DateTime.Get_Current_Date result_format=%Y-%m-%dT%H:%M:%S.%f
101 Utils.Post_Elements_To_URI ${SXP_ISE_ADAPTER_CONFIG_URI} ${sxp_source_config_json}
102 ${ise_harvest_status_json} BuiltIn.Wait_Until_Keyword_Succeeds
105 ... Gain_Uptodate_Harvest_Status
108 RETURN ${ise_harvest_status_json}
110 Gain_Uptodate_Harvest_Status
111 [Documentation] Read ise source harvest status and check if timestamp not older then limit
112 [Arguments] ${session_arg} ${now_timestamp}
113 ${ise_harvest_status} Utils.Get_Data_From_URI ${session_arg} ${SXP_ISE_ADAPTER_OPERATIONAL_URI}
114 ${ise_harvest_status_json} Utils.Json_Parse_From_String ${ise_harvest_status}
115 ${status_timestamp} BuiltIn.Set_Variable
116 ... ${ise_harvest_status_json['gbp-sxp-ise-adapter']['ise-harvest-status']['timestamp']}
117 gbpsxp.Check_iso8601_datetime_younger_then_limit ${status_timestamp} ${now_timestamp}
118 RETURN ${ise_harvest_status_json}
120 Check_Ise_Mock_Server_Is_Online
121 [Documentation] Checks if the port ${ise_port} is occupied on tools system
122 [Arguments] ${ise_port}
123 ${ise_port_occupied} SSHLibrary.Execute_command
124 ... netstat -lnp | grep '${ise_port}'
125 ... return_stdout=False
127 BuiltIn.Should_Be_Equal_As_Integers 0 ${ise_port_occupied}
129 Check_Ise_Harvest_Status
130 [Documentation] Check ise harvest status by templatest written amount
131 [Arguments] ${ise_harvest_status_json} ${expected_templates_amount}
132 ${templates_written} BuiltIn.Set_Variable
133 ... ${ise_harvest_status_json['gbp-sxp-ise-adapter']['ise-harvest-status']['templates-written']}
134 BuiltIn.Should_Be_Equal_As_Integers ${expected_templates_amount} ${templates_written}
136 Clean_ise_source_config
137 [Documentation] Wipe clean ise source configuration
138 BuiltIn.Run_Keyword_And_Ignore_Error Utils.Remove_All_Elements_If_Exist ${SXP_ISE_ADAPTER_CONFIG_URI}