Skip to content
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: diff virtualization.cluster with status #221

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading