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