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

Datasource git on local file system fails #16760

Closed
thefriendlynet opened this issue Jun 28, 2024 · 5 comments · Fixed by #16872
Closed

Datasource git on local file system fails #16760

thefriendlynet opened this issue Jun 28, 2024 · 5 comments · Fixed by #16872
Assignees
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@thefriendlynet
Copy link
Contributor

Deployment Type

Self-hosted

NetBox Version

v4.0.2

Python Version

3.11

Steps to Reproduce

  1. create Datasource type git, URL e.g. ///home/datasources
  2. try sync

Expected Behavior

files synced from local file system

Observed Behavior

SyncError("Fetching remote data failed (TypeError): LocalGitClient.__init__() got an unexpected keyword argument 'quiet'")

netbox/netbox/core/data_backends.py

        clone_args = {
            "branch": self.params.get('branch'),
            "config": self.config,
            "depth": 1,
            "errstream": porcelain.NoneStream(),
            "quiet": True,
        }

"quiet" and "depth" aren't supported by dulwich for local filesystem git repo's

@thefriendlynet thefriendlynet added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Jun 28, 2024
@thefriendlynet
Copy link
Contributor Author

thefriendlynet commented Jun 28, 2024

This might be an issue in the dulwich LocalGitClient code, don't seem to be able to fix it from Netbox.

EDIT: see below for why it seemed my changes to the Netbox code didn't work.
(removing the dulwich code changes to avoid any further confusion)

@jeffgdotorg
Copy link
Collaborator

jeffgdotorg commented Jul 1, 2024

Thanks for reporting a problem you've encountered in NetBox.

I've managed to reproduce the problem you describe in a fresh NetBox 4.0.6 installation. For the benefit of future workers of this issue, here's what I did to set up the bare local Git repo and otherwise prepare the system.

ubuntu@nb406-repro-16760:~$ sudo mkdir /home/datasources
ubuntu@nb406-repro-16760:~$ sudo chown netbox:netbox /home/datasources
ubuntu@nb406-repro-16760:~$ sudo -u netbox git init /home/datasources
hint: Using 'master' as the name for the initial branch. This default branch name
...
Initialized empty Git repository in /home/datasources/.git/
ubuntu@nb406-repro-16760:~$ sudo -u netbox /bin/bash
netbox@nb406-repro-16760:/home/ubuntu$ cd /home/datasources/
netbox@nb406-repro-16760:/home/datasources$ git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)
netbox@nb406-repro-16760:/home/datasources$ cat > README.txt
Hello world, this is an attempt to reproduce NetBox bug issue #16760.

Good luck!
netbox@nb406-repro-16760:/home/datasources$ git add .
netbox@nb406-repro-16760:/home/datasources$ git config --global user.email '***@netboxlabs.com'
netbox@nb406-repro-16760:/home/datasources$ git config --global user.name "Jeff Gehlbach"
netbox@nb406-repro-16760:/home/datasources$ git commit -m "Added a file"
[master (root-commit) f88787d] Added a file
 1 file changed, 3 insertions(+)
 create mode 100644 README.txt
ubuntu@nb406-repro-16760:~$ sudo -i
root@nb406-repro-16760:~# source /opt/netbox/venv/bin/activate
(venv) root@nb406-repro-16760:~# pip3 install dulwich
Collecting dulwich
  Downloading dulwich-0.22.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (4.4 kB)
Requirement already satisfied: urllib3>=1.25 in /opt/netbox/venv/lib/python3.10/site-packages (from dulwich) (2.2.2)
Downloading dulwich-0.22.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (979 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 979.1/979.1 kB 13.9 MB/s eta 0:00:00
Installing collected packages: dulwich
Successfully installed dulwich-0.22.1
(venv) root@nb406-repro-16760:~# systemctl restart netbox netbox-rq

I'm moving your issue along to needs owner status. If you would like to work it through to a PR, please say so and a maintainer will assign it to you.

@jeffgdotorg jeffgdotorg removed their assignment Jul 1, 2024
@jeffgdotorg jeffgdotorg added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: low Does not significantly disrupt application functionality, or a workaround is available and removed status: needs triage This issue is awaiting triage by a maintainer labels Jul 1, 2024
@thefriendlynet
Copy link
Contributor Author

thefriendlynet commented Jul 2, 2024

Thanks for taking the time to add these steps.

EDIT: I didn't restart the Netbox worker, only the Netbox process, that's why my changes to the Netbox code didn't work, duh

This fixes the issue, but is it acceptable if I rework it into a PR ?

--- a/core/data_backends.py
+++ b/core/data_backends.py
@@ -133,6 +133,10 @@
                         "password": self.params.get('password'),
                     }
                 )
+        elif not self.url_scheme:
+            clone_args["depth"] = None
+            del(clone_args["quiet"])
 
         logger.debug(f"Cloning git repo: {self.url}")
         try:

@thefriendlynet
Copy link
Contributor Author

thefriendlynet commented Jul 10, 2024

If you would like to work it through to a PR, please say so and a maintainer will assign it to you.

I'd like to submit a PR based on the diff I posted.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Jul 10, 2024
@jeremystretch
Copy link
Member

@thefriendlynet thanks, I've assigned this to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available 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.

3 participants