Support DNS option

Resolves: RHEL-13936

Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
Gris Ge 2023-11-02 20:01:48 +08:00
parent c4e9fb4326
commit dbb3775b35
6 changed files with 12 additions and 309 deletions

3
.gitignore vendored
View File

@ -10,3 +10,6 @@ SOURCES/nmstate.gpg
/nmstate-1.4.4.tar.gz.asc
/nmstate-vendor-1.4.4.tar.xz
/nmstate.gpg
/nmstate-1.4.5.tar.gz
/nmstate-1.4.5.tar.gz.asc
/nmstate-vendor-1.4.5.tar.xz

View File

@ -1,183 +0,0 @@
0001-covscan-Remove-dead-code.patch
0002-Run-cargo-clippy.patch
0003-ip-Support-static-route-with-auto-ip.patch
0004-test-Refresh-the-expired-CA-keys.patch
From 6ea4790a368260b43c207d19f20c728698ac2184 Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Tue, 25 Apr 2023 14:52:59 +0800
Subject: [PATCH 1/4] covscan: Remove dead code
Removing the dead code found by covscan.
Signed-off-by: Gris Ge <fge@redhat.com>
---
libnmstate/dns.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/libnmstate/dns.py b/libnmstate/dns.py
index 853ece80..043c74a5 100644
--- a/libnmstate/dns.py
+++ b/libnmstate/dns.py
@@ -173,7 +173,6 @@ class DnsState:
},
},
}
- return {}
def _find_ifaces_for_name_servers(
self, ifaces, route_state, ignored_dns_ifaces
--
2.40.1
From 0329b87b7856e244a4a2d34864a6e6eefa49b226 Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Fri, 19 May 2023 17:57:51 +0800
Subject: [PATCH 2/4] Run cargo clippy
Signed-off-by: Gris Ge <fge@redhat.com>
---
rust/src/lib/nispor/linux_bridge.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rust/src/lib/nispor/linux_bridge.rs b/rust/src/lib/nispor/linux_bridge.rs
index c03f03d6..c4cd104b 100644
--- a/rust/src/lib/nispor/linux_bridge.rs
+++ b/rust/src/lib/nispor/linux_bridge.rs
@@ -63,7 +63,7 @@ pub(crate) fn append_bridge_port_config(
port_confs.push(port_conf);
}
- if let Some(mut br_conf) = br_iface.bridge.as_mut() {
+ if let Some(br_conf) = br_iface.bridge.as_mut() {
br_conf.port = Some(port_confs);
}
}
--
2.40.1
From 7c80a3acdb67eb09c3dcbeee7138315b3f855c7f Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Fri, 19 May 2023 18:12:54 +0800
Subject: [PATCH 3/4] ip: Support static route with auto ip
Supporting assigning static route to interface with auto ip. For
example:
```yml
---
interfaces:
- name: eth1
type: ethernet
state: up
ipv4:
dhcp: true
enabled: true
ipv6:
dhcp: true
autoconf: true
enabled: true
routes:
config:
- destination: 198.51.100.0/24
metric: 150
next-hop-address: 192.0.2.1
next-hop-interface: eth1
table-id: 254
- destination: 2001:db8:2::/64
metric: 151
next-hop-address: 2001:db8:1::2
next-hop-interface: eth1
```
Integration test case included and been marked as tier1.
Signed-off-by: Gris Ge <fge@redhat.com>
---
libnmstate/route.py | 52 ++++++-------
tests/integration/dynamic_ip_test.py | 105 +++++++++++++++++++--------
tests/lib/route_test.py | 28 +------
3 files changed, 105 insertions(+), 80 deletions(-)
diff --git a/libnmstate/route.py b/libnmstate/route.py
index d3734279..c92cbbb6 100644
--- a/libnmstate/route.py
+++ b/libnmstate/route.py
@@ -1,21 +1,4 @@
-#
-# Copyright (c) 2020 Red Hat, Inc.
-#
-# This file is part of nmstate
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as published by
-# the Free Software Foundation, either version 2.1 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program. If not, see <https://www.gnu.org/licenses/>.
-#
+# SPDX-License-Identifier: LGPL-2.1-or-later
from collections import defaultdict
import logging
@@ -146,13 +129,6 @@ class RouteEntry(StateEntry):
f"Route {self.to_dict()} next hop to down/absent interface"
)
return False
- if iface.is_dynamic(
- Interface.IPV6 if self.is_ipv6 else Interface.IPV4
- ):
- self._invalid_reason = (
- f"Route {self.to_dict()} next hop to interface with dynamic IP"
- )
- return False
if self.is_ipv6:
if not iface.is_ipv6_enabled():
self._invalid_reason = (
@@ -194,7 +170,10 @@ class RouteState:
rt = RouteEntry(entry)
self._cur_routes[rt.next_hop_interface].add(rt)
if not ifaces or rt.is_valid(ifaces):
- self._routes[rt.next_hop_interface].add(rt)
+ # When user converting static IP to auto IP, we should
+ # not merge current static routes besides desired ones.
+ if not iface_switch_from_static_to_auto_ip(ifaces, rt):
+ self._routes[rt.next_hop_interface].add(rt)
else:
logging.debug(
f"The current route {entry} has been discarded due"
@@ -299,3 +278,24 @@ class RouteState:
{Route.KEY: {Route.CONFIG: cur_routes_info}},
)
)
+
+
+def iface_switch_from_static_to_auto_ip(ifaces, rt):
+ iface_name = rt.next_hop_interface
+ if not iface_name or not ifaces:
+ return False
+
+ if is_ipv6_address(rt.destination):
+ family = Interface.IPV6
+ else:
+ family = Interface.IPV4
+
+ cur_iface = ifaces.get_cur_iface(iface_name, None)
+ des_iface = ifaces.get_iface(iface_name, None)
+ if (
+ cur_iface
+ and des_iface
+ and not cur_iface.is_dynamic(family)
+ and des_iface.is_dynamic(family)
+ ):
+ return True
--
2.40.1

View File

@ -1,44 +0,0 @@
From 88b785ee3424fb010da3e70c4337b3b5ebdf5f5e Mon Sep 17 00:00:00 2001
From: Fernando Fernandez Mancera <ffmancera@riseup.net>
Date: Thu, 24 Aug 2023 17:28:26 +0200
Subject: [PATCH] nm: do not attach ovs-bridge to itself when creating a
profile
If ovs-bridge and ovs-interface shares name and ovs-interface is
modified, during the creation of the ovs-bridge profile we are setting
itself as a controller.
That is wrong and NetworkManager is reporting the following error:
```
libnmstate.error.NmstateLibnmError: Update profile
uuid:ba206f8f-2ed6-486d-a339-9d1f62c5cb84 iface:br1 type:ovs-bridge
failed with error=nm-connection-error-quark: connection.slave-type:
Cannot set 'master' without 'slave-type' (6)
```
In order to solve that, before setting the controller we check that it
is not itself.
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
---
libnmstate/nm/ovs.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/libnmstate/nm/ovs.py b/libnmstate/nm/ovs.py
index f7c589b6..6f732207 100644
--- a/libnmstate/nm/ovs.py
+++ b/libnmstate/nm/ovs.py
@@ -375,5 +375,8 @@ def set_ovs_iface_controller_info(iface_infos):
for iface_info in iface_infos:
ctrl_name = pending_changes.get(iface_info[Interface.NAME])
- if ctrl_name:
+ if ctrl_name and not (
+ ctrl_name == iface_info[Interface.NAME]
+ and iface_info[Interface.TYPE] == InterfaceType.OVS_BRIDGE
+ ):
iface_info[Interface.CONTROLLER] = ctrl_name
--
2.41.0

View File

@ -1,73 +0,0 @@
From 4c1c741d4dd4d68e12c6e27478f1c320820dd003 Mon Sep 17 00:00:00 2001
From: Wen Liang <liangwen12year@gmail.com>
Date: Fri, 29 Sep 2023 14:31:34 -0400
Subject: [PATCH 1/1] ip: Support treating string as int for `prefix-length`
When the network role user is using the `network_state` variable to
configure the network, and if they are using Jinja2 template to
define the `prefix-length`, the type conversion
`prefix-length: "{{ __str_val | int }}"` does not work as expected, the
type for `prefix-length` in the end is still string. Therefore, nmstate
need to support treating string as int for `prefix-length` in order to
make the apply succeed.
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
---
libnmstate/ifaces/base_iface.py | 7 +++++++
libnmstate/schemas/operational-state.yaml | 8 ++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/libnmstate/ifaces/base_iface.py b/libnmstate/ifaces/base_iface.py
index c1a4c04b..b1e4c811 100644
--- a/libnmstate/ifaces/base_iface.py
+++ b/libnmstate/ifaces/base_iface.py
@@ -48,6 +48,7 @@ class IPState:
self._info = info
self._remove_stack_if_disabled()
self._canonicalize_ip_addr()
+ self._canonicalize_ip_prefix()
self._canonicalize_dynamic()
def _canonicalize_dynamic(self):
@@ -71,6 +72,12 @@ class IPState:
addr[InterfaceIP.ADDRESS_IP]
)
+ def _canonicalize_ip_prefix(self):
+ for addr in self.addresses:
+ addr[InterfaceIP.ADDRESS_PREFIX_LENGTH] = int(
+ addr[InterfaceIP.ADDRESS_PREFIX_LENGTH]
+ )
+
def sort_addresses(self):
self.addresses.sort(key=itemgetter(InterfaceIP.ADDRESS_IP))
diff --git a/libnmstate/schemas/operational-state.yaml b/libnmstate/schemas/operational-state.yaml
index 92bd6bd6..8526a0ab 100644
--- a/libnmstate/schemas/operational-state.yaml
+++ b/libnmstate/schemas/operational-state.yaml
@@ -615,7 +615,9 @@ definitions:
ip:
type: string
prefix-length:
- type: integer
+ type:
+ - integer
+ - string
netmask:
type: string
neighbor:
@@ -654,7 +656,9 @@ definitions:
ip:
type: string
prefix-length:
- type: integer
+ type:
+ - integer
+ - string
neighbor:
type: array
items:
--
2.41.0

View File

@ -3,8 +3,8 @@
%define libname libnmstate
Name: nmstate
Version: 1.4.4
Release: 5%{?dist}
Version: 1.4.5
Release: 1%{?dist}
Summary: Declarative network manager API
License: LGPLv2+
URL: https://github.com/%{srcname}/%{srcname}
@ -14,9 +14,6 @@ Source2: https://www.nmstate.io/nmstate.gpg
Source3: %{url}/releases/download/v%{version}/%{srcname}-vendor-%{version}.tar.xz
# Patches 0X are reserved to downstream only
Patch0: BZ_2132570-nm-reverse-IPv6-order-before-adding-them-to-setting.patch
Patch1: BZ_2203277-ip-Support-static-route-with-auto-ip.patch
Patch2: BZ_2231843-nm-do-not-attach-ovs-bridge-to-itself-when-creating-.patch
Patch3: RHEL_3358_ip-Support-treating-string-as-int-for-prefix-length.patch
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: gnupg2
@ -151,6 +148,9 @@ popd
/sbin/ldconfig
%changelog
* Thu Nov 02 2023 Gris Ge <fge@redhat.com> - 1.4.5-1
- Support DNS option. RHEL-13936
* Wed Oct 04 2023 Wen Liang <wenliang@redhat.com> - 1.4.4-5
- Support treating string as int for address prefix-length. RHEL-3358

View File

@ -1,4 +1,4 @@
SHA512 (nmstate-1.4.4.tar.gz) = 89bdf8dcd89ba84845cc48bc3d92e54d60ad48cadca978f50bd8444cc907cf92706f6e22877ee038e84bb20810715405886eb8c1426ae6a995ac34d69cbd6a3e
SHA512 (nmstate-1.4.4.tar.gz.asc) = 9015f4e4888fd41ab33f21a39882a1ebaff47bc6e44d6613fa4ea9072abea4edf2ba4539bc28bfd132da00d28e48a99140415e01dedb141127b03316d8121567
SHA512 (nmstate-vendor-1.4.4.tar.xz) = cab3932041aa52cc26adf459e61dd5b5b93837908eb677a74e173435985292b955da8152165d55884c12b300db1fb49a6c3b1d40639afb5a7803c9eaa30ee8e1
SHA512 (nmstate.gpg) = 8c0188d64660757030772096b3e836f354dbf1f3591bebd1b588aa8abef9c2e37996904e6edb8ee8797afb57237f29dd942a2ceffd24dac50af9e898c0b48c97
SHA512 (nmstate-1.4.5.tar.gz) = f75c2bcb8f2b9541e3f450e283633fd8976ad5a8591e8c13e696cff3d57dd3e61604e2c6d2392f2d089a44988e82bd80f4ea9fd6c6c81890cfc198ea7a431adc
SHA512 (nmstate-1.4.5.tar.gz.asc) = 68598d469d4399b43e5f9546aefe8497ad733b777c159653a6ec0d74f927b60cb2b1981439414acf3a9a3d675e76d916b1b3af9af23f470af2da327aebcac8e7
SHA512 (nmstate.gpg) = bfbf3620045f3c1f15eaf6877fd7407834a75d2650976f2327abd02ddb910aa34500f07a774dd17023c43dcba42a0ffc66f23cd6816fd9694acad2c5eed9e8d3
SHA512 (nmstate-vendor-1.4.5.tar.xz) = 27eb64009b6f81c96b4a884e5f616799ac163f9e5162359f21b04c82b8fe2b20be44172998bcbadc1d0299c3203325b9bea819d13b337bf2e09b7a53dbb58b6f