From 93238d6346d67ee97514c81c373f2678f3ed31d1 Mon Sep 17 00:00:00 2001 From: Kumar Rishabh Date: Mon, 25 Jan 2016 20:38:06 +0530 Subject: [PATCH] Create common resource for handling CLI tools Adds common resource for handling CLI tools in bgpcep suite according to in process creating a keyword library named BGPcliKeywords.robot. https://trello.com/c/OteFdQXz/263-int-test-create-a-common-resource-for-handling-interactive-command-line-tools Change-Id: I91edd2c97b906b333130569b10d4ad5618739b5d Signed-off-by: Kumar Rishabh --- csit/libraries/BGPcliKeywords.robot | 75 +++++++++++++++++++ .../bgpingest/bgp_app_peer_prefixcount.robot | 46 +----------- .../bgpcep/bgpuser/bgp_app_peer_basic.robot | 46 +----------- csit/suites/bgpcep/bgpuser/cases.robot | 14 +--- .../bgpcep/bgpuser/ebgp_peers_basic.robot | 39 +--------- .../bgpcep/bgpuser/ibgp_peers_basic.robot | 52 +------------ 6 files changed, 80 insertions(+), 192 deletions(-) create mode 100644 csit/libraries/BGPcliKeywords.robot diff --git a/csit/libraries/BGPcliKeywords.robot b/csit/libraries/BGPcliKeywords.robot new file mode 100644 index 0000000000..6b59f7ba38 --- /dev/null +++ b/csit/libraries/BGPcliKeywords.robot @@ -0,0 +1,75 @@ +*** Settings *** +Documentation Robot keyword library (Resource) for handling the BGP speaker CLI tools +... +... Copyright (c) 2015 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 library contains keywords to handle command line tools in BGP Application +... for handling shell connections +Library SSHLibrary timeout=10s +Library RequestsLibrary +Variables ${CURDIR}/../variables/Variables.py +Resource ${CURDIR}/Utils.robot + +*** Keywords *** +Start_Console_Tool + [Arguments] ${command} ${tool_opt} + [Documentation] Start the tool ${command} ${tool_opt} + BuiltIn.Log ${command} + ${output}= SSHLibrary.Write ${command} ${tool_opt} + BuiltIn.Log ${output} + +Wait_Until_Console_Tool_Finish + [Arguments] ${timeout} + [Documentation] Wait ${timeout} for the tool exit. + BuiltIn.Wait Until Keyword Succeeds ${timeout} 1s SSHLibrary.Read Until Prompt + +Stop_Console_Tool + [Documentation] Stop the tool if still running. + Utils.Write_Bare_Ctrl_C + ${output}= SSHLibrary.Read delay=1s + BuiltIn.Log ${output} + +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. + ${passed}= BuiltIn.Run_Keyword_And_Return_Status BuiltIn.Run_Keyword_And_Expect_Error No match found for '${ODL_SYSTEM_PROMPT}' in *. Read_Text_Before_Prompt + BuiltIn.Return_From_Keyword_If ${passed} + BGPSpeaker.Dump_BGP_Speaker_Logs + Builtin.Fail The prompt was seen but it was not expected yet + +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} + +Store_File_To_Workspace + [Arguments] ${source_file_name} ${target_file_name} + [Documentation] Store the ${source_file_name} to the workspace as ${target_file_name}. + ${output_log}= SSHLibrary.Execute_Command cat ${source_file_name} + BuiltIn.Log ${output_log} + Create File ${target_file_name} ${output_log} + +Check_File_For_Word_Count + [Arguments] ${file_name} ${word} ${expected_count} + [Documentation] Count ${word} in ${file_name}. Expect ${expected_count} occurence(s) + ${output_log}= SSHLibrary.Execute_Command grep -o '${word}' ${file_name} | wc -l + BuiltIn.Log ${output_log} + BuiltIn.Should_Be_Equal_As_Strings ${output_log} ${expected_count} + +Count_Key_Value_Pairs + [Arguments] ${file_name} ${keyword} ${value}='' + [Documentation] Check file for ${keyword} or ${keyword} ${value} pair and returns number of occurences + ${output_log}= SSHLibrary.Execute_Command grep '${keyword}' ${file_name} | grep -c ${value} + ${count}= Convert To Integer ${output_log} + [Return] ${count} + +Check_File_For_Occurence + [Arguments] ${file_name} ${keyword} ${value}='' + [Documentation] Check file for ${keyword} or ${keyword} ${value} pair and returns number of occurences + ${output_log}= SSHLibrary.Execute_Command grep '${keyword}' ${file_name} | grep -c ${value} + ${count}= Convert To Integer ${output_log} + [Return] ${count} diff --git a/csit/suites/bgpcep/bgpingest/bgp_app_peer_prefixcount.robot b/csit/suites/bgpcep/bgpingest/bgp_app_peer_prefixcount.robot index 891a20bb72..375b499a21 100644 --- a/csit/suites/bgpcep/bgpingest/bgp_app_peer_prefixcount.robot +++ b/csit/suites/bgpcep/bgpingest/bgp_app_peer_prefixcount.robot @@ -32,6 +32,7 @@ Force Tags critical Library SSHLibrary timeout=10s Library RequestsLibrary Variables ${CURDIR}/../../../variables/Variables.py +Resource ${CURDIR}/../../../libraries/BGPcliKeywords.robot Resource ${CURDIR}/../../../libraries/BGPSpeaker.robot Resource ${CURDIR}/../../../libraries/ConfigViaRestconf.robot Resource ${CURDIR}/../../../libraries/FailFast.robot @@ -225,48 +226,3 @@ Open_BGP_Aplicationp_Peer_Console [Documentation] Create a session for BGP peer. SSHLibrary.Open_Connection ${TOOLS_SYSTEM_IP} alias=bgp_app_peer_console Utils.Flexible_Mininet_Login - -Start_Console_Tool - [Arguments] ${command} ${tool_opt} - [Documentation] Start the tool ${command} ${tool_opt} - BuiltIn.Log ${command} - ${output}= SSHLibrary.Write ${command} ${tool_opt} - BuiltIn.Log ${output} - -Wait_Until_Console_Tool_Finish - [Arguments] ${timeout} - [Documentation] Wait ${timeout} for the tool exit. - BuiltIn.Wait Until Keyword Succeeds ${timeout} 1s SSHLibrary.Read Until Prompt - -Stop_Console_Tool - [Documentation] Stop the tool if still running. - Utils.Write_Bare_Ctrl_C - ${output}= SSHLibrary.Read delay=1s - BuiltIn.Log ${output} - -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. - ${passed}= BuiltIn.Run_Keyword_And_Return_Status BuiltIn.Run_Keyword_And_Expect_Error No match found for '${TOOLS_SYSTEM_PROMPT}' in *. Read_Text_Before_Prompt - BuiltIn.Return_From_Keyword_If ${passed} - BGPSpeaker.Dump_BGP_Speaker_Logs - Builtin.Fail The prompt was seen but it was not expected yet - -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} - -Store_File_To_Workspace - [Arguments] ${source_file_name} ${target_file_name} - [Documentation] Store the ${source_file_name} to the workspace as ${target_file_name}. - ${output_log}= SSHLibrary.Execute_Command cat ${source_file_name} - BuiltIn.Log ${output_log} - Create File ${target_file_name} ${output_log} - -Check_File_For_Word_Count - [Arguments] ${file_name} ${word} ${expected_count} - [Documentation] Count ${word} in ${file_name}. Expect ${expected_count} occurence(s) - ${output_log}= SSHLibrary.Execute_Command grep -o '${word}' ${file_name} | wc -l - BuiltIn.Log ${output_log} - BuiltIn.Should_Be_Equal_As_Strings ${output_log} ${expected_count} diff --git a/csit/suites/bgpcep/bgpuser/bgp_app_peer_basic.robot b/csit/suites/bgpcep/bgpuser/bgp_app_peer_basic.robot index 7dd157a976..7aca78e9a2 100644 --- a/csit/suites/bgpcep/bgpuser/bgp_app_peer_basic.robot +++ b/csit/suites/bgpcep/bgpuser/bgp_app_peer_basic.robot @@ -57,6 +57,7 @@ Library RequestsLibrary Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py Variables ${CURDIR}/../../../variables/Variables.py 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 @@ -347,24 +348,6 @@ Switch_To_BGP_Peer_Console Switch_To_BGP_Application_Peer_Console SSHLibrary.Switch Connection bgp_app_peer_console -Start_Console_Tool - [Arguments] ${command} ${tool_opt} - [Documentation] Start the tool ${command} ${tool_opt} - BuiltIn.Log ${command} - ${output}= SSHLibrary.Write ${command} ${tool_opt} - BuiltIn.Log ${output} - -Wait_Until_Console_Tool_Finish - [Arguments] ${timeout} - [Documentation] Wait ${timeout} for the tool exit. - BuiltIn.Wait Until Keyword Succeeds ${timeout} 1s SSHLibrary.Read Until Prompt - -Stop_Console_Tool - [Documentation] Stop the tool if still running. - Utils.Write_Bare_Ctrl_C - ${output}= SSHLibrary.Read delay=1s - BuiltIn.Log ${output} - Wait_For_Topology_To_Change_To [Arguments] ${json_topology} ${filename} ${timeout}=10s ${refresh}=1s [Documentation] Normalize the expected json topology and save it to ${EXPECTED_RESPONSES_FOLDER}. @@ -398,30 +381,3 @@ Normalize_And_Save_Expected_Json OperatingSystem.Create_File ${directory}${/}${filename} ${json_normalized} # TODO: Should we prepend .json to the filename? When we detect it is not already prepended? [Return] ${json_normalized} - -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. - ${passed}= BuiltIn.Run_Keyword_And_Return_Status BuiltIn.Run_Keyword_And_Expect_Error No match found for '${TOOLS_SYSTEM_PROMPT}' in *. Read_Text_Before_Prompt - BuiltIn.Return_From_Keyword_If ${passed} - BGPSpeaker.Dump_BGP_Speaker_Logs - Builtin.Fail The prompt was seen but it was not expected yet - -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} - -Store_File_To_Workspace - [Arguments] ${source_file_name} ${target_file_name} - [Documentation] Store the ${source_file_name} to the workspace as ${target_file_name}. - ${output_log}= SSHLibrary.Execute_Command cat ${source_file_name} - BuiltIn.Log ${output_log} - Create File ${target_file_name} ${output_log} - -Check_File_For_Word_Count - [Arguments] ${file_name} ${word} ${expected_count} - [Documentation] Count ${word} in ${file_name}. Expect ${expected_count} occurence(s) - ${output_log}= SSHLibrary.Execute_Command grep -o '${word}' ${file_name} | wc -l - BuiltIn.Log ${output_log} - BuiltIn.Should_Be_Equal_As_Strings ${output_log} ${expected_count} diff --git a/csit/suites/bgpcep/bgpuser/cases.robot b/csit/suites/bgpcep/bgpuser/cases.robot index 9d3aafd974..edb0a8e79a 100644 --- a/csit/suites/bgpcep/bgpuser/cases.robot +++ b/csit/suites/bgpcep/bgpuser/cases.robot @@ -35,6 +35,7 @@ Library RequestsLibrary Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py Variables ${CURDIR}/../../../variables/Variables.py 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 @@ -284,16 +285,3 @@ Check_Number_Of_Speaker_Connections [Documentation] Run netstat in mininet machine and parse it for number of established connections. Check it is ${howmany}. ${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. - ${passed}= BuiltIn.Run_Keyword_And_Return_Status BuiltIn.Run_Keyword_And_Expect_Error No match found for '${TOOLS_SYSTEM_PROMPT}' in *. Read_Text_Before_Prompt - BuiltIn.Return_From_Keyword_If ${passed} - BGPSpeaker.Dump_BGP_Speaker_Logs - Builtin.Fail The prompt was seen but it was not expected yet - -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} diff --git a/csit/suites/bgpcep/bgpuser/ebgp_peers_basic.robot b/csit/suites/bgpcep/bgpuser/ebgp_peers_basic.robot index c4a840c579..19e5c5d8bb 100644 --- a/csit/suites/bgpcep/bgpuser/ebgp_peers_basic.robot +++ b/csit/suites/bgpcep/bgpuser/ebgp_peers_basic.robot @@ -25,6 +25,7 @@ Library RequestsLibrary Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py Variables ${CURDIR}/../../../variables/Variables.py Variables ${CURDIR}/../../../variables/bgpuser/variables.py ${ODL_SYSTEM_PROMPT} +Resource ${CURDIR}/../../../libraries/BGPcliKeywords.robot Resource ${CURDIR}/../../../libraries/BGPSpeaker.robot Resource ${CURDIR}/../../../libraries/ConfigViaRestconf.robot Resource ${CURDIR}/../../../libraries/FailFast.robot @@ -223,30 +224,6 @@ Teardown_Everything RequestsLibrary.Delete_All_Sessions SSHLibrary.Close_All_Connections -Start_Console_Tool - [Arguments] ${command} ${tool_opt} - [Documentation] Start the tool ${command} ${tool_opt} - BuiltIn.Log ${command} - ${output}= SSHLibrary.Write ${command} ${tool_opt} - BuiltIn.Log ${output} - -Wait_Until_Console_Tool_Finish - [Arguments] ${timeout} - [Documentation] Wait ${timeout} for the tool exit. - BuiltIn.Wait Until Keyword Succeeds ${timeout} 1s SSHLibrary.Read Until Prompt - -Stop_Console_Tool - [Documentation] Stop the tool if still running. - Utils.Write_Bare_Ctrl_C - BuiltIn.Wait Until Keyword Succeeds 10s 1s SSHLibrary.Read Until Prompt - -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. - ${passed}= BuiltIn.Run_Keyword_And_Return_Status BuiltIn.Run_Keyword_And_Expect_Error No match found for '${ODL_SYSTEM_PROMPT}' in *. Read_Text_Before_Prompt - BuiltIn.Return_From_Keyword_If ${passed} - BGPSpeaker.Dump_BGP_Speaker_Logs - Builtin.Fail The prompt was seen but it was not expected yet - 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. @@ -275,17 +252,3 @@ Store_File_To_Workspace ${output_log}= SSHLibrary.Execute_Command cat ${source_file_name} BuiltIn.Log ${output_log} Create File ${target_file_name} ${output_log} - -Check_File_For_Word_Count - [Arguments] ${file_name} ${word} ${expected_count} - [Documentation] Count ${word} in ${file_name}. Expect ${expected_count} occurence(s) - ${output_log}= SSHLibrary.Execute_Command grep -o '${word}' ${file_name} | wc -l - BuiltIn.Log ${output_log} - BuiltIn.Should_Be_Equal_As_Strings ${output_log} ${expected_count} - -Count_Key_Value_Pairs - [Arguments] ${file_name} ${keyword} ${value}='' - [Documentation] Check file for ${keyword} or ${keyword} ${value} pair and returns number of occurences - ${output_log}= SSHLibrary.Execute_Command grep '${keyword}' ${file_name} | grep -c ${value} - ${count}= Convert To Integer ${output_log} - [Return] ${count} diff --git a/csit/suites/bgpcep/bgpuser/ibgp_peers_basic.robot b/csit/suites/bgpcep/bgpuser/ibgp_peers_basic.robot index 2e58c2edbd..e6d3d3ec35 100644 --- a/csit/suites/bgpcep/bgpuser/ibgp_peers_basic.robot +++ b/csit/suites/bgpcep/bgpuser/ibgp_peers_basic.robot @@ -34,6 +34,7 @@ Library DateTime Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py Variables ${CURDIR}/../../../variables/Variables.py Variables ${CURDIR}/../../../variables/bgpuser/variables.py ${ODL_SYSTEM_PROMPT} +Resource ${CURDIR}/../../../libraries/BGPcliKeywords.robot Resource ${CURDIR}/../../../libraries/BGPSpeaker.robot Resource ${CURDIR}/../../../libraries/ConfigViaRestconf.robot Resource ${CURDIR}/../../../libraries/FailFast.robot @@ -328,23 +329,6 @@ Teardown_Everything RequestsLibrary.Delete_All_Sessions SSHLibrary.Close_All_Connections -Start_Console_Tool - [Arguments] ${command} ${tool_opt} - [Documentation] Start the tool ${command} ${tool_opt} - BuiltIn.Log ${command} - ${output}= SSHLibrary.Write ${command} ${tool_opt} - BuiltIn.Log ${output} - -Wait_Until_Console_Tool_Finish - [Arguments] ${timeout} - [Documentation] Wait ${timeout} for the tool exit. - BuiltIn.Wait Until Keyword Succeeds ${timeout} 1s SSHLibrary.Read Until Prompt - -Stop_Console_Tool - [Documentation] Stop the tool if still running. - Utils.Write_Bare_Ctrl_C - BuiltIn.Wait Until Keyword Succeeds 10s 1s SSHLibrary.Read Until Prompt - Check_Example_IPv4_Topology_Content [Arguments] ${string_to_check}=${EMPTY} [Documentation] Check the example-ipv4-topology content for string @@ -360,37 +344,3 @@ Check_Example_IPv4_Topology_Does_Not_Contain BuiltIn.Log ${response.status_code} BuiltIn.Log ${response.text} BuiltIn.Should_Not_Contain ${response.text} ${string_to_check} - -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. - ${passed}= BuiltIn.Run_Keyword_And_Return_Status BuiltIn.Run_Keyword_And_Expect_Error No match found for '${ODL_SYSTEM_PROMPT}' in *. Read_Text_Before_Prompt - BuiltIn.Return_From_Keyword_If ${passed} - BGPSpeaker.Dump_BGP_Speaker_Logs - Builtin.Fail The prompt was seen but it was not expected yet - -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} - -Store_File_To_Workspace - [Arguments] ${source_file_name} ${target_file_name} - [Documentation] Store the ${source_file_name} to the workspace as ${target_file_name}. - ${output_log}= SSHLibrary.Execute_Command cat ${source_file_name} - BuiltIn.Log ${output_log} - Create File ${target_file_name} ${output_log} - -Check_File_For_Word_Count - [Arguments] ${file_name} ${word} ${expected_count} - [Documentation] Count ${word} in ${file_name}. Expect ${expected_count} occurence(s) - ${output_log}= SSHLibrary.Execute_Command grep -o '${word}' ${file_name} | wc -l - BuiltIn.Log ${output_log} - BuiltIn.Should_Be_Equal_As_Strings ${output_log} ${expected_count} - -Check_File_For_Occurence - [Arguments] ${file_name} ${keyword} ${value}='' - [Documentation] Check file for ${keyword} or ${keyword} ${value} pair and returns number of occurences - ${output_log}= SSHLibrary.Execute_Command grep '${keyword}' ${file_name} | grep -c ${value} - ${count}= Convert To Integer ${output_log} - [Return] ${count} -- 2.36.6