cannot delete already existing subnets

Bug #1702527 reported by Greg Lutostanski
30
This bug affects 6 people
Affects Status Importance Assigned to Milestone
MAAS
Fix Released
High
Mike Pontillo
2.2
Won't Fix
High
Unassigned
2.3
Fix Released
High
Mike Pontillo

Bug Description

I cannot delete an already existing subnet from the ui nor the api.

This is only for subnets created automatically during maas installation. I can delete those I create after maas is all the way up.

I see this on version: 2.2.0 (bzr6057-snap)

To reproduce:
snap install maas --devmode
sudo maas init #and complete setup
navigate to http://10.48.0.169:5240/MAAS/#/networks?by=fabric
click on a subnet and try to delete it.

expected outcome:
subnet is deleted

actual outcome:
An error is displayed saying 'Subnet matching query does not exist.'

I also attempted to delete these subnets using the branch from https://github.com/maas/python-libmaas/pull/112 and got the same error.

Any help would be appreciated.

Thanks!

Related branches

Revision history for this message
Andres Rodriguez (andreserl) wrote :

Hi Greg,

Have you tried deleting the subnet via the CLI ? If not, can you please do so and provide your results here? Also please provide:

- Exact way you are trying to delete a subnet (seem via libmaas)
- Logs (/var/snao/common/logs/*) IIRC.

Thanks.

Changed in maas:
status: New → Opinion
status: Opinion → Incomplete
Revision history for this message
Greg Lutostanski (lutostag) wrote :
Download full text (3.2 KiB)

2017-07-05 17:52:18 maasserver.websockets.protocol: [critical] Error on request (33) subnet.delete: Subnet matching query does not exist.

Traceback (most recent call last):
  File "/snap/maas/91/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/snap/maas/91/lib/python3.5/site-packages/provisioningserver/utils/twisted.py", line 842, in worker
    return target()
  File "/snap/maas/91/lib/python3.5/site-packages/twisted/_threads/_threadworker.py", line 46, in work
    task()
  File "/snap/maas/91/lib/python3.5/site-packages/twisted/_threads/_team.py", line 190, in doWork
    task()
--- <exception caught here> ---
  File "/snap/maas/91/lib/python3.5/site-packages/twisted/python/threadpool.py", line 246, in inContext
    result = inContext.theWork()
  File "/snap/maas/91/lib/python3.5/site-packages/twisted/python/threadpool.py", line 262, in <lambda>
    inContext.theWork = lambda: context.call(ctx, func, *args, **kw)
  File "/snap/maas/91/lib/python3.5/site-packages/twisted/python/context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/snap/maas/91/lib/python3.5/site-packages/twisted/python/context.py", line 81, in callWithContext
    return func(*args,**kw)
  File "/snap/maas/91/lib/python3.5/site-packages/provisioningserver/utils/twisted.py", line 875, in callInContext
    return func(*args, **kwargs)
  File "/snap/maas/91/lib/python3.5/site-packages/provisioningserver/utils/twisted.py", line 232, in wrapper
    result = func(*args, **kwargs)
  File "/snap/maas/91/lib/python3.5/site-packages/maasserver/utils/orm.py", line 686, in call_within_transaction
    return func_outside_txn(*args, **kwargs)
  File "/snap/maas/91/lib/python3.5/site-packages/maasserver/utils/orm.py", line 504, in retrier
    return func(*args, **kwargs)
  File "/snap/maas/91/usr/lib/python3.5/contextlib.py", line 30, in inner
    return func(*args, **kwds)
  File "/snap/maas/91/lib/python3.5/site-packages/maasserver/websockets/handlers/subnet.py", line 97, in delete
    subnet.delete()
  File "/snap/maas/91/lib/python3.5/site-packages/maasserver/models/subnet.py", line 471, in delete
    super().delete(*args, **kwargs)
  File "/snap/maas/91/lib/python3.5/site-packages/django/db/models/base.py", line 872, in delete
    collector.delete()
  File "/snap/maas/91/lib/python3.5/site-packages/django/db/models/deletion.py", line 314, in delete
    sender=model, instance=obj, using=self.using
  File "/snap/maas/91/lib/python3.5/site-packages/django/dispatch/dispatcher.py", line 201, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/snap/maas/91/lib/python3.5/site-packages/maasserver/models/signals/staticipaddress.py", line 151, in post_delete_check_range_utilization
    if instance.subnet is None:
  File "/snap/maas/91/lib/python3.5/site-packages/django/db/models/fields/related.py", line 602, in __get__
    rel_obj = qs.get()
  File "/snap/maas/91/lib/python3.5/site-packages/django/db/models/query.py", line 334, in get
    self.model._meta.object_name
maasserver.models.subnet.DoesNotExist: Subnet matching query does not exist.

Is ...

Read more...

tags: added: cdo-q
tags: added: cdo-qa
removed: cdo-q
Revision history for this message
Greg Lutostanski (lutostag) wrote :

Or as a paste to be a bit more readable... https://paste.ubuntu.com/25026706/

Revision history for this message
Greg Lutostanski (lutostag) wrote :
Revision history for this message
Greg Lutostanski (lutostag) wrote :

I am using the code from here for a minimal reproduction: https://paste.ubuntu.com/25026933/

Changed in maas:
status: Incomplete → New
Changed in maas:
milestone: none → 2.3.0
Revision history for this message
Jason Hobbs (jason-hobbs) wrote :

for some reason, you delete subnets by cidr, not id:

http://paste.ubuntu.com/25091374/

Revision history for this message
Mike Pontillo (mpontillo) wrote :

This DoesNotExist exception seems to be occurring due to Django's behavior of implicitly fetching a related object. In this case, we're trying to recalculate the usage of the subnet when the *IP address* that existed on the now-delete subnet is removed. Django believes there to be a subnet related to the IP address, since the subnet is not None, and tries to fetch it. But since it has been deleted, this race condition occurs.

I feel like this is arguably a bug in Django, but we'll have to handle it ourselves.

Revision history for this message
Mike Pontillo (mpontillo) wrote :

@jhobbs, you should be able to delete the subnet by its `id`, too, for the record.

Changed in maas:
status: New → Triaged
importance: Undecided → High
assignee: nobody → Mike Pontillo (mpontillo)
Revision history for this message
Greg Lutostanski (lutostag) wrote :

Worked around it by making a temporary fabric and moving subnets onto that fabric's default vlan. Then updating in place rather than deleting/creating.

https://git.launchpad.net/~lutostag/cpe-foundation/commit/?id=72022fa1db17f3baa1ee8b6fee2b5947ca4210db

So not a blocker for us at the moment.

tags: added: foundations-engine
tags: added: internal
tags: added: canonical-bootstack
Revision history for this message
Peter Sabaini (peter-sabaini) wrote :

For the record, I'm seeing this as well but with a subnet we created ourselves. I'm getting

maasserver.models.subnet.DoesNotExist: Subnet matching query does not exist.

both when deleting via ID and CIDR

Details: http://paste.ubuntu.com/25904255/

Changed in maas:
milestone: 2.3.0 → 2.3.x
Revision history for this message
Omar Lara (elchito) wrote :

For additional information, I have encountered the same behaviour in 2.3.0 (6434-gd354690-0ubuntu1~16.04.1)

https://paste.ubuntu.com/26135301/

Changed in maas:
status: Triaged → Fix Committed
Changed in maas:
milestone: 2.3.x → 2.4.0alpha1
Changed in maas:
status: Fix Committed → Fix Released
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.