Change comparestream usage
[integration/test.git] / csit / suites / bgpcep / pcepuser / pcepuser.robot
1 *** Settings ***
2 Documentation     Basic tests for odl-bgpcep-pcep-all feature.
3 ...
4 ...               Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
5 ...
6 ...               This program and the accompanying materials are made available under the
7 ...               terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...               and is available at http://www.eclipse.org/legal/epl-v10.html
9 Suite Setup       Set_It_Up
10 Suite Teardown    Tear_It_Down
11 Library           OperatingSystem
12 Library           SSHLibrary
13 Library           RequestsLibrary
14 Library           ../../../libraries/norm_json.py
15 Resource          ../../../libraries/NexusKeywords.robot
16 Resource          ../../../libraries/PcepOperations.robot
17 Resource          ../../../libraries/Utils.robot
18 Resource          ../../../libraries/RemoteBash.robot
19 Resource          ../../../libraries/TemplatedRequests.robot
20 Resource          ../../../libraries/CompareStream.robot
21 Resource          ../../../variables/Variables.robot
22 Variables         ../../../variables/pcepuser/variables.py    ${TOOLS_SYSTEM_IP}
23
24 *** Variables ***
25 ${CONFIG_SESSION}    session
26 ${PATH_SESSION_URI}    node/pcc:%2F%2F${TOOLS_SYSTEM_IP}/path-computation-client
27 ${PCEP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/pcepuser/
28
29 *** Test Cases ***
30 Topology_Precondition
31     [Documentation]    Compare current pcep-topology to off_json variable.
32     ...    Timeout is long enough to ODL boot, to see that pcep is ready, with no PCC is connected.
33     [Tags]    critical
34     Wait_Until_Keyword_Succeeds    300s    1s    Compare_Topology    ${off_json}
35
36 Start_Pcc_Mock
37     [Documentation]    Execute pcc-mock on Mininet, fail is Open is not sent, keep it running for next tests.
38     ${command}=    NexusKeywords.Compose_Full_Java_Command    -jar ${filename} --reconnect 1 --local-address ${TOOLS_SYSTEM_IP} --remote-address ${ODL_SYSTEM_IP} 2>&1 | tee pccmock.log
39     Log    ${command}
40     Write    ${command}
41     Read_Until    started, sent proposal Open
42
43 Configure_Speaker_Entity_Identifier
44     [Documentation]    Additional PCEP Speaker configuration for at least oxygen streams.
45     ...    Allows PCEP speaker to determine if state synchronization can be skipped when a PCEP session is restarted.
46     CompareStream.Run_Keyword_If_Less_Than_Oxygen    BuiltIn.Pass_Execution    Test case valid only for versions oxygen and above.
47     &{mapping}    BuiltIn.Create_Dictionary    IP=${ODL_SYSTEM_IP}
48     TemplatedRequests.Put_As_Xml_Templated    ${PCEP_VARIABLES_FOLDER}${/}node_speaker_entity_identifier    mapping=${mapping}    session=${CONFIG_SESSION}
49
50 Topology_Default
51     [Documentation]    Compare pcep-topology to default_json, which includes a tunnel from pcc-mock.
52     ...    Timeout is lower than in Precondition, as state from pcc-mock should be updated quickly.
53     [Tags]    critical
54     Wait_Until_Keyword_succeeds    10s    1s    Compare_Topology    ${default_json}    ${PATH_SESSION_URI}
55
56 Update_Delegated
57     [Documentation]    Perform update-lsp on the mocked tunnel, check response is success.
58     [Tags]    critical
59     ${text}=    Update_Xml_Lsp_Return_Json    ${update_delegated_xml}
60     Pcep_Json_Is_Success    ${text}
61
62 Topology_Updated
63     [Documentation]    Compare pcep-topology to default_json, which includes the updated tunnel.
64     [Tags]    critical
65     Wait_Until_Keyword_succeeds    10s    1s    Compare_Topology    ${updated_json}    ${PATH_SESSION_URI}
66
67 Refuse_Remove_Delegated
68     [Documentation]    Perform remove-lsp on the mocked tunnel, check that mock-pcc has refused to remove it.
69     [Tags]    critical
70     ${text}=    Remove_Xml_Lsp_Return_Json    ${remove_delegated_xml}
71     Pcep_Json_Is_Refused    ${text}
72
73 Topology_Still_Updated
74     [Documentation]    Compare pcep-topology to default_json, which includes the updated tunnel, to verify that refusal did not break topology.
75     [Tags]    critical
76     Wait_Until_Keyword_succeeds    10s    1s    Compare_Topology    ${updated_json}    ${PATH_SESSION_URI}
77
78 Add_Instantiated
79     [Documentation]    Perform add-lsp to create new tunnel, check that response is success.
80     [Tags]    critical
81     ${text}=    Add_Xml_Lsp_Return_Json    ${add_instantiated_xml}
82     Pcep_Json_Is_Success    ${text}
83
84 Topology_Second_Default
85     [Documentation]    Compare pcep-topology to default_json, which includes the updated delegated and default instantiated tunnel.
86     [Tags]    critical
87     Wait_Until_Keyword_succeeds    10s    1s    Compare_Topology    ${updated_default_json}    ${PATH_SESSION_URI}
88
89 Update_Instantiated
90     [Documentation]    Perform update-lsp on the newly instantiated tunnel, check that response is success.
91     [Tags]    critical
92     ${text}=    Update_Xml_Lsp_Return_Json    ${update_instantiated_xml}
93     Pcep_Json_Is_Success    ${text}
94
95 Topology_Second_Updated
96     [Documentation]    Compare pcep-topology to default_json, which includes the updated delegated and updated instantiated tunnel.
97     [Tags]    critical
98     Wait_Until_Keyword_succeeds    10s    1s    Compare_Topology    ${updated_updated_json}    ${PATH_SESSION_URI}
99
100 Remove_Instantiated
101     [Documentation]    Perform remove-lsp on the instantiated tunnel, check that response is success.
102     [Tags]    critical
103     ${text}=    Remove_Xml_Lsp_Return_Json    ${remove_instantiated_xml}
104     Pcep_Json_Is_Success    ${text}
105
106 Topology_Again_Updated
107     [Documentation]    Compare pcep-topology to default_json, which includes the updated tunnel, to verify that instantiated tunnel was removed.
108     [Tags]    critical
109     Wait_Until_Keyword_succeeds    10s    1s    Compare_Topology    ${updated_json}    ${PATH_SESSION_URI}
110
111 Stop_Pcc_Mock
112     [Documentation]    Send ctrl+c to pcc-mock, fails if no prompt is seen
113     ...    after 3 seconds (the default for SSHLibrary)
114     RemoteBash.Write_Bare_Ctrl_C
115     ${output}=    SSHLibrary.Read_Until_Prompt
116     BuiltIn.Log    ${output}
117
118 Topology_Postcondition
119     [Documentation]    Compare curent pcep-topology to "off_json" again.
120     [Tags]    critical
121     Wait_Until_Keyword_Succeeds    10s    1s    Compare_Topology    ${off_json}
122
123 *** Keywords ***
124 Set_It_Up
125     [Documentation]    Create SSH session to Mininet machine, prepare HTTP client session to Controller.
126     ...    Figure out latest pcc-mock version and download it from Nexus to Mininet.
127     NexusKeywords.Initialize_Artifact_Deployment_And_Usage
128     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
129     ${name}=    NexusKeywords.Deploy_Test_Tool    bgpcep    pcep-pcc-mock
130     BuiltIn.Set_Suite_Variable    ${filename}    ${name}
131     PcepOperations.Setup_Pcep_Operations
132
133 Tear_It_Down
134     [Documentation]    Download pccmock.log and Log its contents.
135     ...    Compute and Log the diff between expected and actual normalized responses.
136     ...    Close both HTTP client session and SSH connection to Mininet.
137     SSHLibrary.Get_File    pccmock.log
138     ${pccmocklog}=    OperatingSystem.Run    cat pccmock.log
139     BuiltIn.Log    ${pccmocklog}
140     PcepOperations.Teardown_Pcep_Operations
141     Delete_All_Sessions
142     Close_All_Connections
143
144 Compare_Topology
145     [Arguments]    ${exp}    ${uri}=${EMPTY}
146     [Documentation]    Get current pcep-topology as json, compare both expected and actual json.
147     ...    Error codes and normalized jsons should match exactly.
148     # TODO: Add Node Session State Check For Oxygen, see tcpmd5user
149     # TODO: Possibly remake all tests with TemplatedRequests
150     ${response}=    RequestsLibrary.Get Request    ${CONFIG_SESSION}    ${OPERATIONAL_TOPO_API}/topology/pcep-topology/${uri}
151     BuiltIn.Should_Be_Equal_As_Strings    ${response.status_code}    200
152     TemplatedRequests.Normalize_Jsons_And_Compare    ${exp}    ${response.text}