def test_get_host_nameservers(self, mock_open): RESOLV_CONF = ('# Generated by NetworkManager\n' 'search example.com company.net\n' 'domain example.com\n' 'nameserver 192.168.0.100\n' 'nameserver 8.8.8.8\n' 'nameserver 8.8.4.4\n') expected_nameservers = ['192.168.0.100', '8.8.8.8', '8.8.4.4'] resolv_conf_stream = six.StringIO(RESOLV_CONF) mock_open.return_value.__enter__.return_value = resolv_conf_stream resulted_nameservers = dns.get_host_nameservers() self.assertEqual(expected_nameservers, resulted_nameservers)
def test_get_host_nameservers(self, mock_open): RESOLV_CONF = ( '# Generated by NetworkManager\n' 'search example.com company.net\n' 'domain example.com\n' 'nameserver 192.168.0.100\n' 'nameserver 8.8.8.8\n' 'nameserver 8.8.4.4\n' ) expected_nameservers = ['192.168.0.100', '8.8.8.8', '8.8.4.4'] resolv_conf_stream = six.StringIO(RESOLV_CONF) mock_open.return_value.__enter__.return_value = resolv_conf_stream resulted_nameservers = dns.get_host_nameservers() self.assertEqual(expected_nameservers, resulted_nameservers)
def testGetHostNameservers(self): RESOLV_CONF = ('# Generated by NetworkManager\n' 'search example.com company.net\n' 'domain example.com\n' 'nameserver 192.168.0.100\n' 'nameserver 8.8.8.8\n' 'nameserver 8.8.4.4\n') dnss = ['192.168.0.100', '8.8.8.8', '8.8.4.4'] with namedTemporaryDir() as temp_dir: file_path = os.path.join(temp_dir, 'resolv.conf') for content in (RESOLV_CONF, RESOLV_CONF + '\n'): with MonkeyPatchScope([(dns, 'DNS_CONF_FILE', file_path)]): with open(file_path, 'w') as file_object: file_object.write(content) self.assertEqual(dns.get_host_nameservers(), dnss)
def testGetHostNameservers(self): RESOLV_CONF = ( '# Generated by NetworkManager\n' 'search example.com company.net\n' 'domain example.com\n' 'nameserver 192.168.0.100\n' 'nameserver 8.8.8.8\n' 'nameserver 8.8.4.4\n' ) dnss = ['192.168.0.100', '8.8.8.8', '8.8.4.4'] with namedTemporaryDir() as temp_dir: file_path = os.path.join(temp_dir, 'resolv.conf') for content in (RESOLV_CONF, RESOLV_CONF + '\n'): with MonkeyPatchScope([(dns, 'DNS_CONF_FILE', file_path)]): with open(file_path, 'w') as file_object: file_object.write(content) self.assertEqual( dns.get_host_nameservers(), dnss)
def test_get_host_nameservers_no_resolvconf(self, mock_open): mock_open.return_value.__enter__.side_effect = IOError() nameservers = dns.get_host_nameservers() self.assertEqual(nameservers, [])
def _translate_nameservers(attributes): nservers = dns.get_host_nameservers() if attributes['defaultRoute'] else [] attributes['nameservers'] = nservers