Skip to content

Fix netbox_inventory service query #1438

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

Open
wants to merge 12 commits into
base: devel
Choose a base branch
from

Conversation

StoffelCPR
Copy link

@StoffelCPR StoffelCPR commented Jul 7, 2025

Related Issue

#1430

New Behavior

This is a first iteration of a possible fix for the service integration to post 4.3 Netbox versions.

...

Contrast to Current Behavior

Services remain empty as Netbox has introduced breaking changes

...

Discussion: Benefits and Drawbacks

Benefit:

re-established function to fetching services

Drawback:

Dumb quick fix. I'd need some help properly onboarding my changes into your change management

...

Changes to the Documentation

Probably no

...

Proposed Release Note Entry

Fixed service mapping to new Netbox parent object structure

...

Double Check

  • I have read the comments and followed the CONTRIBUTING.md.
  • I have explained my PR according to the information in the comments or in a linked issue.
  • My PR targets the devel branch.

@StoffelCPR
Copy link
Author

@sc68cal I'm currently struggling really seeing through the inventory tests.

One thing missing for the fix itself is backwards compat. 4.3 introduced the break. 4.2 and 4.1 won't work with my code. Would be cool if you show me a piece of code where you usually handle that kinda stuff.

My commits also re-enable and fix the DeepDiff on the inventory tests. There's HUGE discrepancies apparently

@benoit-ferre
Copy link
Contributor

benoit-ferre commented Jul 9, 2025

@StoffelCPR ,
I think you can do something like this to handle netbox versions.
It's not merged yet but I think this is the right way.
https://github.com/benoit-ferre/netbox_ansible_modules/blob/6fbc923096f6afb505b5d53179adb02818404748/plugins/module_utils/netbox_ipam.py#L219-L229

        if self.endpoint == "services" and self._version_check_greater(
            self.version, "4.3", greater_or_equal=True
        ):
            if "device" in data:
                data["parent_object_type"] = "dcim.device"
                data["parent_object_id"] = data["device"]
                del data["device"]
            elif "virtual_machine" in data:
                data["parent_object_type"] = "virtualization.virtualmachine"
                data["parent_object_id"] = data["virtual_machine"]
                del data["virtual_machine"] 

@StoffelCPR
Copy link
Author

Alrighty.

Thanks @benoit-ferre

You can search in the integration testing jobs under inventory tests if you search for options-flatten that for 4.1 and 4.2 the ansible inventory plugin makes chunked searching with device_id and virtual_machine_id und that for 4.3 it's searching with parent_object_id.

I have the same active for populating the dictionaries.

The famous sentence: It works on my machine.

I've re-enabled the inventory tests in this PR, they now properly work and display the diff to the console again. I believe the inventory tests are degraded and broken since I can't really see the differences expected here. Maybe you can give some input whether to fix this here or open another Issue trying to narrow down what's missing and maybe suggesting fixed (maybe even fix them myself depending on time available)

@StoffelCPR StoffelCPR changed the title [WIP] Fix netbox_inventory service query Fix netbox_inventory service query Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants