Execute service setup against a delegated host using Ansible built-in modules

In order to reduce the packages required to pip install on to the hosts,
we allow the service setup to be delegated to a specific host, defaulting
to the deploy host. We also switch as many tasks as possible to using the
built-in Ansible modules which make use of the shade library.

The 'virtualenv' package is now installed appropriately by the openstack_hosts
role, so there's no need to install it any more. The 'httplib2' package is a
legacy Ansible requirement for the get_url/get_uri module which is no longer
needed. The keystone client library is not required any more now that we're
using the upstream modules. As there are no required packages left, the task
to install them is also removed.

With the dependent patches, the openstack_openrc role is now executed once
on the designated host, so it is no longer required as a meta-dependency for
the role.

Depends-On: https://review.openstack.org/579233
Depends-On: https://review.openstack.org/579959
Change-Id: I4131312eea8c743e7803ccc622b7642c6082a4c8
This commit is contained in:
Jesse Pretorius 2018-07-03 22:04:26 +01:00 committed by Jesse Pretorius (odyssey4me)
parent 92a630b9dc
commit a8a34fe719
9 changed files with 146 additions and 144 deletions

View File

@ -17,6 +17,11 @@
# Only create Gnocchi's identity entities in Keystone # Only create Gnocchi's identity entities in Keystone
gnocchi_identity_only: False gnocchi_identity_only: False
# Set the host which will execute the shade modules
# for the service setup. The host must already have
# clouds.yaml properly configured.
gnocchi_service_setup_host: "{{ openstack_service_setup_host | default('localhost') }}"
#: Enable for debug logging level #: Enable for debug logging level
debug: false debug: false
@ -71,7 +76,6 @@ gnocchi_db_setup_host: "{{ ('galera_all' in groups) | ternary(groups['galera_all
gnocchi_galera_address: "{{ galera_address | default('127.0.0.1') }}" gnocchi_galera_address: "{{ galera_address | default('127.0.0.1') }}"
gnocchi_galera_database: gnocchi gnocchi_galera_database: gnocchi
gnocchi_galera_user: gnocchi gnocchi_galera_user: gnocchi
gnocchi_galera_address: "{{ galera_address }}"
gnocchi_db_sync_options: "" gnocchi_db_sync_options: ""
gnocchi_galera_use_ssl: "{{ galera_use_ssl | default(False) }}" gnocchi_galera_use_ssl: "{{ galera_use_ssl | default(False) }}"
gnocchi_galera_ssl_ca_cert: "{{ galera_ssl_ca_cert | default('/etc/ssl/certs/galera-ca.pem') }}" gnocchi_galera_ssl_ca_cert: "{{ galera_ssl_ca_cert | default('/etc/ssl/certs/galera-ca.pem') }}"
@ -159,12 +163,6 @@ gnocchi_services:
service_enabled: true service_enabled: true
init_config_overrides: "{{ gnocchi_metricd_init_overrides }}" init_config_overrides: "{{ gnocchi_metricd_init_overrides }}"
#: Gnocchi packages that must be installed before anything else
gnocchi_requires_pip_packages:
- virtualenv
- python-keystoneclient # Keystoneclient needed for OSA keystone lib
- httplib2 # so we can use the uri module
#: Common pip packages #: Common pip packages
gnocchi_pip_packages: gnocchi_pip_packages:
- cryptography - cryptography

View File

@ -39,6 +39,5 @@ dependencies:
when: when:
- ansible_pkg_mgr == 'apt' - ansible_pkg_mgr == 'apt'
- galera_client - galera_client
- openstack_openrc
# Extra dependency not installable this way # Extra dependency not installable this way
# git clone https://git.openstack.org/openstack/openstack-ansible-plugins {homedir}/.ansible/plugins # git clone https://git.openstack.org/openstack/openstack-ansible-plugins {homedir}/.ansible/plugins

View File

@ -0,0 +1,17 @@
---
features:
- |
The service setup in keystone for gnocchi will now be executed
through delegation to the ``gnocchi_service_setup_host`` which,
by default, is ``localhost`` (the deploy host). Deployers can
opt to rather change this to the utility container by implementing
the following override in ``user_variables.yml``.
.. code-block:: yaml
gnocchi_service_setup_host: "{{ groups['utility_all'][0] }}"
deprecations:
- |
The variable ``gnocchi_requires_pip_packages`` is no longer required
and has therefore been removed.

View File

@ -16,54 +16,56 @@
# Create the project if needed, assumed to be in default domain. # Create the project if needed, assumed to be in default domain.
# In many cases this will be present but under some circumstances the project # In many cases this will be present but under some circumstances the project
# may be unique to Gnocchi, esp. when Swift is used for storage. # may be unique to Gnocchi, esp. when Swift is used for storage.
- name: Ensure Gnocchi project # We set the python interpreter to the ansible runtime venv if
keystone: # the delegation is to localhost so that we get access to the
command: ensure_project # appropriate python libraries in that venv. If the delegation
project_name: "{{ gnocchi_service_project_name }}" # is to another host, we assume that it is accessible by the
endpoint: "{{ keystone_service_adminurl }}" # system python instead.
login_user: "{{ keystone_admin_user_name }}" - name: Setup the service
login_password: "{{ keystone_auth_admin_password }}" delegate_to: "{{ gnocchi_service_setup_host }}"
login_project_name: "{{ keystone_admin_tenant_name }}" vars:
description: "{{ gnocchi_service_project_description }}" ansible_python_interpreter: >-
insecure: "{{ keystone_service_adminuri_insecure }}" {{ (gnocchi_service_setup_host == 'localhost') | ternary(ansible_playbook_python, ansible_python['executable']) }}
register: add_project block:
until: add_project|success - name: Add service project
retries: 5 os_project:
delay: 10 cloud: default
no_log: True state: present
name: "{{ gnocchi_service_project_name }}"
domain_id: "{{ gnocchi_service_project_domain_id }}"
endpoint_type: admin
verify: "{{ not keystone_service_adminuri_insecure }}"
register: add_service
until: add_service is success
retries: 5
delay: 10
# Create an admin user - name: Add service user
- name: Ensure Gnocchi user os_user:
keystone: cloud: default
command: "ensure_user" state: present
endpoint: "{{ keystone_service_adminurl }}" name: "{{ gnocchi_service_user_name }}"
login_user: "{{ keystone_admin_user_name }}" password: "{{ gnocchi_service_password }}"
login_password: "{{ keystone_auth_admin_password }}" domain: default
login_project_name: "{{ keystone_admin_tenant_name }}" default_project: "{{ gnocchi_service_project_name }}"
user_name: "{{ gnocchi_service_user_name }}" endpoint_type: admin
tenant_name: "{{ gnocchi_service_project_name }}" verify: "{{ not keystone_service_adminuri_insecure }}"
password: "{{ gnocchi_service_password }}" register: add_service
insecure: "{{ keystone_service_adminuri_insecure }}" until: add_service is success
register: add_user retries: 5
until: add_user|success delay: 10
retries: 5 no_log: True
delay: 10
no_log: True
# Add a role to the user - name: Add service user to admin role
- name: Ensure Gnocchi user maps to admin role os_user_role:
keystone: cloud: default
command: "ensure_user_role" state: present
endpoint: "{{ keystone_service_adminurl }}" user: "{{ gnocchi_service_user_name }}"
login_user: "{{ keystone_admin_user_name }}" role: "{{ gnocchi_role_name }}"
login_password: "{{ keystone_auth_admin_password }}" project: "{{ gnocchi_service_project_name }}"
login_project_name: "{{ keystone_admin_tenant_name }}" endpoint_type: admin
user_name: "{{ gnocchi_service_user_name }}" verify: "{{ not keystone_service_adminuri_insecure }}"
tenant_name: "{{ gnocchi_service_project_name }}" register: add_service
role_name: "{{ gnocchi_role_name }}" until: add_service is success
insecure: "{{ keystone_service_adminuri_insecure }}" retries: 5
register: add_admin_role delay: 10
until: add_admin_role|success
retries: 5
delay: 10
no_log: True

View File

@ -33,19 +33,6 @@
{% endfor %} {% endfor %}
when: gnocchi_developer_mode | bool when: gnocchi_developer_mode | bool
- name: Install required pip packages
pip:
name: "{{ gnocchi_requires_pip_packages }}"
state: "{{ gnocchi_pip_package_state }}"
extra_args: >-
{{ gnocchi_developer_mode | ternary(pip_install_developer_constraints | default('--constraint /opt/developer-pip-constraints.txt'), '') }}
{{ (pip_install_upper_constraints is defined) | ternary('--constraint ' + pip_install_upper_constraints | default(''),'') }}
{{ pip_install_options | default('') }}
register: install_packages
until: install_packages|success
retries: 5
delay: 2
- name: Retrieve checksum for venv download - name: Retrieve checksum for venv download
uri: uri:
url: "{{ gnocchi_venv_download_url | replace('tgz', 'checksum') }}" url: "{{ gnocchi_venv_download_url | replace('tgz', 'checksum') }}"

View File

@ -13,45 +13,49 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# Create a service # We set the python interpreter to the ansible runtime venv if
- name: Ensure Gnocchi service # the delegation is to localhost so that we get access to the
keystone: # appropriate python libraries in that venv. If the delegation
command: "ensure_service" # is to another host, we assume that it is accessible by the
endpoint: "{{ keystone_service_adminurl }}" # system python instead.
login_user: "{{ keystone_admin_user_name }}" - name: Setup the service
login_password: "{{ keystone_auth_admin_password }}" delegate_to: "{{ gnocchi_service_setup_host }}"
login_project_name: "{{ keystone_admin_tenant_name }}" vars:
service_name: "{{ gnocchi_service_name }}" ansible_python_interpreter: >-
service_type: "{{ gnocchi_service_type }}" {{ (gnocchi_service_setup_host == 'localhost') | ternary(ansible_playbook_python, ansible_python['executable']) }}
description: "{{ gnocchi_service_description }}" block:
insecure: "{{ keystone_service_adminuri_insecure }}" - name: Add service to the keystone service catalog
register: add_service os_keystone_service:
until: add_service|success cloud: default
retries: 5 state: present
delay: 2 name: "{{ gnocchi_service_name }}"
no_log: True service_type: "{{ gnocchi_service_type }}"
description: "{{ gnocchi_service_description }}"
endpoint_type: admin
verify: "{{ not keystone_service_adminuri_insecure }}"
register: add_service
until: add_service is success
retries: 5
delay: 10
# Create an endpoint - name: Add endpoints to keystone endpoint catalog
- name: Ensure Gnocchi endpoint os_keystone_endpoint:
keystone: cloud: default
command: "ensure_endpoint" state: present
endpoint: "{{ keystone_service_adminurl }}" service: "{{ gnocchi_service_name }}"
login_user: "{{ keystone_admin_user_name }}" endpoint_interface: "{{ item.interface }}"
login_password: "{{ keystone_auth_admin_password }}" url: "{{ item.url }}"
login_project_name: "{{ keystone_admin_tenant_name }}" region: "{{ gnocchi_service_region }}"
region_name: "{{ gnocchi_service_region }}" endpoint_type: admin
service_name: "{{ gnocchi_service_name }}" verify: "{{ not keystone_service_adminuri_insecure }}"
service_type: "{{ gnocchi_service_type }}" register: add_service
insecure: "{{ keystone_service_adminuri_insecure }}" until: add_service is success
endpoint_list: retries: 5
- url: "{{ gnocchi_service_publicurl }}" delay: 10
interface: "public" with_items:
- url: "{{ gnocchi_service_internalurl }}" - interface: "public"
interface: "internal" url: "{{ gnocchi_service_publicurl }}"
- url: "{{ gnocchi_service_adminurl }}" - interface: "internal"
interface: "admin" url: "{{ gnocchi_service_internalurl }}"
register: add_endpoint - interface: "admin"
until: add_endpoint|success url: "{{ gnocchi_service_adminurl }}"
retries: 5
delay: 10
no_log: True

View File

@ -15,5 +15,3 @@
bridges: bridges:
- "br-mgmt" - "br-mgmt"
ansible_python_interpreter: "/usr/bin/python2"

View File

@ -16,47 +16,44 @@
# Very basic testing using examples from http://gnocchi.xyz/rest.html # Very basic testing using examples from http://gnocchi.xyz/rest.html
- name: Playbook for functional testing of gnocchi - name: Playbook for functional testing of gnocchi
hosts: gnocchi_all hosts: localhost
user: root connection: local
gather_facts: false gather_facts: false
vars: vars:
gnocchi_api: "http://localhost:{{ gnocchi_service_port }}" ansible_python_interpreter: "{{ ansible_playbook_python }}"
vars_files:
- common/test-vars.yml
tasks: tasks:
- name: Install openstackclient
pip:
name: "python-openstackclient"
extra_args: >-
{{ gnocchi_developer_mode | ternary(pip_install_developer_constraints | default('--constraint /opt/developer-pip-constraints.txt'), '') }}
{{ pip_install_options | default('') }}
- name: Check the gnocchi-api - name: Check the gnocchi-api
uri: uri:
url: "{{ gnocchi_api }}" url: "{{ gnocchi_service_internaluri }}"
status_code: 200,300 status_code: 200,300
- name: Validate that auth is required - name: Validate that auth is required
uri: uri:
url: "{{ gnocchi_api }}/v1/status" url: "{{ gnocchi_service_internaluri }}/v1/status"
status_code: 401 status_code: 401
- name: Get auth token - name: Authenticate to the cloud and retrieve the service catalog
shell: > os_auth:
. /root/openrc && openstack token issue --format yaml | awk '/^id\:/ {print $2}' cloud: "default"
register: get_keystone_token region_name: "{{ keystone_service_region }}"
changed_when: false # TODO(odyssey4me):
# Restore this once debugging is complete.
- name: set token #no_log: true
set_fact: register: _auth
keystone_token: "{{ get_keystone_token.stdout }}" until: (_auth | success) and (auth_token is defined)
retries: 5
delay: 10
- name: Create a metric - name: Create a metric
uri: uri:
url: "{{ gnocchi_api }}/v1/metric" url: "{{ gnocchi_service_internaluri }}/v1/metric"
method: POST method: POST
body: '{ "archive_policy_name": "high" }' body: '{ "archive_policy_name": "high" }'
headers: headers:
Content-Type: "application/json" Content-Type: "application/json"
X-Auth-Token: "{{ keystone_token }}" X-Auth-Token: "{{ auth_token }}"
return_content: True return_content: True
status_code: 201 status_code: 201
register: metric_create register: metric_create
@ -66,22 +63,22 @@
- name: Add measures - name: Add measures
uri: uri:
url: "{{ gnocchi_api }}/v1/metric/{{ metric_create.json.id }}/measures" url: "{{ gnocchi_service_internaluri }}/v1/metric/{{ metric_create.json.id }}/measures"
method: POST method: POST
body: '[ { "timestamp": "2014-10-06T14:33:57", "value": 43.1 }, { "timestamp": "2014-10-06T14:34:12", "value": 12 }, { "timestamp": "2014-10-06T14:34:20", "value": 2 } ]' body: '[ { "timestamp": "2014-10-06T14:33:57", "value": 43.1 }, { "timestamp": "2014-10-06T14:34:12", "value": 12 }, { "timestamp": "2014-10-06T14:34:20", "value": 2 } ]'
headers: headers:
Content-Type: "application/json" Content-Type: "application/json"
X-Auth-Token: "{{ keystone_token }}" X-Auth-Token: "{{ auth_token }}"
return_content: True return_content: True
status_code: 202 status_code: 202
- name: Retrieve the measures - name: Retrieve the measures
uri: uri:
url: "{{ gnocchi_api }}/v1/metric/{{ metric_create.json.id }}/measures?refresh=true" url: "{{ gnocchi_service_internaluri }}/v1/metric/{{ metric_create.json.id }}/measures?refresh=true"
method: GET method: GET
headers: headers:
Content-Type: "application/json" Content-Type: "application/json"
X-Auth-Token: "{{ keystone_token }}" X-Auth-Token: "{{ auth_token }}"
return_content: True return_content: True
status_code: 200 status_code: 200
register: measures_retrieval register: measures_retrieval
@ -96,11 +93,11 @@
- name: Retrieve the archive policies - name: Retrieve the archive policies
uri: uri:
url: "{{ gnocchi_api }}/v1/archive_policy" url: "{{ gnocchi_service_internaluri }}/v1/archive_policy"
method: GET method: GET
headers: headers:
Content-Type: "application/json" Content-Type: "application/json"
X-Auth-Token: "{{ keystone_token }}" X-Auth-Token: "{{ auth_token }}"
return_content: True return_content: True
status_code: 200 status_code: 200
register: policies_retrieval register: policies_retrieval

View File

@ -17,11 +17,11 @@
hosts: gnocchi_all hosts: gnocchi_all
user: root user: root
gather_facts: true gather_facts: true
vars_files:
- common/test-vars.yml
pre_tasks: pre_tasks:
- include: common/create-grant-db.yml - include: common/create-grant-db.yml
db_password: "{{ gnocchi_container_mysql_password }}" db_password: "{{ gnocchi_container_mysql_password }}"
db_name: "gnocchi" db_name: "gnocchi"
roles: roles:
- role: "os_gnocchi" - role: "os_gnocchi"
vars_files:
- common/test-vars.yml