Repository: openshift/assisted-service (language: python)

Issue:
[release-ocm-2.10] MGMT-17763: Setting Machine network CIDR is forbidden" error is only present on cluster updates
This is an automated cherry-pick of #6359

/assign gamli75

/cherrypick release-ocm-2.9 release-ocm-2.8


Discussion / hints:

Fix patch:
diff --git a/internal/bminventory/inventory.go b/internal/bminventory/inventory.go
index 354c437d3d5..75fd8f176f5 100644
--- a/internal/bminventory/inventory.go
+++ b/internal/bminventory/inventory.go
@@ -2151,6 +2151,7 @@ func (b *bareMetalInventory) updateNonDhcpNetworkParams(updates map[string]inter
 	}
 	if params.ClusterUpdateParams.MachineNetworks != nil &&
 		common.IsSliceNonEmpty(params.ClusterUpdateParams.MachineNetworks) &&
+		interactivity == Interactive &&
 		!reqDualStack {
 		err := errors.New("Setting Machine network CIDR is forbidden when cluster is not in vip-dhcp-allocation mode")
 		log.WithError(err).Warnf("Set Machine Network CIDR")


Test patch:
diff --git a/internal/bminventory/inventory_test.go b/internal/bminventory/inventory_test.go
index 22575c112bc..9388a248825 100644
--- a/internal/bminventory/inventory_test.go
+++ b/internal/bminventory/inventory_test.go
@@ -4707,6 +4707,26 @@ var _ = Describe("cluster", func() {
 					verifyApiErrorString(reply, http.StatusBadRequest,
 						"Setting Machine network CIDR is forbidden when cluster is not in vip-dhcp-allocation mode")
 				})
+				It("Machine network CIDR in non dhcp non interactive", func() {
+					mockClusterUpdatability(2)
+					mockHostApi.EXPECT().GetStagesByRole(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+
+					setAndCheck := func(cidr models.Subnet) {
+						_, err := bm.UpdateClusterNonInteractive(ctx, installer.V2UpdateClusterParams{
+							ClusterID: clusterID,
+							ClusterUpdateParams: &models.V2ClusterUpdateParams{
+								MachineNetworks: []*models.MachineNetwork{{Cidr: cidr}},
+							},
+						})
+						Expect(err).ToNot(HaveOccurred())
+						var machineNetworks []*models.MachineNetwork
+						Expect(db.Where("cluster_id = ?", clusterID).Find(&machineNetworks).Error).ToNot(HaveOccurred())
+						Expect(machineNetworks).To(HaveLen(1))
+						Expect(machineNetworks[0].Cidr).To(Equal(cidr))
+					}
+					setAndCheck("10.11.0.0/16")
+					setAndCheck("1.2.3.0/24")
+				})
 
 				It("Machine network CIDR in non dhcp for dual-stack", func() {
 					mockClusterUpdatability(1)