Handle missing maven-metadata.xml at artifact location better
[integration/test.git] / csit / libraries / NexusKeywords.robot
1 *** Settings ***
2 Documentation     Nexus repository access keywords.
3 ...
4 ...               Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
5 ...
6 ...               This program and the accompanying materials are made available under the
7 ...               terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...               and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...
11 ...               This library encapsulates a bunch of somewhat complex and commonly used
12 ...               netconf operations into reusable keywords to make writing netconf
13 ...               test suites easier.
14 Library           SSHLibrary
15 Library           String
16 Resource          SSHKeywords.robot
17
18 *** Keywords ***
19 Initialize_Artifact_Deployment_And_Usage
20     [Documentation]    Initialize Nexus artifact deployment and usage
21     ...    Create and activate a connection to the tools system and perform
22     ...    additional configuration to allow the remaining keywords to deploy
23     ...    and use artifacts from Nexus on the tools system.
24     # Connect to the ODL machine
25     ${odl}=    SSHKeywords.Open_Connection_To_ODL_System
26     # Deploy the search tool.
27     SSHLibrary.Put_File    ${CURDIR}/../../tools/deployment/search.sh
28     SSHLibrary.Close_Connection
29     # Connect to the Tools System machine
30     ${tools}=    SSHKeywords.Open_Connection_To_Tools_System
31     BuiltIn.Set_Suite_Variable    ${SSHKeywords__tools_system_connection}    ${tools}
32
33 NexusKeywords__Get_Items_To_Look_At
34     [Arguments]    ${component}
35     [Documentation]    Get a list of items that might contain the version number that we are looking for.
36     BuiltIn.Return_From_Keyword_If    '${component}' == 'bgpcep'    pcep-impl
37     [Return]    ${component}-impl
38
39 NexusKeywords__Detect_Version_To_Pull
40     [Arguments]    ${component}
41     [Documentation]    Determine the exact Nexus directory to be used as a source for a particular test tool
42     ...    Figure out what version of the tool needs to be pulled out of the
43     ...    Nexus by looking at the version directory of the subsystem from
44     ...    which the tool is being pulled. This code is REALLY UGLY but there
45     ...    is no way around it until the bug
46     ...    https://bugs.opendaylight.org/show_bug.cgi?id=5206 gets fixed.
47     ...    I also don't want to depend on maven-metadata-local.xml and other
48     ...    bits and pieces of ODL distribution which are not required for ODL
49     ...    to function properly.
50     ${itemlist}=    NexusKeywords__Get_Items_To_Look_At    ${component}
51     ${current_ssh_connection}=    SSHLibrary.Get Connection
52     SSHKeywords.Open_Connection_To_ODL_System
53     ${version}    ${result}=    SSHLibrary.Execute_Command    sh search.sh ${WORKSPACE}/${BUNDLEFOLDER}/system ${itemlist}    return_rc=True
54     SSHLibrary.Close_Connection
55     Restore Current SSH Connection From Index    ${current_ssh_connection.index}
56     BuiltIn.Log    ${version}
57     BuiltIn.Run_Keyword_If    ${result}!=0    BuiltIn.Fail    Component "${component}" not found, cannot locate test tool
58     ${version}    ${location}=    String.Split_String    ${version}    max_split=1
59     [Return]    ${version}    ${location}
60
61 Deploy_Artifact
62     [Arguments]    ${component}    ${artifact}    ${name_prefix}    ${name_suffix}=-executable.jar    ${type}=snapshot
63     [Documentation]    Deploy the specified artifact from Nexus to the cwd of the machine to which the active SSHLibrary connection points.
64     ${urlbase}=    BuiltIn.Set_Variable    ${NEXUSURL_PREFIX}/content/repositories/opendaylight.${type}
65     ${version}    ${location}=    NexusKeywords__Detect_Version_To_Pull    ${component}
66     # TODO: Use RequestsLibrary and String instead of curl and bash utilities?
67     ${url}=    BuiltIn.Set_Variable    ${urlbase}/${location}/${artifact}/${version}
68     ${namepart}=    SSHLibrary.Execute_Command    curl ${url}/maven-metadata.xml | grep value | head -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1
69     BuiltIn.Log    ${namepart}
70     ${length}=    BuiltIn.Get_Length    ${namepart}
71     ${namepart}=    BuiltIn.Set_Variable_If    ${length} == 0    ${version}    ${namepart}
72     ${filename}=    BuiltIn.Set_Variable    ${name_prefix}${namepart}${name_suffix}
73     BuiltIn.Log    ${filename}
74     ${url}=    BuiltIn.Set_Variable    ${url}/${filename}
75     ${response}    ${result}=    SSHLibrary.Execute_Command    wget -q -N ${url} 2>&1    return_rc=True
76     BuiltIn.Log    ${response}
77     BuiltIn.Run_Keyword_If    ${result} != 0    BuiltIn.Fail    Artifact "${artifact}" in component "${component}" could not be downloaded from ${url}
78     [Return]    ${filename}
79
80 Deploy_Test_Tool
81     [Arguments]    ${component}    ${artifact}    ${suffix}=executable    ${type}=snapshot
82     [Documentation]    Deploy a test tool.
83     ...    The test tools have naming convention of the form
84     ...    "${type}/some/dir/somewhere/<tool-name>/<tool-name>-<version-tag>-${suffix}.jar"
85     ...    where "<tool-name>" is the name of the tool and "<version-tag>" is
86     ...    the version tag that is digged out of the maven metadata. This
87     ...    keyword calculates ${name_prefix} and ${name_suffix} for
88     ...    "Deploy_Artifact" and then calls "Deploy_Artifact" to do the real
89     ...    work of deploying the artifact.
90     ${name_prefix}=    BuiltIn.Set_Variable    ${artifact}-
91     ${name_suffix}=    BuiltIn.Set_Variable    -${suffix}.jar
92     ${filename}=    Deploy_Artifact    ${component}    ${artifact}    ${name_prefix}    ${name_suffix}    ${type}
93     [Return]    ${filename}