Skip to content

Commit

Permalink
MGMT-14734: Fix failed to update Nutanix provider cluster when on mul…
Browse files Browse the repository at this point in the history
…ti architecture (#5321)

Co-authored-by: Elior Erez <eerez@redhat.com>
  • Loading branch information
openshift-cherrypick-robot and eliorerz committed Jun 27, 2023
1 parent 6227447 commit 742ee7e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
7 changes: 0 additions & 7 deletions internal/bminventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,6 @@ func (b *bareMetalInventory) validateRegisterClusterInternalParams(params *insta
if err := validations.ValidateHighAvailabilityModeWithPlatform(params.NewClusterParams.HighAvailabilityMode, params.NewClusterParams.Platform); err != nil {
return common.NewApiError(http.StatusBadRequest, err)
}
if err := validations.ValidateArchitectureWithPlatform(&params.NewClusterParams.CPUArchitecture, params.NewClusterParams.Platform); err != nil {
return common.NewApiError(http.StatusBadRequest, err)
}
}

return nil
Expand Down Expand Up @@ -1943,10 +1940,6 @@ func (b *bareMetalInventory) validateUpdateCluster(
return params, common.NewApiError(http.StatusBadRequest, err)
}

if err = validations.ValidateArchitectureWithPlatform(&cluster.CPUArchitecture, platform); err != nil {
return params, common.NewApiError(http.StatusBadRequest, err)
}

params, err = b.validateUpdateClusterIncompatibleFeatures(ctx, cluster, params)
if err != nil {
return params, err
Expand Down
47 changes: 43 additions & 4 deletions internal/bminventory/inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6146,7 +6146,7 @@ var _ = Describe("V2ClusterUpdate cluster", func() {
HighAvailabilityMode: swag.String(models.ClusterHighAvailabilityModeFull),
UserManagedNetworking: swag.Bool(false),
OpenshiftVersion: "4.12",
CPUArchitecture: common.DefaultCPUArchitecture,
CPUArchitecture: models.ClusterCPUArchitectureMulti,
Platform: &models.Platform{
Type: common.PlatformTypePtr(models.PlatformTypeBaremetal),
},
Expand Down Expand Up @@ -6725,6 +6725,26 @@ var _ = Describe("V2ClusterUpdate cluster", func() {
Expect(swag.BoolValue(actual.Platform.IsExternal)).To(BeFalse())
})

It("Update platform=nutanix with multi cpu architecture - success", func() {
err := db.Model(&common.Cluster{}).Where("id = ?", clusterID).Update("cpu_architecture", models.ClusterCPUArchitectureMulti).Error
Expect(err).ShouldNot(HaveOccurred())
mockSuccess()
mockProviderRegistry.EXPECT().SetPlatformUsages(models.PlatformTypeNutanix, gomock.Any(), mockUsage)

reply := bm.V2UpdateCluster(ctx, installer.V2UpdateClusterParams{
ClusterID: clusterID,
ClusterUpdateParams: &models.V2ClusterUpdateParams{
Platform: &models.Platform{Type: common.PlatformTypePtr(models.PlatformTypeNutanix)},
UserManagedNetworking: swag.Bool(false),
},
})
Expect(reply).Should(BeAssignableToTypeOf(installer.NewV2UpdateClusterCreated()))
actual := reply.(*installer.V2UpdateClusterCreated).Payload
Expect(swag.BoolValue(actual.UserManagedNetworking)).To(BeFalse())
Expect(*actual.Platform.Type).To(Equal(models.PlatformTypeNutanix))
Expect(swag.BoolValue(actual.Platform.IsExternal)).To(BeFalse())
})

It("Update UMN=true and platform=nutanix results BadRequestError - failure", func() {
reply := bm.V2UpdateCluster(ctx, installer.V2UpdateClusterParams{
ClusterID: clusterID,
Expand Down Expand Up @@ -12815,7 +12835,7 @@ var _ = Describe("TestRegisterCluster", func() {
Expect(cfg.DiskEncryptionSupport).Should(BeTrue())
bm = createInventory(db, cfg)
bm.clusterApi = cluster.NewManager(cluster.Config{}, common.GetTestLog().WithField("pkg", "cluster-monitor"),
db, commontesting.GetDummyNotificationStream(ctrl), mockEvents, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
db, commontesting.GetDummyNotificationStream(ctrl), mockEvents, nil, nil, nil, nil, nil, mockOperatorManager, nil, nil, nil, nil)
mockUsageReports()
})

Expand Down Expand Up @@ -13050,9 +13070,20 @@ var _ = Describe("TestRegisterCluster", func() {
It("Nutanix platform and arm64 - failed", func() {
mockEvents.EXPECT().SendClusterEvent(gomock.Any(), eventstest.NewEventMatcher(
eventstest.WithNameMatcher(eventgen.ClusterRegistrationFailedEventName),
eventstest.WithMessageContainsMatcher("only x86-64 CPU architecture is supported on Nutanix clusters"),
eventstest.WithMessageContainsMatcher("cannot use Nutanix Platform Integration because it's not compatible with the arm64 architecture on version 4.11"),
eventstest.WithSeverityMatcher(models.EventSeverityError))).Times(1)

mockOSImages.EXPECT().GetCPUArchitectures(gomock.Any()).Return(
[]string{minimalOpenShiftVersionForNutanix, common.ARM64CPUArchitecture}).Times(1)
mockVersions.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&models.ReleaseImage{
CPUArchitecture: swag.String(common.MultiCPUArchitecture),
CPUArchitectures: []string{common.X86CPUArchitecture, common.ARM64CPUArchitecture},
OpenshiftVersion: swag.String("4.11.1"),
URL: swag.String("release_4.11.1"),
Version: swag.String("4.11.1-multi"),
}, nil).Times(1)
mockOperatorManager.EXPECT().GetSupportedOperatorsByType(models.OperatorTypeBuiltin).Return([]*models.MonitoredOperator{&common.TestDefaultConfig.MonitoredOperator}).Times(1)

params := getClusterCreateParams(nil)
params.Platform = &models.Platform{
Type: common.PlatformTypePtr(models.PlatformTypeNutanix),
Expand Down Expand Up @@ -13083,6 +13114,14 @@ var _ = Describe("TestRegisterCluster", func() {
Expect(reply).Should(BeAssignableToTypeOf(installer.NewV2RegisterClusterCreated()))
c := reply.(*installer.V2RegisterClusterCreated).Payload

infraEnvID := strfmt.UUID(uuid.New().String())
err := db.Create(&common.InfraEnv{InfraEnv: models.InfraEnv{
ID: &infraEnvID,
ClusterID: *c.ID,
CPUArchitecture: models.InfraEnvCPUArchitectureArm64,
}}).Error
Expect(err).ShouldNot(HaveOccurred())

reply2 := bm.V2UpdateCluster(ctx, installer.V2UpdateClusterParams{
ClusterID: *c.ID,
ClusterUpdateParams: &models.V2ClusterUpdateParams{
Expand All @@ -13092,7 +13131,7 @@ var _ = Describe("TestRegisterCluster", func() {
UserManagedNetworking: swag.Bool(false),
},
})
verifyApiErrorString(reply2, http.StatusBadRequest, "only x86-64 CPU architecture is supported on Nutanix clusters")
verifyApiErrorString(reply2, http.StatusBadRequest, "cannot use Nutanix Platform Integration because it's not compatible with the arm64 architecture on version 4.11 of OpenShift")
})

It("None platform type", func() {
Expand Down

0 comments on commit 742ee7e

Please sign in to comment.