Extracted Nexus artifact deployment code 90/30190/6
authorJozef Behran <jbehran@cisco.com>
Tue, 24 Nov 2015 12:45:30 +0000 (13:45 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 8 Dec 2015 14:59:15 +0000 (14:59 +0000)
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 <jbehran@cisco.com>
csit/libraries/NetconfKeywords.robot
csit/libraries/NexusKeywords.robot [new file with mode: 0644]
csit/suites/bgpcep/pcepuser/pcepuser.robot
csit/suites/bgpcep/tcpmd5user/tcpmd5user.robot

index 4a5286ff4f62525fe604c345d726c2877dcab7ac..0c5a8d45d7c048326783def9413aaab5b71718ce 100644 (file)
@@ -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 '<latest>' | 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 (file)
index 0000000..6928891
--- /dev/null
@@ -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 '<version>' | 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/<tool-name>/<tool-name>-<version-tag>-${suffix}.jar"
+    ...    where "<tool-name>" is the name of the tool and "<version-tag>" 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}
index 0085821084c34a87bf19a41529a71520fe109a37..3f7d72c510368639465d3f6156db67b135c83af4 100644 (file)
@@ -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}
index 5b8e79cb154001b17410e172e5eaf2cae13a014e..c53f2df1426efb28b24df10e125cbeda7c2bef20 100644 (file)
@@ -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.