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

Catch DoesNotExist preventing startup #961

Merged
merged 1 commit into from
Mar 16, 2023

Conversation

MarcHagen
Copy link
Contributor

@MarcHagen MarcHagen commented Mar 15, 2023

Related Issue:

New Behavior

↩️ Skip creating the superuser
🧬 loaded config '/etc/netbox/config/configuration.py'
🧬 loaded config '/etc/netbox/config/extra.py'
🧬 loaded config '/etc/netbox/config/logging.py'
🧬 loaded config '/etc/netbox/config/plugins.py'
✅ Initialisation is done.
⏳ Waiting for control socket to be created... (1/10)
2023/03/15 20:51:30 [warn] 7#7 Unit is running unprivileged, then it cannot use arbitrary user and group.
2023/03/15 20:51:30 [info] 7#7 unit 1.29.1 started
2023/03/15 20:51:30 [info] 20#20 discovery started
2023/03/15 20:51:30 [notice] 20#20 module: python 3.10.4 "/usr/lib/unit/modules/python3.10.unit.so"
2023/03/15 20:51:30 [info] 7#7 controller started
2023/03/15 20:51:30 [notice] 7#7 process 20 exited with code 0
2023/03/15 20:51:30 [info] 22#22 router started
2023/03/15 20:51:30 [info] 22#22 OpenSSL 3.0.2 15 Mar 2022, 30000020
⚙️ Applying configuration from /etc/unit/nginx-unit.json
2023/03/15 20:51:31 [info] 26#26 "netbox" prototype started
2023/03/15 20:51:31 [info] 27#27 "netbox" application started
🧬 loaded config '/etc/netbox/config/configuration.py'
🧬 loaded config '/etc/netbox/config/extra.py'
🧬 loaded config '/etc/netbox/config/logging.py'
🧬 loaded config '/etc/netbox/config/plugins.py'
✅ Unit configuration loaded successfully
2023/03/15 20:51:33 [notice] 7#7 process 18 exited with code 0
2023/03/15 20:51:45 [info] 36#36 "netbox" application started
🧬 loaded config '/etc/netbox/config/configuration.py'
🧬 loaded config '/etc/netbox/config/extra.py'
🧬 loaded config '/etc/netbox/config/logging.py'
🧬 loaded config '/etc/netbox/config/plugins.py'
127.0.0.1 - - [15/Mar/2023:20:51:48 +0000] "GET /api/ HTTP/1.1" 200 469 "-" "curl/7.81.0"

Contrast to Current Behavior

↩️ Skip creating the superuser
🧬 loaded config '/etc/netbox/config/configuration.py'
🧬 loaded config '/etc/netbox/config/extra.py'
🧬 loaded config '/etc/netbox/config/logging.py'
🧬 loaded config '/etc/netbox/config/plugins.py'
Traceback (most recent call last):
  File "/opt/netbox/netbox/./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/commands/shell.py", line 127, in handle
    exec(sys.stdin.read(), globals())
  File "<string>", line 2, in <module>
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 650, in get
    raise self.model.DoesNotExist(
users.models.Token.DoesNotExist: Token matching query does not exist.

Discussion: Benefits and Drawbacks

Because the check failing to find the defined default token it will exit 1 the python shell failing the startup of netbox.
Catching the DoesNotExist error forces the shell to exit 0, starting netbox.

Changes to the Wiki

No need

Proposed Release Note Entry

Fix netbox not starting if default api token is not found.

Double Check

  • I have read the comments and followed the PR template.
  • I have explained my PR according to the information in the comments.
  • My PR targets the develop branch.

@tobiasge
Copy link
Member

Thank you for this fix. Will do a bugfix release tomorrow.

Copy link

@topranks topranks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 87 in the patched file still throws the exception, it should be removed, leaving the one within the try block only.

Fixes failing startup because of python error:

```
Traceback (most recent call last):
  File "/opt/netbox/netbox/./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/commands/shell.py", line 127, in handle
    exec(sys.stdin.read(), globals())
  File "<string>", line 2, in <module>
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 650, in get
    raise self.model.DoesNotExist(
users.models.Token.DoesNotExist: Token matching query does not exist.
```
@MarcHagen
Copy link
Contributor Author

Ah yes, well my rebase didn't work that well apparently ... pushed the correct version now. (sowy)

@MarcHagen MarcHagen requested a review from topranks March 15, 2023 22:40
@tobiasge tobiasge merged commit 256f23b into netbox-community:develop Mar 16, 2023
@tobiasge tobiasge mentioned this pull request Mar 16, 2023
@MarcHagen MarcHagen deleted the patch-1 branch March 16, 2023 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants