netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
15.98k stars 2.56k forks source link

Error trace front/rear ports #7279

Closed romanmendelproject closed 3 years ago

romanmendelproject commented 3 years ago

NetBox version

v3.0.2

Python version

3.9

Steps to Reproduce

  1. Create device Test1
  2. Create a rear port on the Test1 device
  3. Create device Test2
  4. Create a rear port on the Test2 device
  5. Connect ports to each other
  6. Build a trace for any of the ports 1 2 3 5

Expected Behavior

Image with two devices connected by rear ports

Observed Behavior

Django Version: 3.2.7 Python Version: 3.9.5 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', 'graphiql_debug_toolbar', 'django_filters', 'django_tables2', 'django_prometheus', 'graphene_django', 'mptt', 'rest_framework', 'taggit', 'timezone_field', 'circuits', 'dcim', 'ipam', 'extras', 'tenancy', 'users', 'utilities', 'virtualization', 'django_rq', 'drf_yasg', 'discover_interfaces_plugin.DiscoverInterfacesConfig'] Installed Middleware: ['graphiql_debug_toolbar.middleware.DebugToolbarMiddleware', 'django_prometheus.middleware.PrometheusBeforeMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', 'netbox.middleware.ExceptionHandlingMiddleware', 'netbox.middleware.RemoteUserMiddleware', 'netbox.middleware.LoginRequiredMiddleware', 'netbox.middleware.APIVersionMiddleware', 'netbox.middleware.ObjectChangeMiddleware', 'django_prometheus.middleware.PrometheusAfterMiddleware']

Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, callback_kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view return self.dispatch(request, *args, *kwargs) File "/opt/netbox/netbox/dcim/views.py", line 2392, in dispatch return super().dispatch(request, args, kwargs) File "/opt/netbox/netbox/utilities/views.py", line 93, in dispatch return super().dispatch(request, *args, *kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/django/views/generic/base.py", line 98, in dispatch return handler(request, args, kwargs) File "/opt/netbox/netbox/netbox/views/generic.py", line 71, in get self.get_extra_context(request, instance), File "/opt/netbox/netbox/dcim/views.py", line 2418, in get_extra_context api_viewname = f"{path.origin._meta.app_label}-api:{path.origin._meta.model_name}-trace"

Exception Type: AttributeError at /dcim/rear-ports/8597/trace/ Exception Value: 'NoneType' object has no attribute 'origin'

romanmendelproject commented 3 years ago

In the old version 2, you could start tracing from anywhere. Also, if my interface is connected to the front port of the patch panel, the rear port is connected to the rear port of another patch panel, and the second patch panel is not connected by the front port, then it builds tracing, but not generate image. 6

This way I can get a normal trace if I have interfaces on both sides.

jeremystretch commented 3 years ago

In the old version 2, you could start tracing from anywhere.

Following the same steps in v2.11 would return an empty trace view. A CablePath instance is created only when at least one end terminates to an endpoint (rear ports are not endpoints).

saschaludwig commented 3 years ago

Hi, after updating to b86847c57eda83b3f2c7b13953e8afc142daf385, I still get the below error when tracing incomplete cables. How to reproduce is described in #7294



AttributeError at /api/dcim/interfaces/87/trace/
'NoneType' object has no attribute 'get_absolute_url'

Request Method: GET
Request URL: https://netbox.removed/api/dcim/interfaces/87/trace/?render=svg
Django Version: 3.2.7
Python Executable: /opt/netbox/venv/bin/python3
Python Version: 3.9.2
Python Path: ['/opt/netbox/netbox', '/opt/netbox', '/opt/netbox/venv/bin', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/opt/netbox/venv/lib/python3.9/site-packages']
Server time: Mon, 20 Sep 2021 16:47:46 +0200
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',
'graphiql_debug_toolbar',
'django_filters',
'django_tables2',
'django_prometheus',
'graphene_django',
'mptt',
'rest_framework',
'taggit',
'timezone_field',
'circuits',
'dcim',
'ipam',
'extras',
'tenancy',
'users',
'utilities',
'virtualization',
'django_rq',
'drf_yasg']
Installed Middleware:
['graphiql_debug_toolbar.middleware.DebugToolbarMiddleware',
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'netbox.middleware.ExceptionHandlingMiddleware',
'netbox.middleware.RemoteUserMiddleware',
'netbox.middleware.LoginRequiredMiddleware',
'netbox.middleware.APIVersionMiddleware',
'netbox.middleware.ObjectChangeMiddleware',
'django_prometheus.middleware.PrometheusAfterMiddleware']

Traceback (most recent call last):
 File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
   response = get_response(request)
 File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
   response = wrapped_callback(request, *callback_args, **callback_kwargs)
 File "/opt/netbox/venv/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
   return view_func(*args, **kwargs)
 File "/opt/netbox/venv/lib/python3.9/site-packages/rest_framework/viewsets.py", line 125, in view
   return self.dispatch(request, *args, **kwargs)
 File "/opt/netbox/netbox/netbox/api/views.py", line 201, in dispatch
   return super().dispatch(request, *args, **kwargs)
 File "/opt/netbox/venv/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
   response = self.handle_exception(exc)
 File "/opt/netbox/venv/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
   self.raise_uncaught_exception(exc)
 File "/opt/netbox/venv/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
   raise exc
 File "/opt/netbox/venv/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
   response = handler(request, *args, **kwargs)
 File "/opt/netbox/netbox/dcim/api/views.py", line 59, in trace
   drawing = obj.get_trace_svg(
 File "/opt/netbox/netbox/dcim/models/device_components.py", line 202, in get_trace_svg
   return trace.render()
 File "/opt/netbox/netbox/dcim/svg.py", line 438, in render
   url=near_end.get_absolute_url(),

Exception Type: AttributeError at /api/dcim/interfaces/87/trace/
Exception Value: 'NoneType' object has no attribute 'get_absolute_url'```
sliddjur commented 3 years ago

I am testing release v3.0.3 from docker.

I still dont get a picture of the path when connecing: Device1 with interface -> Front port of device2 -> Rear port of device3.

No error, just blank image.

image

saschaludwig commented 3 years ago

If you click on Download SVG you will see the error which is also thrown while trying to generate the image. It was fixed in 38172b793b3fa51025187901a8302d5503d64c33 which is available in 3.0.4-dev See #7294 for more details.