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 ipam.prefix with is_pool and mark_utilized #222

Merged
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
8 changes: 8 additions & 0 deletions diode-server/netbox/ipam_wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ func (dw *IpamPrefixDataWrapper) Patch(cmp ComparableData, intendedNestedObjects
dw.Prefix.Status = intended.Prefix.Status
}

if dw.Prefix.IsPool == nil {
dw.Prefix.IsPool = intended.Prefix.IsPool
}

if dw.Prefix.MarkUtilized == nil {
dw.Prefix.MarkUtilized = intended.Prefix.MarkUtilized
}

if dw.Prefix.Description == nil {
dw.Prefix.Description = intended.Prefix.Description
}
Expand Down
63 changes: 63 additions & 0 deletions diode-server/reconciler/differ/differ_ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,65 @@ func TestIpamPrepare(t *testing.T) {
},
wantErr: false,
},
{
name: "[P2] ingest ipam.prefix with prefix only - existing object with is pool and mark utilised found - do nothing",
ingestEntity: differ.IngestEntity{
RequestID: "cfa0f129-125c-440d-9e41-e87583cd7d89",
DataType: "ipam.prefix",
Entity: &diodepb.Entity{
Entity: &diodepb.Entity_Prefix{
Prefix: &diodepb.Prefix{
Prefix: "192.168.0.0/32",
Site: &diodepb.Site{
Name: "undefined",
},
},
},
},
},
retrieveObjectStates: []mockRetrieveObjectState{
{
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))),
},
},
},
{
objectType: "ipam.prefix",
objectID: 0,
queryParams: map[string]string{"q": "192.168.0.0/32"},
objectChangeID: 0,
object: &netbox.IpamPrefixDataWrapper{
Prefix: &netbox.IpamPrefix{
ID: 1,
Prefix: "192.168.0.0/32",
Site: &netbox.DcimSite{
ID: 1,
Name: "undefined",
Slug: "undefined",
Status: (*netbox.DcimSiteStatus)(strPtr(string(netbox.DcimSiteStatusActive))),
},
Status: &netbox.DefaultPrefixStatus,
IsPool: boolPtr(true),
MarkUtilized: boolPtr(false),
},
},
},
},
wantChangeSet: changeset.ChangeSet{
ChangeSetID: "5663a77e-9bad-4981-afe9-77d8a9f2b8b5",
ChangeSet: []changeset.Change{},
},
wantErr: false,
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -1876,3 +1935,7 @@ func TestIpamPrepare(t *testing.T) {
})
}
}

func boolPtr(b bool) *bool {
return &b
}
Loading