#9319 [tests] TestDNSResolver failures on systems without or empty /etc/resolv.conf
Closed: fixed a year ago by frenaud. Opened a year ago by slev.

Systems (e.g. sandboxes) may not have /etc/resolv.conf or this file may not contain any configured name servers. For example, It's usual setting for ALTLinux build farm.

https://man7.org/linux/man-pages/man5/resolv.conf.5.html

If this file does not exist, only the name server on the local
machine will be queried, and the search list contains the local
domain name determined from the hostname.

nameserver
...
If no nameserver entries are present, the default is to use the
name server on the local machine.

New TestDNSResolver unit tests introduced in IPA 4.9.11 fails on such system with:

[builder@localhost freeipa-4.9.11]$ make fasttest
...

====================================== FAILURES ======================================
__________________________ TestDNSResolver.test_nameservers __________________________

self = <ipapython.dnsutil.DNSResolver object at 0x7f36389fc610>
f = '/etc/resolv.conf'

    def read_resolv_conf(self, f):
        """Process *f* as a file in the /etc/resolv.conf format.  If f is
        a ``str``, it is used as the name of the file to open; otherwise it
        is treated as the file itself.

        Interprets the following items:

        - nameserver - name server IP address

        - domain - local domain name

        - search - search list for host-name lookup

        - options - supported options are rotate, timeout, edns0, and ndots

        """

        with contextlib.ExitStack() as stack:
            if isinstance(f, str):
                try:
>                   f = stack.enter_context(open(f))
E                   FileNotFoundError: [Errno 2] No such file or directory: '/etc/resolv.conf'

/usr/lib/python3/site-packages/dns/resolver.py:806: FileNotFoundError

During handling of the above exception, another exception occurred:

self = <ipatests.test_ipapython.test_dnsutil.TestDNSResolver object at 0x7f363e41a7a0>

    def test_nameservers(self):
>       res = dnsutil.DNSResolver()

test_ipapython/test_dnsutil.py:108: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../ipapython/dnsutil.py:90: in __init__
    super().__init__(*args, **kwargs)
/usr/lib/python3/site-packages/dns/resolver.py:758: in __init__
    self.read_resolv_conf(filename)
../ipapython/dnsutil.py:138: in read_resolv_conf
    super().read_resolv_conf(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ipapython.dnsutil.DNSResolver object at 0x7f36389fc610>
f = '/etc/resolv.conf'

    def read_resolv_conf(self, f):
        """Process *f* as a file in the /etc/resolv.conf format.  If f is
        a ``str``, it is used as the name of the file to open; otherwise it
        is treated as the file itself.

        Interprets the following items:

        - nameserver - name server IP address

        - domain - local domain name

        - search - search list for host-name lookup

        - options - supported options are rotate, timeout, edns0, and ndots

        """

        with contextlib.ExitStack() as stack:
            if isinstance(f, str):
                try:
                    f = stack.enter_context(open(f))
                except OSError:
                    # /etc/resolv.conf doesn't exist, can't be read, etc.
>                   raise NoResolverConfiguration(f'cannot open {f}')
E                   dns.resolver.NoResolverConfiguration: cannot open /etc/resolv.conf

/usr/lib/python3/site-packages/dns/resolver.py:809: NoResolverConfiguration

...

FAILED test_ipapython/test_dnsutil.py::TestDNSResolver::test_nameservers - dns.resolver.NoResolverConfiguration: cannot open /etc/resolv.conf
FAILED test_ipapython/test_dnsutil.py::TestDNSResolver::test_nameservers_with_ports - dns.resolver.NoResolverConfiguration: cannot open /etc/resolv.conf
FAILED test_ipapython/test_dnsutil.py::TestDNSResolver::test_nameservers_with_bad_ports - dns.resolver.NoResolverConfiguration: cannot open /etc/resolv.conf

dnspython's Resolver fails to read /etc/resolv.conf or report missing name servers.
Actually TestDNSResolver unit tests check only customizednameservers property (setter and getter) and should not depend on existence of /etc/resolv.conf.

Resolver accepts configure option.
https://dnspython.readthedocs.io/en/latest/resolver-class.html

configure, a bool. If True (the default), the resolver instance is configured in the normal
fashion for the operating system the resolver is running on. (I.e. by reading a
/etc/resolv.conf file on POSIX systems and from the registry on Windows systems.)


Metadata Update from @slev:
- Issue assigned to slev

a year ago

master:

  • 2996cc8 tests: Configure DNSResolver as platform agnostic resolver

ipa-4-9:

  • e6f1b36 tests: Configure DNSResolver as platform agnostic resolver

ipa-4-10:

  • d662b12 tests: Configure DNSResolver as platform agnostic resolver

Metadata Update from @frenaud:
- Issue close_status updated to: fixed
- Issue status updated to: Closed (was: Open)

a year ago

Login to comment on this ticket.

Metadata