Skip to content

Commit

Permalink
fix: diff virtualization.cluster with status (#221)
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Fiedorowicz <[email protected]>
  • Loading branch information
mfiedorowicz authored Jan 6, 2025
1 parent 0cc34ef commit 87855e9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 8 deletions.
4 changes: 4 additions & 0 deletions diode-server/netbox/virtualization_wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ func (vw *VirtualizationClusterDataWrapper) Patch(cmp ComparableData, intendedNe
vw.Cluster.Description = intended.Cluster.Description
}

if vw.Cluster.Status == nil || *vw.Cluster.Status == "" {
vw.Cluster.Status = intended.Cluster.Status
}

if actualSite.IsPlaceholder() && intended.Cluster.Site != nil {
intendedSite = extractFromObjectsMap(currentNestedObjectsMap, fmt.Sprintf("%p", intended.Cluster.Site))
}
Expand Down
82 changes: 74 additions & 8 deletions diode-server/reconciler/differ/differ_virt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,6 @@ func TestVirtualizationPrepare(t *testing.T) {
},
},
},
//rawIngestEntity: []byte(`{
// "request_id": "cfa0f129-125c-440d-9e41-e87583cd7d89",
// "data_type": "virtualization.clustertype",
// "entity": {
// "ClusterType": {}
// },
// "state": 0
//}`),
retrieveObjectStates: []mockRetrieveObjectState{},
wantChangeSet: changeset.ChangeSet{
ChangeSetID: "5663a77e-9bad-4981-afe9-77d8a9f2b8b5",
Expand Down Expand Up @@ -408,6 +400,80 @@ func TestVirtualizationPrepare(t *testing.T) {
},
wantErr: true,
},
{
name: "[P3] ingest virtualization.cluster with name only - existing object found with status - do nothing",
ingestEntity: differ.IngestEntity{
RequestID: "cfa0f129-125c-440d-9e41-e87583cd7d89",
DataType: "virtualization.cluster",
Entity: &diodepb.Entity{
Entity: &diodepb.Entity_Cluster{
Cluster: &diodepb.Cluster{
Name: "Test",
},
},
},
},
retrieveObjectStates: []mockRetrieveObjectState{
{
objectType: "virtualization.cluster",
objectID: 0,
queryParams: map[string]string{"q": "Test", "site__name": "undefined"},
objectChangeID: 0,
object: &netbox.VirtualizationClusterDataWrapper{
Cluster: &netbox.VirtualizationCluster{
ID: 1,
Name: "Test",
Status: strPtr(netbox.DefaultVirtualizationStatus),
},
},
},
{
objectType: "virtualization.clustergroup",
objectID: 0,
queryParams: map[string]string{"q": "undefined"},
objectChangeID: 0,
object: &netbox.VirtualizationClusterGroupDataWrapper{
ClusterGroup: &netbox.VirtualizationClusterGroup{
ID: 1,
Name: "undefined",
Slug: "undefined",
},
},
},
{
objectType: "virtualization.clustertype",
objectID: 0,
queryParams: map[string]string{"q": "undefined"},
objectChangeID: 0,
object: &netbox.VirtualizationClusterTypeDataWrapper{
ClusterType: &netbox.VirtualizationClusterType{
ID: 1,
Name: "undefined",
Slug: "undefined",
},
},
},
{
objectType: "dcim.site",
objectID: 0,
queryParams: map[string]string{"q": "undefined"},
objectChangeID: 0,
object: &netbox.DcimSiteDataWrapper{
Site: &netbox.DcimSite{
ID: 1,
Name: "undefined",
Slug: "undefined",
Status: (*netbox.DcimSiteStatus)(strPtr(string(netbox.DcimSiteStatusActive))),
},
},
},
},
wantChangeSet: changeset.ChangeSet{
ChangeSetID: "5663a77e-9bad-4981-afe9-77d8a9f2b8b5",
ChangeSet: []changeset.Change{},
},
wantErr: false,
},
{
name: "[P4] ingest virtualization.virtualmachine with name only - existing object not found - create",
ingestEntity: differ.IngestEntity{
Expand Down

0 comments on commit 87855e9

Please sign in to comment.