From 9046f7eee0a52523af62e8a6b9f5edfeb1e1a3cb Mon Sep 17 00:00:00 2001 From: Muayyad alsadi Date: Sun, 9 Apr 2023 12:00:45 +0300 Subject: [PATCH] #634: follow up --- podman_compose.py | 14 ++++---------- tests/netprio/docker-compose.yaml | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 tests/netprio/docker-compose.yaml diff --git a/podman_compose.py b/podman_compose.py index 3d8ac1b..af45020 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -792,7 +792,7 @@ def get_net_args(compose, cnt): ip = None ip6 = None if cnt_nets and is_dict(cnt_nets): - cnt_nets_prioritized = dict() + prioritized_cnt_nets = [] # cnt_nets is {net_key: net_value, ...} for net_key, net_value in cnt_nets.items(): net_value = net_value or {} @@ -802,16 +802,10 @@ def get_net_args(compose, cnt): if not ip6: ip6 = net_value.get("ipv6_address", None) net_priority = net_value.get("priority", 0) - if not net_priority in cnt_nets_prioritized: - cnt_nets_prioritized[net_priority] = list() - cnt_nets_prioritized[net_priority].append(net_key) - # sort each priority list alphabetically - for prio in cnt_nets_prioritized: - cnt_nets_prioritized[prio].sort() + prioritized_cnt_nets.append((net_priority, net_key,)) # sort dict by priority - cnt_nets_prioritized = dict(sorted(cnt_nets_prioritized.items(), reverse=True)) - # flatten the priority dict to a list - cnt_nets = [name for prios in cnt_nets_prioritized.values() for name in prios] + prioritized_cnt_nets.sort(reverse=True) + cnt_nets = [ net_key for _, net_key in prioritized_cnt_nets ] cnt_nets = norm_as_list(cnt_nets or default_net) net_names = list() for net in cnt_nets: diff --git a/tests/netprio/docker-compose.yaml b/tests/netprio/docker-compose.yaml new file mode 100644 index 0000000..72cad69 --- /dev/null +++ b/tests/netprio/docker-compose.yaml @@ -0,0 +1,16 @@ +--- +# https://github.com/compose-spec/compose-spec/blob/master/spec.md#priority +services: + app: + image: busybox + command: top + networks: + app_net_1: + app_net_2: + priority: 1000 + app_net_3: + priority: 100 +networks: + app_net_1: + app_net_2: + app_net_3: