From 6fb27ad8cbacf488d2fcc74fb6e7beef57dea12c Mon Sep 17 00:00:00 2001
From: Nicolas KAROLAK <nicolas@karolak.fr>
Date: Wed, 16 Oct 2019 06:45:43 +0000
Subject: [PATCH] filter nmcli output with ip pattern

---
 tests/test_dns_records.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/test_dns_records.py b/tests/test_dns_records.py
index ad8358c7..5107e3ce 100755
--- a/tests/test_dns_records.py
+++ b/tests/test_dns_records.py
@@ -18,13 +18,14 @@ from envsetup import utils as u  # noqa: E402
 
 def get_dns_servers() -> set:
     servers = list()
+    ip_pattern = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
 
     if subprocess.getstatusoutput("command -v nmcli")[0] == 0:
         # network-manager
         _, output = subprocess.getstatusoutput(
             "nmcli -f all device show | grep IP4.DNS | awk '{ print $2 }'"
         )
-        servers = [l for l in output.split("\n") if l]
+        servers = [l for l in output.split("\n") if ip_pattern.match(l)]
 
     if not len(servers):
         # resolvconf
@@ -38,7 +39,6 @@ def get_dns_servers() -> set:
         _, output = subprocess.getstatusoutput("systemd-resolve --status")
         lines = [l.strip() for l in output.split("\n")]
         dns_line = False
-        ip_pattern = re.compile("\d+\.\d+\.\d+\.\d+")
         for line in lines:
             if line.startswith("DNS Servers:"):
                 dns_line = True
-- 
GitLab