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

Considerations/Issues with file paths in Backups/Intended/Templates #778

Open
bile0026 opened this issue Jul 1, 2024 · 2 comments
Open
Labels
bug Something isn't working

Comments

@bile0026
Copy link
Contributor

bile0026 commented Jul 1, 2024

Environment

  • Python version: 3.11
  • Nautobot version: 2.2.6
  • nautobot-golden-config version: 2.1.0

Expected Behavior

Backups should be able to be saved to the filesystem and saved to Git

Observed Behavior

Received an error BACKUP CONFIG failed: Subtask: SAVE BACKUP CONFIGURATION TO FILE (failed). This appeared to be due to having a leading / in my backup config path in Golden Config Settings, which I'm assuming was referencing the root of the filesystem. Since Nautobot doesn't run as root it doesn't have access to / in the filesystem.

# correct (references current working directory)
{{obj.location.name}}/{{obj.name | upper}}.cfg

# invalid (references the root of the host/container filesystem)
/{{obj.location.name}}/{{obj.name | upper}}.cfg

Steps to Reproduce

  1. Use a leading / in the path for backup, intended, or template settings in Golden Config settings for a given device.
  2. Run Backup/Intended job for device

Proposed solutions

  1. Pop up a warning if a leading / is detected in the settings page or when the settings are created/updated. i.e. "You have a leading / in your configuration, is this expected?"
  2. Have a more descriptive error thrown if the above backup error occurs (not tested but I believe this would happen with intended as well).
  3. Strip any leading / when the settings are created/updated. This could limit some customer implementations if they are actually storing backups in a root directory that Nautobot does have access to.
@itdependsnetworks
Copy link
Contributor

Would add a check here:

@gsnider2195
Copy link
Contributor

gsnider2195 commented Oct 25, 2024

That's unexpected. This is due to this behavior in os.path.join:
Help on function join in module posixpath:

join(a, *p)
    Join two or more pathname components, inserting '/' as needed.
    If any component is an absolute path, all previous path components
    will be discarded.  An empty last part will result in a path that
    ends with a separator.

@gsnider2195 gsnider2195 added the bug Something isn't working label Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants