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 _render_dns(network_state, existing_dns_path=None): # skip writing resolv.conf if network_state doesn't include any input. if not any([len(network_state.dns_nameservers), len(network_state.dns_searchdomains)]): return None content = resolv_conf.ResolvConf("") if existing_dns_path and os.path.isfile(existing_dns_path): content = resolv_conf.ResolvConf(util.load_file(existing_dns_path)) for nameserver in network_state.dns_nameservers: content.add_nameserver(nameserver) for searchdomain in network_state.dns_searchdomains: content.add_search_domain(searchdomain) header = _make_header(';') content_str = str(content) if not content_str.startswith(header): content_str = header + '\n' + content_str return content_str
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.assertEquals(len(rp.nameservers), 3) rp.add_nameserver('10.2') self.assertRaises(ValueError, rp.add_nameserver, '10.3') self.assertNotIn('10.3', rp.nameservers)
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.assertEquals(len(rp.search_domains), 3) rp.add_search_domain('bbb2.y.com') self.assertEquals(len(rp.search_domains), 4) rp.add_search_domain('bbb3.y.com') self.assertEquals(len(rp.search_domains), 5) rp.add_search_domain('bbb4.y.com') self.assertEquals(len(rp.search_domains), 6) self.assertRaises(ValueError, rp.add_search_domain, 'bbb5.y.com') self.assertEquals(len(rp.search_domains), 6)
def test_parse_same(self): rp = resolv_conf.ResolvConf(BASE_RESOLVE) rp_r = str(rp).strip() self.assertEquals(BASE_RESOLVE, rp_r)