From b9b8e08ac00ef93fca2521ba378cc16df587dad5 Mon Sep 17 00:00:00 2001 From: Logan V Date: Wed, 8 Feb 2017 11:30:13 -0600 Subject: [PATCH] Wait for nova-compute service registration A race condition is caused when nova-compute is started for the first time because it takes a period of time for nova-compute to spin up, register itself with nova API, and become available for cell enrollment. Prior to this there was no wait condition when nova-compute restarts occurred, so the first time nova-compute started, often the compute service was not registered in the database and available for cell enrollment when the enrollment tasks ran. Change-Id: I510f0a957f53d15affa1fc23f809abff52208438 --- defaults/main.yml | 1 + handlers/main.yml | 1 + tasks/main.yml | 7 +++++++ tasks/nova_compute_wait.yml | 25 +++++++++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 tasks/nova_compute_wait.yml diff --git a/defaults/main.yml b/defaults/main.yml index 5171ef87..7c392809 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -457,6 +457,7 @@ nova_requires_pip_packages: - virtualenv-tools - python-keystoneclient # Keystoneclient needed to OSA keystone lib - httplib2 + - python-openstackclient nova_compute_pip_packages: - libvirt-python diff --git a/handlers/main.yml b/handlers/main.yml index bba51977..be881d77 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -23,6 +23,7 @@ name: "{{ item.value.service_name }}" state: "restarted" with_dict: "{{ nova_services }}" + register: nova_service_restart when: - inventory_hostname in groups[item.value.group] - "{{ item.value.condition | default(true) }}" diff --git a/tasks/main.yml b/tasks/main.yml index 0ac561c2..d59d3cbf 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -85,6 +85,13 @@ - name: Flush handlers meta: flush_handlers +- include: nova_compute_wait.yml + when: + - "{{ 'nova_compute' in group_names }}" + - "{{ nova_service_restart | default(dict(changed=False)) | changed }}" + tags: + - nova-config + - include: nova_db_post_setup.yml when: inventory_hostname == groups['nova_api_os_compute'][0] tags: diff --git a/tasks/nova_compute_wait.yml b/tasks/nova_compute_wait.yml new file mode 100644 index 00000000..4e08f08a --- /dev/null +++ b/tasks/nova_compute_wait.yml @@ -0,0 +1,25 @@ +--- +# Copyright 2017, Logan Vig +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Wait for the nova-compute service to initialize + command: openstack --os-cloud default compute service list -f json + changed_when: false + register: nova_service_list + retries: 10 + delay: 5 + until: "{{ ansible_hostname in (nova_service_list.stdout + | from_json + | selectattr('Binary', 'equalto', 'nova-compute') + | map(attribute='Host') | list) }}"