FileNotFoundError exception when upgrading to v4.0 with missing scripts (using data sources) #9459

Closed
opened 2025-12-29 20:50:10 +01:00 by adam · 7 comments
Owner

Originally created by @v0tti on GitHub (Apr 9, 2024).

Deployment Type

Self-Hosted

NetBox Version

v4.0-beta1

Python Version

3.11

Steps to Reproduce

  1. Have a NetBox 3.7 installation with custom scripts that are synced via a data source
  2. Get the NetBox 4.0-beta1 tarball and unpack it to a fresh directory
  3. Copy the config file from the existing NetBox 3.7 installation to the new directory
  4. Perform a clean install of NetBox 4.0-beta1 according to the documentation (adjusted to the new directory)
  5. Execute upgrade.sh

Situations like this might happen if a configuration management system (like Puppet) is used or while restoring from a database backup. In my case scripts and reports are synced via a data source after the upgrade and do not exist during an installation.

Expected Behavior

I would expect to be able to upgrade NetBox while my scripts and reports are not yet synced from the data source and the directories are empty.

Observed Behavior

The following exception is raised while trying to execute upgrade.sh:

  Applying extras.0109_script_model...Traceback (most recent call last):
  File "/opt/netbox-4.0-beta1/netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/core/management/base.py", line 107, in wrapper
    res = handle_func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/core/management/commands/migrate.py", line 356, in handle
    post_migrate_state = executor.migrate(
                         ^^^^^^^^^^^^^^^^^
  File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/db/migrations/executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
            ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/db/migrations/executor.py", line 252, in apply_migration
    state = migration.apply(state, schema_editor)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/db/migrations/migration.py", line 132, in apply
    operation.database_forwards(
  File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/db/migrations/operations/special.py", line 193, in database_forwards
    self.code(from_state.apps, schema_editor)
  File "/opt/netbox-4.0-beta1/netbox/extras/migrations/0109_script_model.py", line 93, in update_scripts
    for script_name in get_module_scripts(module):
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox-4.0-beta1/netbox/extras/migrations/0109_script_model.py", line 63, in get_module_scripts
    module = loader.load_module()
             ^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 605, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 1120, in load_module
  File "<frozen importlib._bootstrap_external>", line 945, in load_module
  File "<frozen importlib._bootstrap>", line 290, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 721, in _load
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 936, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1073, in get_code
  File "<frozen importlib._bootstrap_external>", line 1130, in get_data
FileNotFoundError: [Errno 2] No such file or directory: '/opt/netbox-4.0-beta1/netbox/reports/devices.py'

Placing the files in this directory manually fixes the issue.

Originally created by @v0tti on GitHub (Apr 9, 2024). ### Deployment Type Self-Hosted ### NetBox Version v4.0-beta1 ### Python Version 3.11 ### Steps to Reproduce 1. Have a NetBox 3.7 installation with custom scripts that are synced via a data source 2. Get the NetBox 4.0-beta1 tarball and unpack it to a fresh directory 3. Copy the config file from the existing NetBox 3.7 installation to the new directory 4. Perform a clean install of NetBox 4.0-beta1 according to the documentation (adjusted to the new directory) 5. Execute `upgrade.sh` Situations like this might happen if a configuration management system (like Puppet) is used or while restoring from a database backup. In my case scripts and reports are synced via a data source after the upgrade and do not exist during an installation. ### Expected Behavior I would expect to be able to upgrade NetBox while my scripts and reports are not yet synced from the data source and the directories are empty. ### Observed Behavior The following exception is raised while trying to execute `upgrade.sh`: ``` Applying extras.0109_script_model...Traceback (most recent call last): File "/opt/netbox-4.0-beta1/netbox/manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line utility.execute() File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/core/management/base.py", line 413, in run_from_argv self.execute(*args, **cmd_options) File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/core/management/base.py", line 459, in execute output = self.handle(*args, **options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/core/management/base.py", line 107, in wrapper res = handle_func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/core/management/commands/migrate.py", line 356, in handle post_migrate_state = executor.migrate( ^^^^^^^^^^^^^^^^^ File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/db/migrations/executor.py", line 135, in migrate state = self._migrate_all_forwards( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards state = self.apply_migration( ^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/db/migrations/executor.py", line 252, in apply_migration state = migration.apply(state, schema_editor) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/db/migrations/migration.py", line 132, in apply operation.database_forwards( File "/opt/netbox-4.0-beta1/venv/lib64/python3.11/site-packages/django/db/migrations/operations/special.py", line 193, in database_forwards self.code(from_state.apps, schema_editor) File "/opt/netbox-4.0-beta1/netbox/extras/migrations/0109_script_model.py", line 93, in update_scripts for script_name in get_module_scripts(module): ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox-4.0-beta1/netbox/extras/migrations/0109_script_model.py", line 63, in get_module_scripts module = loader.load_module() ^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap_external>", line 605, in _check_name_wrapper File "<frozen importlib._bootstrap_external>", line 1120, in load_module File "<frozen importlib._bootstrap_external>", line 945, in load_module File "<frozen importlib._bootstrap>", line 290, in _load_module_shim File "<frozen importlib._bootstrap>", line 721, in _load File "<frozen importlib._bootstrap>", line 690, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 936, in exec_module File "<frozen importlib._bootstrap_external>", line 1073, in get_code File "<frozen importlib._bootstrap_external>", line 1130, in get_data FileNotFoundError: [Errno 2] No such file or directory: '/opt/netbox-4.0-beta1/netbox/reports/devices.py' ``` Placing the files in this directory manually fixes the issue.
adam added the type: bugbeta labels 2025-12-29 20:50:10 +01:00
adam closed this issue 2025-12-29 20:50:10 +01:00
Author
Owner

@jeffgdotorg commented on GitHub (Apr 11, 2024):

Thank you for opening a bug report.

The provided steps to reproduce the problem you're seeing need more detail to remove ambiguity. Please revise the issue body so that Steps to Reproduce is an ordered list of specific UI or API actions that even a user unfamiliar with scripts and data sources can use to trigger the problem on a freshly installed system.

@jeffgdotorg commented on GitHub (Apr 11, 2024): Thank you for opening a bug report. The provided steps to reproduce the problem you're seeing need more detail to remove ambiguity. Please revise the issue body so that *Steps to Reproduce* is an ordered list of specific UI or API actions that even a user unfamiliar with scripts and data sources can use to trigger the problem on a freshly installed system.
Author
Owner

@v0tti commented on GitHub (Apr 11, 2024):

Thanks for taking a look at this. I have tried to be more specific about the steps. Please let me know if they need to be even more specific, like specifying how to create such data sources.

@v0tti commented on GitHub (Apr 11, 2024): Thanks for taking a look at this. I have tried to be more specific about the steps. Please let me know if they need to be even more specific, like specifying how to create such data sources.
Author
Owner

@jeffgdotorg commented on GitHub (Apr 17, 2024):

Sorry for the delay getting back; I was out sick the past two days.

Please indulge me just a bit further and break down step 2 into the specific commands you're using. Are you installing from a Git clone or a tarball? Are you blowing away the previous install or overwriting it? Those variables aren't really nailed down unless I know the commands you're using.

@jeffgdotorg commented on GitHub (Apr 17, 2024): Sorry for the delay getting back; I was out sick the past two days. Please indulge me just a bit further and break down step 2 into the specific commands you're using. Are you installing from a Git clone or a tarball? Are you blowing away the previous install or overwriting it? Those variables aren't really nailed down unless I know the commands you're using.
Author
Owner

@v0tti commented on GitHub (Apr 17, 2024):

Sorry for being bad at communicating the exact reproduction steps. It is because I am using a Puppet module that handles this automatically and I am not doing these steps manually one by one.
In this case it is pulling the release tarball and generating the configuration file automatically.

@v0tti commented on GitHub (Apr 17, 2024): Sorry for being bad at communicating the exact reproduction steps. It is because I am using a Puppet module that handles this automatically and I am not doing these steps manually one by one. In this case it is pulling the release tarball and generating the configuration file automatically.
Author
Owner

@jeffgdotorg commented on GitHub (Apr 18, 2024):

Can you share the Puppet module or relevant snippets of it?

I know it may come across as foot-draggy to request this level of detail, but every minute we spend interpolating the exact steps behind your narrative is a minute we're not triaging another issue.

@jeffgdotorg commented on GitHub (Apr 18, 2024): Can you share the Puppet module or relevant snippets of it? I know it may come across as foot-draggy to request this level of detail, but every minute we spend interpolating the exact steps behind your narrative is a minute we're not triaging another issue.
Author
Owner

@v0tti commented on GitHub (Apr 20, 2024):

I am using a patched version of this module: https://github.com/anderssh/ash-netbox

What it does when installing a new version is the following:

  • Download and unpack the tarball to /opt/netbox-{$version}
  • Adjust permissions for the netbox system user and group
  • Create a symlink /opt/netbox pointing to /opt/netbox-{$version}
  • Create a NetBox config file in this directory
  • Create a new venv in this directory
  • Install python requirements in this venv

Because the module does not fully handle upgrades I than manually execute ./upgrade.sh from the /opt/netbox directory.

Hope this clears things up a little bit.

@v0tti commented on GitHub (Apr 20, 2024): I am using a patched version of this module: https://github.com/anderssh/ash-netbox What it does when installing a new version is the following: - Download and unpack the tarball to `/opt/netbox-{$version}` - Adjust permissions for the netbox system user and group - Create a symlink `/opt/netbox` pointing to `/opt/netbox-{$version}` - Create a NetBox config file in this directory - Create a new venv in this directory - Install python requirements in this venv Because the module does not fully handle upgrades I than manually execute `./upgrade.sh` from the `/opt/netbox` directory. Hope this clears things up a little bit.
Author
Owner

@v0tti commented on GitHub (Apr 23, 2024):

This seems to be fixed in v4.0-beta2. Closing this now.

@v0tti commented on GitHub (Apr 23, 2024): This seems to be fixed in v4.0-beta2. Closing this now.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9459