Skip to content

Conversation

@bk2zsto
Copy link
Contributor

@bk2zsto bk2zsto commented Sep 7, 2022

Related Issue

New Behavior

Add serial and asset_tag extraction to netbox.netbox.nb_inventory

Contrast to Current Behavior

serial and asset_tag are currently not extracted

Discussion: Benefits and Drawbacks

serial and asset_tag are useful for inventory operations

A general facility to request arbitrary fields from devices seems possible but likely overkill

Changes to the Documentation

Proposed Release Note Entry

nb_inventory - add serial and asset_tag extraction.

Double Check

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

@bk2zsto
Copy link
Contributor Author

bk2zsto commented Sep 8, 2022

I cant tell from the integration test log what needs to be corrected?

@rodvand
Copy link
Contributor

rodvand commented Sep 8, 2022

I cant tell from the integration test log what needs to be corrected?

In the folder tests/integration/targets/inventory-vX.Y/files/ there are output inventories (.json) which expects to match with the nb_inventory configuration (.yml). As you now return a serial and asset_tag field on devices this needs to be added to the expected output. You should really also add a serial number/asset tag to one or multiple of the devices created in test/integration/netbox-deploy.py and make sure the expected inventory matches the actual inventory returned.

@bk2zsto
Copy link
Contributor Author

bk2zsto commented Jan 18, 2023

My test-fu is not that strong but ...
I am hoping 1a2e238 can live under the original changelog fragment?
Either way, do I need to anything to trigger CI?

@sc68cal
Copy link
Contributor

sc68cal commented Jan 19, 2023

My test-fu is not that strong but ... I am hoping 1a2e238 can live under the original changelog fragment? Either way, do I need to anything to trigger CI?

I approved the CI checks, as you can see. Sorry, it required manual intervention.


def extract_asset_tag(self, host):
return host.get("asset_tag")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these be return a default value of None if they are not set? Such as

host.get("serial", None)

because we cannot guarantee that the asset tag and serial are set? I see you have changed a lot of the test files and set the values to None, which just means that now all our test data has the serial and asset_tag attributes with None values but I see other instances in this file, like:

       site = host.get("site", None)
        if not isinstance(site, dict):
            # Device has no site
            return []

Basically, you need to have this code deal with instances where asset_tag and serial are not attributes that get returned from the NetBox API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. Re: test files I was/am really just fumbling around trying things to get a good CI.
I'll add the default handling and make the test files rational again and see what haps.

@bk2zsto
Copy link
Contributor Author

bk2zsto commented Jan 22, 2023

So the pipeline is/was appeased (3.3 seems to have barfed for something runner-related just now) but I am not completely sure about this:

  1. the whole x-nullable of asset_tag vs. serial makes things wonky. Have confirmed (at least on 2.11) that the REST API returns both fields populated or not but asset_tag is null on empty and serial is "" on empty. I get that they are 2 different values but it still made my head hurt quite a bit trying to make the json files "correct"
  2. as @sc68cal points out all the tests/integration/inventory-vX.Y/files/*.json files are changed by this PR. My thought was that since tests/integration/netbox-deploy.py is creating the inventory for all targets, all the jsons should match. Not a big deal to change them all at once by just hoovering them up with json.load, iterating _meta.hostvars and writing them back out with json.dump but is changing every file necessary and/or correct?
  3. going over master and develop in Netbox I can't tell if the change to append " (asset_tag)" to display is going to stay around
  4. the extract*_ methods in plugins/inventory/nb_inventory.py handle extraction with either host.get(propname,None) or try/except blocks. I think these are equivalent but not sure which is the preferred style for netbox-community/ansible_modules
  5. noisy commit history as I was trying to get a good pipeline. More than willing to close this one our and resubmit cleaned up and/or welcome git-fu suggestions to squash the noise.

@bk2zsto bk2zsto requested a review from sc68cal January 22, 2023 19:46
@sc68cal
Copy link
Contributor

sc68cal commented Jan 24, 2023

@rodvand is pretty good about squashing merging things so don't worry about the commit noise while you were learning, we'll take care of it.

Nice work on getting things passing

@bk2zsto
Copy link
Contributor Author

bk2zsto commented Jan 24, 2023 via email

@sc68cal
Copy link
Contributor

sc68cal commented Jan 24, 2023

This looks pretty good to me but I would like some of the other maintainers to weigh in.

@bk2zsto
Copy link
Contributor Author

bk2zsto commented Feb 9, 2023

Hi @sc68cal and @rodvand ,

This looks pretty good to me but I would like some of the other maintainers to weigh in.

I am trying to package some Ansible PBs for my team and would like to eliminate the dependency on my local fork.
You guys are the only ones I see on the PR so do other ppl need to take a look?
Let me know if I have more cleanup or if merging this has other problems.

Thanks,
Bill

@rodvand rodvand merged commit ee11cd8 into netbox-community:devel Feb 12, 2023
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.

3 participants