Delete machine, can't add machine due to 'duplicate tag'

Potential bug found. With the recent MaaS snap updates 3.2.0 to 3.2.2 (currently on: 3.2.2-12005-g.f0f96fa78) within the past few days, I ended up deleting machine we used as a LXD host and wanted to re-add the machine (again as LXD host). Unfortunately I was unable to and after some digging in the regiond.logs, I found the error:

2022-08-09 17:23:50 metadataserver.api_twisted: [critical] Error saving VM host: {'name': ['Tag with this Name already exists.']}
	Traceback (most recent call last):
	  File "/snap/maas/23178/lib/python3.8/site-packages/maasserver/utils/orm.py", line 756, in call_within_transaction
	    return func_outside_txn(*args, **kwargs)
	  File "/snap/maas/23178/lib/python3.8/site-packages/maasserver/utils/orm.py", line 559, in retrier
	    return func(*args, **kwargs)
	  File "/usr/lib/python3.8/contextlib.py", line 75, in inner
	    return func(*args, **kwds)
	  File "/snap/maas/23178/lib/python3.8/site-packages/metadataserver/api_twisted.py", line 472, in _processMessage
	    _create_vmhost_for_deployment(node)
	--- <exception caught here> ---
	  File "/snap/maas/23178/lib/python3.8/site-packages/metadataserver/api_twisted.py", line 251, in _create_vmhost_for_deployment
	    pod = pod_form.save()
	  File "/snap/maas/23178/lib/python3.8/site-packages/maasserver/forms/pods.py", line 306, in save
	    tag, _ = Tag.objects.get_or_create(
	  File "/snap/maas/23178/usr/lib/python3/dist-packages/django/db/models/manager.py", line 82, in manager_method
	    return getattr(self.get_queryset(), name)(*args, **kwargs)
	  File "/snap/maas/23178/usr/lib/python3/dist-packages/django/db/models/query.py", line 541, in get_or_create
	    return self._create_object_from_params(kwargs, params)
	  File "/snap/maas/23178/usr/lib/python3/dist-packages/django/db/models/query.py", line 575, in _create_object_from_params
	    obj = self.create(**params)
	  File "/snap/maas/23178/usr/lib/python3/dist-packages/django/db/models/query.py", line 422, in create
	    obj.save(force_insert=True, using=self.db)
	  File "/snap/maas/23178/lib/python3.8/site-packages/maasserver/models/tag.py", line 143, in save
	    super().save(*args, **kwargs)
	  File "/snap/maas/23178/lib/python3.8/site-packages/maasserver/models/cleansave.py", line 182, in save
	    self.validate_unique(exclude=[self._meta.pk.name])
	  File "/snap/maas/23178/usr/lib/python3/dist-packages/django/db/models/base.py", line 987, in validate_unique
	    raise ValidationError(errors)
	django.core.exceptions.ValidationError: {'name': ['Tag with this Name already exists.']}

I would delete it, boot the server back up, set the IPMI/power settings, name it (same as before), set network settings, and commission it. Then I would try to deploy it. The deployment would fail with the error above. After doing this several times trying different commissioning OS/kernels, deployment options (KVM host, or not), OS’s, etc, I tried renaming the host from r5-630-39 to r5-630-39a where it then passed deployment. I’m guessing that there is random bits of info not being deleted in the database causing this error.

Hi @james-o-benson,

this certainly looks like a bug. Could you please file a bug report at LaunchPad?

Did some further testing and found it only fails when I select the KVM option. I’ve submitted a ticket:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.