From ad5c94f4e767714693081d338e8a2cc889e17dfa Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Tue, 4 Jun 2024 12:02:18 +0200 Subject: [PATCH] [#1370] Fixed shared net config update --- backend/server/apps/kea/configmodule_test.go | 4 +++- backend/server/database/model/subnet.go | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/server/apps/kea/configmodule_test.go b/backend/server/apps/kea/configmodule_test.go index f3481cf3f..eda9fee5d 100644 --- a/backend/server/apps/kea/configmodule_test.go +++ b/backend/server/apps/kea/configmodule_test.go @@ -2006,6 +2006,7 @@ func TestCommitSharedNetworkUpdate(t *testing.T) { // Copy the shared network and modify it. The modifications should be applied in // the database upon commit. modifiedSharedNetwork := sharedNetworks[0] + modifiedSharedNetwork.Name = "bar" modifiedSharedNetwork.CreatedAt = time.Time{} modifiedSharedNetwork.LocalSharedNetworks = sharedNetworks[0].LocalSharedNetworks[0:1] modifiedSharedNetwork.LocalSharedNetworks[0].KeaParameters.Allocator = storkutil.Ptr("random") @@ -2051,7 +2052,7 @@ func TestCommitSharedNetworkUpdate(t *testing.T) { "shared-networks": [ { "allocator": "random", - "name": "foo" + "name": "bar" } ] } @@ -2071,6 +2072,7 @@ func TestCommitSharedNetworkUpdate(t *testing.T) { updatedSharedNetwork, err := dbmodel.GetSharedNetwork(db, sharedNetworks[0].ID) require.NoError(t, err) require.NotNil(t, updatedSharedNetwork) + require.Equal(t, "bar", updatedSharedNetwork.Name) require.Len(t, updatedSharedNetwork.LocalSharedNetworks, 1) require.NotNil(t, updatedSharedNetwork.LocalSharedNetworks[0].KeaParameters) require.NotNil(t, updatedSharedNetwork.LocalSharedNetworks[0].KeaParameters.Allocator) diff --git a/backend/server/database/model/subnet.go b/backend/server/database/model/subnet.go index 9e43cad11..14ff4148e 100644 --- a/backend/server/database/model/subnet.go +++ b/backend/server/database/model/subnet.go @@ -863,6 +863,13 @@ func commitNetworksIntoDB(tx *pg.Tx, networks []SharedNetwork, subnets []Subnet) network.Name) return nil, err } + } else { + err = UpdateSharedNetwork(tx, network) + if err != nil { + err = pkgerrors.WithMessagef(err, "unable to update shared network %s in the database", + network.Name) + return nil, err + } } if err = AddLocalSharedNetworks(tx, network); err != nil { return nil, err