Skip to content

Conversation

@p-rintz
Copy link
Contributor

@p-rintz p-rintz commented Mar 7, 2023

Initializing the repository from init, before the path has been updated, will lead an exception when the script is not run directly from the repository.

Example exception (during the run in an ansible playbook):
git.exc.InvalidGitRepositoryError: /home/ansible

I ran the script successfully directy from the folder as well as from outside with the line removed:
# python3 nb-dt-import.py
# /opt/Netbox-Device-Type-Library-Import/.venv/bin/python3 /opt/Netbox-Device-Type-Library-Import/nb-dt-import.py

Initializing the repository from init, before the path has been updated, will lead to various errors when the script is not run directly from the repository.
danner26 added a commit to danner26/Device-Type-Library-Import that referenced this pull request Mar 7, 2023
@danner26
Copy link
Member

danner26 commented Mar 7, 2023

Hey @p-rintz good catch. I am in the middle of doing a complete overhaul and I really appreciate you catching this potential regression (might have always been there? dunno). Either way this was a great catch and in the latest release which is yet to come, the actual root cause of the issue is fixed. Now we will utilize REPO_PATH = f"{os.path.dirname(os.path.realpath(__file__))}/repo" for the repo path, which will ensure the folder is always within the same location as the script.

@danner26
Copy link
Member

danner26 commented Mar 7, 2023

In testing, it looks like this issue is exasperated more so the further away you get. Anyway I have implemented a full fix in the dev branch I have right now.. Can you give me access to your repo so I can push those changes into your PR?

That or please implement these changes.
gitcmd.py
Remove self.repo = Repo() on line 14

nb-dt-import.py
Change base_path = './repo/device-types/' to base_path = f'{settings.REPO_PATH}/device-types/' on line 56
Change base_path = './repo/module-types/' to base_path = f'{settings.REPO_PATH}/module-types/' on line 91

settings.py
Change REPO_PATH = "./repo" to REPO_PATH = f"{os.path.dirname(os.path.realpath(__file__))}/repo" on line 15

@danner26 danner26 added type: bug Something isn't working In Review status: revisions needed This issue requires additional information to be actionable labels Mar 7, 2023
@danner26
Copy link
Member

danner26 commented Mar 8, 2023

Thanks @p-rintz! Could you please pull down and test my changes? Once you approve I will merge this :)

@danner26 danner26 removed the status: revisions needed This issue requires additional information to be actionable label Mar 8, 2023
@p-rintz
Copy link
Contributor Author

p-rintz commented Mar 8, 2023

I will do so tomorrow, once I'm at work. Currently 1am here. 😄 Thanks for the quick fix.

@danner26
Copy link
Member

danner26 commented Mar 8, 2023

Awesome! Happy to help

@p-rintz
Copy link
Contributor Author

p-rintz commented Mar 8, 2023

LGTM

Ran through fine both from inside and outside the script-folder.

@danner26 danner26 merged commit 8832370 into netbox-community:master Mar 8, 2023
danner26 added a commit that referenced this pull request Mar 9, 2023
* Removed multiple imports of settings.py

* stating to abstract the netbox api calls to their own class

* Abstracted away determine features from main script, implemented as part of class initialization

* added helper functions to get repos relative & absolute path

* renaming gitcmd to repo

* starting to abstract away the get_files

* fixed issue where spaces and commas in vendor list with/without spaces breaks matching

* Added prelim fix for slugs if same issue vendors arg was facing exists. untested

* Finished abstracting the get_files function. Reduced fors and ifs to be cleaner and more efficent

* abstracted getFiles to repo class. Fixed slug issue not matching because of new slug format. added non-halting log function and renamed exception handler to log handler.

* utilized new logging class throughout script to reduce excess logging

* Abstracted and optimized create manufacturers

* Abstracted the create interfaces for devices to the netbox api class

* Fixed regression where check manufactuerers did not have the latest list

* Fixed regression caused by externally calling script. Discovered from #76

* abstracted all device interfaces to the devicetype class. optimized function calls to reduce duplicate code and reduce extra log calls

* Ran against all devices and passed with flying colors

* formatting settings.py

* formatting repo.py

* formatting main file

* formatting log_handler.py
@p-rintz p-rintz deleted the patch-1 branch March 9, 2023 08:19
danner26 added a commit that referenced this pull request Mar 24, 2023
* Delete gitcmd.py

* Delete nb-dt-import.py

* Add files via upload

* Logging cleanup (#78)

* Removed multiple imports of settings.py

* stating to abstract the netbox api calls to their own class

* Abstracted away determine features from main script, implemented as part of class initialization

* added helper functions to get repos relative & absolute path

* renaming gitcmd to repo

* starting to abstract away the get_files

* fixed issue where spaces and commas in vendor list with/without spaces breaks matching

* Added prelim fix for slugs if same issue vendors arg was facing exists. untested

* Finished abstracting the get_files function. Reduced fors and ifs to be cleaner and more efficent

* abstracted getFiles to repo class. Fixed slug issue not matching because of new slug format. added non-halting log function and renamed exception handler to log handler.

* utilized new logging class throughout script to reduce excess logging

* Abstracted and optimized create manufacturers

* Abstracted the create interfaces for devices to the netbox api class

* Fixed regression where check manufactuerers did not have the latest list

* Fixed regression caused by externally calling script. Discovered from #76

* abstracted all device interfaces to the devicetype class. optimized function calls to reduce duplicate code and reduce extra log calls

* Ran against all devices and passed with flying colors

* formatting settings.py

* formatting repo.py

* formatting main file

* formatting log_handler.py

* added back executable on file (#79)

* Add more info to failed device_type creations (#81)

---------

Co-authored-by: Philipp Rintz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants