4c320b4a1a0ca2b275fc3d2d2804c25dc2fbf8c7
[integration/test.git] / test / 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    prompt=]>
13 Library           RequestsLibrary
14 Library           ${CURDIR}/../../../libraries/HsfJson/hsf_json.py
15 Resource          ${CURDIR}/../../../libraries/PcepOperations.robot
16 Variables         ${CURDIR}/../../../variables/Variables.py
17 Variables         ${CURDIR}/../../../variables/pcepuser/variables.py    ${MININET}
18
19 *** Variables ***
20 ${ExpDir}         ${CURDIR}/expected
21 ${ActDir}         ${CURDIR}/actual
22
23 *** Test Cases ***
24 Topology_Precondition
25     [Documentation]    Compare current pcep-topology to off_json variable.
26     ...    Timeout is long enough to ODL boot, to see that pcep is ready, with no PCC is connected.
27     [Tags]    critical
28     Wait_Until_Keyword_Succeeds    300    1    Compare_Topology    ${off_json}    010_Topology_Precondition
29
30 Start_Pcc_Mock
31     [Documentation]    Execute pcc-mock on Mininet, fail is Open is not sent, keep it running for next tests.
32     ${command}=    Set_Variable    java -jar ${filename} --local-address ${MININET} --remote-address ${CONTROLLER} 2>&1 | tee pccmock.log
33     Log    ${command}
34     Write    ${command}
35     Read_Until    started, sent proposal Open
36
37 Topology_Default
38     [Documentation]    Compare pcep-topology to default_json, which includes a tunnel from pcc-mock.
39     ...    Timeout is lower than in Precondition, as state from pcc-mock should be updated quickly.
40     [Tags]    critical
41     Wait_Until_Keyword_succeeds    5    1    Compare_Topology    ${default_json}    020_Topology_Default
42
43 Update_Delegated
44     [Documentation]    Perform update-lsp on the mocked tunnel, check response is success.
45     [Tags]    critical
46     ${text}=    Update_Xml_Lsp_Return_Json    ${update_delegated_xml}
47     Pcep_Json_Is_Success    ${text}
48
49 Topology_Updated
50     [Documentation]    Compare pcep-topology to default_json, which includes the updated tunnel.
51     [Tags]    critical
52     Wait_Until_Keyword_succeeds    5    1    Compare_Topology    ${updated_json}    030_Topology_Updated
53
54 Refuse_Remove_Delegated
55     [Documentation]    Perform remove-lsp on the mocked tunnel, check that mock-pcc has refused to remove it.
56     [Tags]    critical
57     ${text}=    Remove_Xml_Lsp_Return_Json    ${remove_delegated_xml}
58     Pcep_Json_Is_Refused    ${text}
59
60 Topology_Still_Updated
61     [Documentation]    Compare pcep-topology to default_json, which includes the updated tunnel, to verify that refusal did not break topology.
62     [Tags]    critical
63     Wait_Until_Keyword_succeeds    5    1    Compare_Topology    ${updated_json}    040_Topology_Still_Updated
64
65 Add_Instantiated
66     [Documentation]    Perform add-lsp to create new tunnel, check that response is success.
67     [Tags]    critical
68     ${text}=    Add_Xml_Lsp_Return_Json    ${add_instantiated_xml}
69     Pcep_Json_Is_Success    ${text}
70
71 Topology_Second_Default
72     [Documentation]    Compare pcep-topology to default_json, which includes the updated delegated and default instantiated tunnel.
73     [Tags]    critical
74     Wait_Until_Keyword_succeeds    5    1    Compare_Topology    ${updated_default_json}    050_Topology_Second_Default
75
76 Update_Instantiated
77     [Documentation]    Perform update-lsp on the newly instantiated tunnel, check that response is success.
78     [Tags]    critical
79     ${text}=    Update_Xml_Lsp_Return_Json    ${update_instantiated_xml}
80     Pcep_Json_Is_Success    ${text}
81
82 Topology_Second_Updated
83     [Documentation]    Compare pcep-topology to default_json, which includes the updated delegated and updated instantiated tunnel.
84     [Tags]    critical
85     Wait_Until_Keyword_succeeds    5    1    Compare_Topology    ${updated_updated_json}    060_Topology_Second_Updated
86
87 Remove_Instantiated
88     [Documentation]    Perform remove-lsp on the instantiated tunnel, check that response is success.
89     [Tags]    critical
90     ${text}=    Remove_Xml_Lsp_Return_Json    ${remove_instantiated_xml}
91     Pcep_Json_Is_Success    ${text}
92
93 Topology_Again_Updated
94     [Documentation]    Compare pcep-topology to default_json, which includes the updated tunnel, to verify that instantiated tunnel was removed.
95     [Tags]    critical
96     Wait_Until_Keyword_succeeds    5    1    Compare_Topology    ${updated_json}    070_Topology_Again_Updated
97
98 Stop_Pcc_Mock
99     [Documentation]    Send ctrl+c to pcc-mock, fails if no prompt is seen
100     ...    after 3 seconds (the default for SSHLibrary)
101     ${command}=    Evaluate    chr(int(3))
102     Log    ${command}
103     Write    ${command}
104     Read_Until_Prompt
105
106 Topology_Postcondition
107     [Documentation]    Compare curent pcep-topology to "off_json" again.
108     [Tags]    critical
109     Wait_Until_Keyword_Succeeds    5    1    Compare_Topology    ${off_json}    080_Topology_Postcondition
110
111 *** Keywords ***
112 Set_It_Up
113     [Documentation]    Create SSH session to Mininet machine, prepare HTTP client session to Controller.
114     ...    Figure out latest pcc-mock version and download it from Nexus to Mininet.
115     ...    Also, delete and create directories for json diff handling.
116     Open_Connection    ${MININET}
117     Login_With_Public_Key    ${MININET_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
118     Create_Session    ses    http://${CONTROLLER}:${RESTCONFPORT}/restconf/operational/network-topology:network-topology    auth=${AUTH}
119     ${urlbase}=    Set_Variable    ${NEXUSURL_PREFIX}/content/repositories/opendaylight.snapshot/org/opendaylight/bgpcep/pcep-pcc-mock
120     ${version}=    Execute_Command    curl ${urlbase}/maven-metadata.xml | grep latest | cut -d '>' -f 2 | cut -d '<' -f 1
121     Log    ${version}
122     ${namepart}=    Execute_Command    curl ${urlbase}/${version}/maven-metadata.xml | grep value | head -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1
123     Log    ${namepart}
124     Set_Suite_Variable    ${filename}    pcep-pcc-mock-${namepart}-executable.jar
125     Log    ${filename}
126     ${response}=    Execute_Command    wget -q -N ${urlbase}/${version}/${filename} 2>&1
127     Log    ${response}
128     Remove_Directory    ${ExpDir}
129     Remove_Directory    ${ActDir}
130     Create_Directory    ${ExpDir}
131     Create_Directory    ${ActDir}
132     Setup_Pcep_Operations
133
134 Compare_Topology
135     [Arguments]    ${expected}    ${name}
136     [Documentation]    Get current pcep-topology as json, normalize both expected and actual json.
137     ...    Save normalized jsons to files for later processing.
138     ...    Error codes and normalized jsons should match exactly.
139     ${normexp}=    Hsf_Json    ${expected}
140     Log    ${normexp}
141     Create_File    ${ExpDir}${/}${name}    ${normexp}
142     ${resp}=    RequestsLibrary.Get    ses    topology/pcep-topology
143     Log    ${resp}
144     Log    ${resp.text}
145     ${normresp}=    Hsf_Json    ${resp.text}
146     Log    ${normresp}
147     Create_File    ${ActDir}${/}${name}    ${normresp}
148     Should_Be_Equal_As_Strings    ${resp.status_code}    200
149     Should_Be_Equal    ${normresp}    ${normexp}
150
151 Tear_It_Down
152     [Documentation]    Download pccmock.log and Log its contents.
153     ...    Compute and Log the diff between expected and actual normalized responses.
154     ...    Close both HTTP client session and SSH connection to Mininet.
155     SSHLibrary.Get_File    pccmock.log
156     ${pccmocklog}=    Run    cat pccmock.log
157     Log    ${pccmocklog}
158     ${diff}=    Run    diff -dur ${ExpDir} ${ActDir}
159     Log    ${diff}
160     Teardown_Pcep_Operations
161     Delete_All_Sessions
162     Close_All_Connections