From: Vratko Polak Date: Wed, 7 Oct 2015 16:05:49 +0000 (+0200) Subject: Moved the karaf logging keywords to KarafKeywords X-Git-Tag: release/lithium-sr2^0 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=integration%2Ftest.git;a=commitdiff_plain;h=4811fa54cb585ce14d3b6280beda13af4985234c Moved the karaf logging keywords to KarafKeywords This change defines API-like keywords to be used in suites. Actual implementation may change in subsequent changes. Original idea an main implementation by: Jozef Behran Finishing touches by: Vratko Polak. The keywords are moved with as little modifications as possible (added code to preserve the active SSH connection across these calls, renamed "Connect To Controller Karaf" to "Open Controller Karaf Console On Background" and added requirement that "Open Controller Karaf Console On Background" is used prior to any "Log Message To Controller Karaf"), and without any changes to the rest of the KarafKeywords because these are used in quite a number of other suites. Merging this new code with the existing KarafKeywords codebase is a long and involved work that is better left to another commit. Additionally, this change updates the BGP Functional test to use the new keywords. This serves as an example about how to use these keywords and additionaly provides an additional verification that the keywords are not broken because the integration job will rerun the test which will fail, exposing the breakage. This change prompted for creating yet another resource (SetupUtils.robot) with keywords that are used in the [Setup ...] and [Teardown ...] sections of the suite/test. These are going to be used in further test suites so it is better to create them now to avoid code duplication (actually code triplication as there are 2 more tests being created that need them). Change-Id: I5df655b9532aeeee377d89e21743e74f1050498e Signed-off-by: Jozef Behran Signed-off-by: Vratko Polak --- diff --git a/csit/libraries/KarafKeywords.robot b/csit/libraries/KarafKeywords.robot index 9816d3563d..cee90f3c51 100644 --- a/csit/libraries/KarafKeywords.robot +++ b/csit/libraries/KarafKeywords.robot @@ -6,6 +6,7 @@ Variables ../variables/Variables.py *** Variables *** ${WORKSPACE} /tmp ${BUNDLEFOLDER} distribution-karaf-0.3.0-SNAPSHOT +${KarafKeywords__karaf_connection_index} -1 *** Keywords *** Check Karaf Log File Does Not Have Messages @@ -32,6 +33,7 @@ Verify Feature Is Not Installed Issue Command On Karaf Console [Arguments] ${cmd} ${controller}=${CONTROLLER} ${karaf_port}=${KARAF_SHELL_PORT} ${timeout}=5 [Documentation] Will execute the given ${cmd} by ssh'ing to the karaf console running on ${CONTROLLER} + ... Note that this keyword will open&close new SSH connection, without switching back to previously current session. Open Connection ${controller} port=${karaf_port} prompt=${KARAF_PROMPT} timeout=${timeout} Login ${KARAF_USER} ${KARAF_PASSWORD} Write ${cmd} @@ -76,3 +78,67 @@ Uninstall a Feature ${output}= Issue Command On Karaf Console feature:uninstall ${feature_name} ${controller} ${karaf_port} ${timeout} Log ${output} [Return] ${output} + +Restore Current SSH Connection From Index + [Arguments] ${connection_index} + [Documentation] Restore active SSH connection in SSHLibrary to given index. + ... + ... Restore the currently active connection state in + ... SSHLibrary to match the state returned by "Switch + ... Connection" or "Get Connection". More specifically makes + ... sure that there will be no active connection when the + ... \${connection_index} reported by these means is None. + ... + ... There is a misfeature in SSHLibrary: Invoking "SSHLibrary.Switch_Connection" + ... and passing None as the "index_or_alias" argument to it has exactly the + ... same effect as invoking "Close Connection". + ... https://github.com/robotframework/SSHLibrary/blob/master/src/SSHLibrary/library.py#L560 + ... + ... We want to have Keyword which will "switch out" to previous + ... "no connection active" state without killing the background one. + ... + ... As some suites may hypothetically rely on non-writability of active connection, + ... workaround is applied by opening and closing temporary connection. + ... Unfortunately this will fail if run on Jython and there is no SSH server + ... running on localhost, port 22 but there is nothing easy that can be done about it. + BuiltIn.Run Keyword And Return If ${connection_index} is not None SSHLibrary.Switch Connection ${connection_index} + # The background connection is still current, bury it. + SSHLibrary.Open Connection 127.0.0.1 + SSHLibrary.Close Connection + +Open Controller Karaf Console On Background + [Documentation] Connect to the controller's karaf console, but do not switch to it. + ${current_ssh_connection}= SSHLibrary.Get Connection + SSHLibrary.Open Connection ${CONTROLLER} port=${KARAF_SHELL_PORT} prompt=${KARAF_DETAILED_PROMPT} + ${karaf_connection}= SSHLibrary.Get Connection + SSHLibrary.Login ${KARAF_USER} ${KARAF_PASSWORD} + BuiltIn.Set Suite Variable ${KarafKeywords__karaf_connection_index} ${karaf_connection.index} + Restore Current SSH Connection From Index ${current_ssh_connection.index} + +Execute Controller Karaf Command On Background + [Arguments] ${command} + [Documentation] Send command to karaf without affecting current SSH connection. Read, log and return response. + ... This assumes Karaf connection has index saved and correct prompt set. + BuiltIn.Run Keyword If ${KarafKeywords__karaf_connection_index} == -1 Fail Need to connect to a Karaf Console first + ${current_connection_index}= SSHLibrary.Switch Connection ${KarafKeywords__karaf_connection_index} + ${status_write} ${message_write}= BuiltIn.Run Keyword And Ignore Error SSHLibrary.Write ${command} + ${status_wait} ${message_wait}= BuiltIn.Run Keyword And Ignore Error SSHLibrary.Read Until Prompt + Restore Current SSH Connection From Index ${current_connection_index} + BuiltIn.Run Keyword If '${status_write}' != 'PASS' BuiltIn.Fail Failed to send the command: ${command} + BuiltIn.Log ${message_wait} + BuiltIn.Run Keyword If '${status_wait}' != 'PASS' BuiltIn.Fail Failed to see prompt after sending the command: ${command} + [Return] ${message_wait} + +Log Message To Controller Karaf + [Arguments] ${message} + [Documentation] Send a message into the controller's karaf log file. Do not change current SSH connection. + ${reply}= Execute Controller Karaf Command On Background log:log "ROBOT MESSAGE: ${message}" + [Return] ${reply} + +Log Test Suite Start To Controller Karaf + [Documentation] Log suite name to karaf log, useful in suite setup. + Log Message To Controller Karaf Starting suite ${SUITE_SOURCE} + +Log Testcase Start To Controller Karaf + [Documentation] Log test case name to karaf log, useful in test case setup. + Log Message To Controller Karaf Starting test ${TEST_NAME} diff --git a/csit/libraries/SetupUtils.robot b/csit/libraries/SetupUtils.robot new file mode 100644 index 0000000000..de6e60462e --- /dev/null +++ b/csit/libraries/SetupUtils.robot @@ -0,0 +1,25 @@ +*** Settings *** +Documentation Simple resource with setup keywords which combine FailFast and Karaf logging. +... +... See FailFast.robot documentation for intricacies of that library. +Resource ${CURDIR}/FailFast.robot +Resource ${CURDIR}/KarafKeywords.robot + +*** Keywords *** +Setup_Utils_For_Setup_And_Teardown + [Documentation] Prepare both FailFast and karaf logging, to be used in suite setup. + FailFast.Do_Not_Fail_Fast_From_Now_On + KarafKeywords.Open_Controller_Karaf_Console_On_Background + KarafKeywords.Log_Test_Suite_Start_To_Controller_Karaf + +Setup_Test_With_Logging_And_Fast_Failing + [Documentation] Test case setup which skips on previous failure. If not, logs test case name to Karaf log. + ... Recommended to be used as the default test case setup. + FailFast.Fail_This_Fast_On_Previous_Error + KarafKeywords.Log_Testcase_Start_To_Controller_Karaf + +Setup_Test_With_Logging_And_Without_Fast_Failing + [Documentation] Test case setup which explicitly ignores previous failure and logs test case name to Karaf log. + ... Needed if the recommended default is to be overriden. + FailFast.Run_Even_When_Failing_Fast + KarafKeywords.Log_Testcase_Start_To_Controller_Karaf diff --git a/csit/libraries/Utils.robot b/csit/libraries/Utils.robot index 383178a189..7b64f0d938 100644 --- a/csit/libraries/Utils.robot +++ b/csit/libraries/Utils.robot @@ -10,7 +10,6 @@ Variables ../variables/Variables.py *** Variables *** # TODO: Introduce ${tree_size} and use instead of 1 in the next line. ${start} sudo mn --controller=remote,ip=${CONTROLLER} --topo tree,1 --switch ovsk,protocols=OpenFlow13 -${controller_index} -1 *** Keywords *** Start Suite @@ -40,29 +39,6 @@ Start Mininet Read Until mininet> [Return] ${mininet_conn_id} -Connect To Controller Karaf - [Documentation] Connect to the controller's karaf console. - ${esc}= BuiltIn.Evaluate chr(int(27)) - ${prompt}= Builtin.Set Variable @${esc}[0m${esc}[34mroot${esc}[0m> - ${connection}= SSHLibrary.Open_Connection ${CONTROLLER} port=${KARAF_SHELL_PORT} prompt=${prompt} - Set Suite Variable ${controller_index} ${connection} - SSHLibrary.Login ${KARAF_USER} ${KARAF_PASSWORD} - -Log Message To Controller Karaf - [Arguments] ${message} - [Documentation] Send a message into the controller's karaf log file. - # Background info: If there was no previous SSH connection, the "Get - # Connection" returns an information structure whose "index" field - # resolves to "None", and the "Switch Connection" below does not - # complain. - ${current}= Get_Connection - ${connection}= Set Variable ${current.index} - BuiltIn.Run Keyword If ${controller_index} <> -1 Switch Connection ${controller_index} - BuiltIn.Run Keyword If ${controller_index} == -1 Connect to Controller Karaf - SSHLibrary.Write log:log "ROBOT MESSAGE: ${message}" - SSHLibrary.Read_Until_Prompt - Switch Connection ${connection} - Stop Mininet [Arguments] ${mininet_conn_id} ${prompt}=${DEFAULT_LINUX_PROMPT} [Documentation] Basic setup to stop/clean mininet diff --git a/csit/suites/bgpcep/bgpuser/cases.robot b/csit/suites/bgpcep/bgpuser/cases.robot index 2aef5fa39d..5c3721cb4b 100644 --- a/csit/suites/bgpcep/bgpuser/cases.robot +++ b/csit/suites/bgpcep/bgpuser/cases.robot @@ -12,7 +12,7 @@ Documentation Basic tests for odl-bgpcep-bgp-all feature. ... https://wiki.opendaylight.org/view/BGP_LS_PCEP:Lithium_Feature_Tests#How_to_test_2 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. @@ -20,12 +20,14 @@ Library RequestsLibrary Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py Variables ${CURDIR}/../../../variables/Variables.py Variables ${CURDIR}/../../../variables/bgpuser/variables.py ${MININET} +Resource ${CURDIR}/../../../libraries/BGPSpeaker.robot Resource ${CURDIR}/../../../libraries/ConfigViaRestconf.robot Resource ${CURDIR}/../../../libraries/FailFast.robot -Resource ${CURDIR}/../../../libraries/BGPSpeaker.robot +Resource ${CURDIR}/../../../libraries/KarafKeywords.robot Resource ${CURDIR}/../../../libraries/KillPythonTool.robot -Resource ${CURDIR}/../../../libraries/WaitForFailure.robot +Resource ${CURDIR}/../../../libraries/SetupUtils.robot Resource ${CURDIR}/../../../libraries/Utils.robot +Resource ${CURDIR}/../../../libraries/WaitForFailure.robot *** Variables *** ${directory_for_actual_responses} ${TEMPDIR}/actual @@ -63,7 +65,7 @@ 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 + [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. @@ -104,7 +106,7 @@ 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 + [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. @@ -124,6 +126,7 @@ Delete_Bgp_Peer_Configuration Setup_Everything [Documentation] SSH-login to mininet machine, save prompt to variable, create HTTP session, ... prepare directories for responses, put Python tool to mininet machine, setup imported resources. + SetupUtils.Setup_Utils_For_Setup_And_Teardown SSHLibrary.Open_Connection ${MININET} Utils.Flexible_SSH_Login ${MININET_USER} ${MININET_PASSWORD} ${current_connection}= Get_Connection @@ -141,7 +144,6 @@ Setup_Everything OperatingSystem.Create_Directory ${directory_for_actual_responses} SSHLibrary.Put_File ${CURDIR}/../../../../tools/fastbgp/play.py ConfigViaRestconf.Setup_Config_Via_Restconf - FailFast.Do_Not_Fail_Fast_From_Now_On Teardown_Everything [Documentation] Create and Log the diff between expected and actual responses, make sure Python tool was killed. diff --git a/csit/variables/Variables.py b/csit/variables/Variables.py index f0ba059e7d..09002cdea7 100644 --- a/csit/variables/Variables.py +++ b/csit/variables/Variables.py @@ -34,6 +34,8 @@ CONTROLLER_STOP_TIMEOUT = 120 # Max number of seconds test will wait for a cont # KARAF Variaable KARAF_SHELL_PORT = '8101' +ESCAPE_CHARACTER = chr(int(27)) +KARAF_DETAILED_PROMPT = '@' + ESCAPE_CHARACTER + '[0m' + ESCAPE_CHARACTER + '[34mroot' + ESCAPE_CHARACTER + '[0m>' KARAF_PROMPT = 'opendaylight-user' KARAF_USER = 'karaf' KARAF_PASSWORD = 'karaf'