Remove remnants of sfc project
[integration/test.git] / csit / libraries / Tempest.robot
1 *** Settings ***
2 Documentation       General Utils library. This library has broad scope, it can be used by any robot system tests.
3
4 Library             SSHLibrary
5 Resource            DevstackUtils.robot
6 Resource            OpenStackOperations.robot
7 Resource            SSHKeywords.robot
8 Resource            ../variables/Variables.robot
9
10
11 *** Variables ***
12 @{stable/queens_EXCLUSION_REGEXES}      ${EMPTY}
13 @{stable/rocky_EXCLUSION_REGEXES}       ${EMPTY}
14 @{stable/stein_EXCLUSION_REGEXES}       ${EMPTY}
15 @{master_EXCLUSION_REGEXES}             ${EMPTY}
16 ${BLACKLIST_FILE}                       /tmp/blacklist.txt
17 ${TEMPEST_DIR}                          /opt/stack/tempest
18 ${TEMPEST_CONFIG_FILE}                  ${TEMPEST_DIR}/etc/tempest.conf
19 # Parameter values below are based on releng/builder - changing them requires updates in releng/builder as well
20 ${TEMPEST_TIMEOUT}                      420s
21
22
23 *** Keywords ***
24 Suite Setup
25     OpenStackOperations.OpenStack Suite Setup
26     Tempest.Log In To Tempest Executor And Setup Test Environment
27
28 Run Tempest Tests
29     [Arguments]    ${tempest_regex}    ${timeout}=${TEMPEST_TIMEOUT}    ${debug}=False
30     IF    "${debug}" == "False"
31         Tempest.Run Tempest Tests Without Debug    ${tempest_regex}    timeout=${timeout}
32     END
33     IF    "${debug}" == "True"
34         Tempest.Run Tempest Tests With Debug    ${tempest_regex}    timeout=${timeout}
35     END
36     IF    "${debug}" != "True" and "${debug}" != "False"
37         Fail    debug argument must be True or False
38     END
39
40 Run Tempest Tests Without Debug
41     [Documentation]    Using ostestr will allow us to (by default) run tests in paralllel.
42     ...    Because of the parallel fashion, we must ensure there is no pause on teardown so that flag in tempest.conf is
43     ...    explicitly set to False.
44     [Arguments]    ${tempest_regex}    ${TEMPEST_DIRectory}=${TEMPEST_DIR}    ${timeout}=${TEMPEST_TIMEOUT}
45     IF    "skip_if_${OPENSTACK_BRANCH}" in @{TEST_TAGS}    RETURN
46     IF    "skip_if_${SECURITY_GROUP_MODE}" in @{TEST_TAGS}    RETURN
47     IF    "skip_if_${ODL_SNAT_MODE}" in @{TEST_TAGS}    RETURN
48     ${tempest_conn_id} =    SSHLibrary.Open Connection    ${OS_CNTL_IP}    prompt=${DEFAULT_LINUX_PROMPT_STRICT}
49     SSHKeywords.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
50     DevstackUtils.Write Commands Until Prompt    source ${DEVSTACK_DEPLOY_PATH}/openrc admin admin
51     DevstackUtils.Write Commands Until Prompt    cd ${TEMPEST_DIRectory}
52     SSHLibrary.Read
53     Tempest.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} =    DevstackUtils.Write Commands Until Prompt And Log
59     ...    ostestr --regex ${tempest_regex}
60     ...    timeout=${timeout}
61     SSHLibrary.Close Connection
62     BuiltIn.Should Contain    ${output}    Failed: 0
63
64 Run Tempest Tests With Debug
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     [Arguments]    ${tempest_regex}    ${TEMPEST_DIRectory}=${TEMPEST_DIR}    ${timeout}=${TEMPEST_TIMEOUT}
70     IF    "skip_if_${OPENSTACK_BRANCH}" in @{TEST_TAGS}    RETURN
71     IF    "skip_if_${SECURITY_GROUP_MODE}" in @{TEST_TAGS}    RETURN
72     IF    "skip_if_${ODL_SNAT_MODE}" in @{TEST_TAGS}    RETURN
73     ${tempest_conn_id} =    SSHLibrary.Open Connection    ${OS_CNTL_IP}    prompt=${DEFAULT_LINUX_PROMPT_STRICT}
74     SSHKeywords.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
75     DevstackUtils.Write Commands Until Prompt    source ${DEVSTACK_DEPLOY_PATH}/openrc admin admin
76     DevstackUtils.Write Commands Until Prompt    cd ${TEMPEST_DIRectory}
77     SSHLibrary.Read
78     Tempest Conf Modify Pause On Test Teardown    True
79     SSHLibrary.Set Client Configuration    timeout=${timeout}
80     SSHLibrary.Write    python -m testtools.run ${tempest_regex}
81     ${output} =    SSHLibrary.Read Until Regexp    ${DEFAULT_LINUX_PROMPT_STRICT}|pdb.set_trace()
82     BuiltIn.Log    ${output}
83     OpenStackOperations.Show Debugs
84     OpenStackOperations.Get Test Teardown Debugs
85     SSHLibrary.Switch Connection    ${tempest_conn_id}
86     SSHLibrary.Write    continue
87     ${output} =    SSHLibrary.Read Until Regexp    ${DEFAULT_LINUX_PROMPT_STRICT}|pdb.set_trace()
88     BuiltIn.Log    ${output}
89     SSHLibrary.Write    continue
90     ${output} =    SSHLibrary.Read Until Prompt
91     BuiltIn.Log    ${output}
92     SSHLibrary.Close Connection
93     BuiltIn.Should Contain    ${output}    OK
94     BuiltIn.Should Not Contain    ${output}    FAILED
95
96 Log In To Tempest Executor And Setup Test Environment
97     [Documentation]    Initialize SetupUtils, open SSH connection to a devstack system and source the openstack
98     ...    credentials needed to run the tempest tests. The (sometimes empty) tempest blacklist file will be created
99     ...    and pushed to the tempest executor.
100     Tempest.Create Blacklist File
101     # Tempest tests need an existing external network in order to create routers.
102     OpenStackOperations.Create Network
103     ...    ${EXTERNAL_NET_NAME}
104     ...    --external --default --provider-network-type flat --provider-physical-network ${PUBLIC_PHYSICAL_NETWORK}
105     OpenStackOperations.Create Subnet
106     ...    ${EXTERNAL_NET_NAME}
107     ...    ${EXTERNAL_SUBNET_NAME}
108     ...    ${EXTERNAL_SUBNET}
109     ...    --gateway ${EXTERNAL_GATEWAY} --allocation-pool ${EXTERNAL_SUBNET_ALLOCATION_POOL}
110     OpenStackOperations.List Networks
111     ${control_node_conn_id} =    SSHLibrary.Open Connection    ${OS_CNTL_IP}    prompt=${DEFAULT_LINUX_PROMPT_STRICT}
112     SSHKeywords.Flexible SSH Login    ${OS_USER}
113     DevstackUtils.Write Commands Until Prompt And Log    sudo pip install -U --verbose pip    timeout=120s
114     DevstackUtils.Write Commands Until Prompt And Log    sudo pip install -U --verbose os-testr>=1.0.0    timeout=120s
115     DevstackUtils.Write Commands Until Prompt And Log    ostestr --version
116     DevstackUtils.Write Commands Until Prompt And Log    testr init
117     DevstackUtils.Write Commands Until Prompt    source ${DEVSTACK_DEPLOY_PATH}/openrc admin admin
118     DevstackUtils.Write Commands Until Prompt    sudo rm -rf /opt/stack/tempest/.testrepository
119     ${net_id} =    OpenStackOperations.Get Net Id    ${EXTERNAL_NET_NAME}
120     Tempest.Tempest Conf Add External Network And Floating Network Name    ${net_id}
121
122 Tempest Conf Add External Network And Floating Network Name
123     [Documentation]    Tempest will be run with a config file - this function will add the
124     ...    given external network ID to the configuration file.
125     [Arguments]    ${external_network_id}
126     Tempest.Modify Config In File On Existing SSH Connection
127     ...    ${TEMPEST_CONFIG_FILE}
128     ...    set
129     ...    network
130     ...    public_network_id
131     ...    ${external_network_id}
132     Tempest.Modify Config In File On Existing SSH Connection
133     ...    ${TEMPEST_CONFIG_FILE}
134     ...    set
135     ...    DEFAULT
136     ...    debug
137     ...    False
138     Tempest.Modify Config In File On Existing SSH Connection
139     ...    ${TEMPEST_CONFIG_FILE}
140     ...    set
141     ...    DEFAULT
142     ...    log_level
143     ...    INFO
144     Tempest.Modify Config In File On Existing SSH Connection
145     ...    ${TEMPEST_CONFIG_FILE}
146     ...    set
147     ...    network
148     ...    floating_network_name
149     ...    ${EXTERNAL_NET_NAME}
150     DevstackUtils.Write Commands Until Prompt    sudo cat ${TEMPEST_CONFIG_FILE}
151     DevstackUtils.Write Commands Until Prompt    sudo chmod 777 ${TEMPEST_CONFIG_FILE}
152
153 Tempest Conf Modify Pause On Test Teardown
154     [Documentation]    Sets the DEFAULT section flag for pausing the test teardown. If True the tempest test case
155     ...    being executed will break to a pdb() debug shell when it hits it's teardown() function.
156     [Arguments]    ${pause_flag}
157     Tempest.Modify Config In File On Existing SSH Connection
158     ...    ${TEMPEST_CONFIG_FILE}
159     ...    set
160     ...    DEFAULT
161     ...    pause_teardown
162     ...    ${pause_flag}
163
164 Modify Config In File On Existing SSH Connection
165     [Documentation]    uses crudini to populate oslo cofg file.
166     [Arguments]    ${config_file}    ${modifier}    ${config_section}    ${config_key}    ${config_value}=${EMPTY}
167     # this keyword is only one line so seems like extra overhead, but this may be a good candidate to move
168     # to a library at some point, when/if other suites need to use it, so wanted to make it generic.
169     DevstackUtils.Write Commands Until Prompt
170     ...    sudo -E crudini --${modifier} ${config_file} ${config_section} ${config_key} ${config_value}
171
172 Create Blacklist File
173     [Documentation]    For each exclusion regex in the required @{${OPENSTACK_BRANCH}_EXCLUSION_REGEXES} list a new
174     ...    line will be created in the required ${BLACKLIST_FILE} location. This file is pushed to the OS_CONTROL_NODE
175     ...    which is assumed to be the tempest executor.
176     OperatingSystem.Create File    ${BLACKLIST_FILE}
177     FOR    ${exclusion}    IN    @{${OPENSTACK_BRANCH}_EXCLUSION_REGEXES}
178         OperatingSystem.Append To File    ${BLACKLIST_FILE}    ${exclusion}\n
179     END
180     OperatingSystem.Log File    ${BLACKLIST_FILE}
181     SSHKeywords.Copy File To Remote System    ${OS_CNTL_IP}    ${BLACKLIST_FILE}    ${BLACKLIST_FILE}