b611c1ed9b65d84bec14bab45e6b50d5297a5917
[integration/test.git] / csit / libraries / DevstackUtils.robot
1 *** Settings ***
2 Documentation     General Utils library. This library has broad scope, it can be used by any robot system tests.
3 Library           SSHLibrary
4 Library           String
5 Library           DateTime
6 Library           Process
7 Library           Collections
8 Library           RequestsLibrary
9 Library           ./UtilLibrary.py
10 Resource          KarafKeywords.robot
11 Resource          OpenStackOperations.robot
12 Resource          SSHKeywords.robot
13 Variables         ../variables/Variables.py
14
15 *** Variables ***
16 ${default_devstack_prompt_timeout}    10s
17 ${DEVSTACK_SYSTEM_PASSWORD}    \    # set to empty, but provide for others to override if desired
18 ${blacklist_file}    /tmp/blacklist.txt
19 @{stable/newton_exclusion_regexes}    ${EMPTY}
20 @{stable/ocata_exclusion_regexes}    ${EMPTY}
21 @{stable/pike_exclusion_regexes}    ${EMPTY}
22 @{master_exclusion_regexes}    ${EMPTY}
23 ${tempest_dir}    /opt/stack/tempest
24 ${tempest_config_file}    ${tempest_dir}/etc/tempest.conf
25 ${external_physical_network}    physnet1
26 ${external_net_name}    external-net
27 ${external_subnet_name}    external-subnet
28 # Parameter values below are based on releng/builder - changing them requires updates in releng/builder as well
29 ${external_gateway}    10.10.10.250
30 ${external_subnet_allocation_pool}    start=10.10.10.2,end=10.10.10.249
31 ${external_subnet}    10.10.10.0/24
32 ${default_timeout}    420s
33
34 *** Keywords ***
35 Run Tempest Tests
36     [Arguments]    ${tempest_regex}    ${timeout}=${default_timeout}    ${debug}=False
37     Run Keyword If    "${debug}"=="False"    Run Tempest Tests Without Debug    ${tempest_regex}    timeout=${timeout}
38     Run Keyword If    "${debug}"=="True"    Run Tempest Tests With Debug    ${tempest_regex}    timeout=${timeout}
39     Run Keyword If    "${debug}"!="True" and "${debug}"!="False"    Fail    debug argument must be True or False
40
41 Run Tempest Tests Without Debug
42     [Arguments]    ${tempest_regex}    ${tempest_directory}=${tempest_dir}    ${timeout}=${default_timeout}
43     [Documentation]    Using ostestr will allow us to (by default) run tests in paralllel.
44     ...    Because of the parallel fashion, we must ensure there is no pause on teardown so that flag in tempest.conf is
45     ...    explicitly set to False.
46     Return From Keyword If    "skip_if_${OPENSTACK_BRANCH}" in @{TEST_TAGS}
47     Return From Keyword If    "skip_if_${SECURITY_GROUP_MODE}" in @{TEST_TAGS}
48     ${tempest_conn_id}=    SSHLibrary.Open Connection    ${OS_CONTROL_NODE_IP}    prompt=${DEFAULT_LINUX_PROMPT_STRICT}
49     SSHKeywords.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
50     Write Commands Until Prompt    source ${DEVSTACK_DEPLOY_PATH}/openrc admin admin
51     Write Commands Until Prompt    cd ${tempest_directory}
52     SSHLibrary.Read
53     Tempest Conf Modify Pause On Test Teardown    False
54     SSHLibrary.Set Client Configuration    timeout=${timeout}
55     # There are tons of deprecation error messages when we use ostestr in our CSIT environment (openstack via devstack)
56     # The robot log files are very large and one culprit is all these deprecation warnings. If we redirect stderr to
57     # /dev/null we should be able to ignore them. We will miss any other errors, however.
58     ${output}=    Write Commands Until Prompt    ostestr --regex ${tempest_regex} 2>/dev/null    timeout=${timeout}
59     Log    ${output}
60     SSHLibrary.Close Connection
61     Should Contain    ${output}    Failed: 0
62
63 Run Tempest Tests With Debug
64     [Arguments]    ${tempest_regex}    ${tempest_directory}=${tempest_dir}    ${timeout}=${default_timeout}
65     [Documentation]    After setting pause_teardown=True in tempest.conf, use the python -m testtools.run module to execute
66     ...    a single tempest test case. We need to run only one tempest test case at a time as there will
67     ...    be potentional for an unkown number of debug pdb() prompts to catch and continue if we are running multiple
68     ...    test cases with a single command. Essentially, this keyword only handles one breakpoint at a single teardown.
69     Return From Keyword If    "skip_if_${OPENSTACK_BRANCH}" in @{TEST_TAGS}
70     Return From Keyword If    "skip_if_${SECURITY_GROUP_MODE}" in @{TEST_TAGS}
71     ${tempest_conn_id}=    SSHLibrary.Open Connection    ${OS_CONTROL_NODE_IP}    prompt=${DEFAULT_LINUX_PROMPT_STRICT}
72     SSHKeywords.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
73     Write Commands Until Prompt    source ${DEVSTACK_DEPLOY_PATH}/openrc admin admin
74     Write Commands Until Prompt    cd ${tempest_directory}
75     SSHLibrary.Read
76     Tempest Conf Modify Pause On Test Teardown    True
77     SSHLibrary.Set Client Configuration    timeout=${timeout}
78     SSHLibrary.Write    python -m testtools.run ${tempest_regex}
79     ${output}=    SSHLibrary.Read Until Regexp    ${DEFAULT_LINUX_PROMPT_STRICT}|pdb.set_trace()
80     Log    ${output}
81     Show Debugs
82     Get Test Teardown Debugs
83     SSHLibrary.Switch Connection    ${tempest_conn_id}
84     SSHLibrary.Write    continue
85     ${output}=    SSHLibrary.Read Until Regexp    ${DEFAULT_LINUX_PROMPT_STRICT}|pdb.set_trace()
86     Log    ${output}
87     SSHLibrary.Write    continue
88     ${output}=    SSHLibrary.Read Until Prompt
89     Log    ${output}
90     SSHLibrary.Close Connection
91     Should Contain    ${output}    OK
92     Should Not Contain    ${output}    FAILED
93
94 Log In To Tempest Executor And Setup Test Environment
95     [Documentation]    Initialize SetupUtils, open SSH connection to a devstack system and source the openstack
96     ...    credentials needed to run the tempest tests. The (sometimes empty) tempest blacklist file will be created
97     ...    and pushed to the tempest executor.
98     Create Blacklist File
99     SetupUtils.Setup_Utils_For_Setup_And_Teardown
100     # source_pwd is expected to exist in the below Create Network, Create Subnet keywords.    Might be a bug.
101     ${source_pwd}    Set Variable    yes
102     Set Suite Variable    ${source_pwd}
103     # Tempest tests need an existing external network in order to create routers.
104     Create Network    ${external_net_name}    --external --default --provider-network-type flat --provider-physical-network ${PUBLIC_PHYSICAL_NETWORK}
105     Create Subnet    ${external_net_name}    ${external_subnet_name}    ${external_subnet}    --gateway ${external_gateway} --allocation-pool ${external_subnet_allocation_pool}
106     List Networks
107     ${control_node_conn_id}=    SSHLibrary.Open Connection    ${OS_CONTROL_NODE_IP}    prompt=${DEFAULT_LINUX_PROMPT_STRICT}
108     SSHKeywords.Flexible SSH Login    ${OS_USER}
109     Write Commands Until Prompt    source ${DEVSTACK_DEPLOY_PATH}/openrc admin admin
110     Write Commands Until Prompt    sudo rm -rf /opt/stack/tempest/.testrepository
111     ${net_id}=    Get Net Id    ${external_net_name}    ${control_node_conn_id}
112     Tempest Conf Add External Network And Floating Network Name    ${net_id}
113
114 Tempest Conf Add External Network And Floating Network Name
115     [Arguments]    ${external_network_id}
116     [Documentation]    Tempest will be run with a config file - this function will add the
117     ...    given external network ID to the configuration file.
118     Modify Config In File On Existing SSH Connection    ${tempest_config_file}    set    network    public_network_id    ${external_network_id}
119     Modify Config In File On Existing SSH Connection    ${tempest_config_file}    set    DEFAULT    debug    False
120     Modify Config In File On Existing SSH Connection    ${tempest_config_file}    set    DEFAULT    log_level    INFO
121     Modify Config In File On Existing SSH Connection    ${tempest_config_file}    set    network    floating_network_name    ${external_net_name}
122     Write Commands Until Prompt    sudo cat ${tempest_config_file}
123     Write Commands Until Prompt    sudo chmod 777 ${tempest_config_file}
124
125 Tempest Conf Modify Pause On Test Teardown
126     [Arguments]    ${pause_flag}
127     [Documentation]    Sets the DEFAULT section flag for pausing the test teardown. If True the tempest test case
128     ...    being executed will break to a pdb() debug shell when it hits it's teardown() function.
129     Modify Config In File On Existing SSH Connection    ${tempest_config_file}    set    DEFAULT    pause_teardown    ${pause_flag}
130
131 Modify Config In File On Existing SSH Connection
132     [Arguments]    ${config_file}    ${modifier}    ${config_section}    ${config_key}    ${config_value}=${EMPTY}
133     [Documentation]    uses crudini to populate oslo cofg file.
134     # this keyword is only one line so seems like extra overhead, but this may be a good candidate to move
135     # to a library at some point, when/if other suites need to use it, so wanted to make it generic.
136     Write Commands Until Prompt    sudo -E crudini --${modifier} ${config_file} ${config_section} ${config_key} ${config_value}
137
138 Clean Up After Running Tempest
139     [Documentation]    Clean up any extra leftovers that were created to allow tempest tests to run.
140     Delete Network    ${external_net_name}
141     List Networks
142     Close All Connections
143
144 Create Blacklist File
145     [Documentation]    For each exclusion regex in the required @{${OPENSTACK_BRANCH}_exclusion_regexes} list a new
146     ...    line will be created in the required ${blacklist_file} location. This file is pushed to the OS_CONTROL_NODE
147     ...    which is assumed to be the tempest executor.
148     OperatingSystem.Create File    ${blacklist_file}
149     : FOR    ${exclusion}    IN    @{${OPENSTACK_BRANCH}_exclusion_regexes}
150     \    OperatingSystem.Append To File    ${blacklist_file}    ${exclusion}\n
151     Log File    ${blacklist_file}
152     SSHKeywords.Copy File To Remote System    ${OS_CONTROL_NODE_IP}    ${blacklist_file}    ${blacklist_file}
153
154 Devstack Suite Setup
155     [Arguments]    ${source_pwd}=no    ${odl_ip}=${ODL_SYSTEM_IP}
156     [Documentation]    Login to the Openstack Control Node to run tempest suite
157     Create Session    session    http://${odl_ip}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}
158     ${devstack_conn_id}=    SSHLibrary.Open Connection    ${OS_CONTROL_NODE_IP}    prompt=${DEFAULT_LINUX_PROMPT}
159     Set Suite Variable    ${devstack_conn_id}
160     Set Suite Variable    ${source_pwd}
161     Log    ${devstack_conn_id}
162     SSHKeywords.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
163     SSHLibrary.Set Client Configuration    timeout=${default_devstack_prompt_timeout}
164
165 Write Commands Until Prompt
166     [Arguments]    ${cmd}    ${timeout}=${default_devstack_prompt_timeout}
167     [Documentation]    quick wrapper for Write and Read Until Prompt Keywords to make test cases more readable
168     Log    ${cmd}
169     SSHLibrary.Set Client Configuration    timeout=${timeout}
170     SSHLibrary.Read
171     SSHLibrary.Write    ${cmd};echo Command Returns $?
172     ${output}=    SSHLibrary.Read Until Prompt
173     [Return]    ${output}