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
This commit is contained in:
Gaudenz Steinlin 2023-12-19 23:09:07 +01:00
parent d186d9b921
commit cccf4c03f1
No known key found for this signature in database
GPG Key ID: 640E36E7F6FC7F12
6 changed files with 94 additions and 1 deletions

View File

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

50
tests/group_vars/all.yml Normal file
View File

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

View File

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

View File

@ -18,3 +18,5 @@ lxc_cache_distro_packages: "{{ _lxc_cache_distro_packages |
reject('match', '^openssh.*') |
list }}"
lxc_cache_sshd_configuration: []
is_metal: True

View File

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

36
tests/test-modules.yml Normal file
View File

@ -0,0 +1,36 @@
---
# Copyright 2016, Gaudenz Steinlin <gaudenz.steinlin@cloudscale.ch>
#
# 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