From cafb8d5e1af143c83ca3dfe239e50d8bbc5f6ac5 Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Fri, 29 Nov 2024 23:34:41 +0100 Subject: Fix nova-compute startup after reprovisioning We need to restore the /var/lib/nova/compute_id file to avoid nova-compute failing to start with the following error: nova.exception.InvalidConfiguration: No local node identity found, but this is not our first startup on this host. Refusing to start after potentially having lost that state! K-A now query IDs of hypervisors by their hostname and create necessary compute_id file under node config directory for nova-compute before starting nova-compute containers. The compute_id file gets copied under /var/lib/nova/ on container start up. Co-Authored-By: bjorn lofdahl Co-Authored-By: Seunghun Lee Co-Authored-By: Owen Jones Change-Id: If635577fa240f0953ad02d2c28473480d9ad011d Closes-Bug: #2051011 Signed-off-by: Owen Jones Signed-off-by: Maksim Malchuk (cherry picked from commit 3e4cfd49da38c7db2ac3ad47a75dc89b14cbb513) --- ansible/roles/nova-cell/tasks/config.yml | 60 ++++++++++++++++++++++ .../roles/nova-cell/templates/nova-compute.json.j2 | 6 +++ .../notes/bug-2051011-e78146d498a5875a.yaml | 6 +++ 3 files changed, 72 insertions(+) create mode 100644 releasenotes/notes/bug-2051011-e78146d498a5875a.yaml diff --git a/ansible/roles/nova-cell/tasks/config.yml b/ansible/roles/nova-cell/tasks/config.yml index f9e9c10ee..83569eedd 100644 --- a/ansible/roles/nova-cell/tasks/config.yml +++ b/ansible/roles/nova-cell/tasks/config.yml @@ -54,6 +54,66 @@ when: - vendordata_file.stat.exists +- name: Ensure compute_id exists in nova_compute volume + vars: + service: "{{ nova_cell_services['nova-compute'] }}" + hypervisor_nodename: "{{ hostvars[inventory_hostname].ansible_facts.nodename }}" + when: service | service_enabled_and_mapped_to_host + block: + - name: List all hypervisors + kolla_toolbox: + container_engine: "{{ kolla_container_engine }}" + module_name: openstack.cloud.resources + module_args: + auth: "{{ openstack_auth }}" + cloud: "{{ openstack_auth_cloud }}" + ca_cert: "{{ openstack_cacert }}" + region_name: "{{ openstack_region_name }}" + endpoint_type: "{{ openstack_interface }}" + service: "compute" + type: "hypervisor" + register: hypervisors + check_mode: false + become: true + delegate_to: "{{ groups[nova_cell_conductor_group][0] }}" + + - name: Match current hypervisor + ansible.builtin.set_fact: + matched_hypervisors: >- + {{ hypervisors.resources | selectattr('name', 'equalto', hypervisor_nodename) }} + when: hypervisors.resources | length > 0 + + - name: Assert that only one hypervisor was matched + ansible.builtin.assert: + that: + - matched_hypervisors | length == 1 + fail_msg: | + "Found multiple compute services with same host name, please check your Nova " + "compute agents list and fix it. The query with hypervisor name " + "'{{ hypervisor_nodename }}' returned following: {{ matched_hypervisors }}" + when: + - hypervisors.resources | length > 0 + - matched_hypervisors | length > 0 + + - name: Copy the matched hypervisor UUID to compute_id + ansible.builtin.copy: + content: "{{ matched_hypervisors[0].id }}" + dest: "{{ node_config_directory }}/nova-compute/compute_id" + mode: "0660" + become: true + when: + - hypervisors.resources | length > 0 + - matched_hypervisors | length == 1 + + # If the host was never registered, create a new hypervisor id and copy as compute_id + - name: Generate a new UUID then copy to compute_id + ansible.builtin.copy: + content: "{{ hypervisor_nodename | to_uuid }}" + dest: "{{ node_config_directory }}/nova-compute/compute_id" + mode: "0660" + become: true + when: hypervisors.resources | length == 0 or matched_hypervisors | length == 0 + - name: Copying over config.json files for services become: true ansible.builtin.template: diff --git a/ansible/roles/nova-cell/templates/nova-compute.json.j2 b/ansible/roles/nova-cell/templates/nova-compute.json.j2 index 400301d21..b90367a42 100644 --- a/ansible/roles/nova-cell/templates/nova-compute.json.j2 +++ b/ansible/roles/nova-cell/templates/nova-compute.json.j2 @@ -6,6 +6,12 @@ "dest": "/etc/nova/nova.conf", "owner": "nova", "perm": "0600" + }, + { + "source": "{{ container_config_directory }}/compute_id", + "dest": "/var/lib/nova/compute_id", + "owner": "nova", + "perm": "0600" }{% if nova_policy_file is defined %}, { "source": "{{ container_config_directory }}/{{ nova_policy_file }}", diff --git a/releasenotes/notes/bug-2051011-e78146d498a5875a.yaml b/releasenotes/notes/bug-2051011-e78146d498a5875a.yaml new file mode 100644 index 000000000..1195b2d6e --- /dev/null +++ b/releasenotes/notes/bug-2051011-e78146d498a5875a.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixes ``nova-compute`` failing to start after ``/var/lib/nova`` content has + been wiped, for example following a reprovisioning. + `LP#2051011 `__ -- cgit v1.2.3