Bump pre-commit-hooks to v4.1.0
[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           RequestsLibrary
4 Library           SSHLibrary
5 Resource          OpenStackOperations.robot
6 Resource          ../variables/Variables.robot
7
8 *** Variables ***
9 ${DEFAULT_DEVSTACK_PROMPT_TIMEOUT}    10s
10 ${DEVSTACK_SYSTEM_PASSWORD}    \    # set to empty, but provide for others to override if desired
11 ${OS_CNTL_CONN_ID}    None
12 ${OS_CMP1_CONN_ID}    None
13 ${OS_CMP2_CONN_ID}    None
14 ${OS_CNTL_IP}     ${EMPTY}
15 ${OS_CMP1_IP}     ${EMPTY}
16 ${OS_CMP2_IP}     ${EMPTY}
17 @{OS_ALL_IPS}     @{EMPTY}
18 @{OS_CMP_IPS}     @{EMPTY}
19 ${OS_NODE_CNT}    ${1}
20
21 *** Keywords ***
22 Open Connection
23     [Arguments]    ${name}    ${ip}
24     ${conn_id} =    SSHLibrary.Open Connection    ${ip}    prompt=${DEFAULT_LINUX_PROMPT}
25     SSHKeywords.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
26     BuiltIn.Set Suite Variable    \${${name}}    ${conn_id}
27     [Return]    ${conn_id}
28
29 Devstack Suite Setup
30     [Arguments]    ${odl_ip}=${ODL_SYSTEM_IP}
31     [Documentation]    Open connections to the nodes
32     SSHLibrary.Set Default Configuration    timeout=${DEFAULT_DEVSTACK_PROMPT_TIMEOUT}
33     DevstackUtils.Get DevStack Nodes Data
34     RequestsLibrary.Create Session    session    http://${odl_ip}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}
35
36 Write Commands Until Prompt
37     [Arguments]    ${cmd}    ${timeout}=${DEFAULT_DEVSTACK_PROMPT_TIMEOUT}
38     [Documentation]    quick wrapper for Write and Read Until Prompt Keywords to make test cases more readable
39     SSHLibrary.Set Client Configuration    timeout=${timeout}
40     SSHLibrary.Read
41     SSHLibrary.Write    ${cmd};echo Command Returns $?
42     ${output} =    SSHLibrary.Read Until Prompt
43     [Return]    ${output}
44
45 Write Commands Until Prompt And Log
46     [Arguments]    ${cmd}    ${timeout}=${DEFAULT_DEVSTACK_PROMPT_TIMEOUT}
47     [Documentation]    quick wrapper for Write and Read Until Prompt Keywords to make test cases more readable
48     ${output} =    DevstackUtils.Write Commands Until Prompt    ${cmd}    ${timeout}
49     BuiltIn.Log    ${output}
50     [Return]    ${output}
51
52 Log Devstack Nodes Data
53     ${output} =    BuiltIn.Catenate    SEPARATOR=\n    OS_CNTL_HOSTNAME: ${OS_CNTL_HOSTNAME} - OS_CNTL_IP: ${OS_CNTL_IP} - OS_CONTROL_NODE_IP: ${OS_CONTROL_NODE_IP}    OS_CMP1_HOSTNAME: ${OS_CMP1_HOSTNAME} - OS_CMP1_IP: ${OS_CMP1_IP} - OS_COMPUTE_1_IP: ${OS_COMPUTE_1_IP}    OS_CMP2_HOSTNAME: ${OS_CMP2_HOSTNAME} - OS_CMP2_IP: ${OS_CMP2_IP} - OS_COMPUTE_2_IP: ${OS_COMPUTE_2_IP}    OS_ALL_IPS: @{OS_ALL_IPS}
54     ...    OS_CMP_IPS: @{OS_CMP_IPS}    OS_NODE_CNT: ${OS_NODE_CNT}    OS_ALL_CONN_IDS: @{OS_ALL_CONN_IDS}    OS_CMP_CONN_IDS: @{OS_CMP_CONN_IDS}
55     BuiltIn.Log    DevStack Nodes Data:\n${output}
56
57 Get DevStack Hostnames
58     [Documentation]    Assign hostname global variables for DevStack nodes
59     ${OS_CNTL_HOSTNAME} =    OpenStackOperations.Get Hypervisor Hostname From IP    ${OS_CNTL_IP}
60     ${OS_CMP1_HOSTNAME} =    OpenStackOperations.Get Hypervisor Hostname From IP    ${OS_CMP1_IP}
61     ${OS_CMP2_HOSTNAME} =    OpenStackOperations.Get Hypervisor Hostname From IP    ${OS_CMP2_IP}
62     BuiltIn.Set Suite Variable    ${OS_CNTL_HOSTNAME}
63     BuiltIn.Set Suite Variable    ${OS_CMP1_HOSTNAME}
64     BuiltIn.Set Suite Variable    ${OS_CMP2_HOSTNAME}
65
66 Set Node Data For AllinOne Setup
67     [Documentation]    Assign global variables for DevStack nodes where the Control Node enables Compute service also.
68     BuiltIn.Set Suite Variable    ${OS_CMP1_IP}    ${OS_CNTL_IP}
69     BuiltIn.Set Suite Variable    ${OS_CMP2_IP}    ${OS_CNTL_IP}
70     BuiltIn.Set Suite Variable    @{OS_ALL_IPS}    ${OS_CNTL_IP}
71     BuiltIn.Set Suite Variable    @{OS_CMP_IPS}    ${OS_CNTL_IP}
72     BuiltIn.Set Suite Variable    ${OS_CMP1_CONN_ID}    ${OS_CNTL_CONN_ID}
73     BuiltIn.Set Suite Variable    ${OS_CMP2_CONN_ID}    ${OS_CNTL_CONN_ID}
74     BuiltIn.Set Suite Variable    @{OS_ALL_CONN_IDS}    ${OS_CNTL_CONN_ID}
75     BuiltIn.Set Suite Variable    @{OS_CMP_CONN_IDS}    ${OS_CNTL_CONN_ID}
76
77 Set Node Data For Control And Compute Node Setup
78     [Documentation]    Assign global variables for DevStack nodes where the control node is also the compute
79     BuiltIn.Set Suite Variable    ${OS_CMP1_IP}    ${OS_CNTL_IP}
80     BuiltIn.Set Suite Variable    ${OS_CMP2_IP}    ${OS_COMPUTE_1_IP}
81     BuiltIn.Set Suite Variable    @{OS_ALL_IPS}    ${OS_CNTL_IP}    ${OS_CMP2_IP}
82     BuiltIn.Set Suite Variable    @{OS_CMP_IPS}    ${OS_CMP1_IP}    ${OS_CMP2_IP}
83     BuiltIn.Set Suite Variable    ${OS_CMP1_CONN_ID}    ${OS_CNTL_CONN_ID}
84     DevstackUtils.Open Connection    OS_CMP2_CONN_ID    ${OS_COMPUTE_1_IP}
85     BuiltIn.Set Suite Variable    @{OS_ALL_CONN_IDS}    ${OS_CNTL_CONN_ID}    ${OS_CMP2_CONN_ID}
86     BuiltIn.Set Suite Variable    @{OS_CMP_CONN_IDS}    ${OS_CNTL_CONN_ID}    ${OS_CMP2_CONN_ID}
87
88 Set Node Data For Control And Two Compute Node Setup
89     [Documentation]    Assign global variables for DevStack nodes where the control node is different than the compute
90     BuiltIn.Set Suite Variable    ${OS_CMP1_IP}    ${OS_COMPUTE_1_IP}
91     BuiltIn.Set Suite Variable    ${OS_CMP2_IP}    ${OS_COMPUTE_2_IP}
92     BuiltIn.Set Suite Variable    @{OS_ALL_IPS}    ${OS_CNTL_IP}    ${OS_CMP1_IP}    ${OS_CMP2_IP}
93     BuiltIn.Set Suite Variable    @{OS_CMP_IPS}    ${OS_CMP1_IP}    ${OS_CMP2_IP}
94     DevstackUtils.Open Connection    OS_CMP1_CONN_ID    ${OS_COMPUTE_1_IP}
95     DevstackUtils.Open Connection    OS_CMP2_CONN_ID    ${OS_COMPUTE_2_IP}
96     BuiltIn.Set Suite Variable    @{OS_ALL_CONN_IDS}    ${OS_CNTL_CONN_ID}    ${OS_CMP1_CONN_ID}    ${OS_CMP2_CONN_ID}
97     BuiltIn.Set Suite Variable    @{OS_CMP_CONN_IDS}    ${OS_CMP1_CONN_ID}    ${OS_CMP2_CONN_ID}
98
99 Get DevStack Nodes Data
100     [Documentation]    Assign global variables for DevStack nodes
101     BuiltIn.Set Suite Variable    ${OS_CNTL_IP}    ${OS_CONTROL_NODE_IP}
102     DevstackUtils.Open Connection    OS_CNTL_CONN_ID    ${OS_CNTL_IP}
103     BuiltIn.Run Keyword If    "${OPENSTACK_TOPO}" == "1cmb-0ctl-0cmp"    DevstackUtils.Set Node Data For AllinOne Setup
104     ...    ELSE IF    "${OPENSTACK_TOPO}" == "1cmb-0ctl-1cmp"    DevstackUtils.Set Node Data For Control And Compute Node Setup
105     ...    ELSE IF    "${OPENSTACK_TOPO}" == "0cmb-1ctl-2cmp"    DevstackUtils.Set Node Data For Control And Two Compute Node Setup
106     ${OS_NODE_CNT} =    BuiltIn.Get Length    ${OS_ALL_IPS}
107     BuiltIn.Set Suite Variable    ${OS_NODE_CNT}
108     DevstackUtils.Get DevStack Hostnames
109     DevstackUtils.Log Devstack Nodes Data