Fix use case on purging DNS option

Resolves: RHEL-13936

Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
Gris Ge 2023-11-15 12:16:30 +08:00
parent dbb3775b35
commit d20c308040
2 changed files with 162 additions and 1 deletions

View File

@ -0,0 +1,157 @@
From c95e26154cfe105faedb6fe6187e89da658e6d02 Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Tue, 14 Nov 2023 16:08:35 +0800
Subject: [PATCH 1/2] dns: Fix DNS option `ndots`, `timeout` and `attempts`
The `ndots`, `timeout` and `attempts` DNS options are allowed to
hold a integer value in the format of `<opt_name>:<int>`. Previously,
nmstate is treating them as invalid DNS option. This patch fix it.
Now this YAML is supported:
```yml
dns-resolver:
config:
options:
- rotate
- ndots:9
```
Integration test cases included.
Signed-off-by: Gris Ge <fge@redhat.com>
---
libnmstate/dns.py | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/libnmstate/dns.py b/libnmstate/dns.py
index f792b896..5bb512e8 100644
--- a/libnmstate/dns.py
+++ b/libnmstate/dns.py
@@ -19,14 +19,12 @@ EMPTY_DNS = {
REMOVE_DNS_CONFIG = {DNS.CONFIG: EMPTY_DNS}
-SUPPORTED_DNS_OPTIONS = [
- "attempts",
+SUPPORTED_DNS_OPTS_NO_VALUE = [
"debug",
"edns0",
"inet6",
"ip6-bytestring",
"ip6-dotint",
- "ndots",
"no-aaaa",
"no-check-names",
"no-ip6-dotint",
@@ -35,11 +33,16 @@ SUPPORTED_DNS_OPTIONS = [
"rotate",
"single-request",
"single-request-reopen",
- "timeout",
"trust-ad",
"use-vc",
]
+SUPPORTED_DNS_OPTS_WITH_VALUE = [
+ "ndots",
+ "timeout",
+ "attempts",
+]
+
class DnsState:
PRIORITY_METADATA = "_priority"
@@ -73,10 +76,24 @@ class DnsState:
def _canonicalize_dns_options(self):
for opt in self.config_options:
- if opt not in SUPPORTED_DNS_OPTIONS:
+ if opt.find(":") > 0:
+ opt = opt[: opt.find(":")]
+ if opt not in SUPPORTED_DNS_OPTS_WITH_VALUE:
+ raise NmstateValueError(
+ "Option '{}' is not supported to hold "
+ "a value, only support these without "
+ "value: {} and these with values: {}:n",
+ opt,
+ ", ".join(SUPPORTED_DNS_OPTS_NO_VALUE),
+ ":n, ".join(SUPPORTED_DNS_OPTS_WITH_VALUE),
+ )
+ elif opt not in SUPPORTED_DNS_OPTS_NO_VALUE:
raise NmstateValueError(
- f"Unsupported DNS option {opt}, only support: "
- f"{', '.join(SUPPORTED_DNS_OPTIONS)}",
+ "Option '{}' is not supported, only support these "
+ "without value: {} and these with values: {}:n",
+ opt,
+ ", ".join(SUPPORTED_DNS_OPTS_NO_VALUE),
+ ":n, ".join(SUPPORTED_DNS_OPTS_WITH_VALUE),
)
@property
--
2.42.1
From af07271ec5044ec092a3b66c0955636819ccde04 Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Tue, 14 Nov 2023 16:16:53 +0800
Subject: [PATCH 2/2] dns: Fix purging DNS config
When user desires:
```yml
---
dns-resolver:
config:
search: []
```
It means user want to remove all search but preserve servers and
options, current nmstate incorrectly treat this as purge also.
This patch only treat these two as purge.
```yml
dns-resolver:
config: {}
```
and
```yml
dns-resolver:
config:
server: []
search: []
options: []
```
Integration test cases included.
Signed-off-by: Gris Ge <fge@redhat.com>
---
libnmstate/nm/dns.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/libnmstate/nm/dns.py b/libnmstate/nm/dns.py
index 60ebbba7..b811fdb2 100644
--- a/libnmstate/nm/dns.py
+++ b/libnmstate/nm/dns.py
@@ -158,7 +158,11 @@ def get_dns_config_iface_names(acs_and_ipv4_profiles, acs_and_ipv6_profiles):
for nm_ac, ip_profile in chain(
acs_and_ipv6_profiles, acs_and_ipv4_profiles
):
- if ip_profile.props.dns or ip_profile.props.dns_search:
+ if (
+ ip_profile.props.dns
+ or ip_profile.props.dns_search
+ or ip_profile.props.dns_options
+ ):
try:
iface_name = nm_ac.get_devices()[0].get_iface()
iface_names.append(iface_name)
--
2.42.1

View File

@ -4,7 +4,7 @@
Name: nmstate
Version: 1.4.5
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Declarative network manager API
License: LGPLv2+
URL: https://github.com/%{srcname}/%{srcname}
@ -14,6 +14,7 @@ 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
Patch10: RHEL-13936-dns-opt-fix.patch
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: gnupg2
@ -148,6 +149,9 @@ popd
/sbin/ldconfig
%changelog
* Wed Nov 15 2023 Gris Ge <fge@redhat.com> - 1.4.5-2
- Fix use case on purging DNS option. RHEL-13936
* Thu Nov 02 2023 Gris Ge <fge@redhat.com> - 1.4.5-1
- Support DNS option. RHEL-13936