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