From d7e319b91f43f93a29e07df116e4c134b6c28c34 Mon Sep 17 00:00:00 2001 From: Jiri Podivin Date: Mon, 14 Nov 2022 14:55:58 +0100 Subject: [PATCH] Refactoring default-node-count validation to use openstack-collection modules Hypervisor statistics check has been dropped entirely, as it relies on API deprecated by I515e484ade6c6455f82a3067940a418a0d7d965a[0] Since reliable and standard compliant installation of ansible modules is only possible using a collection, or system package manager, the ansible-lint settings were adjusted to mock newly introduced modules. Note about necessary dependencies was added to validation description. Explanation of the mocks was added to other, previously mocked, modules, in order to facilitate future development. [0] https://opendev.org/openstack/nova/commit/1f67ce24961a156dba56cacc75cbdd0800a7feee Resolves: rhbz#2149177 Depends-On: https://review.opendev.org/c/openstack/tripleo-ansible/+/862150 Signed-off-by: Jiri Podivin Change-Id: I70765bfbe3f319fef8112ac633b1b3c38fb1488c (cherry picked from commit 560ac9673987d2ade2daca91faeaf8597e6d96e7) (cherry picked from commit 53f97be07431451ab0ea1715414988a8f4e641ae) --- .ansible-lint | 8 ++-- bindep.txt | 4 ++ playbooks/default-node-count.yaml | 2 +- roles/default_node_count/tasks/main.yml | 62 +++++++++++++++---------- roles/default_node_count/vars/main.yml | 2 + 5 files changed, 50 insertions(+), 28 deletions(-) diff --git a/.ansible-lint b/.ansible-lint index 4fe66128d..e7e2694e2 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -8,9 +8,11 @@ rulesdir: # Mock modules or roles in order to pass ansible-playbook --syntax-check mock_modules: - - hiera - - validations_read_ini - - warn + - hiera # Modules can only be installed by rpm + - validations_read_ini # Modules can only be installed by rpm + - warn # Modules can only be installed by rpm + - tripleo_overcloud_role_list # Modules can only be installed by rpm + - tripleo_overcloud_role_show # Modules can only be installed by rpm mock_roles: - check_latest_packages_version diff --git a/bindep.txt b/bindep.txt index 9e8b71c3f..9b23d5dad 100644 --- a/bindep.txt +++ b/bindep.txt @@ -39,3 +39,7 @@ gzip # Required to build language docs gettext + +# Ansible module and role dependencies +tripleo-ansible [platform:rpm] +ansible-collections-openstack [platform:rpm] diff --git a/playbooks/default-node-count.yaml b/playbooks/default-node-count.yaml index a84f6743a..02d42aaa4 100644 --- a/playbooks/default-node-count.yaml +++ b/playbooks/default-node-count.yaml @@ -5,7 +5,7 @@ name: Verify hypervisor statistics description: | This validation checks that the nodes and hypervisor statistics - add up. + add up. Validation requires system installation of tripleo-ansible package. groups: - pre-deployment categories: diff --git a/roles/default_node_count/tasks/main.yml b/roles/default_node_count/tasks/main.yml index 35d44cbb8..60d5126ab 100644 --- a/roles/default_node_count/tasks/main.yml +++ b/roles/default_node_count/tasks/main.yml @@ -1,39 +1,53 @@ --- -- name: Retrieve the hypervisor statistics - set_fact: - statistics: "{{ lookup('nova_hypervisor_statistics', wantlist=True) }}" +- name: Get list of baremetal nodes + openstack.cloud.baremetal_node_info: + cloud: undercloud + register: baremetal_nodes -- name: Get default role counts - set_fact: - roles_info: "{{ lookup('roles_info', wantlist=True) }}" +- name: Get baremetal node details + openstack.cloud.baremetal_node_info: + cloud: undercloud + node: "{{ item }}" + with_items: "{{ baremetal_nodes | community.general.json_query('baremetal_nodes[*].name') }}" + register: node_details -- name: Set requested count +- name: Get clean node list set_fact: - requested_count: "{{ roles_info|sum(attribute='count') }}" + baremetal_nodes_details: "{{ [item] + baremetal_nodes_details }}" + with_items: "{{ node_details | community.general.json_query('results[*].baremetal_nodes') }}" -- name: Get associated nodes +- name: Get active node count set_fact: - associated_nodes: "{{ lookup('ironic_nodes', 'associated', wantlist=True) }}" + active_nodes: "{{ baremetal_nodes_details | community.general.json_query('[?provision_state==`available`]') | count() }}" -- name: Get available nodes +- name: Get associated node count set_fact: - available_nodes: "{{ lookup('ironic_nodes', 'provision_state', ['available'], wantlist=True) }}" + associated_nodes: "{{ baremetal_nodes_details | community.general.json_query('[*].associated') | count() }}" -- name: Set count of available nodes +- name: Set total available node count set_fact: - available_count: "{{ ((associated_nodes|length) + (available_nodes|length))|int }}" + available_count: "{{ active_nodes | int + associated_nodes | int }}" + +- name: Get overcloud role list + tripleo_overcloud_role_list: + register: role_list + +- name: Get details for each role + tripleo_overcloud_role_show: + role_name: "{{ item }}" + default_values: + CountDefault: 0 + FlavorDefault: 'baremetal' + with_items: "{{ role_list.role_list }}" + register: role_details + +- name: Get requested node count + set_fact: + requested_node_count: "{{ role_details | community.general.json_query('results[*].role_detail.CountDefault') | sum() }}" - name: Fail when requested is more than available fail: msg: > Not enough baremetal nodes - available: {{ available_count }}, - requested: {{ requested_count }} - failed_when: requested_count|int > available_count|int - -- name: Fail when hypervisor count is less than available count - fail: - msg: > - Only {{ statistics.count }} nodes are exposed to Nova of - {{ available_count }} requests. Check that enough nodes are - in 'available' state with maintenance mode off. - failed_when: statistics.count < available_count|int + requested: {{ requested_node_count }} + failed_when: requested_node_count|int > available_count|int diff --git a/roles/default_node_count/vars/main.yml b/roles/default_node_count/vars/main.yml index 744ae8351..520238d02 100644 --- a/roles/default_node_count/vars/main.yml +++ b/roles/default_node_count/vars/main.yml @@ -6,3 +6,5 @@ metadata: add up. groups: - pre-deployment + +baremetal_nodes_details: []