Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
    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)
Exemple #4
0
    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)
Exemple #5
0
    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, [])
Exemple #6
0
def _translate_nameservers(attributes):
    nservers = dns.get_host_nameservers() if attributes['defaultRoute'] else []
    attributes['nameservers'] = nservers
Exemple #7
0
def _translate_nameservers(attributes):
    nservers = dns.get_host_nameservers() if attributes['defaultRoute'] else []
    attributes['nameservers'] = nservers
Exemple #8
0
    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, [])