From 2d0cfd5ad8e049f30cad10d977a5fae8bc4e6b64 Mon Sep 17 00:00:00 2001 From: Gris Ge Date: Thu, 10 Nov 2022 15:51:25 +0800 Subject: [PATCH] ip: Preserve the IP address order when applying When applying the IP address, we should preserve the order for use case whether user is expecting non-first ones been set with `secondary` flag. In RHEL/CentOS 8, NetworkManager is using reverted IPv6 address according to https://bugzilla.redhat.com/show_bug.cgi?id=2139443 Hence downstream nmstate will ship additional patch to fix it. The upstream nmstate will not revert the IPv6 address list before sending to NM. The downstream build of RHEL 8 has different behaviour than copr build from git main branch. It is hard to tell whether we are using downstream build or git build at runtime, hence we ship the `test_preserve_ipv6_addresses_order` test in RHEL 8. Integration test case included. Signed-off-by: Gris Ge --- libnmstate/ifaces/base_iface.py | 4 +- tests/integration/static_ip_address_test.py | 67 ++++++++++++++++++++- tests/integration/testlib/env.py | 5 ++ tests/integration/testlib/iproutelib.py | 14 +++++ tests/lib/ifaces/ip_state_test.py | 2 + 5 files changed, 89 insertions(+), 3 deletions(-) diff --git a/libnmstate/ifaces/base_iface.py b/libnmstate/ifaces/base_iface.py index fb2b7bb6..f29f9ac9 100644 --- a/libnmstate/ifaces/base_iface.py +++ b/libnmstate/ifaces/base_iface.py @@ -47,7 +47,6 @@ class IPState: self._family = family self._info = info self._remove_stack_if_disabled() - self._sort_addresses() self._canonicalize_ip_addr() self._canonicalize_dynamic() @@ -71,7 +70,7 @@ class IPState: addr[InterfaceIP.ADDRESS_IP] ) - def _sort_addresses(self): + def sort_addresses(self): self.addresses.sort(key=itemgetter(InterfaceIP.ADDRESS_IP)) def _remove_stack_if_disabled(self): @@ -431,6 +430,7 @@ class BaseIface: self.sort_port() for family in (Interface.IPV4, Interface.IPV6): ip_state = self.ip_state(family) + ip_state.sort_addresses() ip_state.remove_link_local_address() self._info[family] = ip_state.to_dict() state = self.to_dict() -- 2.38.1