Repository navigation
Conversation
The scope id from cluster_scope_id_relation was passed to the cluster as the configured string. NBCluster only accepts a Site, SiteGroup, Location or Region object as scope_id, so every cluster logged "Invalid data type for 'scope_id'" and was left with a scope_type and no scope. Look up the object of the configured scope type by its NetBox id. Log an error and leave the scope unset if the type is unsupported, the id is not a number or no such object exists in NetBox. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
semx
left a comment
There was a problem hiding this comment.
Reproduced it against NetBox 4.7.2 with the vcsim captures: on development every run logs Invalid data type for 'scope_id' and NetBox answers Please select a sitegroup., with this branch the cluster gets the site group and the second run changes nothing. A missing id logs a clear error, good.
Two things before merge:
str(scope_id).strip().isdigit()is true for Unicode digits like³, andint()then raises and stops the whole run.isdecimal()avoids that.- The non-numeric id and the unsupported type branches have no tests. Also
NetBoxMappings().get()resolves any netbox-sync type, sodcim.devicepasses the first check and ends in twoInvalid data typeerrors; checking against the four cluster scope types would give one clear message.
Optional: mention in the option description that the scope options need NetBox 4.2 or newer, below that they're ignored silently.
Review follow-up: - check the configured scope type against the four cluster scope types. Any other netbox-sync type (i.e. dcim.device) passed the check before and ended in two "Invalid data type" errors. - use str.isdecimal(), str.isdigit() accepts characters like '³' which int() rejects, which stopped the whole run. - add tests for a non-numeric id, a superscript digit and an unsupported type. - note in both option descriptions that cluster scopes need NetBox >= 4.2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for reproducing it. Both points are addressed:
|
semx
left a comment
There was a problem hiding this comment.
Thanks, looks good now. I ran it against NetBox 4.7.2 with dcim.device, ³ and an id that doesn't exist: each one just logs an error and the cluster keeps no scope. On the previous commit ³ took the whole run down with a ValueError, so that was worth catching.
With
cluster_scope_type_relationandcluster_scope_id_relationconfigured, the VMware source passed the configured scope id to the cluster as a plain string.NBClusteronly accepts a Site, SiteGroup, Location or Region object asscope_id, so every cluster failed with:The cluster then got the new
scope_typebut no scope.Changes:
module/sources/vmware/connection.py: look up the object of the configured scope type by its NetBox id and use it asscope_id. The scope type must be one ofdcim.site,dcim.sitegroup,dcim.locationordcim.region, and the id must be a decimal number. If either check fails, or no object with that id exists, log one error and leave the scope unset.module/sources/vmware/config.py,settings-example.ini: note that the cluster scope options need NetBox 4.2 or newer and are ignored below that.tests/test_cluster_scope.py: one test checks that a configured SiteGroup id is resolved to the SiteGroup object. Others check that a missing id, a non-numeric id, a superscript digit (³) or an unsupported scope type (dcim.device) sets neither scope type nor scope and logs one clear error.Tested against NetBox 4.7.2 with a vCenter source and
cluster_scope_type_relation: .* = dcim.sitegroup,cluster_scope_id_relation: .* = 1: all clusters are scoped to the site group, and the dry-run logs no errors.pytest: 378 passed, 8 skipped (vcsim installed).🤖 Generated with Claude Code