summaryrefslogtreecommitdiff
path: root/tests/unittests/distros/test_resolv.py
diff options
context:
space:
mode:
authorzdc <zdc@users.noreply.github.com>2022-03-26 15:41:59 +0200
committerGitHub <noreply@github.com>2022-03-26 15:41:59 +0200
commitaa60d48c2711cdcd9f88a4e5c77379adb0408231 (patch)
tree349631a02467dae0158f6f663cc8aa8537974a97 /tests/unittests/distros/test_resolv.py
parent5c4b3943343a85fbe517e5ec1fc670b3a8566b4b (diff)
parent31448cccedd8f841fb3ac7d0f2e3cdefe08a53ba (diff)
downloadvyos-cloud-init-aa60d48c2711cdcd9f88a4e5c77379adb0408231.tar.gz
vyos-cloud-init-aa60d48c2711cdcd9f88a4e5c77379adb0408231.zip
Merge pull request #51 from zdc/T2117-sagitta-22.1
T2117: Cloud-init updated to 22.1
Diffstat (limited to 'tests/unittests/distros/test_resolv.py')
-rw-r--r--tests/unittests/distros/test_resolv.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/unittests/distros/test_resolv.py b/tests/unittests/distros/test_resolv.py
new file mode 100644
index 00000000..65e78101
--- /dev/null
+++ b/tests/unittests/distros/test_resolv.py
@@ -0,0 +1,64 @@
+# This file is part of cloud-init. See LICENSE file for license information.
+
+import re
+
+from cloudinit.distros.parsers import resolv_conf
+from tests.unittests.helpers import TestCase
+
+BASE_RESOLVE = """
+; generated by /sbin/dhclient-script
+search blah.yahoo.com yahoo.com
+nameserver 10.15.44.14
+nameserver 10.15.30.92
+"""
+BASE_RESOLVE = BASE_RESOLVE.strip()
+
+
+class TestResolvHelper(TestCase):
+ def test_parse_same(self):
+ rp = resolv_conf.ResolvConf(BASE_RESOLVE)
+ rp_r = str(rp).strip()
+ self.assertEqual(BASE_RESOLVE, rp_r)
+
+ def test_local_domain(self):
+ rp = resolv_conf.ResolvConf(BASE_RESOLVE)
+ self.assertIsNone(rp.local_domain)
+
+ rp.local_domain = "bob"
+ self.assertEqual("bob", rp.local_domain)
+ self.assertIn("domain bob", str(rp))
+
+ def test_nameservers(self):
+ rp = resolv_conf.ResolvConf(BASE_RESOLVE)
+ self.assertIn("10.15.44.14", rp.nameservers)
+ self.assertIn("10.15.30.92", rp.nameservers)
+ rp.add_nameserver("10.2")
+ self.assertIn("10.2", rp.nameservers)
+ self.assertIn("nameserver 10.2", str(rp))
+ self.assertNotIn("10.3", rp.nameservers)
+ self.assertEqual(len(rp.nameservers), 3)
+ rp.add_nameserver("10.2")
+ rp.add_nameserver("10.3")
+ self.assertNotIn("10.3", rp.nameservers)
+
+ def test_search_domains(self):
+ rp = resolv_conf.ResolvConf(BASE_RESOLVE)
+ self.assertIn("yahoo.com", rp.search_domains)
+ self.assertIn("blah.yahoo.com", rp.search_domains)
+ rp.add_search_domain("bbb.y.com")
+ self.assertIn("bbb.y.com", rp.search_domains)
+ self.assertTrue(re.search(r"search(.*)bbb.y.com(.*)", str(rp)))
+ self.assertIn("bbb.y.com", rp.search_domains)
+ rp.add_search_domain("bbb.y.com")
+ self.assertEqual(len(rp.search_domains), 3)
+ rp.add_search_domain("bbb2.y.com")
+ self.assertEqual(len(rp.search_domains), 4)
+ rp.add_search_domain("bbb3.y.com")
+ self.assertEqual(len(rp.search_domains), 5)
+ rp.add_search_domain("bbb4.y.com")
+ self.assertEqual(len(rp.search_domains), 6)
+ self.assertRaises(ValueError, rp.add_search_domain, "bbb5.y.com")
+ self.assertEqual(len(rp.search_domains), 6)
+
+
+# vi: ts=4 expandtab