-
Notifications
You must be signed in to change notification settings - Fork 252
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
Fix cables status choice being provided by OPTIONS #457
Fix cables status choice being provided by OPTIONS #457
Conversation
I would like to add some tests to make sure any model that uses the |
Looks like the |
I thought I had responded, but I guess I didn't hit comment. I don't think I have an opinion on this so whichever way y'all think is beneficial and I will implement it. |
This should be fine see
If you look at the code, despite the filter conditions, the two metadata subclasses are doing nearly the same thing:
I would reckon that with a little debugging we could probably adapt |
I did try and get that working, but wasn't successful as I think that makes the most sense at this point. I will give it another go and hit you up if I have issues with it. |
…peField, add new dynamic test, add example test for Cables.
I'm about to push up working changes as well as new tests, but wanted to get y'alls feedback on testing. I think I also discovered another bug that the statuses that are returned are not properly filtered for the endpoint. Cables should only have three status choices and virtual machines should have 6. Numbers are arbitrary, but this is with a fresh install of Nautobot. >>> nb.dcim.cables.choices()['status']
[{'value': 'active', 'display': 'Active'}, {'value': 'available', 'display': 'Available'}, {'value': 'connected', 'display': 'Connected'}, {'value': 'container', 'display': 'Container'}, {'value': 'decommissioned', 'display': 'Decommissioned'}, {'value': 'decommissioning', 'display': 'Decommissioning'}, {'value': 'deprecated', 'display': 'Deprecated'}, {'value': 'deprovisioning', 'display': 'Deprovisioning'}, {'value': 'dhcp', 'display': 'DHCP'}, {'value': 'failed', 'display': 'Failed'}, {'value': 'inventory', 'display': 'Inventory'}, {'value': 'offline', 'display': 'Offline'}, {'value': 'planned', 'display': 'Planned'}, {'value': 'provisioning', 'display': 'Provisioning'}, {'value': 'reserved', 'display': 'Reserved'}, {'value': 'retired', 'display': 'Retired'}, {'value': 'slaac', 'display': 'SLAAC'}, {'value': 'staged', 'display': 'Staged'}, {'value': 'staging', 'display': 'Staging'}]
>>> nb.virtualization.virtual_machines.choices()['status']
[{'value': 'active', 'display': 'Active'}, {'value': 'available', 'display': 'Available'}, {'value': 'connected', 'display': 'Connected'}, {'value': 'container', 'display': 'Container'}, {'value': 'decommissioned', 'display': 'Decommissioned'}, {'value': 'decommissioning', 'display': 'Decommissioning'}, {'value': 'deprecated', 'display': 'Deprecated'}, {'value': 'deprovisioning', 'display': 'Deprovisioning'}, {'value': 'dhcp', 'display': 'DHCP'}, {'value': 'failed', 'display': 'Failed'}, {'value': 'inventory', 'display': 'Inventory'}, {'value': 'offline', 'display': 'Offline'}, {'value': 'planned', 'display': 'Planned'}, {'value': 'provisioning', 'display': 'Provisioning'}, {'value': 'reserved', 'display': 'Reserved'}, {'value': 'retired', 'display': 'Retired'}, {'value': 'slaac', 'display': 'SLAAC'}, {'value': 'staged', 'display': 'Staged'}, {'value': 'staging', 'display': 'Staging'}] I haven't been able to dig into it too much, but I believe this is the culprit. https://github.com/nautobot/nautobot/blob/develop/nautobot/extras/api/serializers.py#L621 |
I think the bug identification and your analysis are correct. It should be possible to do something similar on the serializer field to what the form field does with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
… will go through other apps to test expected choices in the next day or two.
This should be ready for review now with applicable tests and a few minor updates to properly return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elegant decision just making StatusFieldMetadata
a subclass of ContentTypeMetadata
!
Fixes: #452 452
Remove the
metadata_class
asStatusViewSetMixin
uses it to properly set the metadata returned.