Deploy Openstack Using Robot Keywords
[integration/test.git] / tools / deployment / openstack_ha / deploy / 02_rabbitmq_setup.robot
1 *** Settings ***
2 Documentation     Test suite to verify packet flows between vm instances.
3 Suite Setup       OpenStackInstallUtils.Get All Ssh Connections
4 Suite Teardown    Close All Connections
5 Library           SSHLibrary
6 Library           OperatingSystem
7 Library           RequestsLibrary
8 Resource          ../libraries/OpenStackInstallUtils.robot
9 Resource          ../libraries/SystemUtils.robot
10 Resource          ../libraries/Utils.robot
11
12 *** Test Cases ***
13 Setup RabbitMQ
14     Run Keyword If    2 > ${NUM_CONTROL_NODES}    Install RabbitMQ    ${OS_CONTROL_1_IP}
15     Run Keyword If    2 > ${NUM_CONTROL_NODES}    Start RabbitMQ    ${OS_CONTROL_1_IP}
16     Run Keyword If    2 > ${NUM_CONTROL_NODES}    Add Openstack MQ    ${OS_CONTROL_1_IP}    openstack    rabbit
17     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Install RabbitMQ    ${OS_CONTROL_1_IP}
18     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Start Stop And Copy Cookie File    ${OS_CONTROL_1_IP}    rabbit    rabbit
19     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Install RabbitMQ    ${OS_CONTROL_2_IP}
20     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Install RabbitMQ    ${OS_CONTROL_3_IP}
21     Run Keyword If    3 < ${NUM_CONTROL_NODES}    Install RabbitMQ    ${OS_CONTROL_4_IP}
22     Run Keyword If    4 < ${NUM_CONTROL_NODES}    Install RabbitMQ    ${OS_CONTROL_5_IP}
23     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Setup RabbitMQ Cluster    ${OS_CONTROL_2_IP}    rabbit    ${OS_CONTROL_1_HOSTNAME}
24     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Setup RabbitMQ Cluster    ${OS_CONTROL_3_IP}    rabbit    ${OS_CONTROL_1_HOSTNAME}
25     Run Keyword If    3 < ${NUM_CONTROL_NODES}    Setup RabbitMQ Cluster    ${OS_CONTROL_4_IP}    rabbit    ${OS_CONTROL_1_HOSTNAME}
26     Run Keyword If    4 < ${NUM_CONTROL_NODES}    Setup RabbitMQ Cluster    ${OS_CONTROL_5_IP}    rabbit    ${OS_CONTROL_1_HOSTNAME}
27     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Generic HAProxy Entry    ${HAPROXY_IP}    ${HAPROXY_IP}    5672    rabbitmq
28
29 *** Keywords ***
30 Install RabbitMQ
31     [Arguments]    ${os_node_cxn}
32     Run Keyword If    '${OS_APPS_PRE_INSTALLED}' == 'no'    Install Rpm Package    ${os_node_cxn}    rabbitmq-server
33     Enable Service    ${os_node_cxn}    rabbitmq-server
34
35 Start RabbitMQ
36     [Arguments]    ${os_node_cxn}
37     Enable Service    ${os_node_cxn}    rabbitmq-server
38     Start Service    ${os_node_cxn}    rabbitmq-server
39
40 Start Stop And Copy Cookie File
41     [Arguments]    ${os_node_cxn}    ${rabbit_user}    ${rabbit_pass}
42     Enable Service    ${os_node_cxn}    rabbitmq-server
43     Start Service    ${os_node_cxn}    rabbitmq-server
44     Add Openstack MQ    ${os_node_cxn}    openstack    rabbit
45     Get RabbitMQ Cookie File    ${os_node_cxn}
46
47 Add Openstack MQ
48     [Arguments]    ${os_node_cxn}    ${rabbit_user}    ${rabbit_pass}
49     Add Rabbitmq User    ${os_node_cxn}    ${rabbit_user}    ${rabbit_pass}
50     Enable Access to Rabbitmq vhost    ${os_node_cxn}    ${rabbit_user}
51
52 Setup RabbitMQ Cluster
53     [Arguments]    ${os_node_cxn}    ${rabbit_user}    ${src_hostname}
54     Copy RabbitMQ Cookie File    ${os_node_cxn}    ${rabbit_user}    ${src_hostname}
55
56 Add Rabbitmq User
57     [Arguments]    ${os_node_cxn}    ${rabbit_user}    ${rabbit_pass}
58     [Documentation]    Add a user to Rabbit MQ
59     Switch Connection    ${os_node_cxn}
60     ${output}    ${rc}=    Execute Command    sudo rabbitmqctl add_user ${rabbit_user} ${rabbit_pass}    return_rc=True    return_stdout=True
61     Log    ${output}
62     #Should Not Be True    ${rc}
63     [Return]    ${output}
64
65 Change Rabbitmq Password
66     [Arguments]    ${os_node_cxn}    ${rabbit_user}    ${rabbit_pass}
67     [Documentation]    Add a user to Rabbit MQ
68     Switch Connection    ${os_node_cxn}
69     ${output}    ${rc}=    Execute Command    sudo rabbitmqctl change_password ${rabbit_user} ${rabbit_pass}    return_rc=True    return_stdout=True
70     Log    ${output}
71     Should Not Be True    ${rc}
72     [Return]    ${output}
73
74 Enable Access to Rabbitmq vhost
75     [Arguments]    ${os_node_cxn}    ${rabbit_user}
76     [Documentation]    Add a user to Rabbit MQ
77     Switch Connection    ${os_node_cxn}
78     ${output}    ${rc}=    Execute Command    rabbitmqctl set_permissions ${rabbit_user} ".*" ".*" ".*"    return_rc=True    return_stdout=True
79     Log    ${output}
80     Should Not Be True    ${rc}
81     [Return]    ${output}
82
83 Stop RabbitMQ
84     [Arguments]    ${os_node_cxn}
85     [Documentation]    Stop the RabbitMQ user
86     Switch Connection    ${os_node_cxn}
87     ${output}    ${rc}=    Execute Command    rabbitmqctl stop_app    return_rc=True    return_stdout=True
88     Log    ${output}
89     Should Not Be True    ${rc}
90     [Return]    ${output}
91
92 Get RabbitMQ Cookie File
93     [Arguments]    ${os_node_cxn}
94     [Documentation]    Get the Cookie file from the primary node
95     Switch Connection    ${os_node_cxn}
96     ${output}    ${rc}=    Execute Command    rabbitmqctl stop_app    return_rc=True    return_stdout=True
97     Log    ${output}
98     Should Not Be True    ${rc}
99     SSHLibrary.Get File    /var/lib/rabbitmq/.erlang.cookie    /tmp/
100     ${output}    ${rc}=    Execute Command    rabbitmqctl start_app    return_rc=True    return_stdout=True
101     Log    ${output}
102     Should Not Be True    ${rc}
103     ${output}    ${rc}=    Execute Command    rabbitmqctl cluster_status    return_rc=True    return_stdout=True
104     Log    ${output}
105     Should Not Be True    ${rc}
106
107 Copy RabbitMQ Cookie File
108     [Arguments]    ${os_node_cxn}    ${rabbit_user}    ${src_hostname}
109     [Documentation]    Copy the rabbit cookie file to other servers to join the cluster
110     Switch Connection    ${os_node_cxn}
111     SSHLibrary.Put File    /tmp/.erlang.cookie    /var/lib/rabbitmq/.erlang.cookie
112     ${output}    ${rc}=    Execute Command    chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie    return_rc=True    return_stdout=True
113     Log    ${output}
114     Should Not Be True    ${rc}
115     ${output}    ${rc}=    Execute Command    chmod 400 /var/lib/rabbitmq/.erlang.cookie    return_rc=True    return_stdout=True
116     Log    ${output}
117     Should Not Be True    ${rc}
118     Enable Service    ${os_node_cxn}    rabbitmq-server
119     Start Service    ${os_node_cxn}    rabbitmq-server
120     ${output}    ${rc}=    Execute Command    rabbitmqctl stop_app    return_rc=True    return_stdout=True
121     Log    ${output}
122     Should Not Be True    ${rc}
123     ${output}    ${rc}=    Execute Command    rabbitmqctl join_cluster --ram ${rabbit_user}@${src_hostname}    return_rc=True    return_stdout=True
124     Log    ${output}
125     Should Not Be True    ${rc}
126     ${output}    ${rc}=    Execute Command    rabbitmqctl start_app    return_rc=True    return_stdout=True
127     Log    ${output}
128     Should Not Be True    ${rc}
129     ${output}    ${rc}=    Execute Command    rabbitmqctl cluster_status    return_rc=True    return_stdout=True
130     Log    ${output}
131     Should Not Be True    ${rc}
132     Run Command    ${os_node_cxn}    sudo rabbitmqctl set_policy ha-all '^(?!amq\.).*' '{"ha-mode": "all"}'