Deploy Openstack Using Robot Keywords
[integration/test.git] / tools / deployment / openstack_ha / deploy / 03_keystone_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/OpenStackOperations.robot
10 Resource          ../libraries/SystemUtils.robot
11 Resource          ../libraries/Utils.robot
12
13 *** Test Cases ***
14 Install Identity
15     Create And Configure Keystone Db    ${OS_CONTROL_1_IP}    root    mysql    ${OS_CONTROL_1_HOSTNAME}
16     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Create And Configure Keystone Db Other Nodes    ${OS_CONTROL_2_IP}    root    mysql    ${OS_CONTROL_2_HOSTNAME}
17     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Create And Configure Keystone Db Other Nodes    ${OS_CONTROL_3_IP}    root    mysql    ${OS_CONTROL_3_HOSTNAME}
18     Run Keyword If    3 < ${NUM_CONTROL_NODES}    Create And Configure Keystone Db Other Nodes    ${OS_CONTROL_4_IP}    root    mysql    ${OS_CONTROL_4_HOSTNAME}
19     Run Keyword If    4 < ${NUM_CONTROL_NODES}    Create And Configure Keystone Db Other Nodes    ${OS_CONTROL_5_IP}    root    mysql    ${OS_CONTROL_5_HOSTNAME}
20     Run Keyword If    2 > ${NUM_CONTROL_NODES}    Install Configure Keystone    ${OS_CONTROL_1_IP}    ${OS_CONTROL_1_HOSTNAME}
21     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Install Configure Keystone    ${OS_CONTROL_1_IP}    ${HAPROXY_HOSTNAME}
22     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Install Configure Keystone    ${OS_CONTROL_2_IP}    ${HAPROXY_HOSTNAME}
23     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Install Configure Keystone    ${OS_CONTROL_3_IP}    ${HAPROXY_HOSTNAME}
24     Run Keyword If    3 < ${NUM_CONTROL_NODES}    Install Configure Keystone    ${OS_CONTROL_4_IP}    ${HAPROXY_HOSTNAME}
25     Run Keyword If    4 < ${NUM_CONTROL_NODES}    Install Configure Keystone    ${OS_CONTROL_5_IP}    ${HAPROXY_HOSTNAME}
26     ${token}=    Run Command    ${OS_CONTROL_1_IP}    openssl rand -hex 10
27     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Set Admin Token    ${OS_CONTROL_1_IP}    ${token}
28     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Set Admin Token    ${OS_CONTROL_2_IP}    ${token}
29     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Set Admin Token    ${OS_CONTROL_3_IP}    ${token}
30     Run Keyword If    3 < ${NUM_CONTROL_NODES}    Set Admin Token    ${OS_CONTROL_4_IP}    ${token}
31     Run Keyword If    4 < ${NUM_CONTROL_NODES}    Set Admin Token    ${OS_CONTROL_5_IP}    ${token}
32     Keystone Manage Setup    ${OS_CONTROL_1_IP}    keystone    keystone
33     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Copy Fernet Keys    ${OS_CONTROL_1_IP}    ${OS_CONTROL_2_IP}
34     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Copy Fernet Keys    ${OS_CONTROL_1_IP}    ${OS_CONTROL_3_IP}
35     Run Keyword If    3 < ${NUM_CONTROL_NODES}    Copy Fernet Keys    ${OS_CONTROL_1_IP}    ${OS_CONTROL_4_IP}
36     Run Keyword If    4 < ${NUM_CONTROL_NODES}    Copy Fernet Keys    ${OS_CONTROL_1_IP}    ${OS_CONTROL_5_IP}
37     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Chown File    ${OS_CONTROL_2_IP}    /etc/keystone/fernet-keys    keystone    keystone
38     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Chown File    ${OS_CONTROL_3_IP}    /etc/keystone/fernet-keys    keystone    keystone
39     Run Keyword If    3 < ${NUM_CONTROL_NODES}    Chown File    ${OS_CONTROL_4_IP}    /etc/keystone/fernet-keys    keystone    keystone
40     Run Keyword If    4 < ${NUM_CONTROL_NODES}    Chown File    ${OS_CONTROL_5_IP}    /etc/keystone/fernet-keys    keystone    keystone
41     Start Keystone    ${OS_CONTROL_1_IP}
42     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Start Keystone    ${OS_CONTROL_2_IP}
43     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Start Keystone    ${OS_CONTROL_3_IP}
44     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Generic HAProxy Entry    ${HAPROXY_IP}    ${HAPROXY_IP}    35357    keystone-admin
45     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Generic HAProxy Entry    ${HAPROXY_IP}    ${HAPROXY_IP}    5000    keystone-public
46     Run Keyword If    2 > ${NUM_CONTROL_NODES}    Create stackrc    ${OS_CONTROL_1_HOSTNAME}
47     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Create stackrc    ${HAPROXY_HOSTNAME}
48     Run Keyword If    2 > ${NUM_CONTROL_NODES}    Setup And Bootstrap    ${OS_CONTROL_1_IP}    ${OS_CONTROL_1_HOSTNAME}
49     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Setup And Bootstrap    ${OS_CONTROL_1_IP}    ${HAPROXY_HOSTNAME}
50     Create Project Service
51
52 *** Keywords ***
53 Create And Configure Keystone Db
54     [Arguments]    ${os_node_cxn}    ${mysql_user}    ${mysql_pass}    ${host_name}
55     Create Database for Mysql    ${os_node_cxn}    ${mysql_user}    ${mysql_pass}    keystone
56     Grant Privileges To Mysql Database    ${os_node_cxn}    ${mysql_user}    ${mysql_pass}    keystone.*    keystone    ${host_name}
57     ...    keystone
58     Grant Privileges To Mysql Database    ${os_node_cxn}    ${mysql_user}    ${mysql_pass}    keystone.*    keystone    localhost
59     ...    keystone
60     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Grant Privileges To Mysql Database    ${os_node_cxn}    ${mysql_user}    ${mysql_pass}    keystone.*
61     ...    keystone    ${HAPROXY_HOSTNAME}    keystone
62
63 Create And Configure Keystone Db Other Nodes
64     [Arguments]    ${os_node_cxn}    ${mysql_user}    ${mysql_pass}    ${host_name}
65     Grant Privileges To Mysql Database    ${os_node_cxn}    ${mysql_user}    ${mysql_pass}    keystone.*    keystone    ${host_name}
66     ...    keystone
67     Grant Privileges To Mysql Database    ${os_node_cxn}    ${mysql_user}    ${mysql_pass}    keystone.*    keystone    localhost
68     ...    keystone
69     Grant Privileges To Mysql Database    ${os_node_cxn}    ${mysql_user}    ${mysql_pass}    keystone.*    keystone    ${HAPROXY_HOSTNAME}
70     ...    keystone
71
72 Install Configure Keystone
73     [Arguments]    ${os_node_cxn}    ${host_name}
74     Run Keyword If    '${OS_APPS_PRE_INSTALLED}' == 'no'    Install Rpm Package    ${os_node_cxn}    openstack-keystone httpd mod_wsgi rsync
75     Crudini Edit    ${os_node_cxn}    /etc/keystone/keystone.conf    database    connection    "mysql+pymysql://keystone:keystone@${host_name}/keystone"
76     Crudini Edit    ${os_node_cxn}    /etc/keystone/keystone.conf    token    provider    fernet
77     Crudini Edit    ${os_node_cxn}    /etc/keystone/keystone.conf    catalog    driver    sql
78     Crudini Edit    ${os_node_cxn}    /etc/keystone/keystone.conf    identity    driver    sql
79     Run Keyword If    2 < ${NUM_CONTROL_NODES}    Crudini Edit    ${os_node_cxn}    /etc/keystone/keystone.conf    DEFAULT    transport_url
80     ...    "rabbit://openstack:rabbit@${OS_CONTROL_1_HOSTNAME},openstack:rabbit@${OS_CONTROL_2_HOSTNAME},openstack:rabbit@${OS_CONTROL_3_HOSTNAME}"
81     Run Keyword If    2 > ${NUM_CONTROL_NODES}    Crudini Edit    ${os_node_cxn}    /etc/keystone/keystone.conf    DEFAULT    transport_url
82     ...    "rabbit://openstack:rabbit@${host_name}"
83     Crudini Edit    ${os_node_cxn}    /etc/keystone/keystone.conf    oslo_messaging_rabbit    rabbit_max_retries    0
84     Crudini Edit    ${os_node_cxn}    /etc/keystone/keystone.conf    oslo_messaging_rabbit    rabbit_ha_queues    true
85     Create Softlink    ${os_node_cxn}    /usr/share/keystone/wsgi-keystone.conf    /etc/httpd/conf.d/
86
87 Start Keystone
88     [Arguments]    ${os_node_cxn}
89     Enable Service    ${os_node_cxn}    httpd
90     Start Service    ${os_node_cxn}    httpd
91
92 Set Admin Token
93     [Arguments]    ${os_node_cxn}    ${token}
94     Crudini Edit    ${os_node_cxn}    /etc/keystone/keystone.conf    DEFAULT    admin_token    ${token}
95
96 Copy Fernet Keys
97     [Arguments]    ${os_node_cxn}    ${target_ip}
98     Rsync Directory    ${os_node_cxn}    ${target_ip}    /etc/keystone/fernet-keys    /etc/keystone
99
100 Setup And Bootstrap
101     [Arguments]    ${os_node_cxn}    ${host_name}
102     Run Command As User    ${os_node_cxn}    "keystone-manage db_sync"    keystone
103     Keystone Manage Bootstrap    ${os_node_cxn}    ${host_name}    RegionOne
104
105 Create stackrc
106     [Arguments]    ${haproxy_ip}
107     Create Local File    /tmp/stackrc
108     Write To Local File    /tmp/stackrc    "export OS_USERNAME=admin"
109     Append To Local File    /tmp/stackrc    "export OS_PASSWORD=admin"
110     Append To Local File    /tmp/stackrc    "export OS_PROJECT_NAME=admin"
111     Append To Local File    /tmp/stackrc    "export OS_USER_DOMAIN_NAME=Default"
112     Append To Local File    /tmp/stackrc    "export OS_PROJECT_DOMAIN_NAME=Default"
113     Append To Local File    /tmp/stackrc    "export OS_AUTH_URL=http://${haproxy_ip}:35357/v3"
114     Append To Local File    /tmp/stackrc    "export OS_IDENTITY_API_VERSION=3"
115     Append To Local File    /tmp/stackrc    "export OS_IMAGE_API_VERSION=2"
116
117 Create Project Service
118     Create Project    default    "ServiceProject"    service    rc_file=/tmp/stackrc
119
120 Keystone Manage Setup
121     [Arguments]    ${os_node_cxn}    ${keystone_user}    ${keystone_password}
122     Switch Connection    ${os_node_cxn}
123     ${output}    ${rc}=    Execute Command    sudo keystone-manage fernet_setup --keystone-user ${keystone_user} --keystone-group ${keystone_password}    return_rc=True    return_stdout=True
124     Log    ${output}
125     Should Not Be True    ${rc}
126
127 Keystone Manage Bootstrap
128     [Arguments]    ${os_node_cxn}    ${host_name}    ${region_name}
129     Switch Connection    ${os_node_cxn}
130     ${output}    ${rc}=    Execute Command    sudo keystone-manage bootstrap --bootstrap-password admin --bootstrap-admin-url http://${host_name}:35357/v3/ --bootstrap-internal-url http://${host_name}:5000/v3/ --bootstrap-public-url http://${host_name}:5000/v3/ --bootstrap-region-id ${region_name}    return_rc=True    return_stdout=True
131     Log    ${output}
132     Should Not Be True    ${rc}