Include needed Assure_* keywords in BGP tests
[integration/test.git] / csit / suites / bgpcep / bgpuser / cases.robot
index 43f14ddaadbf76a3b56ae4be607852e1ddadc3ba..d00b73f9253711c8e6be4955960747611156c710 100644 (file)
@@ -7,30 +7,54 @@ Documentation     Basic tests for odl-bgpcep-bgp-all feature.
 ...               terms of the Eclipse Public License v1.0 which accompanies this distribution,
 ...               and is available at http://www.eclipse.org/legal/epl-v10.html
 ...
+...               TODO: Rename this file after Beryllium is out, for example to basic.robot
 ...
-...               Brief description of what this suite should do:
+...               Test suite performs basic BGP functional test cases:
+...               BGP peer initiated coonection
+...               - introduce and check 3 prefixes in one update message
+...               ODL controller initiated coonection:
+...               - introduce and check 3 prefixes in one update message
+...               - introduce 2 prefixes in first update message and then additional 2 prefixes
+...               in another update while the very first prefix is withdrawn
+...               - introduce 3 prefixes and try to withdraw the first one
+...               (to be ignored by controller) in a single update message
+...
+...               Brief description how to perform BGP functional test:
 ...               https://wiki.opendaylight.org/view/BGP_LS_PCEP:Lithium_Feature_Tests#How_to_test_2
+...
+...               Reported bugs:
+...               https://bugs.opendaylight.org/show_bug.cgi?id=4409
+...               https://bugs.opendaylight.org/show_bug.cgi?id=4634
 Suite Setup       Setup_Everything
 Suite Teardown    Teardown_Everything
-Test Setup        FailFast.Fail_This_Fast_On_Previous_Error
+Test Setup        SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
 Test Teardown     FailFast.Start_Failing_Fast_If_This_Failed
 Library           OperatingSystem
-Library           SSHLibrary    prompt=]>    timeout=10s    # FIXME: The prompt should have default value from a common resource, and should be overwritable by pybot -v in scripts.
+Library           SSHLibrary    timeout=10s
 Library           RequestsLibrary
 Library           ${CURDIR}/../../../libraries/HsfJson/hsf_json.py
 Variables         ${CURDIR}/../../../variables/Variables.py
-Variables         ${CURDIR}/../../../variables/bgpuser/variables.py    ${MININET}
+Variables         ${CURDIR}/../../../variables/bgpuser/variables.py    ${TOOLS_SYSTEM_IP}
+Resource          ${CURDIR}/../../../libraries/BGPcliKeywords.robot
+Resource          ${CURDIR}/../../../libraries/BGPSpeaker.robot
 Resource          ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
 Resource          ${CURDIR}/../../../libraries/FailFast.robot
+Resource          ${CURDIR}/../../../libraries/KarafKeywords.robot
 Resource          ${CURDIR}/../../../libraries/KillPythonTool.robot
-Resource          ${CURDIR}/../../../libraries/WaitForFailure.robot
+Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
+Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
 Resource          ${CURDIR}/../../../libraries/Utils.robot
+Resource          ${CURDIR}/../../../libraries/WaitForFailure.robot
 
 *** Variables ***
-${directory_for_actual_responses}    ${TEMPDIR}/actual
-${directory_for_expected_responses}    ${TEMPDIR}/expected
-${directory_with_template_folders}    ${CURDIR}/../../../variables/bgpuser/
-${HOLDTIME}    180
+${ACTUAL_RESPONSES_FOLDER}    ${TEMPDIR}/actual
+${EXPECTED_RESPONSES_FOLDER}    ${TEMPDIR}/expected
+${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpuser/
+${TOOLS_SYSTEM_PROMPT}    ${DEFAULT_LINUX_PROMPT}
+${HOLDTIME}       180
+${BGP_TOOL_LOG_LEVEL}    info
+${CONTROLLER_LOG_LEVEL}    INFO
+${CONTROLLER_BGP_LOG_LEVEL}    DEFAULT
 
 *** Test Cases ***
 Check_For_Empty_Topology_Before_Talking
@@ -41,22 +65,20 @@ Check_For_Empty_Topology_Before_Talking
 
 Reconfigure_ODL_To_Accept_Connection
     [Documentation]    Configure BGP peer module with initiate-connection set to false.
-    ${template_as_string}=    BuiltIn.Set_Variable    {'IP': '${MININET}', 'HOLDTIME': '${HOLDTIME}', 'INITIATE': 'false'}
-    Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}bgp_peer    ${template_as_string}
+    ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer', 'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'false'}
+    ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
 
 Start_Talking_BGP_speaker
     [Documentation]    Start Python speaker to connect to ODL, verify that the tool does not promptly exit.
-    ${command}=    BuiltIn.Set_Variable    python play.py --amount 2 --myip=${MININET} --myport=17900 --peerip=${CONTROLLER} --peerport=1790
     # Myport value is needed for checking whether connection at precise port was established.
-    # TODO: Do we want to define ${BGP_PORT} in Variables.py?
-    BuiltIn.Log    ${command}
-    ${output}=    SSHLibrary.Write    ${command}
+    BGPSpeaker.Start_BGP_Speaker    --amount 3 --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT} --${BGP_TOOL_LOG_LEVEL}
     Read_And_Fail_If_Prompt_Is_Seen
 
 Check_Talking_Connection_Is_Established
     [Documentation]    See TCP (BGP) connection in established state.
     # This case is separate from the previous one, to resemble structure of the second half of this suite more closely.
     Check_Speaker_Is_Connected
+    [Teardown]    Utils.Report_Failure_Due_To_Bug    5171
 
 Check_Talking_Topology_Is_Filled
     [Documentation]    See new routes in example-ipv4-topology as a proof that synchronization was correct.
@@ -65,8 +87,9 @@ Check_Talking_Topology_Is_Filled
 
 Kill_Talking_BGP_Speaker
     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
-    [Setup]    FailFast.Run_Even_When_Failing_Fast
-    Kill_BGP_Speaker
+    [Tags]    critical
+    [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
+    BGPSpeaker.Kill_BGP_Speaker
     FailFast.Do_Not_Fail_Fast_From_Now_On
     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
@@ -78,10 +101,7 @@ Check_For_Empty_Topology_After_Talking
 
 Start_Listening_BGP_Speaker
     [Documentation]    Start Python speaker in listening mode, verify that the tool does not exit quickly.
-    ${command}=    BuiltIn.Set_Variable    python play.py --amount 2 --listen --myip=${MININET} --myport=17900 --peerip=${CONTROLLER}
-    # TODO: ${BGP_TOOL_PORT} is probably not worth the trouble.
-    Builtin.Log    ${command}
-    ${output}=    SSHLibrary.Write    ${command}
+    BGPSpeaker.Start_BGP_Speaker    --amount 3 --listen --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --${BGP_TOOL_LOG_LEVEL}
     Read_And_Fail_If_Prompt_Is_Seen
 
 Check_Listening_Connection_Is_Not_Established_Yet
@@ -95,8 +115,8 @@ Check_For_Empty_Topology_Before_Listening
 
 Reconfigure_ODL_To_Initiate_Connection
     [Documentation]    Replace BGP peer config module, now with initiate-connection set to true.
-    ${template_as_string}=    BuiltIn.Set_Variable    {'IP': '${MININET}', 'HOLDTIME': '${HOLDTIME}', 'INITIATE': 'true'}
-    Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}bgp_peer    ${template_as_string}
+    ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer', 'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'true'}
+    ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
 
 Check_Listening_Connection_Is_Established
     [Documentation]    See TCP (BGP) connection in established state.
@@ -109,10 +129,11 @@ Check_Listening_Topology_Is_Filled
 
 Kill_Listening_BGP_Speaker
     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
-    [Setup]    FailFast.Run_Even_When_Failing_Fast
-    Kill_BGP_Speaker
+    [Tags]    critical
+    [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
+    BGPSpeaker.Kill_BGP_Speaker
     FailFast.Do_Not_Fail_Fast_From_Now_On
-    # NOTE: It is still possible to remain failing, if both previous and this test failed.
+    # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
 
 Check_For_Empty_Topology_After_Listening
@@ -120,38 +141,99 @@ Check_For_Empty_Topology_After_Listening
     [Tags]    critical
     Wait_For_Topology_To_Change_To    ${empty_json}    060_Empty.json
 
+Start_Listening_BGP_Speaker_Case_2
+    [Documentation]    BGP Speaker introduces 2 prefixes in the first update & another 2 prefixes while the very first is withdrawn in 2nd update
+    BGPSpeaker.Start_BGP_Speaker    --amount 3 --listen --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --prefill=2 --insert=2 --withdraw=1 --updates=single --firstprefix=8.0.0.240 --${BGP_TOOL_LOG_LEVEL}
+    Read_And_Fail_If_Prompt_Is_Seen
+
+Check_Listening_Connection_Is_Established_Case_2
+    [Documentation]    See TCP (BGP) connection in established state.
+    Check_Speaker_Is_Connected
+
+Check_Listening_Topology_Is_Filled_Case_2
+    [Documentation]    See new routes in example-ipv4-topology as a proof that synchronization was correct.
+    [Tags]    critical
+    Wait_For_Topology_To_Change_To    ${filled_json}    050_Filled.json
+    [Teardown]    Report_Failure_Due_To_Bug    4409
+
+Kill_Listening_BGP_Speaker_Case_2
+    [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
+    [Tags]    critical
+    [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
+    BGPSpeaker.Kill_BGP_Speaker
+    FailFast.Do_Not_Fail_Fast_From_Now_On
+    # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
+    [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
+
+Check_For_Empty_Topology_After_Listening_Case_2
+    [Documentation]    Post-condition: Check example-ipv4-topology is empty again.
+    [Tags]    critical
+    Wait_For_Topology_To_Change_To    ${empty_json}    060_Empty.json
+
+Start_Listening_BGP_Speaker_Case_3
+    [Documentation]    BGP Speaker introduces 3 prefixes while the first one occures again in the withdrawn list (to be ignored bu controller)
+    BGPSpeaker.Start_BGP_Speaker    --amount 2 --listen --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --prefill=0 --insert=3 --withdraw=1 --updates=single --${BGP_TOOL_LOG_LEVEL}
+    Read_And_Fail_If_Prompt_Is_Seen
+
+Check_Listening_Connection_Is_Established_Case_3
+    [Documentation]    See TCP (BGP) connection in established state.
+    Check_Speaker_Is_Connected
+
+Check_Listening_Topology_Is_Filled_Case_3
+    [Documentation]    See new routes in example-ipv4-topology as a proof that synchronization was correct.
+    [Tags]    critical
+    Wait_For_Topology_To_Change_To    ${filled_json}    050_Filled.json
+    [Teardown]    Report_Failure_Due_To_Bug    4634
+
+Kill_Listening_BGP_Speaker_Case_3
+    [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
+    [Tags]    critical
+    [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
+    BGPSpeaker.Kill_BGP_Speaker
+    FailFast.Do_Not_Fail_Fast_From_Now_On
+    # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
+    [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
+
+Check_For_Empty_Topology_After_Listening_Case_3
+    [Documentation]    Post-condition: Check example-ipv4-topology is empty again.
+    [Tags]    critical
+    Wait_For_Topology_To_Change_To    ${empty_json}    060_Empty.json
+
 Delete_Bgp_Peer_Configuration
     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
-    Delete_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}bgp_peer
+    ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer'}
+    ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
     # TODO: Do we need to check something else?
 
 *** Keywords ***
 Setup_Everything
-    [Documentation]    SSH-login to mininet machine, save prompt to variable, create HTTP session,
+    [Documentation]    SSH-login to mininet machine, create HTTP session,
     ...    prepare directories for responses, put Python tool to mininet machine, setup imported resources.
-    SSHLibrary.Open_Connection    ${MININET}
-    Flexible SSH Login     ${MININET_USER}    ${MININET_PASSWORD}
-    ${current_connection}=    Get_Connection
-    ${current_prompt}=    BuiltIn.Set_Variable    ${current_connection.prompt}
-    BuiltIn.Log    ${current_prompt}
-    Builtin.Set_Suite_Variable    ${prompt}    ${current_prompt}
-    RequestsLibrary.Create_Session    ses    http://${CONTROLLER}:${RESTCONFPORT}${OPERATIONAL_TOPO_API}    auth=${AUTH}
+    SetupUtils.Setup_Utils_For_Setup_And_Teardown
+    SSHLibrary.Set_Default_Configuration    prompt=${TOOLS_SYSTEM_PROMPT}
+    RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${OPERATIONAL_TOPO_API}    auth=${AUTH}
     # TODO: Do not include slash in ${OPERATIONAL_TOPO_API}, having it typed here is more readable.
     # TODO: Alternatively, create variable in Variables which starts with http.
     # Both TODOs would probably need to update every suite relying on current Variables.
-    OperatingSystem.Remove_Directory    ${directory_for_expected_responses}    recursive=True
-    OperatingSystem.Remove_Directory    ${directory_for_actual_responses}    recursive=True
+    OperatingSystem.Remove_Directory    ${EXPECTED_RESPONSES_FOLDER}    recursive=True
+    OperatingSystem.Remove_Directory    ${ACTUAL_RESPONSES_FOLDER}    recursive=True
     # The previous suite may have been using the same directories.
-    OperatingSystem.Create_Directory    ${directory_for_expected_responses}
-    OperatingSystem.Create_Directory    ${directory_for_actual_responses}
+    OperatingSystem.Create_Directory    ${EXPECTED_RESPONSES_FOLDER}
+    OperatingSystem.Create_Directory    ${ACTUAL_RESPONSES_FOLDER}
+    SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}
+    Utils.Flexible_Mininet_Login
+    SSHKeywords.Require_Python
+    SSHKeywords.Assure_Library_Ipaddr    target_dir=.
     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/play.py
     ConfigViaRestconf.Setup_Config_Via_Restconf
-    FailFast.Do_Not_Fail_Fast_From_Now_On
+    KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_LOG_LEVEL}
+    KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_BGP_LOG_LEVEL} org.opendaylight.bgpcep
+    KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_BGP_LOG_LEVEL} org.opendaylight.protocol
 
 Teardown_Everything
     [Documentation]    Create and Log the diff between expected and actual responses, make sure Python tool was killed.
     ...    Tear down imported Resources.
-    ${diff}=    OperatingSystem.Run    diff -dur ${directory_for_expected_responses} ${directory_for_actual_responses}
+    ${diff}=    OperatingSystem.Run    diff -dur ${EXPECTED_RESPONSES_FOLDER} ${ACTUAL_RESPONSES_FOLDER}
     BuiltIn.Log    ${diff}
     KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
     ConfigViaRestconf.Teardown_Config_Via_Restconf
@@ -160,26 +242,26 @@ Teardown_Everything
 
 Wait_For_Topology_To_Change_To
     [Arguments]    ${json_topology}    ${filename}    ${timeout}=10s    ${refresh}=1s
-    [Documentation]    Normalize the expected json topology and save it to ${directory_for_expected_responses}.
-    ...    Wait until Compare_Topology matches. ${directory_for_actual_responses} will hold its last result.
-    ${topology_normalized}=    Normalize_And_Save_Expected_Json    ${json_topology}    ${filename}    ${directory_for_expected_responses}
+    [Documentation]    Normalize the expected json topology and save it to ${EXPECTED_RESPONSES_FOLDER}.
+    ...    Wait until Compare_Topology matches. ${ACTUAL_RESPONSES_FOLDER} will hold its last result.
+    ${topology_normalized}=    Normalize_And_Save_Expected_Json    ${json_topology}    ${filename}    ${EXPECTED_RESPONSES_FOLDER}
     BuiltIn.Wait_Until_Keyword_Succeeds    ${timeout}    ${refresh}    Compare_Topology    ${topology_normalized}    ${filename}
 
 Verify_That_Topology_Does_Not_Change_From
     [Arguments]    ${json_topology}    ${filename}    ${timeout}=10s    ${refresh}=1s
-    [Documentation]    Normalize the expected json topology and save it to ${directory_for_expected_responses}.
-    ...    Verify that Compare_Topology keeps passing. ${directory_for_actual_responses} will hold its last result.
-    ${topology_normalized}=    Normalize_And_Save_Expected_Json    ${json_topology}    ${filename}    ${directory_for_expected_responses}
+    [Documentation]    Normalize the expected json topology and save it to ${EXPECTED_RESPONSES_FOLDER}.
+    ...    Verify that Compare_Topology keeps passing. ${ACTUAL_RESPONSES_FOLDER} will hold its last result.
+    ${topology_normalized}=    Normalize_And_Save_Expected_Json    ${json_topology}    ${filename}    ${EXPECTED_RESPONSES_FOLDER}
     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    ${timeout}    ${refresh}    Compare_Topology    ${topology_normalized}    ${filename}
 
 Compare_Topology
     [Arguments]    ${expected_normalized}    ${filename}
-    [Documentation]    Get current example-ipv4-topology as json, normalize it, save to ${directory_for_actual_responses}.
+    [Documentation]    Get current example-ipv4-topology as json, normalize it, save to ${ACTUAL_RESPONSES_FOLDER}.
     ...    Check that status code is 200, check that normalized jsons match exactly.
-    ${response}=    RequestsLibrary.Get    ses    topology/example-ipv4-topology
+    ${response}=    RequestsLibrary.Get Request    operational    topology/example-ipv4-topology
     BuiltIn.Log    ${response.status_code}
     BuiltIn.Log    ${response.text}
-    ${actual_normalized}=    Normalize_And_Save_Expected_Json    ${response.text}    ${filename}    ${directory_for_actual_responses}
+    ${actual_normalized}=    Normalize_And_Save_Expected_Json    ${response.text}    ${filename}    ${ACTUAL_RESPONSES_FOLDER}
     BuiltIn.Should_Be_Equal_As_Strings    ${response.status_code}    200
     BuiltIn.Should_Be_Equal    ${actual_normalized}    ${expected_normalized}
 
@@ -192,13 +274,6 @@ Normalize_And_Save_Expected_Json
     # TODO: Should we prepend .json to the filename? When we detect it is not already prepended?
     [Return]    ${json_normalized}
 
-Kill_BGP_Speaker
-    [Documentation]    Interrupt play.py, fail if no prompt is seen within SSHLibrary timeout.
-    ...    Also, check that TCP connection is no longer established.
-    Write_Bare_Ctrl_C
-    SSHLibrary.Read_Until_Prompt
-    Check_Speaker_Is_Not_Connected
-
 Check_Speaker_Is_Not_Connected
     [Documentation]    Give it a few tries to see zero established connections.
     BuiltIn.Wait_Until_Keyword_Succeeds    3s    1s    Check_Number_Of_Speaker_Connections    0
@@ -210,21 +285,5 @@ Check_Speaker_Is_Connected
 Check_Number_Of_Speaker_Connections
     [Arguments]    ${howmany}
     [Documentation]    Run netstat in mininet machine and parse it for number of established connections. Check it is ${howmany}.
-    ${output}=    SSHLibrary.Execute_Command    netstat -npt 2> /dev/null | grep -E ":17900 .+ ESTABLISHED .+python" | wc -l
+    ${output}=    SSHKeywords.Count_Port_Occurences    17900    ESTABLISHED    python
     BuiltIn.Should_Be_Equal_As_Strings    ${output}    ${howmany}
-
-Read_And_Fail_If_Prompt_Is_Seen
-    [Documentation]    Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout.
-    BuiltIn.Run_Keyword_And_Expect_Error    No match found for '${prompt}' in *.    Read_Text_Before_Prompt
-
-Read_Text_Before_Prompt
-    [Documentation]    Log text gathered by SSHLibrary.Read_Until_Prompt.
-    ...    This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
-    ${text}=    SSHLibrary.Read_Until_Prompt
-    BuiltIn.Log    ${text}
-
-Write_Bare_Ctrl_C
-    [Documentation]    Construct ctrl+c character and SSH-write it (without endline). Do not read anything yet.
-    # TODO: Place this keyword to some Resource so that it can be re-used in other suites.
-    ${command}=    BuiltIn.Evaluate    chr(int(3))
-    SSHLibrary.Write_Bare    ${command}