From 0185e21f53621042ebd121b97be881d3ffff0327 Mon Sep 17 00:00:00 2001 From: Jozef Behran Date: Tue, 24 Nov 2015 13:45:30 +0100 Subject: [PATCH] Extracted Nexus artifact deployment code The code that downloads executable utility artifacts from Nexus and deploys them to be ready to be executed on the Mininet machine was extracted into a new NexusKeywords.robot resource. Three suites (well, actually two suite and one resource) were updated to use the new resource, one is PCEP User test suite, the other is TCP MD5 suite and the last one is Netconf CRUD (this one was updated indirectly by updating NetconfKeywords.robot where the duplicated code actually resided). The reason is that another new test suite (Netconf performance via RestPerfClient) needs another Nexus artifact (RestPerfClient in this case) and thus another instance of the Nexus deployment code was about to be created, leading to code triplification. Thus this change to remove that technical debt. Change-Id: I5959c8ed9ea55ff84f9f2ad76104dfc464e7ba32 Signed-off-by: Jozef Behran --- csit/libraries/NetconfKeywords.robot | 12 +--- csit/libraries/NexusKeywords.robot | 55 +++++++++++++++++++ csit/suites/bgpcep/pcepuser/pcepuser.robot | 12 +--- .../suites/bgpcep/tcpmd5user/tcpmd5user.robot | 14 +---- 4 files changed, 63 insertions(+), 30 deletions(-) create mode 100644 csit/libraries/NexusKeywords.robot diff --git a/csit/libraries/NetconfKeywords.robot b/csit/libraries/NetconfKeywords.robot index 4a5286ff4f..0c5a8d45d7 100644 --- a/csit/libraries/NetconfKeywords.robot +++ b/csit/libraries/NetconfKeywords.robot @@ -15,6 +15,7 @@ Library Collections Library DateTime Library RequestsLibrary Resource NetconfViaRestconf.robot +Resource NexusKeywords.robot Resource SSHKeywords.robot *** Variables *** @@ -131,16 +132,7 @@ Install_And_Start_Testtool ... for the additional schemas is deleted on the remote machine and ... the additional schemas argument is left out. # Install test tool on the machine. - # TODO: The "urlbase" line is very similar to what pcep suites do. Reduce this code duplication. - ${urlbase}= BuiltIn.Set_Variable ${NEXUSURL_PREFIX}/content/repositories/opendaylight.snapshot/org/opendaylight/netconf/netconf-testtool - ${version}= SSHLibrary.Execute_Command curl ${urlbase}/maven-metadata.xml | grep '' | cut -d '>' -f 2 | cut -d '<' -f 1 - BuiltIn.Log ${version} - ${namepart}= SSHLibrary.Execute_Command curl ${urlbase}/${version}/maven-metadata.xml | grep value | head -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1 - BuiltIn.Log ${namepart} - BuiltIn.Set_Suite_Variable ${filename} netconf-testtool-${namepart}-executable.jar - BuiltIn.Log ${filename} - ${response}= SSHLibrary.Execute_Command curl ${urlbase}/${version}/${filename} >${filename} - BuiltIn.Log ${response} + ${filename}= NexusKeywords.Deploy_Test_Tool netconf/netconf-testtool ${schemas_option}= NetconfKeywords__Deploy_Additional_Schemas ${schemas} # Start the testtool ${command} BuiltIn.Set_Variable java -Xmx1G -XX:MaxPermSize=256M -jar ${filename} ${options} --device-count ${device-count} --debug ${debug} ${schemas_option} diff --git a/csit/libraries/NexusKeywords.robot b/csit/libraries/NexusKeywords.robot new file mode 100644 index 0000000000..6928891a9d --- /dev/null +++ b/csit/libraries/NexusKeywords.robot @@ -0,0 +1,55 @@ +*** Settings *** +Documentation Nexus repository access keywords. +... +... 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 encapsulates a bunch of somewhat complex and commonly used +... netconf operations into reusable keywords to make writing netconf +... test suites easier. +Library SSHLibrary + +*** Keywords *** +NexusKeywords__Get_Version_From_Metadata + ${version}= SSHLibrary.Execute_Command cat metadata.xml | grep latest | cut -d '>' -f 2 | cut -d '<' -f 1 + BuiltIn.Log ${version} + BuiltIn.Return_From_Keyword_If '${version}' != '' ${version} + ${version}= SSHLibrary.Execute_Command cat metadata.xml | grep '' | sort | tail -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1 + BuiltIn.Return_From_Keyword_If '${version}' != '' ${version} + BuiltIn.Fail Unrecognized metadata format, cannot determine the location of the requested artifact. + +Deploy_Artifact + [Arguments] ${directory} ${name_prefix} ${name_suffix}=-executable.jar ${type}=snapshot + [Documentation] Deploy the specified artifact from Nexus to the cwd of the machine to which the active SSHLibrary connection points. + ${urlbase}= BuiltIn.Set_Variable ${NEXUSURL_PREFIX}/content/repositories/opendaylight.${type}/org/opendaylight/${directory} + ${response}= SSHLibrary.Execute_Command curl ${urlbase}/maven-metadata.xml >metadata.xml + BuiltIn.Log ${response} + # TODO: Use RequestsLibrary and String instead of curl and bash utilities? + ${version}= NexusKeywords__Get_Version_From_Metadata + ${namepart}= SSHLibrary.Execute_Command curl ${urlbase}/${version}/maven-metadata.xml | grep value | head -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1 + BuiltIn.Log ${namepart} + ${filename}= BuiltIn.Set_Variable ${name_prefix}${namepart}${name_suffix} + BuiltIn.Log ${filename} + ${response}= SSHLibrary.Execute_Command wget -q -N ${urlbase}/${version}/${filename} 2>&1 + BuiltIn.Log ${response} + [Return] ${filename} + +Deploy_Test_Tool + [Arguments] ${name} ${suffix}=executable ${type}=snapshot + [Documentation] Deploy a test tool. + ... The test tools have naming convention of the form + ... "${type}/some/dir/somewhere//--${suffix}.jar" + ... where "" is the name of the tool and "" is + ... the version tag that is digged out of the maven metadata. This + ... keyword calculates ${name_prefix} and ${name_suffix} for + ... "Deploy_Artifact" and then calls "Deploy_Artifact" to do the real + ... work of deploying the artifact. + ${name_part}= BuiltIn.Evaluate '${name}'.split("/").pop() + ${name_prefix}= BuiltIn.Set_Variable ${name_part}- + ${name_suffix}= BuiltIn.Set_Variable -${suffix}.jar + ${filename}= Deploy_Artifact ${name} ${name_prefix} ${name_suffix} ${type} + [Return] ${filename} diff --git a/csit/suites/bgpcep/pcepuser/pcepuser.robot b/csit/suites/bgpcep/pcepuser/pcepuser.robot index 0085821084..3f7d72c510 100644 --- a/csit/suites/bgpcep/pcepuser/pcepuser.robot +++ b/csit/suites/bgpcep/pcepuser/pcepuser.robot @@ -12,6 +12,7 @@ Library OperatingSystem Library SSHLibrary Library RequestsLibrary Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py +Resource ${CURDIR}/../../../libraries/NexusKeywords.robot Resource ${CURDIR}/../../../libraries/PcepOperations.robot Resource ${CURDIR}/../../../libraries/Utils.robot Variables ${CURDIR}/../../../variables/Variables.py @@ -121,15 +122,8 @@ Set_It_Up Utils.Flexible_Mininet_Login # FIXME: Unify Module prefix usage across whole file. Create_Session ses http://${CONTROLLER}:${RESTCONFPORT}/restconf/operational/network-topology:network-topology auth=${AUTH} - ${urlbase}= Set_Variable ${NEXUSURL_PREFIX}/content/repositories/opendaylight.snapshot/org/opendaylight/bgpcep/pcep-pcc-mock - ${version}= Execute_Command curl ${urlbase}/maven-metadata.xml | grep latest | cut -d '>' -f 2 | cut -d '<' -f 1 - Log ${version} - ${namepart}= Execute_Command curl ${urlbase}/${version}/maven-metadata.xml | grep value | head -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1 - Log ${namepart} - Set_Suite_Variable ${filename} pcep-pcc-mock-${namepart}-executable.jar - Log ${filename} - ${response}= Execute_Command wget -q -N ${urlbase}/${version}/${filename} 2>&1 - Log ${response} + ${name}= NexusKeywords.Deploy_Test_Tool bgpcep/pcep-pcc-mock + BuiltIn.Set_Suite_Variable ${filename} ${name} Remove_Directory ${ExpDir} Remove_Directory ${ActDir} Create_Directory ${ExpDir} diff --git a/csit/suites/bgpcep/tcpmd5user/tcpmd5user.robot b/csit/suites/bgpcep/tcpmd5user/tcpmd5user.robot index 5b8e79cb15..c53f2df142 100644 --- a/csit/suites/bgpcep/tcpmd5user/tcpmd5user.robot +++ b/csit/suites/bgpcep/tcpmd5user/tcpmd5user.robot @@ -21,6 +21,7 @@ Library String Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py Resource ${CURDIR}/../../../libraries/ConfigViaRestconf.robot Resource ${CURDIR}/../../../libraries/FailFast.robot +Resource ${CURDIR}/../../../libraries/NexusKeywords.robot Resource ${CURDIR}/../../../libraries/PcepOperations.robot Resource ${CURDIR}/../../../libraries/WaitForFailure.robot Variables ${CURDIR}/../../../variables/Variables.py @@ -162,17 +163,8 @@ Set_It_Up BuiltIn.Log ${current_prompt} BuiltIn.Set_Suite_Variable ${prompt} ${current_prompt} RequestsLibrary.Create_Session ses http://${CONTROLLER}:${RESTCONFPORT}${OPERATIONAL_TOPO_API} auth=${AUTH} - # TODO: See corresponding bgpuser TODO. - ${urlbase}= BuiltIn.Set_Variable ${NEXUSURL_PREFIX}/content/repositories/opendaylight.snapshot/org/opendaylight/bgpcep/pcep-pcc-mock - ${version}= SSHLibrary.Execute_Command curl ${urlbase}/maven-metadata.xml | grep latest | cut -d '>' -f 2 | cut -d '<' -f 1 - # TODO: Use RequestsLibrary and String instead of curl and bash utilities? - BuiltIn.Log ${version} - ${namepart}= SSHLibrary.Execute_Command curl ${urlbase}/${version}/maven-metadata.xml | grep value | head -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1 - BuiltIn.Log ${namepart} - BuiltIn.Set_Suite_Variable ${filename} pcep-pcc-mock-${namepart}-executable.jar - BuiltIn.Log ${filename} - ${response}= SSHLibrary.Execute_Command wget -q -N ${urlbase}/${version}/${filename} 2>&1 - BuiltIn.Log ${response} + ${name}= NexusKeywords.Deploy_Test_Tool bgpcep/pcep-pcc-mock + BuiltIn.Set_Suite_Variable ${filename} ${name} OperatingSystem.Remove_Directory ${directory_for_expected_responses} recursive=True OperatingSystem.Remove_Directory ${directory_for_actual_responses} recursive=True # The previous suite may have been using the same directories. -- 2.36.6