Update Robot Framework format - step 7
[integration/test.git] / csit / suites / groupbasedpolicy / GBPSXP / ep_provider_register_part.robot
1 *** Settings ***
2 Documentation       Test suite for Group Based Policy, sxp-ep-provider component.
3
4 Library             OperatingSystem    WITH NAME    os
5 Library             RequestsLibrary
6 Library             SSHLibrary
7 Library             ../../../libraries/GbpSxp.py    WITH NAME    gbpsxp
8 Resource            ../../../variables/Variables.robot
9 Resource            ../../../libraries/Utils.robot
10 Resource            ../../../libraries/TemplatedRequests.robot
11 Resource            ${CURDIR}/../../../libraries/KarafKeywords.robot
12 Resource            ../../../libraries/GbpSxp.robot
13
14 Suite Setup         Suite_Startup
15 Suite Teardown      Suite_Cleanup
16 Test Setup          GbpSxp.Prepare_Ssh_Tooling
17 Test Teardown       Wipe_Clean_Ep_Templates_And_Sxp_Node
18
19
20 *** Variables ***
21 ${EP_PROVIDER_TEMPLATES_FILE}           ${CURDIR}/../../../variables/gbp/gbpsxp-ep-provider-templates
22 ${SXP_NODE_CONFIG_FILE}                 ${CURDIR}/../../../variables/gbp/gbpsxp-node.json
23 ${SXP_NODE_ADD_ENTRY_FILE}              ${CURDIR}/../../../variables/gbp/gbpsxp-node-add-entry.json
24 ${GBP_RPC_UNREGISTER_ENDPOINT_FILE}     ${CURDIR}/../../../variables/gbp/gbpsxp-rpc-unregister-endpoint.json
25 ${GBP_EXPECTED_ENDPOINTS_FILE}          ${CURDIR}/../../../variables/gbp/gbpsxp-endpoint
26 ${ISE_MOCK_SERVER_API_FOLDER}           mock-server-tc010
27 ${CONFIGURE_ISE_SOURCE_FILE}            ${CURDIR}/../../../variables/gbp/gbpsxp-ise-source.json
28 ${SXP_NODE_NAME}                        1.1.1.1
29
30
31 *** Test Cases ***
32 Register_EP_Using_Manual_Inputs
33     [Documentation]    Elicit endpoint registration by providing ep-policy-template, ep-forwarding-template and ip-sgt binding
34     Utils.Add_Elements_To_URI_From_File    ${SXP_EP_PROVIDER_CONFIG_URI}    ${EP_PROVIDER_TEMPLATES_FILE}-2.1.json
35     Create_sxp_node    session    ${SXP_NODE_CONFIG_FILE}    1.1.1.1
36     Utils.Post_Elements_To_URI_From_File    ${SXP_NODE_RPC_ADD_ENTRY_URI}    ${SXP_NODE_ADD_ENTRY_FILE}
37     ${expected_endpoints}    os.Get_File    ${GBP_EXPECTED_ENDPOINTS_FILE}-2.1.json
38     Wait_For_Endpoint_And_Check    session    ${expected_endpoints}
39
40 Register_EP_Using_Manual_Inputs_And_Ise
41     [Documentation]    Elicit endpoint registration by providing ep-forwarding-template and ip-sgt binding (ep-policy-template will loaded from ise-API)
42     Utils.Add_Elements_To_URI_From_File    ${SXP_EP_PROVIDER_CONFIG_URI}    ${EP_PROVIDER_TEMPLATES_FILE}-2.2.json
43     gbpsxp.Deploy_Ise_Mock_Server    ${ISE_MOCK_SERVER_API_FOLDER}    ${ISE_REST_PORT}
44     ${ise_harvest_status_json}    gbpsxp.Configure_Ise_Source_And_Gain_Harvest_Status
45     ...    session
46     ...    ${CONFIGURE_ISE_SOURCE_FILE}
47     ...    http://${TOOLS_SYSTEM_IP}:${ISE_REST_PORT}
48     gbpsxp.Check_Ise_Harvest_Status    ${ise_harvest_status_json}    5
49     Create_sxp_node    session    ${SXP_NODE_CONFIG_FILE}    ${SXP_NODE_NAME}
50     Utils.Post_Elements_To_URI_From_File    ${SXP_NODE_RPC_ADD_ENTRY_URI}    ${SXP_NODE_ADD_ENTRY_FILE}
51     ${expected_endpoints}    os.Get_File    ${GBP_EXPECTED_ENDPOINTS_FILE}-2.2.json
52     Wait_For_Endpoint_And_Check    session    ${expected_endpoints}
53     gbpsxp.Clean_ise_source_config
54     gbpsxp.Teardown_Ise_Mock_Server    ${ISE_MOCK_SERVER_API_FOLDER}
55
56
57 *** Keywords ***
58 Suite_Startup
59     [Documentation]    Setup session and set karaf log levels
60     RequestsLibrary.Create_Session
61     ...    session
62     ...    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
63     ...    auth=${AUTH}
64     ...    headers=${HEADERS}
65     KarafKeywords.Setup_Karaf_Keywords
66     ${karaf_debug_enabled}    BuiltIn.Get_Variable_Value    ${KARAF_DEBUG}    ${False}
67     IF    ${karaf_debug_enabled}
68         KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set DEBUG org.opendaylight.sxp
69     END
70     IF    ${karaf_debug_enabled}
71         KarafKeywords.Execute_Controller_Karaf_Command_On_Background
72         ...    log:set DEBUG org.opendaylight.groupbasedpolicy.renderer
73     END
74     IF    ${karaf_debug_enabled}
75         KarafKeywords.Execute_Controller_Karaf_Command_On_Background
76         ...    log:set DEBUG org.opendaylight.groupbasedpolicy.sxp
77     END
78     IF    ${karaf_debug_enabled}
79         KarafKeywords.Execute_Controller_Karaf_Command_On_Background
80         ...    log:set DEBUG org.opendaylight.groupbasedpolicy.sxp_ep_provider
81     END
82
83 Suite_Cleanup
84     [Documentation]    Cleanup session and set karaf log levels to default
85     ${karaf_debug_enabled}    BuiltIn.Get_Variable_Value    ${KARAF_DEBUG}    ${False}
86     IF    ${karaf_debug_enabled}
87         KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set INFO org.opendaylight.sxp
88     END
89     IF    ${karaf_debug_enabled}
90         KarafKeywords.Execute_Controller_Karaf_Command_On_Background
91         ...    log:set INFO org.opendaylight.groupbasedpolicy.renderer
92     END
93     IF    ${karaf_debug_enabled}
94         KarafKeywords.Execute_Controller_Karaf_Command_On_Background
95         ...    log:set INFO org.opendaylight.groupbasedpolicy.sxp
96     END
97     IF    ${karaf_debug_enabled}
98         KarafKeywords.Execute_Controller_Karaf_Command_On_Background
99         ...    log:set INFO org.opendaylight.groupbasedpolicy.sxp_ep_provider
100     END
101     RequestsLibrary.Delete_All_Sessions
102
103 Wipe_Clean_Ep_Templates_And_Sxp_Node
104     [Documentation]    Delete sxp-ep-provider templates and sxp node
105     BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Remove_All_Elements_If_Exist    ${SXP_EP_PROVIDER_CONFIG_URI}
106     BuiltIn.Run_Keyword_And_Ignore_Error
107     ...    Utils.Remove_All_Elements_If_Exist
108     ...    ${SXP_TOPOLOGY_NODE_CONFIG_URI}/node/${SXP_NODE_NAME}
109     BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Remove_All_Elements_If_Exist    ${GBP_TENANT_CONFIG_URI}
110     Utils.Post_Elements_To_URI_From_File    ${GBP_RPC_UNREGISTER_ENDPOINT_URI}    ${GBP_RPC_UNREGISTER_ENDPOINT_FILE}
111     BuiltIn.Wait_Until_Keyword_Succeeds    5    1    Check_For_Clean_Endpoints    session
112     gbpsxp.Teardown_Ssh_Tooling
113
114 Check_For_Clean_Endpoints
115     [Documentation]    Ensure that there are no endpoints in the system
116     [Arguments]    ${session_arg}
117     ${actual_endpoints}    Utils.Get_Data_From_URI    ${session_arg}    ${GBP_ENDPOINTS_URI}
118     ${actual_endpoints_json}    Utils.Json_Parse_From_String    ${actual_endpoints}
119     BuiltIn.Should_Be_Empty    ${actual_endpoints_json['endpoints']['address-endpoints']}
120
121 Wait_For_Endpoint_And_Check
122     [Documentation]    Wait for endpoint to appear in DS/operational and compare to expected endpoint
123     [Arguments]    ${session_arg}    ${expected_endpoints}
124     ${actual_endpoints_no_timestamp}    BuiltIn.Wait_Until_Keyword_Succeeds
125     ...    5
126     ...    1
127     ...    Get_Endpoints_And_Clean_Timestamp
128     ...    ${session_arg}
129     TemplatedRequests.Normalize_Jsons_And_Compare    ${expected_endpoints}    ${actual_endpoints_no_timestamp}
130
131 Get_Endpoints_And_Clean_Timestamp
132     [Documentation]    Read endpoints from DS/operational and clean timestamp for simple comparison
133     [Arguments]    ${session_arg}
134     ${actual_endpoints}    Utils.Get_Data_From_URI    ${session_arg}    ${GBP_ENDPOINTS_URI}
135     ${actual_endpoints_json}    Utils.Json_Parse_From_String    ${actual_endpoints}
136     ${actual_endpoints_no_timestamp}    gbpsxp.Remove_Endpoint_Timestamp    ${actual_endpoints_json}
137     RETURN    ${actual_endpoints_no_timestamp}
138
139 Create_sxp_node
140     [Documentation]    Create sxp node and wait till it appears in DS/operational
141     [Arguments]    ${session_arg}    ${sxp_node_config_file}    ${sxp_node_id}
142     ${previous_topology_config}    BuiltIn.Run_Keyword_And_Ignore_Error
143     ...    Utils.Get_Data_From_URI
144     ...    ${session_arg}
145     ...    ${SXP_TOPOLOGY_NODE_CONFIG_URI}
146     BuiltIn.Log    ${previous_topology_config}
147     Utils.Add_Elements_To_URI_From_File_And_Verify
148     ...    ${SXP_TOPOLOGY_NODE_CONFIG_URI}/node/${sxp_node_id}
149     ...    ${sxp_node_config_file}
150     ${sxp_node_config_readback}    Utils.Get_Data_From_URI
151     ...    ${session_arg}
152     ...    ${SXP_TOPOLOGY_NODE_CONFIG_URI}/node/${sxp_node_id}
153     BuiltIn.Wait_Until_Keyword_Succeeds
154     ...    20
155     ...    2
156     ...    Check_If_Sxp_Node_Is_Enabled
157     ...    ${session_arg}
158     ...    ${SXP_TOPOLOGY_NODE_OPERATIONAL_URI}/node/${sxp_node_id}
159
160 Check_If_Sxp_Node_Is_Enabled
161     [Documentation]    Read node enabled leaf and check if it is true
162     [Arguments]    ${session_arg}    ${node_uri}
163     ${sxp_node}    Utils.Get_Data_From_URI    ${session_arg}    ${node_uri}
164     ${sxp_node_json}    Utils.Json_Parse_From_String    ${sxp_node}
165     ${sxp_node_enabled}    gbpsxp.Resolve_sxp_node_is_enabled    ${sxp_node_json}
166     BuiltIn.Should_Be_Equal_As_Strings    True    ${sxp_node_enabled}