Skip to content

Commit

Permalink
MGMT-16588: Adding host with incompatible platform to day2 cluster sh…
Browse files Browse the repository at this point in the history
…ould fail (#5946)
  • Loading branch information
danmanor committed Feb 12, 2024
1 parent 8256335 commit fe09431
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
56 changes: 56 additions & 0 deletions internal/host/validations_test.go
Expand Up @@ -1453,6 +1453,62 @@ var _ = Describe("Validations test", func() {
_, _, found := getValidationResult(h.ValidationsInfo, diskEncryptionID)
Expect(found).To(BeFalse())
})

})

Context("Cluster platform compatability validation", func() {
BeforeEach(func() {
mockProviderRegistry.EXPECT().
IsHostSupported(commontesting.EqPlatformType(models.PlatformTypeVsphere), gomock.Any()).
Return(true, nil).
Times(1)
})

It("day2 Nutanix host - with Nutanix cluster should pass validation", func() {
c := generateDay2Cluster()
c.Platform = &models.Platform{Type: common.PlatformTypePtr(models.PlatformTypeNutanix)}
Expect(db.Create(&c).Error).ShouldNot(HaveOccurred())

h := getDay2Host()
h.Inventory = common.GenerateTestInventory()
configBytes, err := json.Marshal(ignition_types.Config{})
Expect(err).To(Not(HaveOccurred()))
h.APIVipConnectivity = hostutil.GenerateTestAPIConnectivityResponseSuccessString(string(configBytes))
Expect(db.Create(&h).Error).ShouldNot(HaveOccurred())

mockProviderRegistry.EXPECT().
IsHostSupported(commontesting.EqPlatformType(models.PlatformTypeNutanix), h).
Return(true, nil).
Times(1)
mockAndRefreshStatus(h)

h = &hostutil.GetHostFromDB(*h.ID, h.InfraEnvID, db).Host
status, _, _ := getValidationResult(h.ValidationsInfo, CompatibleWithClusterPlatform)
Expect(status).To(BeEquivalentTo(ValidationSuccess))
})

It("day2 non nutanix host - with Nutanix cluster should fail validation", func() {
c := generateDay2Cluster()
c.Platform = &models.Platform{Type: common.PlatformTypePtr(models.PlatformTypeNutanix)}
Expect(db.Create(&c).Error).ShouldNot(HaveOccurred())

h := getDay2Host()
h.Inventory = common.GenerateTestInventory()
configBytes, err := json.Marshal(ignition_types.Config{})
Expect(err).To(Not(HaveOccurred()))
h.APIVipConnectivity = hostutil.GenerateTestAPIConnectivityResponseSuccessString(string(configBytes))
Expect(db.Create(&h).Error).ShouldNot(HaveOccurred())

mockProviderRegistry.EXPECT().
IsHostSupported(commontesting.EqPlatformType(models.PlatformTypeNutanix), h).
Return(false, nil).
Times(1)
mockAndRefreshStatus(h)

h = &hostutil.GetHostFromDB(*h.ID, h.InfraEnvID, db).Host
status, _, _ := getValidationResult(h.ValidationsInfo, CompatibleWithClusterPlatform)
Expect(status).To(BeEquivalentTo(ValidationFailure))
})
})

Context("VSphere host UUID enable validation", func() {
Expand Down
3 changes: 0 additions & 3 deletions internal/host/validator.go
Expand Up @@ -361,9 +361,6 @@ func (v *validator) compatibleWithClusterPlatform(c *validationContext) (Validat
if c.infraEnv != nil {
return ValidationSuccessSuppressOutput, ""
}
if *c.cluster.Kind == models.ClusterKindAddHostsCluster {
return ValidationSuccess, fmt.Sprintf("Host is compatible with cluster platform %s", common.PlatformTypeValue(c.cluster.Platform.Type))
}
if c.inventory == nil || common.PlatformTypeValue(c.cluster.Platform.Type) == "" {
return ValidationPending, "Missing inventory or platform isn't set"
}
Expand Down
1 change: 0 additions & 1 deletion subsystem/day2_cluster_test.go
Expand Up @@ -508,7 +508,6 @@ var _ = Describe("Day2 cluster tests", func() {
h = getHostV2(infraEnvID, *host.ID)
Expect(*h.Status).Should(Equal("discovering"))
})

})

var _ = Describe("Day2 cluster with bind/unbind hosts", func() {
Expand Down

0 comments on commit fe09431

Please sign in to comment.