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] 1f67ce2496

Resolves: rhbz#2149177

Depends-On: https://review.opendev.org/c/openstack/tripleo-ansible/+/862150

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I70765bfbe3f319fef8112ac633b1b3c38fb1488c
This commit is contained in:
Jiri Podivin 2022-11-14 14:55:58 +01:00
parent 072985c66d
commit 560ac96739
5 changed files with 50 additions and 28 deletions

View File

@ -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

View File

@ -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]

View File

@ -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:

View File

@ -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

View File

@ -6,3 +6,5 @@ metadata:
add up.
groups:
- pre-deployment
baremetal_nodes_details: []