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