Refactored baremetal_port and baremetal_port_info modules

Sorted argument specs and documentation of both modules.

Refactored both modules to be subclasses of OpenStackModule class.

Renamed baremetal_port's module attributes 'uuid' to 'id' and
'portgroup' to 'port_group' to match openstacksdk. Added the previous
attribute names as aliases to keep backward compatibility. Added
alias 'pxe_enabled' for 'is_pxe_enabled' which was previously set
programmatically.

Changed baremetal_port module to return attribute 'port' only when
state is present. It will return no values (except Ansible's default
values) when state is absent. Previous return value 'id' can be
retrieved from port's dictionary entry 'id'.
The non-standard return value 'result' has been dropped because its
content can easily be reconstructed with Ansible's is changed check.

The non-standard return value 'changes' has been dropped because its
content was only returned on updates, has no known uses and can
easily be reconstructed in Ansible by comparing the updated port
dictionary with a copy of the pre-updated port dictionary.

Module baremetal_port_info will no longer fail when no port with a
matching id or name or address could be found. Instead it will return
an empty list like other *_info modules.

baremetal_port_info's return attribute 'baremetal_ports' has been
renamed to 'ports' to be consistent with other modules. The former
name will keep to be available for now to keep backward compatibility.

Both modules convert their return values into dictionaries without
computed (redundant) values. They do not drop values such as links
anymore though, because we do not withhold information from users.

Updated DOCUMENTATION, EXAMPLES and RETURN docstrings in both modules.

Added integration tests for both modules. They will not run in CI atm,
because we do not have Ironic enabled in our DevStack environment.

Change-Id: I54b3ea9917fbbbdf381ef934a0d92e2857f6d51b
This commit is contained in:
Jakob Meng
2022-09-28 11:26:31 +02:00
parent 65a7e74b2b
commit 99074ccd12
4 changed files with 326 additions and 285 deletions

View File

@@ -0,0 +1,14 @@
expected_fields:
- address
- created_at
- extra
- id
- internal_info
- is_pxe_enabled
- links
- local_link_connection
- name
- node_id
- physical_network
- port_group_id
- updated_at

View File

@@ -0,0 +1,112 @@
---
# TODO: Actually run this role in CI. Atm we do not have DevStack's ironic plugin enabled.
- name: Create baremetal node
openstack.cloud.baremetal_node:
cloud: "{{ cloud }}"
driver_info:
ipmi_address: "1.2.3.4"
ipmi_username: "admin"
ipmi_password: "secret"
name: ansible_baremetal_node
nics:
- mac: "aa:bb:cc:aa:bb:cc"
state: present
register: node
- name: Create baremetal port
openstack.cloud.baremetal_port:
cloud: "{{ cloud }}"
state: present
node: ansible_baremetal_node
address: fa:16:3e:aa:aa:aa
is_pxe_enabled: False
register: port
- debug: var=port
- name: Assert return values of baremetal_port module
assert:
that:
- not port.port.is_pxe_enabled
# allow new fields to be introduced but prevent fields from being removed
- expected_fields|difference(port.port.keys())|length == 0
- name: Fetch baremetal ports
openstack.cloud.baremetal_port_info:
cloud: "{{ cloud }}"
register: ports
- name: Assert module results of baremetal_port_info module
assert:
that:
- ports.ports|list|length > 0
- name: assert return values of baremetal_port_info module
assert:
that:
# allow new fields to be introduced but prevent fields from being removed
- expected_fields|difference(ports.ports.0.keys())|length == 0
- name: Fetch baremetal port by id
openstack.cloud.baremetal_port_info:
cloud: "{{ cloud }}"
id: "{{ port.port.id }}"
register: ports
- name: assert module results of baremetal_port_info module
assert:
that:
- ports.ports|list|length == 1
- ports.ports.0.id == port.port.id
- name: Update baremetal port
openstack.cloud.baremetal_port:
cloud: "{{ cloud }}"
state: present
id: "{{ port.port.id }}"
is_pxe_enabled: True
register: updated_port
- name: Assert return values of updated baremetal port
assert:
that:
- update_port is changed
- update_port.port.id == port.port.id
- update_port.port.address == port.port.address
- update_port.port.is_pxe_enabled
- name: Update baremetal port again
openstack.cloud.baremetal_port:
cloud: "{{ cloud }}"
state: present
id: "{{ port.port.id }}"
is_pxe_enabled: True
register: updated_port
- name: Assert return values of updated baremetal port
assert:
that:
- update_port is not changed
- update_port.port.id == port.port.id
- name: Delete Bare Metal port
openstack.cloud.baremetal_port:
cloud: "{{ cloud }}"
state: absent
id: "{{ port.port.id }}"
- name: Fetch baremetal ports
openstack.cloud.baremetal_port_info:
cloud: "{{ cloud }}"
register: ports
- name: Assert no baremetal port is left
assert:
that:
- ports.ports|list|length == 0
- name: Delete baremetal node
openstack.cloud.baremetal_node:
cloud: "{{ cloud }}"
name: ansible_baremetal_node
state: absent