mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-07 22:03:09 +00:00
Merge "fix(trunk): Always add relevant sub_ports"
This commit is contained in:
@@ -53,7 +53,7 @@
|
|||||||
- ip_address: 10.5.6.55
|
- ip_address: 10.5.6.55
|
||||||
register: subport
|
register: subport
|
||||||
|
|
||||||
- name: Create trunk
|
- name: Create trunk without subports
|
||||||
openstack.cloud.trunk:
|
openstack.cloud.trunk:
|
||||||
cloud: "{{ cloud }}"
|
cloud: "{{ cloud }}"
|
||||||
state: present
|
state: present
|
||||||
@@ -61,15 +61,17 @@
|
|||||||
port: "{{ parent_port_name }}"
|
port: "{{ parent_port_name }}"
|
||||||
register: trunk
|
register: trunk
|
||||||
|
|
||||||
- debug: var=trunk
|
- name: Display return values of trunk module
|
||||||
|
ansible.builtin.debug:
|
||||||
|
var: trunk
|
||||||
|
|
||||||
- name: assert return values of trunk module
|
- name: Assert return values of trunk module
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
# allow new fields to be introduced but prevent fields from being removed
|
# allow new fields to be introduced but prevent fields from being removed
|
||||||
- expected_fields|difference(trunk.trunk.keys())|length == 0
|
- expected_fields|difference(trunk.trunk.keys())|length == 0
|
||||||
|
|
||||||
- name: Add subport to trunk
|
- name: Add subport to trunk by name
|
||||||
openstack.cloud.trunk:
|
openstack.cloud.trunk:
|
||||||
cloud: "{{ cloud }}"
|
cloud: "{{ cloud }}"
|
||||||
state: present
|
state: present
|
||||||
@@ -79,14 +81,66 @@
|
|||||||
- port: "{{ subport_name }}"
|
- port: "{{ subport_name }}"
|
||||||
segmentation_type: vlan
|
segmentation_type: vlan
|
||||||
segmentation_id: 123
|
segmentation_id: 123
|
||||||
|
register: trunk_subport_by_name
|
||||||
|
|
||||||
- name: Update subport from trunk
|
- name: Assert the subport is part of the trunk
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- trunk_subport_by_name.trunk.sub_ports|length == 1
|
||||||
|
|
||||||
|
- name: Remove subport from trunk
|
||||||
openstack.cloud.trunk:
|
openstack.cloud.trunk:
|
||||||
cloud: "{{ cloud }}"
|
cloud: "{{ cloud }}"
|
||||||
state: present
|
state: present
|
||||||
name: "{{ trunk_name }}"
|
name: "{{ trunk_name }}"
|
||||||
port: "{{ parent_port_name }}"
|
port: "{{ parent_port_name }}"
|
||||||
sub_ports: []
|
sub_ports: []
|
||||||
|
register: trunk_subport_removed
|
||||||
|
|
||||||
|
- name: Assert no subports are part of the trunk
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- trunk_subport_removed.trunk.sub_ports|length == 0
|
||||||
|
|
||||||
|
- name: Add subport to trunk by ID
|
||||||
|
openstack.cloud.trunk:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: present
|
||||||
|
name: "{{ trunk_name }}"
|
||||||
|
port: "{{ parent_port_name }}"
|
||||||
|
sub_ports:
|
||||||
|
- port: "{{ subport.port.id }}"
|
||||||
|
segmentation_type: vlan
|
||||||
|
segmentation_id: 123
|
||||||
|
register: trunk_subport_by_id
|
||||||
|
|
||||||
|
- name: Assert the subport is part of the trunk
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- trunk_subport_by_id.trunk.sub_ports|length == 1
|
||||||
|
|
||||||
|
- name: Delete trunk
|
||||||
|
openstack.cloud.trunk:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: absent
|
||||||
|
name: "{{ trunk_name }}"
|
||||||
|
|
||||||
|
- name: Create trunk without subports
|
||||||
|
openstack.cloud.trunk:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: present
|
||||||
|
name: "{{ trunk_name }}"
|
||||||
|
port: "{{ parent_port_name }}"
|
||||||
|
sub_ports:
|
||||||
|
- port: "{{ subport.port.id }}"
|
||||||
|
segmentation_type: vlan
|
||||||
|
segmentation_id: 123
|
||||||
|
register: trunk_with_subports
|
||||||
|
|
||||||
|
- name: Assert the subport is part of the trunk
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- trunk_with_subports.trunk.sub_ports|length == 1
|
||||||
|
|
||||||
- name: Delete trunk
|
- name: Delete trunk
|
||||||
openstack.cloud.trunk:
|
openstack.cloud.trunk:
|
||||||
|
|||||||
@@ -201,6 +201,11 @@ class TrunkModule(OpenStackModule):
|
|||||||
if state == 'present' and not trunk:
|
if state == 'present' and not trunk:
|
||||||
# create trunk
|
# create trunk
|
||||||
trunk = self._create(name_or_id, port)
|
trunk = self._create(name_or_id, port)
|
||||||
|
|
||||||
|
# add sub ports
|
||||||
|
update = self._build_update(trunk, sub_ports)
|
||||||
|
trunk = self._update(trunk, update)
|
||||||
|
|
||||||
self.exit_json(changed=True,
|
self.exit_json(changed=True,
|
||||||
trunk=trunk.to_dict(computed=False))
|
trunk=trunk.to_dict(computed=False))
|
||||||
elif state == 'present' and trunk:
|
elif state == 'present' and trunk:
|
||||||
@@ -232,7 +237,7 @@ class TrunkModule(OpenStackModule):
|
|||||||
if found is False:
|
if found is False:
|
||||||
psp = self.params['sub_ports'] or []
|
psp = self.params['sub_ports'] or []
|
||||||
for k in psp:
|
for k in psp:
|
||||||
if sp['name'] == k['port']:
|
if sp['name'] == k['port'] or sp['id'] == k['port']:
|
||||||
spobj = {
|
spobj = {
|
||||||
'port_id': sp['id'],
|
'port_id': sp['id'],
|
||||||
'segmentation_type': k['segmentation_type'],
|
'segmentation_type': k['segmentation_type'],
|
||||||
|
|||||||
Reference in New Issue
Block a user