From cccf4c03f134fbdcbe0664610064fcfc73671ad8 Mon Sep 17 00:00:00 2001 From: Gaudenz Steinlin Date: Tue, 19 Dec 2023 23:09:07 +0100 Subject: [PATCH] Ensure consistent ordering of network_mappings The provider_networks module returned the network_mappings in a random order changing with every invocation. This returns the entries sorted and adds a test to ensure the ordering is consistent between invocations. Change-Id: Iaec4534ebd8ff80cf7c7e3a1c8f187dd3990e4bc --- plugins/modules/provider_networks | 2 +- tests/group_vars/all.yml | 50 +++++++++++++++++++++++++++++ tests/group_vars/all_containers.yml | 2 ++ tests/group_vars/hosts.yml | 2 ++ tests/inventory | 3 ++ tests/test-modules.yml | 36 +++++++++++++++++++++ 6 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tests/group_vars/all.yml create mode 100644 tests/test-modules.yml diff --git a/plugins/modules/provider_networks b/plugins/modules/provider_networks index 9a98f928..da509b85 100644 --- a/plugins/modules/provider_networks +++ b/plugins/modules/provider_networks @@ -427,7 +427,7 @@ def main(): 'network_geneve_ranges_list': pnp.network_geneve_ranges, 'network_flat_networks': ','.join(pnp.network_flat_networks), 'network_flat_networks_list': pnp.network_flat_networks, - 'network_mappings': ','.join(list(set(pnp.network_mappings))), + 'network_mappings': ','.join(sorted(set(pnp.network_mappings))), 'network_mappings_list': pnp.network_mappings, 'network_types': ','.join(pnp.network_types), 'network_sriov_mappings': ','.join(pnp.network_sriov_mappings), diff --git a/tests/group_vars/all.yml b/tests/group_vars/all.yml new file mode 100644 index 00000000..9e83f0fd --- /dev/null +++ b/tests/group_vars/all.yml @@ -0,0 +1,50 @@ +provider_networks: + - network: + container_bridge: "br-mgmt" + container_type: "veth" + container_interface: "eth1" + ip_from_q: "container" + type: "raw" + group_binds: + - all_containers + - hosts + is_container_address: true + - network: + container_bridge: "br-vxlan" + container_type: "veth" + container_interface: "eth10" + ip_from_q: "tunnel" + type: "vxlan" + range: "1:1000" + net_name: "vxlan" + group_binds: + - neutron_linuxbridge_agent + - network: + container_bridge: "br-vlan" + container_type: "veth" + container_interface: "eth12" + host_bind_override: "eth12" + type: "flat" + net_name: "flat" + group_binds: + - neutron_linuxbridge_agent + - network: + container_bridge: "br-vlan" + container_type: "veth" + container_interface: "eth11" + type: "vlan" + range: "101:200,301:400" + net_name: "vlan" + group_binds: + - neutron_linuxbridge_agent + - network: + container_bridge: "br-storage" + container_type: "veth" + container_interface: "eth2" + ip_from_q: "storage" + type: "raw" + group_binds: + - glance_api + - cinder_api + - cinder_volume + - nova_compute diff --git a/tests/group_vars/all_containers.yml b/tests/group_vars/all_containers.yml index c17e4c0b..46a0c8d7 100644 --- a/tests/group_vars/all_containers.yml +++ b/tests/group_vars/all_containers.yml @@ -30,3 +30,5 @@ physical_host: localhost openssh_server_package: openssh-server openssh_server_service: "{{ (ansible_facts['os_family'] == 'Debian') | ternary('ssh', 'sshd') }}" + +is_metal: False diff --git a/tests/group_vars/hosts.yml b/tests/group_vars/hosts.yml index aa865d36..6f9d5bc7 100644 --- a/tests/group_vars/hosts.yml +++ b/tests/group_vars/hosts.yml @@ -18,3 +18,5 @@ lxc_cache_distro_packages: "{{ _lxc_cache_distro_packages | reject('match', '^openssh.*') | list }}" lxc_cache_sshd_configuration: [] + +is_metal: True diff --git a/tests/inventory b/tests/inventory index 2fd500c9..2ae04d10 100644 --- a/tests/inventory +++ b/tests/inventory @@ -18,3 +18,6 @@ fakehost ansible_host=1.1.1.1 fake_hosts [fake_containers] fakecontainer container_name=fakecontainer physical_host=fakehost + +[neutron_linuxbridge_agent] +localhost diff --git a/tests/test-modules.yml b/tests/test-modules.yml new file mode 100644 index 00000000..fba3fbaa --- /dev/null +++ b/tests/test-modules.yml @@ -0,0 +1,36 @@ +--- +# Copyright 2016, Gaudenz Steinlin +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + + +- name: Test modules + hosts: localhost + connection: local + gather_facts: no + tasks: + - name: Test network mapping consistent order + provider_networks: + provider_networks: "{{ provider_networks }}" + bind_prefix: "{{ provider_network_bind_prefix | default('') }}" + is_metal: "{{ is_metal }}" + group_names: "{{ group_names }}" + register: pndata + loop: "{{ range(10) | list }}" + + - name: Verify network mappings have a consistent order + assert: + that: >- + pndata.results | map(attribute='network_mappings') | unique | length + == 1