Convert bgpcep/throughpcep suite to use NexusKeywords
[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           OperatingSystem
15 Library           SSHLibrary
16 Library           String
17 Resource          SSHKeywords.robot
18
19 *** Keywords ***
20 Initialize_Artifact_Deployment_And_Usage
21     [Arguments]    ${tools_system_connect}=True
22     [Documentation]    Places search utility to ODL system, which will be needed for version detection.
23     ...    By default also initialize a SSH connection to Tools system,
24     ...    as following Keywords assume a working connection towards target system.
25     # Connect to the ODL machine.
26     ${odl}=    SSHKeywords.Open_Connection_To_ODL_System
27     # Deploy the search tool.
28     SSHLibrary.Put_File    ${CURDIR}/../../tools/deployment/search.sh
29     SSHLibrary.Close_Connection
30     # Optionally connect to the Tools System machine.
31     BuiltIn.Return_From_Keyword_If    not (${tools_system_connect})    # the argument may be a convoluted Python expression
32     SSHKeywords.Open_Connection_To_Tools_System
33
34 NexusKeywords__Get_Items_To_Look_At
35     [Arguments]    ${component}
36     [Documentation]    Get a list of items that might contain the version number that we are looking for.
37     BuiltIn.Return_From_Keyword_If    '${component}' == 'bgpcep'    pcep-impl
38     [Return]    ${component}-impl
39
40 NexusKeywords__Detect_Version_To_Pull
41     [Arguments]    ${component}
42     [Documentation]    Determine the exact Nexus directory to be used as a source for a particular test tool
43     ...    Figure out what version of the tool needs to be pulled out of the
44     ...    Nexus by looking at the version directory of the subsystem from
45     ...    which the tool is being pulled. This code is REALLY UGLY but there
46     ...    is no way around it until the bug
47     ...    https://bugs.opendaylight.org/show_bug.cgi?id=5206 gets fixed.
48     ...    I also don't want to depend on maven-metadata-local.xml and other
49     ...    bits and pieces of ODL distribution which are not required for ODL
50     ...    to function properly.
51     ${itemlist}=    NexusKeywords__Get_Items_To_Look_At    ${component}
52     ${current_ssh_connection}=    SSHLibrary.Get Connection
53     SSHKeywords.Open_Connection_To_ODL_System
54     ${version}    ${result}=    SSHLibrary.Execute_Command    sh search.sh ${WORKSPACE}/${BUNDLEFOLDER}/system ${itemlist}    return_rc=True
55     SSHLibrary.Close_Connection
56     Restore Current SSH Connection From Index    ${current_ssh_connection.index}
57     BuiltIn.Log    ${version}
58     BuiltIn.Run_Keyword_If    ${result}!=0    BuiltIn.Fail    Component "${component}" not found, cannot locate test tool
59     ${version}    ${location}=    String.Split_String    ${version}    max_split=1
60     [Return]    ${version}    ${location}
61
62 Deploy_Artifact
63     [Arguments]    ${component}    ${artifact}    ${name_prefix}    ${name_suffix}=-executable.jar
64     [Documentation]    Deploy the specified artifact from Nexus to the cwd of the machine to which the active SSHLibrary connection points.
65     ...    Must have ${BUNDLE_URL} variable set to the URL from which the
66     ...    tested ODL distribution was downloaded and this place must be
67     ...    inside a repository created by a standard distribution
68     ...    construction job.
69     ${urlbase}=    String.Fetch_From_Left    ${BUNDLE_URL}    /org/opendaylight
70     ${version}    ${location}=    NexusKeywords__Detect_Version_To_Pull    ${component}
71     # TODO: Use RequestsLibrary and String instead of curl and bash utilities?
72     ${url}=    BuiltIn.Set_Variable    ${urlbase}/${location}/${artifact}/${version}
73     ${namepart}=    SSHLibrary.Execute_Command    curl ${url}/maven-metadata.xml | grep value | head -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1
74     BuiltIn.Log    ${namepart}
75     ${length}=    BuiltIn.Get_Length    ${namepart}
76     ${namepart}=    BuiltIn.Set_Variable_If    ${length} == 0    ${version}    ${namepart}
77     ${filename}=    BuiltIn.Set_Variable    ${name_prefix}${namepart}${name_suffix}
78     BuiltIn.Log    ${filename}
79     ${url}=    BuiltIn.Set_Variable    ${url}/${filename}
80     ${response}    ${result}=    SSHLibrary.Execute_Command    wget -q -N ${url} 2>&1    return_rc=True
81     BuiltIn.Log    ${response}
82     BuiltIn.Run_Keyword_If    ${result} != 0    BuiltIn.Fail    Artifact "${artifact}" in component "${component}" could not be downloaded from ${url}
83     [Return]    ${filename}
84
85 Deploy_Test_Tool
86     [Arguments]    ${component}    ${artifact}    ${suffix}=executable
87     [Documentation]    Deploy a test tool.
88     ...    The test tools have naming convention of the form
89     ...    "<repository_url>/some/dir/somewhere/<tool-name>/<tool-name>-<version-tag>-${suffix}.jar"
90     ...    where "<tool-name>" is the name of the tool and "<version-tag>" is
91     ...    the version tag that is digged out of the maven metadata. This
92     ...    keyword calculates ${name_prefix} and ${name_suffix} for
93     ...    "Deploy_Artifact" and then calls "Deploy_Artifact" to do the real
94     ...    work of deploying the artifact.
95     ${name_prefix}=    BuiltIn.Set_Variable    ${artifact}-
96     ${name_suffix}=    BuiltIn.Set_Variable    -${suffix}.jar
97     ${filename}=    Deploy_Artifact    ${component}    ${artifact}    ${name_prefix}    ${name_suffix}
98     [Return]    ${filename}