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