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

Cannot add or remove scripts from Custom Scripts after updating to 3.5.0 #12416

Closed
parkerschoenig opened this issue May 1, 2023 · 6 comments · Fixed by #12456
Closed

Cannot add or remove scripts from Custom Scripts after updating to 3.5.0 #12416

parkerschoenig opened this issue May 1, 2023 · 6 comments · Fixed by #12456
Assignees
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@parkerschoenig
Copy link

parkerschoenig commented May 1, 2023

NetBox version

v.3.5.0

Python version

3.8

Steps to Reproduce

  1. Add any custom Python script into /opt/netbox/netbox/scripts
  2. Access Scripts tab on Web UI, newly added script that was put into /opt/netbox/netbox/scripts does not show up

OR

  1. Remove any existing script from /opt/netbox/netbox/scripts that was present before upgrading to v3.5.0
  2. Access Scripts tab on web UI, this will result in an error message on web UI.

Originally I thought this was due to a bug with the netbox-secrets plugin (not supported on 3.5.0 yet, hence why the Changelog doesn't work) so I have removed the netbox-secrets plugin and dropped the related tables from the psql DB according to the Remove a Plugin documentation and restarted NetBox, however the issue with the custom scripts.

Expected Behavior

New scripts should be present in the "Scripts" tab in NetBox, removed script should not be present / not error.

Observed Behavior

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

The complete exception is provided below:

<class 'FileNotFoundError'>

[Errno 2] No such file or directory: '/opt/netbox/netbox/scripts/add_device_type_components.py'

Python version: 3.8.10
NetBox version: 3.5.0

@parkerschoenig parkerschoenig added the type: bug A confirmed report of unexpected behavior in the application label May 1, 2023
@jeremystretch
Copy link
Member

It's not clear from your description exactly what steps you're taking. How are you adding the new script? What script are you removing? Please edit your post above to provide clear instructions so that someone else can attempt to replicate the behavior.

@jeremystretch jeremystretch added the status: revisions needed This issue requires additional information to be actionable label May 1, 2023
@parkerschoenig
Copy link
Author

Apologies. I have tried to make the steps to reproduce more clear, basically I already had a custom script in /opt/netbox/netbox/scripts long before upgrading to 3.5.0 and I can see that script in the "scripts" tab in NetBox. If I try to add more scripts into /opt/netbox/netbox/scripts they do not show up in the "scripts" tab in NetBox. It only just shows that one script that was present before the upgrade.

But also, if I remove that script that existed in /opt/netbox/netbox/scripts before upgrading to 3.5.0 (meaning there is no custom scripts present in /opt/netbox/netbox/scripts at all) and I go to the "scripts" tab in NetBox, I get the following error:

<class 'FileNotFoundError'>

[Errno 2] No such file or directory: '/opt/netbox/netbox/scripts/<script_name>.py'

Python version: 3.8.10
NetBox version: 3.5.0

@kkthxbye-code
Copy link
Contributor

I think the issue here is that scripts and reports work significantly different in 3.5.0 than before, and to be honest it's not really documented very well in the release notes.

There's now a concrete database representation of an "installed" script in the database, see: #12068

The reason your scripts were there after the upgrade, is that a migration runs, importing the scripts from the script folder. The new way of working with scripts consist of using the Add script button on the script page and either uploading the script directly, or using the new data sync feature. Deleting scripts is done by using the delete script button.

To be honest, I haven't had a lot of time myself to play around with the new script/report setup in 3.5.0, so another maintainer might be able to shine more light on the intended workflow.

@jeremystretch jeremystretch added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation and removed status: revisions needed This issue requires additional information to be actionable labels May 2, 2023
@arthanson arthanson self-assigned this May 2, 2023
@arthanson arthanson removed the status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation label May 3, 2023
@arthanson
Copy link
Collaborator

To clarify the reproduction steps here:

"Access Scripts tab on Web UI, newly added script that was put into /opt/netbox/netbox/scripts does not show up"

This is by design. To add scripts in 3.5 you need to add them in the UI.

For the second issue, to reproduce:

  1. have a script in NetBox v3.4 in the scripts directory
  2. Do an upgrade to v3.5
  3. Delete the script (after doing the upgrade)
  4. Go to the scripts page and see the error

@parkerschoenig
Copy link
Author

To clarify the reproduction steps here:

"Access Scripts tab on Web UI, newly added script that was put into /opt/netbox/netbox/scripts does not show up"

This is by design. To add scripts in 3.5 you need to add them in the UI.

For the second issue, to reproduce:

  1. have a script in NetBox v3.4 in the scripts directory
  2. Do an upgrade to v3.5
  3. Delete the script (after doing the upgrade)
  4. Go to the scripts page and see the error

Correct, yes - to fix this, I re-added the script via CLI back into /opt/netbox/netbox/scripts, then deleted it via the UI. Then, re-added it via the UI and all looks good.

However, I have ran into another error that I will open a different bug report for. If you upload a script that by chance has an error, such as an indentation error, or in this example an undefined variable, you will get the following error message for after the upload:

<class 'NameError'>

name 'StringVar' is not defined

Python version: 3.8.10
NetBox version: 3.5.0

Then if you access the Scripts tab in the UI you will be presented with that error, so there is no way to delete it or view other scripts. The fix is to either edit and fix the script in /opt/netbox/netbox/scripts or remove all the contents from the script itself and then you should be able to access the scripts tab again.

@arthanson
Copy link
Collaborator

@parkerschoenig I've got a pending PR in that should hopefully fix both these issues.

@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label May 4, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2023
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

Successfully merging a pull request may close this issue.

4 participants