Skip to content

Commit

Permalink
MGMT-15491: Validate vSphere disk.EnableUUID ignoring cluster platform
Browse files Browse the repository at this point in the history
  • Loading branch information
eliorerz committed Aug 6, 2023
1 parent 83852f8 commit 5c19d95
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 70 deletions.
2 changes: 1 addition & 1 deletion internal/common/common_unitest_db.go
Expand Up @@ -407,7 +407,7 @@ func openTestDB(dbName string) (*gorm.DB, error) {
})
}

for attempts := 0; attempts < 5; attempts++ {
for attempts := 0; attempts < 30; attempts++ {
db, err := open()
if err == nil {
return db, nil
Expand Down
11 changes: 9 additions & 2 deletions internal/host/host_test.go
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/openshift/assisted-service/internal/provider/registry"
"math"
"net/http"
"os"
Expand Down Expand Up @@ -2831,6 +2832,9 @@ var _ = Describe("AutoAssignRole", func() {
mockHwValidator.EXPECT().ListEligibleDisks(gomock.Any()).AnyTimes()
mockHwValidator.EXPECT().GetHostValidDisks(gomock.Any()).Return(nil, nil).AnyTimes()
mockOperators := operators.NewMockAPI(ctrl)
mockProviderRegistry := registry.NewMockProviderRegistry(ctrl)
mockProviderRegistry.EXPECT().IsHostSupported(models.PlatformTypeBaremetal, gomock.Any()).Return(true, nil).AnyTimes()
mockProviderRegistry.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
db, dbName = common.PrepareTestDB()
clusterId = strfmt.UUID(uuid.New().String())
infraEnvId = strfmt.UUID(uuid.New().String())
Expand All @@ -2850,7 +2854,7 @@ var _ = Describe("AutoAssignRole", func() {
defaultConfig,
dummy,
mockOperators,
nil,
mockProviderRegistry,
false,
nil,
mockVersions,
Expand Down Expand Up @@ -3024,6 +3028,9 @@ var _ = Describe("IsValidMasterCandidate", func() {
ctrl = gomock.NewController(GinkgoT())
mockOperators := operators.NewMockAPI(ctrl)
hwValidator := hardware.NewValidator(testLog, *hwValidatorCfg, mockOperators)
mockProviderRegistry := registry.NewMockProviderRegistry(ctrl)
mockProviderRegistry.EXPECT().IsHostSupported(models.PlatformTypeBaremetal, gomock.Any()).Return(true, nil).AnyTimes()
mockProviderRegistry.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
mockOperators.EXPECT().GetRequirementsBreakdownForHostInCluster(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]*models.OperatorHostRequirements{}, nil)
mockOperators.EXPECT().GetPreflightRequirementsBreakdownForCluster(gomock.Any(), gomock.Any()).AnyTimes().Return([]*models.OperatorHardwareRequirements{}, nil)
mockVersions := versions.NewMockHandler(ctrl)
Expand All @@ -3041,7 +3048,7 @@ var _ = Describe("IsValidMasterCandidate", func() {
defaultConfig,
dummy,
mockOperators,
nil,
mockProviderRegistry,
false,
nil,
mockVersions,
Expand Down
8 changes: 5 additions & 3 deletions internal/host/hostrole_test.go
Expand Up @@ -38,6 +38,7 @@ var _ = Describe("Suggested-Role on Refresh", func() {
mockHwValidator *hardware.MockValidator
validatorCfg *hardware.ValidatorCfg
operatorsManager *operators.Manager
mockProviderRegistry *registry.MockProviderRegistry
)

initHwValidator := func() {
Expand Down Expand Up @@ -69,12 +70,12 @@ var _ = Describe("Suggested-Role on Refresh", func() {
mockEvents = eventsapi.NewMockHandler(ctrl)
operatorsManager = operators.NewManager(common.GetTestLog(), nil, operators.Options{}, nil, nil)
initHwValidator()
pr := registry.NewMockProviderRegistry(ctrl)
pr.EXPECT().IsHostSupported(gomock.Any(), gomock.Any()).Return(true, nil).AnyTimes()
mockProviderRegistry = registry.NewMockProviderRegistry(ctrl)
mockProviderRegistry.EXPECT().IsHostSupported(models.PlatformTypeBaremetal, gomock.Any()).Return(true, nil).AnyTimes()
mockVersions := versions.NewMockHandler(ctrl)
mockVersions.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(&models.ReleaseImage{URL: swag.String("quay.io/openshift/some-image::latest")}, nil).AnyTimes()
hapi = NewManager(common.GetTestLog(), db, nil, mockEvents, mockHwValidator, nil, validatorCfg, nil, defaultConfig, nil, operatorsManager, pr, false, nil, mockVersions)
hapi = NewManager(common.GetTestLog(), db, nil, mockEvents, mockHwValidator, nil, validatorCfg, nil, defaultConfig, nil, operatorsManager, mockProviderRegistry, false, nil, mockVersions)
})

tests := []struct {
Expand Down Expand Up @@ -110,6 +111,7 @@ var _ = Describe("Suggested-Role on Refresh", func() {
for i := range tests {
t := tests[i]
It(t.name, func() {
mockProviderRegistry.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
cluster = hostutil.GenerateTestCluster(clusterId)
Expect(db.Create(&cluster).Error).ToNot(HaveOccurred())

Expand Down
6 changes: 4 additions & 2 deletions internal/host/monitor_test.go
Expand Up @@ -63,7 +63,8 @@ var _ = Describe("monitor_disconnection", func() {
mockHwValidator.EXPECT().GetHostValidDisks(gomock.Any()).Return(nil, nil).AnyTimes()
mockOperators := operators.NewMockAPI(ctrl)
pr := registry.NewMockProviderRegistry(ctrl)
pr.EXPECT().IsHostSupported(gomock.Any(), gomock.Any()).Return(true, nil).AnyTimes()
pr.EXPECT().IsHostSupported(models.PlatformTypeBaremetal, gomock.Any()).Return(true, nil).AnyTimes()
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
mockVersions := versions.NewMockHandler(ctrl)
mockVersions.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(&models.ReleaseImage{URL: swag.String("quay.io/openshift/some-image::latest")}, nil).AnyTimes()
Expand Down Expand Up @@ -197,7 +198,8 @@ var _ = Describe("TestHostMonitoring - with cluster", func() {
mockHwValidator.EXPECT().GetHostValidDisks(gomock.Any()).Return(nil, nil).AnyTimes()
mockOperators := operators.NewMockAPI(ctrl)
pr := registry.NewMockProviderRegistry(ctrl)
pr.EXPECT().IsHostSupported(gomock.Any(), gomock.Any()).Return(true, nil).AnyTimes()
pr.EXPECT().IsHostSupported(models.PlatformTypeBaremetal, gomock.Any()).Return(true, nil).AnyTimes()
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
mockVersions = versions.NewMockHandler(ctrl)
mockVersions.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(&models.ReleaseImage{URL: swag.String("quay.io/openshift/some-image::latest")}, nil).AnyTimes()
Expand Down
95 changes: 47 additions & 48 deletions internal/host/transition_test.go
Expand Up @@ -781,7 +781,8 @@ var _ = Describe("Install", func() {
mockHwValidator = hardware.NewMockValidator(ctrl)
operatorsManager := operators.NewManager(common.GetTestLog(), nil, operators.Options{}, nil, nil)
pr := registry.NewMockProviderRegistry(ctrl)
pr.EXPECT().IsHostSupported(gomock.Any(), gomock.Any()).Return(true, nil).AnyTimes()
pr.EXPECT().IsHostSupported(models.PlatformTypeBaremetal, gomock.Any()).Return(true, nil).AnyTimes()
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
mockVersions := versions.NewMockHandler(ctrl)
mockVersions.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(&models.ReleaseImage{URL: swag.String("quay.io/openshift/some-image::latest")}, nil).AnyTimes()
Expand Down Expand Up @@ -1321,7 +1322,8 @@ var _ = Describe("Refresh Host", func() {
operatorsManager = operators.NewManager(common.GetTestLog(), nil, operatorsOptions, nil, nil)
mockHwValidator.EXPECT().GetHostInstallationPath(gomock.Any()).Return("/dev/sda").AnyTimes()
pr = registry.NewMockProviderRegistry(ctrl)
pr.EXPECT().IsHostSupported(gomock.Any(), gomock.Any()).Return(true, nil).AnyTimes()
pr.EXPECT().IsHostSupported(models.PlatformTypeBaremetal, gomock.Any()).Return(true, nil).AnyTimes()

mockVersions := versions.NewMockHandler(ctrl)
mockVersions.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(&models.ReleaseImage{URL: swag.String("quay.io/openshift/some-image::latest")}, nil).AnyTimes()
Expand All @@ -1339,6 +1341,7 @@ var _ = Describe("Refresh Host", func() {
Context("connection timeout", func() {

BeforeEach(func() {
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
mockDefaultClusterHostRequirements(mockHwValidator)
})

Expand Down Expand Up @@ -1459,6 +1462,7 @@ var _ = Describe("Refresh Host", func() {
Context("host installation timeout - cluster is pending user action", func() {

BeforeEach(func() {
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
mockDefaultClusterHostRequirements(mockHwValidator)
})

Expand All @@ -1485,6 +1489,7 @@ var _ = Describe("Refresh Host", func() {
for _, t := range tests {
t := t
It(fmt.Sprintf("checking timeout from stage %s", t.stage), func() {
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
hostCheckInAt := strfmt.DateTime(time.Now())
host = hostutil.GenerateTestHost(hostId, infraEnvId, clusterId, models.HostStatusInstallingInProgress)
host.Inventory = hostutil.GenerateMasterInventory()
Expand Down Expand Up @@ -1577,6 +1582,9 @@ var _ = Describe("Refresh Host", func() {
}

It("Known to insufficient", func() {
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
pr.EXPECT().GetSupportedProvidersByHosts(gomock.Any()).Return([]models.PlatformType{models.PlatformTypeBaremetal}, nil).AnyTimes()

createHost(models.HostStatusKnown)
createCluster()
updateClusterPlatform(models.PlatformTypeVsphere)
Expand All @@ -1586,49 +1594,14 @@ var _ = Describe("Refresh Host", func() {
Expect(err).ToNot(HaveOccurred())
host = hostutil.GetHostFromDB(*host.ID, host.InfraEnvID, db).Host
Expect(*host.Status).To(BeEquivalentTo(models.HostStatusInsufficient))

// Flip it back
mockStatus()
updateClusterPlatform(models.PlatformTypeBaremetal)
err = db.First(&cluster, "id = ?", clusterId).Error
Expect(err).ShouldNot(HaveOccurred())
err = hapi.RefreshStatus(ctx, &host, db)
Expect(err).ToNot(HaveOccurred())
host = hostutil.GetHostFromDB(*host.ID, host.InfraEnvID, db).Host
Expect(*host.Status).To(BeEquivalentTo(models.HostStatusKnown))
})

It("Pending for input to insufficient", func() {
createHost(models.HostStatusPendingForInput)
createCluster()
updateClusterPlatform(models.PlatformTypeVsphere)
Expect(common.DeleteRecordsByClusterID(db, *cluster.ID, []interface{}{&models.MachineNetwork{}})).ShouldNot(HaveOccurred())
err := db.First(&cluster, "id = ?", clusterId).Error
Expect(err).ShouldNot(HaveOccurred())
mockStatus()
err = hapi.RefreshStatus(ctx, &host, db)
Expect(err).ToNot(HaveOccurred())
host = hostutil.GetHostFromDB(*host.ID, host.InfraEnvID, db).Host
Expect(*host.Status).To(BeEquivalentTo(models.HostStatusInsufficient))

// Flip it back
mockStatus()
updateClusterPlatform(models.PlatformTypeBaremetal)
// The CIDR array rebuilt between the previous deletion to this stage
Expect(common.DeleteRecordsByClusterID(db, *cluster.ID, []interface{}{&models.MachineNetwork{}})).ShouldNot(HaveOccurred())
err = db.First(&cluster, "id = ?", clusterId).Error
Expect(err).ShouldNot(HaveOccurred())
err = hapi.RefreshStatus(ctx, &host, db)
Expect(err).ToNot(HaveOccurred())
host = hostutil.GetHostFromDB(*host.ID, host.InfraEnvID, db).Host
Expect(*host.Status).To(BeEquivalentTo(models.HostStatusPendingForInput))
})
})
})

Context("host disconnected", func() {

BeforeEach(func() {
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
mockDefaultClusterHostRequirements(mockHwValidator)
})

Expand Down Expand Up @@ -1733,6 +1706,7 @@ var _ = Describe("Refresh Host", func() {

Context("host disconnected", func() {
BeforeEach(func() {
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
mockDefaultClusterHostRequirements(mockHwValidator)
})

Expand Down Expand Up @@ -1835,6 +1809,7 @@ var _ = Describe("Refresh Host", func() {
Context("host installation timeout", func() {

BeforeEach(func() {
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
mockDefaultClusterHostRequirements(mockHwValidator)
})

Expand Down Expand Up @@ -1886,7 +1861,9 @@ var _ = Describe("Refresh Host", func() {
})

Context("host installationInProgress timeout", func() {

BeforeEach(func() {
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
mockDefaultClusterHostRequirements(mockHwValidator)
mockHwValidator.EXPECT().GetHostInstallationPath(gomock.Any()).Return("abc").AnyTimes()
})
Expand Down Expand Up @@ -2030,6 +2007,10 @@ var _ = Describe("Refresh Host", func() {
})

Context("Validate host", func() {
BeforeEach(func() {
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
})

tests := []struct {
// Test parameters
name string
Expand Down Expand Up @@ -2310,6 +2291,10 @@ var _ = Describe("Refresh Host", func() {
}

Context("Preparing for installation", func() {
BeforeEach(func() {
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
})

tests := []struct {
// Test parameters
name string
Expand Down Expand Up @@ -2514,6 +2499,9 @@ var _ = Describe("Refresh Host", func() {
})

Context("Preparing successful", func() {
BeforeEach(func() {
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
})
tests := []struct {
// Test parameters
name string
Expand Down Expand Up @@ -2596,6 +2584,10 @@ var _ = Describe("Refresh Host", func() {
Context("All transitions", func() {
var srcState string

BeforeEach(func() {
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
})

type TransitionTestStruct struct {
// Test parameters
name string
Expand Down Expand Up @@ -4514,6 +4506,7 @@ var _ = Describe("Refresh Host", func() {
})
Context("Pending timed out", func() {
BeforeEach(func() {
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
mockDefaultClusterHostRequirements(mockHwValidator)
})
tests := []struct {
Expand Down Expand Up @@ -4577,6 +4570,7 @@ var _ = Describe("Refresh Host", func() {

BeforeEach(func() {
otherHostID = strfmt.UUID(uuid.New().String())
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
ntpSources = defaultNTPSources
imageStatuses = map[string]*models.ContainerImageAvailability{common.TestDefaultConfig.ImageName: common.TestImageStatusesSuccess}
mockDefaultClusterHostRequirements(mockHwValidator)
Expand Down Expand Up @@ -5024,6 +5018,7 @@ var _ = Describe("Refresh Host", func() {
Context("Cluster Errors", func() {
BeforeEach(func() {
mockDefaultClusterHostRequirements(mockHwValidator)
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
mockHwValidator.EXPECT().GetHostInstallationPath(gomock.Any()).Return("abc").AnyTimes()
})

Expand Down Expand Up @@ -5096,6 +5091,8 @@ var _ = Describe("Refresh Host", func() {

BeforeEach(func() {
mockDefaultClusterHostRequirements(mockHwValidator)
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()

defaultNTPSourcesInBytes, err := json.Marshal(defaultNTPSources)
Expect(err).NotTo(HaveOccurred())
cluster = hostutil.GenerateTestCluster(clusterId)
Expand Down Expand Up @@ -5169,6 +5166,7 @@ var _ = Describe("Refresh Host", func() {

BeforeEach(func() {
mockDefaultClusterHostRequirements(mockHwValidator)
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
mockEvents.EXPECT().SendHostEvent(gomock.Any(), eventstest.NewEventMatcher(
eventstest.WithNameMatcher(eventgen.HostStatusUpdatedEventName),
eventstest.WithHostIdMatcher(hostId.String()),
Expand Down Expand Up @@ -5230,6 +5228,8 @@ var _ = Describe("Refresh Host", func() {
Expect(err).ShouldNot(HaveOccurred())
BeforeEach(func() {
mockDefaultClusterHostRequirements(mockHwValidator)
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()

mockVersions := versions.NewMockHandler(ctrl)
mockVersions.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(&models.ReleaseImage{URL: swag.String("quay.io/openshift/some-image::latest")}, nil).AnyTimes()
Expand Down Expand Up @@ -5476,6 +5476,8 @@ var _ = Describe("Refresh Host", func() {
mockVersions := versions.NewMockHandler(ctrl)
mockVersions.EXPECT().GetReleaseImage(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(&models.ReleaseImage{URL: swag.String("quay.io/openshift/some-image::latest")}, nil).AnyTimes()
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()

hapi = NewManager(common.GetTestLog(), db, testing.GetDummyNotificationStream(ctrl), mockEvents, mockHwValidator, nil, validatorCfg, nil, defaultConfig, nil, operatorsManager, pr, false, nil, mockVersions)
mockDefaultClusterHostRequirements(mockHwValidator)
cluster = hostutil.GenerateTestCluster(clusterId)
Expand Down Expand Up @@ -6092,14 +6094,11 @@ var _ = Describe("Upgrade agent feature", func() {
Eligible: true,
},
}}
mockHwValidator.EXPECT().ListEligibleDisks(gomock.Any()).
Return(disks).AnyTimes()
mockHwValidator.EXPECT().GetHostInstallationPath(gomock.Any()).
Return("/dev/sda").AnyTimes()
pr.EXPECT().IsHostSupported(gomock.Any(), gomock.Any()).
Return(true, nil).AnyTimes()
mockEvents.EXPECT().SendHostEvent(gomock.Any(), gomock.Any()).
AnyTimes()
mockHwValidator.EXPECT().ListEligibleDisks(gomock.Any()).Return(disks).AnyTimes()
mockHwValidator.EXPECT().GetHostInstallationPath(gomock.Any()).Return("/dev/sda").AnyTimes()
pr.EXPECT().IsHostSupported(models.PlatformTypeBaremetal, gomock.Any()).Return(true, nil).AnyTimes()
pr.EXPECT().IsHostSupported(models.PlatformTypeVsphere, gomock.Any()).Return(false, nil).AnyTimes()
mockEvents.EXPECT().SendHostEvent(gomock.Any(), gomock.Any()).AnyTimes()

// Refresh the host:
err := hapi.RefreshStatus(ctx, &host, db)
Expand Down Expand Up @@ -6255,7 +6254,7 @@ func (ts *testState) SetState(state stateswitch.State) error {
return nil
}

var allValidationIDs []validationID = []validationID{
var allValidationIDs = []validationID{
IsMediaConnected,
IsConnected,
HasInventory,
Expand Down Expand Up @@ -6298,7 +6297,7 @@ var allValidationIDs []validationID = []validationID{
IsReleaseDomainNameResolvedCorrectly,
}

var allConditions []conditionId = []conditionId{
var allConditions = []conditionId{
InstallationDiskSpeedCheckSuccessful,
ClusterPreparingForInstallation,
ClusterPendingUserAction,
Expand Down

0 comments on commit 5c19d95

Please sign in to comment.