X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=csit%2Flibraries%2FRemoteBash.robot;h=b0d758f4e6795a776e16c0991209df5e728f2ae6;hb=02dd570f7544c8cd6eb17bda775de9bccc89f923;hp=e6c022c01560add1ca1f992e77b0789954f97e48;hpb=7e5a8e3140f4ae6ae45e05047650617b3f85253a;p=integration%2Ftest.git diff --git a/csit/libraries/RemoteBash.robot b/csit/libraries/RemoteBash.robot index e6c022c015..b0d758f4e6 100644 --- a/csit/libraries/RemoteBash.robot +++ b/csit/libraries/RemoteBash.robot @@ -1,28 +1,30 @@ *** Settings *** -Documentation Resource for managing bash execution when SSHLibrary.Execute_Command is not enough. +Documentation Resource for managing bash execution when SSHLibrary.Execute_Command is not enough. ... -... Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved. +... Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved. ... -... This program and the accompanying materials are made available under the -... terms of the Eclipse Public License v1.0 which accompanies this distribution, -... and is available at http://www.eclipse.org/legal/epl-v10.html +... This program and the accompanying materials are made available under the +... terms of the Eclipse Public License v1.0 which accompanies this distribution, +... and is available at http://www.eclipse.org/legal/epl-v10.html ... ... -... There are many test tools that need to be started from bash, -... and then either waited upon or aborted. -... Typical hurdles are usage of virtualenv or preventing idle SSH sessions from closing down. -... This Resource contains keywords specifically for these situations, -... in order to avoid SSHKeywords growing too big. +... There are many test tools that need to be started from bash, +... and then either waited upon or aborted. +... Typical hurdles are usage of virtualenv or preventing idle SSH sessions from closing down. +... This Resource contains keywords specifically for these situations, +... in order to avoid SSHKeywords growing too big. ... -... Each keyword assumes There is a SSH session already esteablished and active, -... with properties such as timeout already configured. -... No keyword should close or switch away from that session, -... but the configured timeout may be changed if requested. +... Each keyword assumes There is a SSH session already esteablished and active, +... with properties such as timeout already configured. +... No keyword should close or switch away from that session, +... but the configured timeout may be changed if requested. ... -... TODO: Backport improvements from project-specific Resources, -... for example logging to generated filename from NetconfKeywords and NexusKeywords. -Library SSHLibrary -Resource ${CURDIR}/SSHKeywords.robot +... TODO: Backport improvements from project-specific Resources, +... for example logging to generated filename from NetconfKeywords and NexusKeywords. + +Library SSHLibrary +Resource ${CURDIR}/SSHKeywords.robot + *** Keywords *** Write_Bare_Ctrl_C @@ -38,10 +40,10 @@ Write_Bare_Ctrl_D SSHLibrary.Write_Bare ${ctrl_d} Flush_Read - [Arguments] ${delay}=1 [Documentation] Attempt to read excess data (probably just multiple prompts), ignoring failure. ... Log the data or error message. Return None. ... \${delay} parameter tunes how long a period of inactivity has to be to consider all excess data to be read. + [Arguments] ${delay}=1 ${status} ${message} = BuiltIn.Run_Keyword_And_Ignore_Error SSHLibrary.Read delay=${delay} BuiltIn.Log ${message} @@ -52,33 +54,33 @@ Abort_Execution ${text} = SSHLibrary.Read_Until_Prompt BuiltIn.Log ${text} Flush_Read - [Return] ${text} + RETURN ${text} RemoteBash__Wait_Iteration [Documentation] Send a newline and wait for prompt. On success, return the text before the prompt. ... The newline is there to avoid disconnection due to idling. SSHLibrary.Write ${EMPTY} ${text} = SSHLibrary.Read_Until_Prompt - [Return] ${text} + RETURN ${text} Wait_Without_Idle - [Arguments] ${timeout} ${refresh}=1s [Documentation] Wait until prompt, while sending newlines to avoid idling. ... Flush read and return the text before prompt. + [Arguments] ${timeout} ${refresh}=1s ${text} = Wait_Until_Keyword_Succeeds ${timeout} ${refresh} RemoteBash__Wait_Iteration Flush_Read - [Return] ${text} + RETURN ${text} Invoke_With_Timeout - [Arguments] ${command} ${timeout} [Documentation] Enter ${command}, wait until it finishes and return the output. ... If it does not finish within timeout, abort it and fail. ... In either case, flush read. + [Arguments] ${command} ${timeout} # TODO: Total duration is WUKS timeout plus RUP timeout. Should we do some computation? SSHLibrary.Write ${command} ${text} = Wait_Without_Idle ${timeout} + RETURN ${text} [Teardown] BuiltIn.Run_Keyword_If "${KEYWORD_STATUS}" != "PASS" Abort_Execution - [Return] ${text} RemoteBash__Log_Text_Before_Prompt [Documentation] Log text gathered by SSHLibrary.Read_Until_Prompt. @@ -90,12 +92,12 @@ Verify_Tool_Has_Not_Finished_Yet [Documentation] Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout. ... Log any text seen, to help debug what happened when the tool exited early. ${status} ${message} = BuiltIn.Run_Keyword_And_Ignore_Error RemoteBash__Log_Text_Before_Prompt - BuiltIn.Return_From_Keyword_If "${status}" == "FAIL" + IF "${status}" == "FAIL" RETURN Builtin.Fail The prompt was seen but it was not expected yet. Check_Return_Code - [Arguments] ${expected_rc}=0 [Documentation] Get return code of the previous command, fail if it does not match the expectation.. + [Arguments] ${expected_rc}=0 SSHLibrary.Write echo \$? ${rc_and_prompt} = SSHLibrary.Read_Until_Prompt ${rc} = String.Fetch_From_Left ${rc_and_prompt} ${\n}