Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / suites / groupbasedpolicy / GBPSXP / ep_provider_renderer_part.robot
1 *** Settings ***
2 Documentation     Test suite for Group Based Policy, sxp-ep-provider component.
3 Suite Setup       Setup_Http_And_Netconf
4 Suite Teardown    Teardown_Http_And_Netconf
5 Test Setup        Prepare_Renderer_Prerequisities
6 Test Teardown     Wipe_Clean_Renderer_Policy_Cohort
7 Library           OperatingSystem    WITH NAME    os
8 Library           RequestsLibrary    WITH NAME    reqLib
9 Library           SSHLibrary
10 Library           ../../../libraries/GbpSxp.py    WITH NAME    gbpsxp
11 Resource          ../../../variables/Variables.robot
12 Resource          ../../../variables/sfc/Variables.robot
13 Resource          ../../../libraries/Utils.robot
14 Resource          ../../../libraries/TemplatedRequests.robot
15 Resource          ../../../libraries/NetconfKeywords.robot
16 Resource          ../../../libraries/GbpSxp.robot
17
18 *** Variables ***
19 ${EP_PROVIDER_TEMPLATES_FILE}    ${CURDIR}/../../../variables/gbp/gbpsxp-ep-policy-templates
20 ${IOS_XE_SCHEMAS_FOLDER}    ${CURDIR}/../../../variables/gbp/ios-xe-schemas
21 ${GBP_RENDERER_POLICY_FILE}    ${CURDIR}/../../../variables/gbp/gbpsxp-renderer-policy.json
22 # netconf
23 @{IOS_XE_IP}      ${TOOLS_SYSTEM_IP}    ${TOOLS_SYSTEM_2_IP}
24 @{IOS_XE_NODE_NAMES}    ios-xe-mock-1    ios-xe-mock-2
25 ${NETCONF_CONFIG_IOSXE_NODE_FILE}    ${CURDIR}/../../../variables/gbp/ios-xe-netconf-node.json
26 # sfc configuration
27 ${SFC_SERVICE_FUNCTIONS_FILE}    ${CURDIR}/../../../variables/gbp/sfc/service-functions.json
28 ${SFC_SF_FORWARDERS_FILE}    ${CURDIR}/../../../variables/gbp/sfc/service-function-forwarders.json
29 ${SFC_SF_CHAINS_FILE}    ${CURDIR}/../../../variables/gbp/sfc/service-function-chains.json
30 ${SFC_SF_PATHS_FILE}    ${CURDIR}/../../../variables/gbp/sfc/service-function-paths.json
31
32 *** Test Cases ***
33 Configure_Sfc_And_Ios_Xe_Renderer_Using_Generated_Sgt
34     [Documentation]    Elicit netconf device configuration by providing sfc configurations and ios-xe renderer policy
35     ${renderer_policy}    ${next_version}    Provision_renderer_policy    session    ${GBP_RENDERER_POLICY_FILE}
36     Utils.Add_Elements_To_URI_And_Verify    ${GBP_RENDERER_CONFIG_URI}/renderer-policy    ${renderer_policy}
37     BuiltIn.Wait_Until_Keyword_Succeeds    30    2    Check_Renderer_Policy_Status_Version    session    ${next_version}
38     ${security_group_json}    BuiltIn.Wait_Until_Keyword_Succeeds    20    2    Seek_Security_Group    session    ${NETCONF_CONFIG_URI}/node/${IOS_XE_NODE_NAMES[1]}/${MOUNTPOINT_IOSXE_SUFFIX}
39     BuiltIn.Log    ${security_group_json['source']['tag']}    level=DEBUG
40     BuiltIn.Log    ${security_group_json['destination']['tag']}    level=DEBUG
41     BuiltIn.Should_Be_Equal_As_Integers    100    ${security_group_json['source']['tag']}
42     BuiltIn.Should_Be_Equal_As_Integers    101    ${security_group_json['destination']['tag']}
43     ${expected_templates}    os.Get_File    ${EP_PROVIDER_TEMPLATES_FILE}-3.1.json
44     ${actual_templates}    Utils.Get_Data_From_URI    session    ${SXP_EP_PROVIDER_CONFIG_URI}
45     TemplatedRequests.Normalize_Jsons_And_Compare    ${expected_templates}    ${actual_templates}
46
47 Configure_Sfc_And_Ios_Xe_Renderer_Using_Existing_Sgt
48     [Documentation]    Elicit netconf device configuration by providing sfc configurations and ios-xe renderer policy and ep-policy-templates
49     Utils.Add_Elements_To_URI_From_File    ${SXP_EP_PROVIDER_CONFIG_URI}    ${EP_PROVIDER_TEMPLATES_FILE}-3.2.json
50     ${renderer_policy}    ${next_version}    Provision_renderer_policy    session    ${GBP_RENDERER_POLICY_FILE}
51     Utils.Add_Elements_To_URI_And_Verify    ${GBP_RENDERER_CONFIG_URI}/renderer-policy    ${renderer_policy}
52     BuiltIn.Wait_Until_Keyword_Succeeds    30    2    Check_Renderer_Policy_Status_Version    session    ${next_version}
53     ${security_group_json}    BuiltIn.Wait_Until_Keyword_Succeeds    20    2    Seek_Security_Group    session    ${NETCONF_CONFIG_URI}/node/${IOS_XE_NODE_NAMES[1]}/${MOUNTPOINT_IOSXE_SUFFIX}
54     BuiltIn.Log    ${security_group_json['source']['tag']}    level=DEBUG
55     BuiltIn.Log    ${security_group_json['destination']['tag']}    level=DEBUG
56     BuiltIn.Should_Be_Equal_As_Integers    43    ${security_group_json['source']['tag']}
57     BuiltIn.Should_Be_Equal_As_Integers    42    ${security_group_json['destination']['tag']}
58
59 *** Keywords ***
60 Setup_Http_And_Netconf
61     [Documentation]    Setup http session, setup ssh session to tools, deploy netconf-testtool (with ios-xe schemas) and start
62     reqLib.Create_Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}
63     ${tools_1_session}    GbpSxp.Prepare_Ssh_Tooling    ${TOOLS_SYSTEM_IP}
64     ${tools_2_session}    GbpSxp.Prepare_Ssh_Tooling    ${TOOLS_SYSTEM_2_IP}
65     @{tools_sessions}    BuiltIn.Create_List    ${tools_1_session}    ${tools_2_session}
66     BuiltIn.Set_Suite_Variable    ${TOOLS_SESSIONS}    ${tools_sessions}
67     NetconfKeywords.Setup_NetconfKeywords
68     ${run_netconf_testtool_manually}    BuiltIn.Get_Variable_Value    ${run_netconf_testtool_manually}    ${False}
69     ${logfile}    Utils.Get_Log_File_Name    testtool
70     BuiltIn.Run_Keyword_If    ${run_netconf_testtool_manually}    BuiltIn.Set_Suite_Variable    ${testtool_log}    ${logfile}
71     FOR    ${ssh_session}    IN    @{TOOLS_SESSIONS}
72         SSHKeywords.Restore_Current_Ssh_Connection_From_Index    ${ssh_session}
73         BuiltIn.Run_Keyword_Unless    ${run_netconf_testtool_manually}    Install_And_Start_Testtool    device-count=1    debug=false    schemas=${IOS_XE_SCHEMAS_FOLDER}
74         ...    mdsal=true
75     END
76
77 Teardown_Http_And_Netconf
78     [Documentation]    Close http session, close ssh session to tools, stop netconf-testtool
79     FOR    ${ssh_session}    IN    @{TOOLS_SESSIONS}
80         BuiltIn.Log    ${ssh_session}
81         SSHKeywords.Restore_Current_Ssh_Connection_From_Index    ${ssh_session}
82         Stop_Testtool
83     END
84     gbpsxp.Teardown_Ssh_Tooling    ${TOOLS_SESSIONS}
85     RequestsLibrary.Delete_All_Sessions
86
87 Prepare_Renderer_Prerequisities
88     [Documentation]    Prepare sfc configurations, connect netconf device
89     FOR    ${INDEX}    IN RANGE    0    2
90         BuiltIn.Log    ${INDEX}
91         ${netconf_node_configuration_json}    Utils.Json_Parse_From_File    ${NETCONF_CONFIG_IOSXE_NODE_FILE}
92         ${netconf_node_configuration}    gbpsxp.Replace_Netconf_Node_Host    ${netconf_node_configuration_json}    ${IOS_XE_NODE_NAMES[${INDEX}]}    ${IOS_XE_IP[${INDEX}]}
93         BuiltIn.Log    ${netconf_node_configuration}    level=DEBUG
94         Utils.Add_Elements_To_URI_And_Verify    ${NETCONF_CONFIG_URI}/node/${IOS_XE_NODE_NAMES[${INDEX}]}    ${netconf_node_configuration}
95     END
96     FOR    ${INDEX}    IN RANGE    0    2
97         BuiltIn.Log    ${INDEX}
98         BuiltIn.Wait_Until_Keyword_Succeeds    30    2    Check_Netconf_Node_Status    session    ${NETCONF_OPERATIONAL_URI}/node/${IOS_XE_NODE_NAMES[${INDEX}]}
99         BuiltIn.Wait_Until_Keyword_Succeeds    10x    3s    TemplatedRequests.Get_From_Uri    ${NETCONF_CONFIG_URI}/node/${IOS_XE_NODE_NAMES[${INDEX}]}/yang-ext:mount    session=session
100     END
101     Utils.Add_Elements_To_URI_From_File    ${SERVICE_FUNCTIONS_URI}    ${SFC_SERVICE_FUNCTIONS_FILE}
102     &{ip_mgmt_map}    BuiltIn.Create_Dictionary    SFF1=${TOOLS_SYSTEM_2_IP}    SFF2=${TOOLS_SYSTEM_IP}
103     ${sfc_sf_forwarders_json}    Utils.Json_Parse_From_File    ${SFC_SF_FORWARDERS_FILE}
104     ${sfc_sf_forwarders}    gbpsxp.Replace_Ip_Mgmt_Address_In_Forwarder    ${sfc_sf_forwarders_json}    ${ip_mgmt_map}
105     Utils.Add_Elements_To_URI_And_Verify    ${SERVICE_FORWARDERS_URI}    ${sfc_sf_forwarders}
106     Utils.Add_Elements_To_URI_From_File    ${SERVICE_CHAINS_URI}    ${SFC_SF_CHAINS_FILE}
107     Utils.Add_Elements_To_URI_From_File    ${SERVICE_FUNCTION_PATHS_URI}    ${SFC_SF_PATHS_FILE}
108
109 Check_Netconf_Node_Status
110     [Arguments]    ${session_arg}    ${node_operational_uri}
111     [Documentation]    Check if connection status of given node is 'connected'
112     ${node_content}    Utils.Get_Data_From_URI    ${session_arg}    ${node_operational_uri}
113     ${node_content_json}    Utils.Json_Parse_From_String    ${node_content}
114     BuiltIn.Should_Be_Equal_As_Strings    connected    ${node_content_json['node'][0]['netconf-node-topology:connection-status']}
115
116 Wipe_Clean_Renderer_Policy_Cohort
117     [Documentation]    Delete ep-policy-templates, renderer-policy, sfc configuraions, netconf-device config
118     BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Remove_All_Elements_If_Exist    ${SERVICE_FUNCTIONS_URI}
119     BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Remove_All_Elements_If_Exist    ${SERVICE_FORWARDERS_URI}
120     BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Remove_All_Elements_If_Exist    ${SERVICE_CHAINS_URI}
121     BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Remove_All_Elements_If_Exist    ${SERVICE_FUNCTION_PATHS_URI}
122     BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Remove_All_Elements_If_Exist    ${GBP_RENDERER_CONFIG_URI}
123     # clean netconf-device config (behind mountpoint) and disconnect by removing it from DS/config
124     FOR    ${ios_xe_node_name}    IN    @{IOS_XE_NODE_NAMES}
125         BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Remove_All_Elements_If_Exist    ${NETCONF_CONFIG_URI}/node/${ios_xe_node_name}/${MOUNTPOINT_IOSXE_SUFFIX}
126         BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Remove_All_Elements_If_Exist    ${NETCONF_CONFIG_URI}/node/${ios_xe_node_name}
127     END
128     FOR    ${ios_xe_node_name}    IN    @{IOS_XE_NODE_NAMES}
129         BuiltIn.Wait_Until_Keyword_Succeeds    5    1    Utils.No_Content_From_URI    session    ${NETCONF_OPERATIONAL_URI}/node/${ios_xe_node_name}
130     END
131     BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Remove_All_Elements_If_Exist    ${SXP_EP_PROVIDER_CONFIG_URI}
132     BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Remove_All_Elements_If_Exist    ${GBP_TENANT_CONFIG_URI}
133
134 Seek_Security_Group
135     [Arguments]    ${session_arg}    ${config_uri}
136     [Documentation]    Read given DS and seek CONFIG['native']['class-map'][0]['match']['security-group']
137     ${device_ds_config}    Utils.Get_Data_From_URI    ${session_arg}    ${config_uri}
138     ${device_ds_config_json}    Utils.Json_Parse_From_String    ${device_ds_config}
139     [Return]    ${device_ds_config_json['native']['class-map'][0]['match']['security-group']}
140
141 Propose_Renderer_Configuration_Next_Version
142     [Arguments]    ${session_arg}
143     [Documentation]    Read current renderer configuration status and compute next version or use 0 if status absents
144     ${renderer_policy}    BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Get_Data_From_URI    ${session_arg}    ${GBP_RENDERER_POLICY_OPERATIONAL_URI}
145     BuiltIn.Return_From_Keyword_If    '${renderer_policy[0]}' != 'PASS'    0
146     ${renderer_policy_json}    Utils.Json_Parse_From_String    ${renderer_policy[1]}
147     ${current_version}    BuiltIn.Convert_To_Integer    ${renderer_policy_json['renderer-policy']['version']}
148     [Return]    ${current_version + 1}
149
150 Provision_renderer_policy
151     [Arguments]    ${session_arg}    ${renderer_policy_file}
152     [Documentation]    Replace version number in given renderer-policy in order to be the next expected value
153     ${renderer_policy_json}    Utils.Json_Parse_From_File    ${renderer_policy_file}
154     ${next_version}    Propose_Renderer_Configuration_Next_Version    ${session_arg}
155     ${renderer_policy_updated}    gbpsxp.Replace_Renderer_Policy_Version    ${renderer_policy_json}    ${next_version}
156     [Return]    ${renderer_policy_updated}    ${next_version}
157
158 Check_Renderer_Policy_Status_Version
159     [Arguments]    ${session_arg}    ${expected_version}
160     [Documentation]    Read current renderer policy version and compare it to expected version
161     ${renderer_policy}    Utils.Get_Data_From_URI    ${session_arg}    ${GBP_RENDERER_POLICY_OPERATIONAL_URI}
162     ${renderer_policy_json}    Utils.Json_Parse_From_String    ${renderer_policy}
163     BuiltIn.Should_Be_Equal_As_Integers    ${renderer_policy_json['renderer-policy']['version']}    ${expected_version}