Fix two idempotency issues when updating VMs. #859
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related Issue
#823
New Behavior
Using
netbox.netbox.netbox_virtual_machineto update the vCPU count of a VM in netbox is now idempotent from version 2.10 onward.Using
netbox.netbox.netbox_virtual_machineto update a VM in netbox that has custom_fields with no values is also idempotent from version 2.10 onward.Plus a couple of pretty minor changes (that can be removed easily if undesired):
_version_check_greaternow returns a type consistent value (i.e. False instead of None by default).Contrast to Current Behavior
In the current behaviour, I'd get a float value replacing my integer value on the
vcpusfield every time (netbox 2.10).And if I had a
custom_fieldswith valueNone, the module would systematically return astate: changedwith an empty diff (netbox 2.10 and 3.2).Discussion: Benefits and Drawbacks
To do that, I dropped the use of a formatted string and instead use the same types as pynetbox, i.e. integer / float, depending on the situation. The user can use either type and it'll work fine, so long as pynetbox and the targeted netbox are able to handle it. Otherwise, an error is raised, e.g.
pynetbox.core.query.RequestError: The request failed with code 400 Bad Request: {'vcpus': ['Ensure that there are no more than 6 digits in total.']}I manually tested on 2.10 and 3.2 instances, with different
vcpusvalues (2, 2.0, 2.1, 2.10, 2.12), and I get a consistent, idempotent behaviour.Additionally, there was a piece of code that would always generate diffs if the original or updated objects contained a custom field with a value of None.
I chose to replicate the existing behaviour on the updated object rather than delete the loop over the original object. But admittedly, I do not understand the purpose of this piece of code. If anyone has knowledge about this, I'd be happy to learn more.
Existing tests pass, and I've also added an idempotence test on the execution of the
netbox_virtual_machinemodule.Proposed Release Note Entry
Fix #823: Fix idempotence of netbox_virtual_machine module.
Double Check
develbranch.