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

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

/assign openshift-cherrypick-robot

/cherrypick release-ocm-2.8


Discussion / hints:

Fix patch:
diff --git a/internal/bminventory/inventory.go b/internal/bminventory/inventory.go
index 073874e541e..6b6cbffcbe5 100644
--- a/internal/bminventory/inventory.go
+++ b/internal/bminventory/inventory.go
@@ -2120,6 +2120,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 b55c67393ff..7f5a574b166 100644
--- a/internal/bminventory/inventory_test.go
+++ b/internal/bminventory/inventory_test.go
@@ -4769,6 +4769,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)