Update yang-model-validator test suite
[integration/test.git] / csit / suites / yangtools / yang-model-validator / yang-model-validator.robot
1 *** Settings ***
2 Documentation     Suite for testing performance of yang-model-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 yang-model-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    yang-model-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     ${yang_files_to_validate} =    Get_Yang_Files_From_Dirs    ${dirs_to_process}
44     BuiltIn.Set_Suite_Variable    ${yang_files_to_validate}
45     BuiltIn.Set_Suite_Variable    \${p_option_value}
46
47 Deploy_And_Start_Odl_Yang_Validator_Utility
48     [Documentation]    Download appropriate version of yang-model-validator artifact
49     ...    and run it for each single yang file in the prepared set.
50     ...    The version is either given by ${EXPLICIT_YANG_SYSTEM_TEST_URL},
51     ...    or constructed from Jenkins-shaped ${BUNDLE_URL}, or downloaded from Nexus based on ODL version.
52     ${status}    ${multipatch_url} =    BuiltIn.Run_Keyword_And_Ignore_Error    Construct_Multipatch_Url
53     ${url} =    Builtin.Set_Variable_If    "${status}" == "PASS"    ${multipatch_url}    ${EXPLICIT_YANG_SYSTEM_TEST_URL}
54     : FOR    ${yang_file}    IN    @{yang_files_to_validate}
55     \    ${logfile} =    NexusKeywords.Install_And_Start_Java_Artifact    component=yangtools    artifact=yang-model-validator    suffix=jar-with-dependencies    tool_options=-p ${p_option_value} ${yang_file}
56     \    ...    explicit_url=${url}
57     \    BuiltIn.Set_Suite_Variable    \${logfile}
58     \    Wait_Until_Utility_Finishes
59     \    Check_Return_Code
60
61 Collect_Files_To_Archive
62     [Documentation]    Download created files so Releng scripts would archive it.
63     [Setup]    Setup_Test_With_Logging_And_Without_Fast_Failing
64     BuiltIn.Run_Keyword_And_Ignore_Error    SSHLibrary.Get_File    ${logfile}
65
66 *** Keywords ***
67 Setup_Suite
68     [Documentation]    Activate dependency Resources, create SSH connection.
69     SetupUtils.Setup_Utils_For_Setup_And_Teardown
70     NexusKeywords.Initialize_Artifact_Deployment_And_Usage    tools_system_connect=False
71     SSHKeywords.Open_Connection_To_ODL_System
72
73 Teardown_Test
74     [Documentation]    Make sure CWD is set back to dot, then proceed with SetupUtils stuff.
75     SSHKeywords.Set_Cwd    .
76     SetupUtils.Teardown_Test_Show_Bugs_And_Start_Fast_Failing_If_Test_Failed
77
78 Get_Recursive_Dirs
79     [Arguments]    ${root}=.
80     [Documentation]    Return list of sub-directories discovered recursively under ${root} relative to
81     ...    the current working directory for a new shell spawned over the active SSH session.
82     ...    This implementation returns absolute paths as that is easier.
83     ${depth_1} =    SSHLibrary.List_Directories_In_Directory    path=${root}    absolute=True
84     ${subtrees} =    BuiltIn.Create_List
85     : FOR    ${subdir}    IN    @{depth_1}
86     \    ${tree} =    Get_Recursive_Dirs    root=${subdir}
87     \    # Relative paths would require prepending ${subdir}${/} to each @{tree} element.
88     \    Collections.Append_To_List    ${subtrees}    ${tree}
89     ${flat_list} =    Collections.Combine_Lists    ${depth_1}    @{subtrees}
90     [Return]    ${flat_list}
91
92 Get_Yang_Files_From_Dirs
93     [Arguments]    ${dirs_to_process}
94     [Documentation]    Return list of yang files from provided directories
95     ${collected_yang_files} =    BuiltIn.Create_List
96     : FOR    ${dir}    IN    @{dirs_to_process}
97     \    ${yang_files_in_dir} =    SSHLibrary.List_Files_In_Directory    path=${dir}    pattern=*.yang    absolute=True
98     \    ${collected_yang_files} =    Collections.Combine_Lists    ${collected_yang_files}    ${yang_files_in_dir}
99     [Return]    ${collected_yang_files}
100
101 Construct_Multipatch_Url
102     [Documentation]    If ${EXPLICIT_YANG_SYSTEM_TEST_URL} is non-empty, return it. Otherwise:
103     ...    Check whether ${BUNDLE_URL} is from multipatch build (or similar maven style job),
104     ...    Check whether yang-model-validator was built there as well,
105     ...    and return URL with proper version, or fail.
106     BuiltIn.Return_From_Keyword_If    """${EXPLICIT_YANG_SYSTEM_TEST_URL}""" != ""    ${EXPLICIT_YANG_SYSTEM_TEST_URL}
107     ${marker} =    BuiltIn.Set_Variable    /org.opendaylight.integration$distribution-karaf
108     ${is_multipatch} =    BuiltIn.Run_Keyword_And_Return_Status    BuiltIn.Should_Contain    ${BUNDLE_URL}    ${marker}
109     BuiltIn.Should_Be_True    ${is_multipatch}
110     ${yst_base_url} =    String.Fetch_From_Left    ${BUNDLE_URL}    ${marker}
111     RequestsLibrary.Create_Session    alias=cmu    url=${yst_base_url}
112     ${yst_general_uri} =    BuiltIn.Set_Variable    org.opendaylight.yangtools$yang-model-validator/artifact/org.opendaylight.yangtools/yang-model-validator
113     ${yst_html} =    TemplatedRequests.Get_From_Uri    ${yst_general_uri}    session=cmu
114     # The following two lines are very specific to a particular Jenkins html layout.
115     ${yst_almost_version} =    String.Fetch_From_Right    ${yst_html}    <td><a href="
116     ${yst_version} =    String.Fetch_From_Left    ${yst_almost_version}    ">
117     ${url} =    BuiltIn.Set_Variable    ${yst_base_url}/${yst_general_uri}/${yst_version}/yang-model-validator-${yst_version}-jar-with-dependencies.jar
118     BuiltIn.Return_From_Keyword    ${url}
119
120 Wait_Until_Utility_Finishes
121     [Documentation]    Repeatedly send endline to keep session alive; pass on prompt, fail on timeout.
122     RemoteBash.Wait_Without_Idle    60m
123
124 Check_Return_Code
125     [Documentation]    Get return code of previous command (the utility), pass if it is zero.
126     RemoteBash.Check_Return_Code