[Fix] Patch MaaS recursion limit issue

- Bug 1729715 causes a regiond exception due to infinite
  recursion. Apply a proposed patch to attempt a fix.

Change-Id: I025cdddfa7f6786e327987e2a245980a54d5ffd3
This commit is contained in:
Scott Hussey 2018-04-10 11:36:41 -05:00
parent 57e8557eb1
commit 524188787c
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,63 @@
=== modified file 'src/maasserver/models/signals/interfaces.py'
--- src/maasserver/models/signals/interfaces.py 2016-07-30 01:17:54 +0000
+++ src/maasserver/models/signals/interfaces.py 2016-09-10 07:09:35 +0000
@@ -45,6 +45,28 @@
signals = SignalsManager()
+class InterfaceVisitingThreadLocal(threading.local):
+ """Since infinite recursion could occur in an arbitrary interface
+ hierarchy, use thread-local storage to ensure that each interface is only
+ visited once.
+ """
+ def __init__(self):
+ super().__init__()
+ self.visiting = set()
+
+enabled_or_disabled_thread_local = InterfaceVisitingThreadLocal()
+
+
+def ensure_link_up(interface):
+ visiting = enabled_or_disabled_thread_local.visiting
+ if interface.id not in visiting:
+ try:
+ visiting.add(interface.id)
+ interface.ensure_link_up()
+ finally:
+ visiting.discard(interface.id)
+
+
def interface_enabled_or_disabled(instance, old_values, **kwargs):
"""When an interface is enabled be sure at minimum a LINK_UP is created.
When an interface is disabled make sure that all its links are removed,
@@ -53,9 +75,10 @@
return
if instance.is_enabled():
# Make sure it has a LINK_UP link, and for its children.
- instance.ensure_link_up()
+ ensure_link_up(instance)
for rel in instance.children_relationships.all():
- rel.child.ensure_link_up()
+ ensure_link_up(rel.child)
+
else:
# Was disabled. Remove the links.
for ip_address in instance.ip_addresses.exclude(
@@ -140,16 +163,7 @@
klass, ['params'], delete=False)
-class InterfaceUpdateParentsThreadLocal(threading.local):
- """Since infinite recursion could occur in an arbitrary interface
- hierarchy, use thread-local stroage to ensure that each interface is only
- visited once.
- """
- def __init__(self):
- super().__init__()
- self.visiting = set()
-
-update_parents_thread_local = InterfaceUpdateParentsThreadLocal()
+update_parents_thread_local = InterfaceVisitingThreadLocal()
def update_interface_parents(sender, instance, created, **kwargs):

View File

@ -54,9 +54,11 @@ RUN apt-get download maas-region-controller=$MAAS_VERSION && \
COPY 2.3_nat_fix.patch /tmp/2.3_nat_fix.patch
COPY 2.3_proxy_port.patch /tmp/2.3_proxy_port.patch
COPY 2.3_route.patch /tmp/2.3_route.patch
COPY 2.3_recursion_fix.patch /tmp/2.3_recursion_fix.patch
RUN cd /usr/lib/python3/dist-packages/maasserver/utils && patch __init__.py < /tmp/2.3_nat_fix.patch
RUN cd /usr/lib/python3/dist-packages/maasserver && patch compose_preseed.py < /tmp/2.3_proxy_port.patch
RUN cd /usr/lib/python3/dist-packages/maasserver && patch preseed_network.py < /tmp/2.3_route.patch
RUN cd /usr/lib/python3/dist-packages/maasserver/models/signals && patch interfaces.py < /tmp/2.3_recursion_fix.patch
# initalize systemd
CMD ["/sbin/init"]