4357a26f6b9e3c435a7af92ac21a636321737e41
[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
20 *** Keywords ***
21 Open Connection
22     [Arguments]    ${name}    ${ip}
23     ${conn_id} =    SSHLibrary.Open Connection    ${ip}    prompt=${DEFAULT_LINUX_PROMPT}
24     SSHKeywords.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
25     BuiltIn.Set Suite Variable    \${${name}}    ${conn_id}
26     [Return]    ${conn_id}
27
28 Devstack Suite Setup
29     [Arguments]    ${odl_ip}=${ODL_SYSTEM_IP}
30     [Documentation]    Open connections to the nodes
31     SSHLibrary.Set Default Configuration    timeout=${DEFAULT_DEVSTACK_PROMPT_TIMEOUT}
32     DevstackUtils.Get DevStack Nodes Data
33     RequestsLibrary.Create Session    session    http://${odl_ip}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}
34
35 Write Commands Until Prompt
36     [Arguments]    ${cmd}    ${timeout}=${DEFAULT_DEVSTACK_PROMPT_TIMEOUT}
37     [Documentation]    quick wrapper for Write and Read Until Prompt Keywords to make test cases more readable
38     SSHLibrary.Set Client Configuration    timeout=${timeout}
39     SSHLibrary.Read
40     SSHLibrary.Write    ${cmd};echo Command Returns $?
41     ${output} =    SSHLibrary.Read Until Prompt
42     [Return]    ${output}
43
44 Write Commands Until Prompt And Log
45     [Arguments]    ${cmd}    ${timeout}=${DEFAULT_DEVSTACK_PROMPT_TIMEOUT}
46     [Documentation]    quick wrapper for Write and Read Until Prompt Keywords to make test cases more readable
47     ${output} =    DevstackUtils.Write Commands Until Prompt    ${cmd}    ${timeout}
48     BuiltIn.Log    ${output}
49     [Return]    ${output}
50
51 Log Devstack Nodes Data
52     ${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}
53     ...    OS_CMP_IPS: @{OS_CMP_IPS}
54     BuiltIn.Log    DevStack Nodes Data:\n${output}
55
56 Get DevStack Hostnames
57     [Documentation]    Assign hostname global variables for DevStack nodes
58     ${OS_CNTL_HOSTNAME} =    OpenStackOperations.Get Hypervisor Hostname From IP    ${OS_CNTL_IP}
59     ${OS_CMP1_HOSTNAME} =    OpenStackOperations.Get Hypervisor Hostname From IP    ${OS_CMP1_IP}
60     ${OS_CMP2_HOSTNAME} =    OpenStackOperations.Get Hypervisor Hostname From IP    ${OS_CMP2_IP}
61     BuiltIn.Set Suite Variable    ${OS_CNTL_HOSTNAME}
62     BuiltIn.Set Suite Variable    ${OS_CMP1_HOSTNAME}
63     BuiltIn.Set Suite Variable    ${OS_CMP2_HOSTNAME}
64
65 Set Node Data For AllinOne Setup
66     [Documentation]    Assign global variables for DevStack nodes where the Control Node enables Compute service also.
67     BuiltIn.Set Suite Variable    ${OS_CMP1_IP}    ${OS_CNTL_IP}
68     BuiltIn.Set Suite Variable    ${OS_CMP2_IP}    ${OS_CNTL_IP}
69     BuiltIn.Set Suite Variable    @{OS_ALL_IPS}    ${OS_CNTL_IP}
70     BuiltIn.Set Suite Variable    @{OS_CMP_IPS}    ${OS_CNTL_IP}
71     BuiltIn.Set Suite Variable    ${OS_CMP1_CONN_ID}    ${OS_CNTL_CONN_ID}
72     BuiltIn.Set Suite Variable    ${OS_CMP2_CONN_ID}    ${OS_CNTL_CONN_ID}
73     BuiltIn.Set Suite Variable    @{OS_ALL_CONN_IDS}    ${OS_CNTL_CONN_ID}
74
75 Set Node Data For Control And Compute Node Setup
76     [Documentation]    Assign global variables for DevStack nodes where the control node is also the compute
77     BuiltIn.Set Suite Variable    ${OS_CMP1_IP}    ${OS_CNTL_IP}
78     BuiltIn.Set Suite Variable    ${OS_CMP2_IP}    ${OS_COMPUTE_1_IP}
79     BuiltIn.Set Suite Variable    @{OS_ALL_IPS}    ${OS_CNTL_IP}    ${OS_CMP2_IP}
80     BuiltIn.Set Suite Variable    @{OS_CMP_IPS}    ${OS_CMP1_IP}    ${OS_CMP2_IP}
81     BuiltIn.Set Suite Variable    ${OS_CMP1_CONN_ID}    ${OS_CNTL_CONN_ID}
82     DevstackUtils.Open Connection    OS_CMP2_CONN_ID    ${OS_COMPUTE_1_IP}
83     BuiltIn.Set Suite Variable    @{OS_ALL_CONN_IDS}    ${OS_CNTL_CONN_ID}    ${OS_CMP2_CONN_ID}
84
85 Set Node Data For Control Only Node Setup
86     [Documentation]    Assign global variables for DevStack nodes where the control node is different than the compute
87     BuiltIn.Set Suite Variable    ${OS_CMP1_IP}    ${OS_COMPUTE_1_IP}
88     BuiltIn.Set Suite Variable    ${OS_CMP2_IP}    ${OS_COMPUTE_2_IP}
89     BuiltIn.Set Suite Variable    @{OS_ALL_IPS}    ${OS_CNTL_IP}    ${OS_CMP1_IP}    ${OS_CMP2_IP}
90     BuiltIn.Set Suite Variable    @{OS_CMP_IPS}    ${OS_CMP1_IP}    ${OS_CMP2_IP}
91     DevstackUtils.Open Connection    OS_CMP1_CONN_ID    ${OS_COMPUTE_1_IP}
92     DevstackUtils.Open Connection    OS_CMP2_CONN_ID    ${OS_COMPUTE_2_IP}
93     BuiltIn.Set Suite Variable    @{OS_ALL_CONN_IDS}    ${OS_CNTL_CONN_ID}    ${OS_CMP1_CONN_ID}    ${OS_CMP2_CONN_ID}
94
95 Get DevStack Nodes Data
96     [Documentation]    Assign global variables for DevStack nodes
97     BuiltIn.Set Suite Variable    ${OS_CNTL_IP}    ${OS_CONTROL_NODE_IP}
98     DevstackUtils.Open Connection    OS_CNTL_CONN_ID    ${OS_CNTL_IP}
99     BuiltIn.Run Keyword If    ${NUM_OS_SYSTEM} == 1    DevstackUtils.Set Node Data For AllinOne Setup
100     ...    ELSE IF    ${NUM_OS_SYSTEM} == 2    DevstackUtils.Set Node Data For Control And Compute Node Setup
101     ...    ELSE IF    ${NUM_OS_SYSTEM} == 3    DevstackUtils.Set Node Data For Control Only Node Setup
102     DevstackUtils.Get DevStack Hostnames
103     DevstackUtils.Log Devstack Nodes Data