Testplan, suite, variables and support library for basic PCEP testing.
[integration/test.git] / test / csit / suites / bgpcep / basicpcep / basicpcep.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           ${CURDIR}/../../../libraries/RequestsLibrary.py
14 Library           ${CURDIR}/../../../libraries/HsfJson/hsf_json.py
15 Variables         ${CURDIR}/../../../variables/Variables.py
16 Variables         ${CURDIR}/../../../variables/basicpcep/variables.py    ${MININET}
17
18 *** Variables ***
19 ${ExpDir}         ${CURDIR}/expected
20 ${ActDir}         ${CURDIR}/actual
21
22 *** Test Cases ***
23 Topology_Precondition
24     [Documentation]    Compare current pcep-topology to "offjson" variable.
25     ...    Timeout is long enough to see that pcep is ready, with no PCC is connected.
26     [Tags]    critical
27     Wait_Until_Keyword_Succeeds    900    1    Compare_Topology    ${offjson}    Pre
28
29 Start_Pcc_Mock
30     [Documentation]    Execute pcc-mock on Mininet, fail is Open is not sent, keep it running for next tests.
31     ${command}=    Set_Variable    java -jar ${filename} --local-address ${MININET} --remote-address ${CONTROLLER} 2>&1 | tee pccmock.log
32     Log    ${command}
33     Write    ${command}
34     Read_Until    started, sent proposal Open
35
36 Topology_Intercondition
37     [Documentation]    Compare pcep-topology to "onjson", which includes a tunnel from pcc-mock.
38     [Tags]    critical
39     Wait_Until_Keyword_succeeds    30    1    Compare_Topology    ${onjson}    Inter
40
41 Stop_Pcc_Mock
42     [Documentation]    Send ctrl+c to pcc-mock, fails if no prompt is seen
43     ...    after 3 seconds (the default for SSHLibrary)
44     ${command}=    Evaluate    chr(int(3))
45     Log    ${command}
46     Write    ${command}
47     Read_Until_Prompt
48
49 Topology_Postcondition
50     [Documentation]    Compare curent pcep-topology to "offjson" again.
51     ...    Timeout is lower than in Precondition,
52     ...    but data from pcc-mock should be gone quickly.
53     [Tags]    critical
54     Wait_Until_Keyword_Succeeds    30    1    Compare_Topology    ${offjson}    Post
55
56 *** Keywords ***
57 Set_It_Up
58     [Documentation]    Create SSH session to Mininet machine, prepare HTTP client session to Controller.
59     ...    Figure out latest pcc-mock version and download it from Nexus to Mininet.
60     ...    Also, delete and create directories for json diff handling.
61     Open_Connection    ${MININET}
62     Login_With_Public_Key    ${MININET_USER}    ${USER_HOME}/.ssh/id_rsa    any
63     Create_Session    ses    http://${CONTROLLER}:8181/restconf/operational/network-topology:network-topology    auth=${AUTH}
64     ${urlbase}=    Set_Variable    https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/org/opendaylight/bgpcep/pcep-pcc-mock
65     ${version}=    Execute_Command    curl ${urlbase}/maven-metadata.xml | grep latest | cut -d '>' -f 2 | cut -d '<' -f 1
66     Log    ${version}
67     ${namepart}=    Execute_Command    curl ${urlbase}/${version}/maven-metadata.xml | grep value | head -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1
68     Log    ${namepart}
69     Set_Suite_Variable    ${filename}    pcep-pcc-mock-${namepart}-executable.jar
70     Log    ${filename}
71     ${response}=    Execute_Command    wget -q -N ${urlbase}/${version}/${filename} 2>&1
72     Log    ${response}
73     Remove_Directory    ${ExpDir}
74     Remove_Directory    ${ActDir}
75     Create_Directory    ${ExpDir}
76     Create_Directory    ${ActDir}
77
78 Compare_Topology
79     [Arguments]    ${expected}    ${name}
80     [Documentation]    Get current pcep-topology as json, normalize both expected and actual json.
81     ...    Save normalized jsons to files for later processing.
82     ...    Error codes and normalized jsons should match exactly.
83     ${normexp}=    Hsf_Json    ${expected}
84     Log    ${normexp}
85     Create_File    ${ExpDir}${/}${name}    ${normexp}
86     ${resp}=    RequestsLibrary.Get    ses    topology/pcep-topology
87     Log    ${resp}
88     Log    ${resp.text}
89     ${normresp}=    Hsf_Json    ${resp.text}
90     Log    ${normresp}
91     Create_File    ${ActDir}${/}${name}    ${normresp}
92     Should_Be_Equal_As_Strings    ${resp.status_code}    200
93     Should_Be_Equal    ${normresp}    ${normexp}
94
95 Tear_It_Down
96     [Documentation]    Download pccmock.log and Log its contents.
97     ...    Compute and Log the diff between expected and actual normalized responses.
98     ...    Close both HTTP client session and SSH connection to Mininet.
99     SSHLibrary.Get_File    pccmock.log
100     ${pccmocklog}=    Run    cat pccmock.log
101     Log    ${pccmocklog}
102     ${diff}=    Run    diff -dur ${ExpDir} ${ActDir}
103     Log    ${diff}
104     Delete_All_Sessions
105     Close_All_Connections