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