Blame SOURCES/BZ_1850698-Fix-remove-dns-config.patch

47b589
From 54e49943b636eab9453189381e93c68050c1e423 Mon Sep 17 00:00:00 2001
47b589
From: Gris Ge <fge@redhat.com>
47b589
Date: Sun, 28 Jun 2020 20:05:08 +0800
47b589
Subject: [PATCH] dns: Fix remove dns config
47b589
47b589
Current code raise NmstateVerificationError when user not providing
47b589
the full state:
47b589
        DNS.CONFIG: {DNS.SERVER: [], DNS.SEARCH: []}
47b589
47b589
Now supporting remove static DNS config via:
47b589
    * DNS.CONFIG: {}
47b589
    * DNS.CONFIG: {DNS.SERVER: []}
47b589
    * DNS.CONFIG: {DNS.SEARCH: []}
47b589
    * DNS.CONFIG: {DNS.SERVER: [], DNS.SEARCH: []}
47b589
47b589
Test case updated for this.
47b589
47b589
Signed-off-by: Gris Ge <fge@redhat.com>
47b589
---
47b589
 libnmstate/dns.py | 12 ++++++++----
47b589
 1 file changed, 8 insertions(+), 4 deletions(-)
47b589
47b589
diff --git a/libnmstate/dns.py b/libnmstate/dns.py
47b589
index 3196fc4..1ec0d81 100644
47b589
--- a/libnmstate/dns.py
47b589
+++ b/libnmstate/dns.py
47b589
@@ -33,14 +33,16 @@ class DnsState:
47b589
 
47b589
     def __init__(self, des_dns_state, cur_dns_state):
47b589
         self._config_changed = False
47b589
-        if des_dns_state:
47b589
+        if des_dns_state is None or des_dns_state.get(DNS.CONFIG) is None:
47b589
+            # Use current config if DNS.KEY not defined or DNS.CONFIG not
47b589
+            # defined.
47b589
+            self._dns_state = cur_dns_state or {}
47b589
+        else:
47b589
             self._dns_state = des_dns_state
47b589
             self._validate()
47b589
             self._config_changed = _is_dns_config_changed(
47b589
                 des_dns_state, cur_dns_state
47b589
             )
47b589
-        else:
47b589
-            self._dns_state = cur_dns_state or {}
47b589
         self._cur_dns_state = deepcopy(cur_dns_state) if cur_dns_state else {}
47b589
 
47b589
     @property
47b589
@@ -179,7 +181,9 @@ class DnsState:
47b589
 
47b589
     def verify(self, cur_dns_state):
47b589
         cur_dns = DnsState(des_dns_state=None, cur_dns_state=cur_dns_state,)
47b589
-        if self.config != cur_dns.config:
47b589
+        if self.config.get(DNS.SERVER) != cur_dns.config.get(
47b589
+            DNS.SERVER
47b589
+        ) or self.config.get(DNS.SEARCH) != cur_dns.config.get(DNS.SEARCH):
47b589
             raise NmstateVerificationError(
47b589
                 format_desired_current_state_diff(
47b589
                     {DNS.KEY: self.config}, {DNS.KEY: cur_dns.config},
47b589
-- 
47b589
2.27.0
47b589