Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when creating Virtual Chassis #1977

Closed
andyshinn opened this issue Mar 21, 2018 · 12 comments
Closed

Error when creating Virtual Chassis #1977

andyshinn opened this issue Mar 21, 2018 · 12 comments
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@andyshinn
Copy link

Issue type

[ ] Feature request
[x] Bug report
[ ] Documentation

Environment

  • Python version: 3.6.4
  • NetBox version: v2.3.1

Running as a Docker container (built myself from v2.3.1 tag). DEBUG is set True.

Description

I am getting an error trying to create a virtual chassis for two devices. I am able to make virtual chassis for other devices so it seems to be specific to these two. I initially added these two devices to a Virtual Chassis cluster by mistake before I realized the correct way to create a Virtual Chassis.

Steps:

  1. Navigate to Devices view.
  2. Check the box next to both devices.
  3. On bottom of page click Create Virtual Chassis.
  4. Set Master and Position for each and click Create.

The below error is then shown:

There was a problem with your request. Please contact an administrator.

The complete exception is provided below:

<class 'django.db.utils.IntegrityError'>

duplicate key value violates unique constraint "dcim_device_virtual_chassis_id_vc_position_efea7133_uniq"
DETAIL:  Key (virtual_chassis_id, vc_position)=(5, 1) already exists.

Request Method: | POST
-- | --
http://lb.netbox.staging.keenai.com:8000/dcim/virtual-chassis/add/
1.11.11
IntegrityError
duplicate key value violates unique constraint "dcim_device_virtual_chassis_id_vc_position_efea7133_uniq" DETAIL:  Key (virtual_chassis_id, vc_position)=(8, 1) already exists.
/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py in execute, line 64
/usr/local/bin/python
3.6.4
['/usr/src/app/netbox',  '/usr/local/lib/python36.zip',  '/usr/local/lib/python3.6',  '/usr/local/lib/python3.6/lib-dynload',  '/usr/local/lib/python3.6/site-packages']

Traceback:

Environment:


Request Method: POST
Request URL: http://lb.netbox.staging.mydomain.com:8000/dcim/virtual-chassis/add/

Django Version: 1.11.11
Python Version: 3.6.4
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'corsheaders',
 'debug_toolbar',
 'django_filters',
 'django_tables2',
 'mptt',
 'rest_framework',
 'rest_framework_swagger',
 'timezone_field',
 'circuits',
 'dcim',
 'ipam',
 'extras',
 'secrets',
 'tenancy',
 'users',
 'utilities',
 'virtualization')
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'utilities.middleware.ExceptionHandlingMiddleware',
 'utilities.middleware.LoginRequiredMiddleware',
 'utilities.middleware.APIVersionMiddleware')



Traceback:

File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

The above exception (duplicate key value violates unique constraint "dcim_device_virtual_chassis_id_vc_position_efea7133_uniq"
DETAIL:  Key (virtual_chassis_id, vc_position)=(8, 1) already exists.
) was the direct cause of the following exception:

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/mixins.py" in dispatch
  92.         return super(PermissionRequiredMixin, self).dispatch(request, *args, **kwargs)

File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch
  88.         return handler(request, *args, **kwargs)

File "/usr/src/app/netbox/dcim/views.py" in post
  2114.                         device.save()

File "/usr/src/app/netbox/dcim/models.py" in save
  1046.         super(Device, self).save(*args, **kwargs)

File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py" in save
  808.                        force_update=force_update, update_fields=update_fields)

File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py" in save_base
  838.             updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)

File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py" in _save_table
  905.                                       forced_update)

File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py" in _do_update
  955.         return filtered._update(values) > 0

File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py" in _update
  664.         return query.get_compiler(self.db).execute_sql(CURSOR)

File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
  1204.         cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)

File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
  899.             raise original_exception

File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
  889.             cursor.execute(sql, params)

File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  79.             return super(CursorDebugWrapper, self).execute(sql, params)

File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

File "/usr/local/lib/python3.6/site-packages/django/db/utils.py" in __exit__
  94.                 six.reraise(dj_exc_type, dj_exc_value, traceback)

File "/usr/local/lib/python3.6/site-packages/django/utils/six.py" in reraise
  685.             raise value.with_traceback(tb)

File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

Exception Type: IntegrityError at /dcim/virtual-chassis/add/
Exception Value: duplicate key value violates unique constraint "dcim_device_virtual_chassis_id_vc_position_efea7133_uniq"
DETAIL:  Key (virtual_chassis_id, vc_position)=(8, 1) already exists.

I don't see anywhere I can remove the devices from another cluster or virtual chassis. Possible bug or did I do something wrong?

@jeremystretch
Copy link
Member

When you view either device individually, do you see a virtual chassis box with an option to delete the virtual chassis?

If not, try assigning the devices to different positions. I'm not sure how it managed to get out of whack.

If that doesn't work, you can manually clear any virtual chassis associations from the devices via the command shell. You'll need to grab the numeric ID for each device (check the URL for each).

$ ./manage.py nbshell
### NetBox interactive shell (jstretch-workstation)
### Python 3.5.2 | Django 1.11.10 | NetBox 2.3.2-dev
### lsmodels() will show available models. Use help(<model>) for more info.
>>> Device.objects.filter(pk__in=[<id1>, <id2>, ...]).update(virtual_chassis=None, vc_position=None, vc_priority=None)

@jeremystretch jeremystretch added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Mar 21, 2018
@andyshinn
Copy link
Author

There is no Virtual Chassis box for either device.

I also tried clearing the association:

root@9fb11a851748:/usr/src/app# python netbox/manage.py nbshell
### NetBox interactive shell (9fb11a851748)
### Python 3.6.4 | Django 1.11.11 | NetBox 2.3.1
### lsmodels() will show available models. Use help(<model>) for more info.
>>> Device.objects.filter(pk__in=[6,7]).update(virtual_chassis=None, vc_position=None, vc_priority=None)
2

But the same error occurs. How can I check out what dcim_device_virtual_chassis_id_vc_position_efea7133_uniq contains?

@jeremystretch
Copy link
Member

There is probably at least one other device assigned to the virtual chassis. Device.objects.exclude(virtual_chassis=None) will return a queryset of all devices which are part of a virtual chassis.

@andyshinn
Copy link
Author

There were 4 other devices (for two other virtual chassis that I created). I removed those virtual chassis as well. Still the same issue. Is there a way to remove dcim_device_virtual_chassis_id_vc_position_efea7133_uniq?

@andyshinn
Copy link
Author

Very strange, I was able to create with different positions and then after edit the positions back to normal. Not quite sure if it is a bug or not. Feel free to close if it doesn't seem like a bug as I can't figure out how to reproduce.

@emarton77
Copy link

Hello,
I was able to replicate this. Please note this was the first Virtual chassis I created.
This was done on Netbox 2.3.2

  • created the devices with the steps from the first post
  • from devices selected the 2 devices and create virtual chassis
  • selected master and added the possition
  • Virtual chassis was created fine, i was seeing the virtual chassis box when viewing each device individually, however on the master device interfaces were doubled (probably should list the interfaces from both devices). For me bc they had the same name was confusing so wanted to delete the virtual chassis and create it back with secondary device renamed interfaces.
  • deleted Virtual chassis, nothing is showing up under Devices > Virtual Chassis
  • Trying to create the Virtual chassis again I get this error:
<class 'django.db.utils.IntegrityError'>
duplicate key value violates unique constraint "dcim_device_virtual_chassis_id_vc_position_efea7133_uniq"
DETAIL:  Key (virtual_chassis_id, vc_position)=(5, 1) already exists.

Also tried these, still getting the same error afterwards:

>>> Device.objects.filter(pk__in=[287,288]).update(virtual_chassis=None, vc_position=None, vc_priority=None)
2
>>> Device.objects.exclude(virtual_chassis=None)
<QuerySet []>

I was able to create it with different priority and edit it afterwards.

@andyshinn
Copy link
Author

I will note that it was also only on the first virtual chassis that I created. I didn't have the issue on subsequent ones.

@lowpolyfire
Copy link

I have been able to reproduce the error in version 2.3.6.

It's when I create a Virtual Chassis with 2 Devices and I specify 0 as the master's position. When I use positions 1 and 2, it works.

@jeremystretch
Copy link
Member

I'm not able to recreate this on v2.3.6. I can create a virtual chassis of two devices with the master in position 0 and do not receive an error.

Closing this out as it's been open for months with no progress. If someone wants to post the complete list of exact steps needed to recreate this on a stable release, I'll take another look at it.

@jeremystretch jeremystretch removed the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Jul 18, 2018
@lowpolyfire
Copy link

I have made a short webm video showing the problem: https://webmshare.com/play/KAB5b

@jeremystretch jeremystretch reopened this Jul 18, 2018
@jeremystretch jeremystretch added type: bug A confirmed report of unexpected behavior in the application status: accepted This issue has been accepted for implementation labels Jul 18, 2018
@jeremystretch
Copy link
Member

Thanks @computer045. Ok, so the missing detail was that the second device is being assigned as the master. I have confirmed this now.

@lowpolyfire
Copy link

I hope it's the same bug as the original reporter. Since he wasn't able to reproduce it, I am not sure. That is the only scenario where I had the error.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

4 participants