6be59165229b7dd171ba0ad1bde5bbcd54c5df01
[integration/test.git] / csit / suites / yangtools / odl-yang-validator / odl-yang-validator.robot
1 *** Settings ***
2 Documentation     Suite for testing performance of odl-yang-validator utility.
3 ...
4 ...               Copyright (c) 2016,2017 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 suite measures time (only as a test case duration) needed
12 ...               for odl-yang-validator to execute on a set of yang model.
13 ...
14 ...               The set of Yang modules is large and fixed (no changes in future).
15 ...               It is the same set of models as in mdsal binding-parent suite.
16 Suite Setup       Setup_Suite
17 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Fast_Failing    # TODO: Suite Teardown to close SSH connections and other cleanup?
18 Test Teardown     Teardown_Test
19 Default Tags      1node    odl-yang-validator    critical
20 Library           RequestsLibrary
21 Library           SSHLibrary
22 Library           String
23 Resource          ${CURDIR}/../../../libraries/NexusKeywords.robot
24 Resource          ${CURDIR}/../../../libraries/RemoteBash.robot
25 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
26 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
27 Resource          ${CURDIR}/../../../libraries/TemplatedRequests.robot
28 Resource          ${CURDIR}/../../../libraries/YangCollection.robot
29
30 *** Variables ***
31 ${EXPLICIT_YANG_SYSTEM_TEST_URL}    ${EMPTY}
32
33 *** Test Cases ***
34 Kill_Odl
35     [Documentation]    The ODL instance consumes resources, kill it.
36     ClusterManagement.Kill_Members_From_List_Or_All
37
38 Prepare_Yang_Files_To_Test
39     [Documentation]    Set up collection of Yang files to test with.
40     YangCollection.Static_Set_As_Src
41     ${dirs_to_process} =    Get_Recursive_Dirs    root=src/main/yang
42     ${p_option_value} =    BuiltIn.Catenate    SEPARATOR=:    @{dirs_to_process}
43     BuiltIn.Set_Suite_Variable    \${p_option_value}
44
45 Deploy_And_Start_Yang_System_Test_Utility
46     [Documentation]    Download appropriate version of odl-yang-validator artifact and start it against the prepared set.
47     ...    The version is either given by ${EXPLICIT_YANG_SYSTEM_TEST_URL},
48     ...    or constructed from Jenkins-shaped ${BUNDLE_URL}, or downloaded from Nexus based on ODL version.
49     ${status}    ${multipatch_url} =    BuiltIn.Run_Keyword_And_Ignore_Error    Construct_Multipatch_Url
50     ${url} =    Builtin.Set_Variable_If    "${status}" == "PASS"    ${multipatch_url}    ${EXPLICIT_YANG_SYSTEM_TEST_URL}
51     ${logfile} =    NexusKeywords.Install_And_Start_Java_Artifact    component=yangtools    artifact=odl-yang-validator    suffix=jar-with-dependencies    tool_options=-p ${p_option_value}    explicit_url=${url}
52     BuiltIn.Set_Suite_Variable    \${logfile}
53
54 Wait_Until_Utility_Finishes
55     [Documentation]    Repeatedly send endline to keep session alive; pass on prompt, fail on timeout.
56     RemoteBash.Wait_Without_Idle    60m
57
58 Check_Return_Code
59     [Documentation]    Get return code of previous command (the utility), pass if it is zero.
60     RemoteBash.Check_Return_Code
61
62 Collect_Files_To_Archive
63     [Documentation]    Download created files so Releng scripts would archive it.
64     [Setup]    Setup_Test_With_Logging_And_Without_Fast_Failing
65     BuiltIn.Run_Keyword_And_Ignore_Error    SSHLibrary.Get_File    ${logfile}
66
67 *** Keywords ***
68 Setup_Suite
69     [Documentation]    Activate dependency Resources, create SSH connection.
70     SetupUtils.Setup_Utils_For_Setup_And_Teardown
71     NexusKeywords.Initialize_Artifact_Deployment_And_Usage    tools_system_connect=False
72     SSHKeywords.Open_Connection_To_ODL_System
73
74 Teardown_Test
75     [Documentation]    Make sure CWD is set back to dot, then proceed with SetupUtils stuff.
76     SSHKeywords.Set_Cwd    .
77     SetupUtils.Teardown_Test_Show_Bugs_And_Start_Fast_Failing_If_Test_Failed
78
79 Get_Recursive_Dirs
80     [Arguments]    ${root}=.
81     [Documentation]    Return list of sub-directories discovered recursively under ${root} relative to
82     ...    the current working directory for a new shell spawned over the active SSH session.
83     ...    This implementation returns absolute paths as that is easier.
84     ${depth_1} =    SSHLibrary.List_Directories_In_Directory    path=${root}    absolute=True
85     ${subtrees} =    BuiltIn.Create_List
86     : FOR    ${subdir}    IN    @{depth_1}
87     \    ${tree} =    Get_Recursive_Dirs    root=${subdir}
88     \    # Relative paths would require prepending ${subdir}${/} to each @{tree} element.
89     \    Collections.Append_To_List    ${subtrees}    ${tree}
90     ${flat_list} =    Collections.Combine_Lists    ${depth_1}    @{subtrees}
91     [Return]    ${flat_list}
92
93 Construct_Multipatch_Url
94     [Documentation]    If ${EXPLICIT_YANG_SYSTEM_TEST_URL} is non-empty, return it. Otherwise:
95     ...    Check whether ${BUNDLE_URL} is from multipatch build (or similar maven style job),
96     ...    Check whether odl-yang-validator was built there as well,
97     ...    and return URL with proper version, or fail.
98     BuiltIn.Return_From_Keyword_If    """${EXPLICIT_YANG_SYSTEM_TEST_URL}""" != ""    ${EXPLICIT_YANG_SYSTEM_TEST_URL}
99     ${marker} =    BuiltIn.Set_Variable    /org.opendaylight.integration$distribution-karaf
100     ${is_multipatch} =    BuiltIn.Run_Keyword_And_Return_Status    BuiltIn.Should_Contain    ${BUNDLE_URL}    ${marker}
101     BuiltIn.Should_Be_True    ${is_multipatch}
102     ${yst_base_url} =    String.Fetch_From_Left    ${BUNDLE_URL}    ${marker}
103     RequestsLibrary.Create_Session    alias=cmu    url=${yst_base_url}
104     ${yst_general_uri} =    BuiltIn.Set_Variable    org.opendaylight.yangtools$odl-yang-validator/artifact/org.opendaylight.yangtools/odl-yang-validator
105     ${yst_html} =    TemplatedRequests.Get_From_Uri    ${yst_general_uri}    session=cmu
106     # The following two lines are very specific to a particular Jenkins html layout.
107     ${yst_almost_version} =    String.Fetch_From_Right    ${yst_html}    <td><a href="
108     ${yst_version} =    String.Fetch_From_Left    ${yst_almost_version}    ">
109     ${url} =    BuiltIn.Set_Variable    ${yst_base_url}/${yst_general_uri}/${yst_version}/odl-yang-validator-${yst_version}-jar-with-dependencies.jar
110     BuiltIn.Return_From_Keyword    ${url}