get_default_dns_servers() is broken when use_rack_proxy = false

Bug #1907131 reported by Adam Beeman
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MAAS
Expired
Medium
Unassigned
3.0
Won't Fix
Undecided
Unassigned

Bug Description

So, we want to disable the use of the .maas-internal DNS domain, since we've found that sometimes it doesn't resolve for us when we're using an external proxy. I found that when the use_rack_proxy global setting is false, MAAS constructs phone-home URLs for cloud-init using IP addresses instead of using hostnames in the .maas-internal domain. But, started getting problems generating a new dhcpd.conf file after making this change, with this traceback:

2020-12-04 22:36:31 maasserver.rack_controller: [critical] Failed configuring DHCP on rack controller 'id:46'.
        Traceback (most recent call last):
          File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 1442, in gotResult
            _inlineCallbacks(r, g, deferred)
          File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 1432, in _inlineCallbacks
            deferred.errback()
          File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 500, in errback
            self._startRunCallbacks(fail)
          File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 567, in _startRunCallbacks
            self._runCallbacks()
        --- <exception caught here> ---
          File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 653, in _runCallbacks
            current.result = callback(current.result, *args, **kw)
          File "/usr/lib/python3/dist-packages/maasserver/rack_controller.py", line 278, in <lambda>
            d.addErrback(lambda f: f.trap(NoConnectionsAvailable))
          File "/usr/lib/python3/dist-packages/twisted/python/failure.py", line 359, in trap
            self.raiseException()
          File "/usr/lib/python3/dist-packages/twisted/python/failure.py", line 385, in raiseException
            raise self.value.with_traceback(self.tb)
          File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 1384, in _inlineCallbacks
            result = result.throwExceptionIntoGenerator(g)
          File "/usr/lib/python3/dist-packages/twisted/python/failure.py", line 408, in throwExceptionIntoGenerator
            return g.throw(self.type, self.value, self.tb)
          File "/usr/lib/python3/dist-packages/maasserver/dhcp.py", line 853, in configure_dhcp
            config = yield deferToDatabase(get_dhcp_configuration, rack_controller)
          File "/usr/lib/python3/dist-packages/twisted/python/threadpool.py", line 250, in inContext
            result = inContext.theWork()
          File "/usr/lib/python3/dist-packages/twisted/python/threadpool.py", line 266, in <lambda>
            inContext.theWork = lambda: context.call(ctx, func, *args, **kw)
          File "/usr/lib/python3/dist-packages/twisted/python/context.py", line 122, in callWithContext
            return self.currentContext().callWithContext(ctx, func, *args, **kw)
          File "/usr/lib/python3/dist-packages/twisted/python/context.py", line 85, in callWithContext
            return func(*args,**kw)
          File "/usr/lib/python3/dist-packages/provisioningserver/utils/twisted.py", line 885, in callInContext
            return func(*args, **kwargs)
          File "/usr/lib/python3/dist-packages/provisioningserver/utils/twisted.py", line 217, in wrapper
            result = func(*args, **kwargs)
          File "/usr/lib/python3/dist-packages/maasserver/utils/orm.py", line 737, in call_within_transaction
            return func_outside_txn(*args, **kwargs)
          File "/usr/lib/python3/dist-packages/maasserver/utils/orm.py", line 540, in retrier
            return func(*args, **kwargs)
          File "/usr/lib/python3.6/contextlib.py", line 52, in inner
            return func(*args, **kwds)
          File "/usr/lib/python3/dist-packages/maasserver/dhcp.py", line 781, in get_dhcp_configuration
            use_rack_proxy=use_rack_proxy,
          File "/usr/lib/python3/dist-packages/maasserver/dhcp.py", line 649, in get_dhcp_configure_for
            rack_controller, subnet, use_rack_proxy
          File "/usr/lib/python3/dist-packages/maasserver/dhcp.py", line 587, in get_default_dns_servers
            elif default_region_ip in dns_servers:
        builtins.TypeError: argument of type 'NoneType' is not iterable

Inspection of the code above shows a simple python type error which is easily corrected! The line in question is:
    elif default_region_ip in dns_servers:

Earlier in this function, dns_servers is set to None if get_dns_server_addresses() doesn't return anything. In my case, I'm sure there's a complicated reason why there was no answer, possibly related to some IPv6 subnets which are being discovered, though I'm not ready to support them in MAAS. Regardless, the workaround to make MAAS default to the region controller IP for DNS here is to change the buggy line above to:
    elif dns_servers and default_region_ip in dns_servers:

Revision history for this message
Adam Beeman (abeeman) wrote :

We're running MAAS 2.8.2, btw. This bug doesn't appear to exist in 2.8.1, in quite the same way, as the function is implemented a bit differently.

Revision history for this message
Adam Beeman (abeeman) wrote :

It's possible this is also happening because we have some rack switches advertising IPv6 networks via dhcp-helper and the region controller doesn't have an IPv6 address on it. Even so, the code change suggested above should be helpful to avoid the Type Error.

Alberto Donato (ack)
Changed in maas:
status: New → Triaged
importance: Undecided → Medium
milestone: none → 3.0.1
Changed in maas:
milestone: 3.0.1 → none
Revision history for this message
Adam Collard (adam-collard) wrote :

This area of code has changed quite a lot, can you still reproduce this in a recent build of MAAS (3.3.x onwards)?

Changed in maas:
status: Triaged → Incomplete
Revision history for this message
Adam Beeman (abeeman) wrote :

Unfortunately we're no longer running MAAS in the affected environments, so I'm not able to reproduce now.

Alberto Donato (ack)
Changed in maas:
status: Incomplete → New
status: New → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for MAAS because there has been no activity for 60 days.]

Changed in maas:
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.