Fix yangtools test tool installation
[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/CompareStream.robot
24 Resource          ${CURDIR}/../../../libraries/NexusKeywords.robot
25 Resource          ${CURDIR}/../../../libraries/RemoteBash.robot
26 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
27 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
28 Resource          ${CURDIR}/../../../libraries/TemplatedRequests.robot
29 Resource          ${CURDIR}/../../../libraries/YangCollection.robot
30
31 *** Variables ***
32 ${TEST_TOOL_NAME}    yang-model-validator
33 ${EXPLICIT_YANG_SYSTEM_TEST_URL}    ${EMPTY}
34 ${NITROGEN_YANG_SYSTEM_TEST_URL}    ${NEXUS_RELEASE_BASE_URL}/org/opendaylight/yangtools/${TEST_TOOL_NAME}/2.0.0/${TEST_TOOL_NAME}-2.0.0-jar-with-dependencies.jar
35 ${OXYGEN_YANG_SYSTEM_TEST_URL}    ${NEXUS_RELEASE_BASE_URL}/org/opendaylight/yangtools/${TEST_TOOL_NAME}/2.0.1/${TEST_TOOL_NAME}-2.0.1-jar-with-dependencies.jar
36
37 *** Test Cases ***
38 Kill_Odl
39     [Documentation]    The ODL instance consumes resources, kill it.
40     ClusterManagement.Kill_Members_From_List_Or_All
41
42 Prepare_Yang_Files_To_Test
43     [Documentation]    Set up collection of Yang files to test with.
44     YangCollection.Static_Set_As_Src
45     ${dirs_to_process} =    Get_Recursive_Dirs    root=src/main/yang
46     ${p_option_value} =    BuiltIn.Catenate    SEPARATOR=:    @{dirs_to_process}
47     ${yang_files_to_validate} =    Get_Yang_Files_From_Dirs    ${dirs_to_process}
48     BuiltIn.Set_Suite_Variable    ${yang_files_to_validate}
49     BuiltIn.Set_Suite_Variable    \${p_option_value}
50
51 Deploy_And_Start_Odl_Yang_Validator_Utility
52     [Documentation]    Download appropriate version of ${TEST_TOOL_NAME} artifact
53     ...    and run it for each single yang file in the prepared set.
54     ...    The version is either given by ${EXPLICIT_YANG_SYSTEM_TEST_URL},
55     ...    or constructed from Jenkins-shaped ${BUNDLE_URL}, or downloaded from Nexus based on ODL version.
56     : FOR    ${yang_file}    IN    @{yang_files_to_validate}
57     \    ${logfile} =    NexusKeywords.Install_And_Start_Java_Artifact    component=yangtools    artifact=${TEST_TOOL_NAME}    suffix=jar-with-dependencies    tool_options=-p ${p_option_value} ${yang_file}
58     \    ...    explicit_url=${EXPLICIT_YANG_SYSTEM_TEST_URL}
59     \    BuiltIn.Set_Suite_Variable    \${logfile}
60     \    Wait_Until_Utility_Finishes
61     \    Check_Return_Code
62
63 Collect_Files_To_Archive
64     [Documentation]    Download created files so Releng scripts would archive it.
65     [Setup]    Setup_Test_With_Logging_And_Without_Fast_Failing
66     BuiltIn.Run_Keyword_And_Ignore_Error    SSHLibrary.Get_File    ${logfile}
67
68 *** Keywords ***
69 Setup_Suite
70     [Documentation]    Activate dependency Resources, create SSH connection.
71     SetupUtils.Setup_Utils_For_Setup_And_Teardown
72     ${TEST_TOOL_NAME}=    CompareStream.Set_Variable_If_At_Most_Carbon    yang-system-test    ${TEST_TOOL_NAME}
73     ${EXPLICIT_YANG_SYSTEM_TEST_URL}=    CompareStream.Set_Variable_If_At_Least_Nitrogen    ${NITROGEN_YANG_SYSTEM_TEST_URL}    ${EMPTY}
74     ${EXPLICIT_YANG_SYSTEM_TEST_URL}=    CompareStream.Set_Variable_If_At_Least_Oxygen    ${OXYGEN_YANG_SYSTEM_TEST_URL}    ${EXPLICIT_YANG_SYSTEM_TEST_URL}
75     Set Suite Variable    ${TEST_TOOL_NAME}
76     Set Suite Variable    ${EXPLICIT_YANG_SYSTEM_TEST_URL}
77     NexusKeywords.Initialize_Artifact_Deployment_And_Usage    tools_system_connect=False
78     SSHKeywords.Open_Connection_To_ODL_System
79
80 Teardown_Test
81     [Documentation]    Make sure CWD is set back to dot, then proceed with SetupUtils stuff.
82     SSHKeywords.Set_Cwd    .
83     SetupUtils.Teardown_Test_Show_Bugs_And_Start_Fast_Failing_If_Test_Failed
84
85 Get_Recursive_Dirs
86     [Arguments]    ${root}=.
87     [Documentation]    Return list of sub-directories discovered recursively under ${root} relative to
88     ...    the current working directory for a new shell spawned over the active SSH session.
89     ...    This implementation returns absolute paths as that is easier.
90     ${depth_1} =    SSHLibrary.List_Directories_In_Directory    path=${root}    absolute=True
91     ${subtrees} =    BuiltIn.Create_List
92     : FOR    ${subdir}    IN    @{depth_1}
93     \    ${tree} =    Get_Recursive_Dirs    root=${subdir}
94     \    # Relative paths would require prepending ${subdir}${/} to each @{tree} element.
95     \    Collections.Append_To_List    ${subtrees}    ${tree}
96     ${flat_list} =    Collections.Combine_Lists    ${depth_1}    @{subtrees}
97     [Return]    ${flat_list}
98
99 Get_Yang_Files_From_Dirs
100     [Arguments]    ${dirs_to_process}
101     [Documentation]    Return list of yang files from provided directories
102     ${collected_yang_files} =    BuiltIn.Create_List
103     : FOR    ${dir}    IN    @{dirs_to_process}
104     \    ${yang_files_in_dir} =    SSHLibrary.List_Files_In_Directory    path=${dir}    pattern=*.yang    absolute=True
105     \    ${collected_yang_files} =    Collections.Combine_Lists    ${collected_yang_files}    ${yang_files_in_dir}
106     [Return]    ${collected_yang_files}
107
108 Wait_Until_Utility_Finishes
109     [Documentation]    Repeatedly send endline to keep session alive; pass on prompt, fail on timeout.
110     RemoteBash.Wait_Without_Idle    60m
111
112 Check_Return_Code
113     [Documentation]    Get return code of previous command (the utility), pass if it is zero.
114     RemoteBash.Check_Return_Code