3affe6803b9d7fe31726af2bc69974365e038163
[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
35 *** Test Cases ***
36 Kill_Odl
37     [Documentation]    The ODL instance consumes resources, kill it.
38     ClusterManagement.Kill_Members_From_List_Or_All
39
40 Prepare_Yang_Files_To_Test
41     [Documentation]    Set up collection of Yang files to test with.
42     YangCollection.Static_Set_As_Src
43     ${dirs_to_process} =    Get_Recursive_Dirs    root=src/main/yang
44     ${p_option_value} =    BuiltIn.Catenate    SEPARATOR=:    @{dirs_to_process}
45     ${yang_files_to_validate} =    Get_Yang_Files_From_Dirs    ${dirs_to_process}
46     BuiltIn.Set_Suite_Variable    ${yang_files_to_validate}
47     BuiltIn.Set_Suite_Variable    \${p_option_value}
48
49 Deploy_And_Start_Odl_Yang_Validator_Utility
50     [Documentation]    Download appropriate version of ${TEST_TOOL_NAME} artifact
51     ...    and run it for each single yang file in the prepared set.
52     ...    The version is either given by ${EXPLICIT_YANG_SYSTEM_TEST_URL},
53     ...    or constructed from Jenkins-shaped ${BUNDLE_URL}, or downloaded from Nexus based on ODL version.
54     FOR    ${yang_file}    IN    @{yang_files_to_validate}
55         ${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}
56         ...    explicit_url=${EXPLICIT_YANG_SYSTEM_TEST_URL}
57         BuiltIn.Set_Suite_Variable    \${logfile}
58         Wait_Until_Utility_Finishes
59         Check_Return_Code
60     END
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     END
91     ${flat_list} =    Collections.Combine_Lists    ${depth_1}    @{subtrees}
92     [Return]    ${flat_list}
93
94 Get_Yang_Files_From_Dirs
95     [Arguments]    ${dirs_to_process}
96     [Documentation]    Return list of yang files from provided directories
97     ${collected_yang_files} =    BuiltIn.Create_List
98     FOR    ${dir}    IN    @{dirs_to_process}
99         ${yang_files_in_dir} =    SSHLibrary.List_Files_In_Directory    path=${dir}    pattern=*.yang    absolute=True
100         ${collected_yang_files} =    Collections.Combine_Lists    ${collected_yang_files}    ${yang_files_in_dir}
101     END
102     [Return]    ${collected_yang_files}
103
104 Wait_Until_Utility_Finishes
105     [Documentation]    Repeatedly send endline to keep session alive; pass on prompt, fail on timeout.
106     RemoteBash.Wait_Without_Idle    60m
107
108 Check_Return_Code
109     [Documentation]    Get return code of previous command (the utility), pass if it is zero.
110     RemoteBash.Check_Return_Code