Skip to content

Commit

Permalink
NO-JIRA: Enable skip mco reboot functionality only if openshift versi…
Browse files Browse the repository at this point in the history
…on is 4.15 and higher
  • Loading branch information
ori-amizur committed Nov 8, 2023
1 parent 2d47e9a commit 1535cec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
10 changes: 9 additions & 1 deletion internal/host/hostcommands/install_cmd.go
Expand Up @@ -24,6 +24,8 @@ import (
"gorm.io/gorm"
)

const baseVersionForSkipMcoReboot = "4.15.0"

type installCmd struct {
baseCmd
db *gorm.DB
Expand Down Expand Up @@ -114,7 +116,13 @@ func (i *installCmd) getFullInstallerCommand(ctx context.Context, cluster *commo
CheckCvo: swag.Bool(i.instructionConfig.CheckClusterVersion),
InstallerImage: swag.String(i.instructionConfig.InstallerImage),
BootDevice: swag.String(bootdevice),
EnableSkipMcoReboot: i.enableSkipMcoReboot,
}
if i.enableSkipMcoReboot {
enableSkipMcoReboot, err := common.BaseVersionGreaterOrEqual(baseVersionForSkipMcoReboot, cluster.OpenshiftVersion)
if err != nil {
return "", errors.Wrapf(err, "Could not find if openshift version is greater or equal to %s", baseVersionForSkipMcoReboot)
}
request.EnableSkipMcoReboot = enableSkipMcoReboot
}

// those flags are not used on day2 installation
Expand Down
31 changes: 17 additions & 14 deletions internal/host/hostcommands/install_cmd_test.go
Expand Up @@ -108,16 +108,19 @@ var _ = Describe("installcmd", func() {
})
})
DescribeTable("enable MCO reboot values",
func(enableMcoReboot bool) {
func(enableMcoReboot bool, version string, expected bool) {
installCommand := NewInstallCmd(common.GetTestLog(), db, mockValidator, mockRelease, instructionConfig, mockEvents, mockVersions, enableMcoReboot)
mockValidator.EXPECT().GetHostInstallationPath(gomock.Any()).Return(common.TestDiskId).Times(1)
mockGetReleaseImage(1)
mockImages(1)
Expect(db.Model(&common.Cluster{}).Where("id = ?", *host.ClusterID).Update("openshift_version", version).Error).ToNot(HaveOccurred())
installCmdSteps, stepErr = installCommand.GetSteps(ctx, &host)
validateInstallCommand(installCommand, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host.ID, common.TestDiskId, nil, models.ClusterHighAvailabilityModeFull, enableMcoReboot)
validateInstallCommand(installCommand, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host.ID, common.TestDiskId, nil, models.ClusterHighAvailabilityModeFull, expected, version)
},
Entry("Enbale MCO reboot is false", false),
Entry("Enbale MCO reboot is true", true),
Entry("Enbale MCO reboot is false", false, "4.15.0", false),
Entry("Enbale MCO reboot is true. Lower version", true, "4.14.0", false),
Entry("Enbale MCO reboot is true. Equal version", true, "4.15.0", true),
Entry("Enbale MCO reboot is true. Higher version", true, "4.16.0", true),
)

It("get_step_one_master_success", func() {
Expand All @@ -126,7 +129,7 @@ var _ = Describe("installcmd", func() {
mockImages(1)
installCmdSteps, stepErr = installCmd.GetSteps(ctx, &host)
postvalidation(false, false, installCmdSteps[0], stepErr, models.HostRoleMaster)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host.ID, common.TestDiskId, nil, models.ClusterHighAvailabilityModeFull, true)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host.ID, common.TestDiskId, nil, models.ClusterHighAvailabilityModeFull, false, common.TestDefaultConfig.OpenShiftVersion)
hostFromDb := hostutil.GetHostFromDB(*host.ID, infraEnvId, db)
Expect(hostFromDb.InstallerVersion).Should(Equal(DefaultInstructionConfig.InstallerImage))
})
Expand All @@ -139,13 +142,13 @@ var _ = Describe("installcmd", func() {
mockImages(3)
installCmdSteps, stepErr = installCmd.GetSteps(ctx, &host)
postvalidation(false, false, installCmdSteps[0], stepErr, models.HostRoleMaster)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host.ID, common.TestDiskId, nil, models.ClusterHighAvailabilityModeFull, true)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host.ID, common.TestDiskId, nil, models.ClusterHighAvailabilityModeFull, false, common.TestDefaultConfig.OpenShiftVersion)
installCmdSteps, stepErr = installCmd.GetSteps(ctx, &host2)
postvalidation(false, false, installCmdSteps[0], stepErr, models.HostRoleMaster)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host2.ID, common.TestDiskId, nil, models.ClusterHighAvailabilityModeFull, true)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host2.ID, common.TestDiskId, nil, models.ClusterHighAvailabilityModeFull, false, common.TestDefaultConfig.OpenShiftVersion)
installCmdSteps, stepErr = installCmd.GetSteps(ctx, &host3)
postvalidation(false, false, installCmdSteps[0], stepErr, models.HostRoleBootstrap)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleBootstrap, infraEnvId, clusterId, *host3.ID, common.TestDiskId, nil, models.ClusterHighAvailabilityModeFull, true)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleBootstrap, infraEnvId, clusterId, *host3.ID, common.TestDiskId, nil, models.ClusterHighAvailabilityModeFull, false, common.TestDefaultConfig.OpenShiftVersion)
})
It("invalid_inventory", func() {
host.Inventory = "blah"
Expand Down Expand Up @@ -231,7 +234,7 @@ var _ = Describe("installcmd", func() {
prepareGetStep(sdb)
installCmdSteps, stepErr = installCmd.GetSteps(ctx, &host)
postvalidation(false, false, installCmdSteps[0], stepErr, models.HostRoleMaster)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host.ID, sdb.ID, getBootableDiskNames(disks), models.ClusterHighAvailabilityModeFull, true)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host.ID, sdb.ID, getBootableDiskNames(disks), models.ClusterHighAvailabilityModeFull, false, common.TestDefaultConfig.OpenShiftVersion)
hostFromDb := hostutil.GetHostFromDB(*host.ID, infraEnvId, db)
Expect(hostFromDb.InstallerVersion).Should(Equal(DefaultInstructionConfig.InstallerImage))
verifyDiskFormatCommand(installCmdSteps[0], sda.ID, true)
Expand All @@ -252,7 +255,7 @@ var _ = Describe("installcmd", func() {
prepareGetStep(sddd)
installCmdSteps, stepErr = installCmd.GetSteps(ctx, &host)
postvalidation(false, false, installCmdSteps[0], stepErr, models.HostRoleMaster)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host.ID, sddd.ID, getBootableDiskNames(disks), models.ClusterHighAvailabilityModeFull, true)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host.ID, sddd.ID, getBootableDiskNames(disks), models.ClusterHighAvailabilityModeFull, false, common.TestDefaultConfig.OpenShiftVersion)
hostFromDb := hostutil.GetHostFromDB(*host.ID, infraEnvId, db)
Expect(hostFromDb.InstallerVersion).Should(Equal(DefaultInstructionConfig.InstallerImage))
verifyDiskFormatCommand(installCmdSteps[0], sda.ID, true)
Expand All @@ -274,7 +277,7 @@ var _ = Describe("installcmd", func() {
prepareGetStep(sddd)
installCmdSteps, stepErr = installCmd.GetSteps(ctx, &host)
postvalidation(false, false, installCmdSteps[0], stepErr, models.HostRoleMaster)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host.ID, sddd.ID, getBootableDiskNames(disks), models.ClusterHighAvailabilityModeFull, true)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host.ID, sddd.ID, getBootableDiskNames(disks), models.ClusterHighAvailabilityModeFull, false, common.TestDefaultConfig.OpenShiftVersion)
hostFromDb := hostutil.GetHostFromDB(*host.ID, infraEnvId, db)
Expect(hostFromDb.InstallerVersion).Should(Equal(DefaultInstructionConfig.InstallerImage))
verifyDiskFormatCommand(installCmdSteps[0], sda.ID, true)
Expand Down Expand Up @@ -320,7 +323,7 @@ var _ = Describe("installcmd", func() {
prepareGetStep(sdb)
installCmdSteps, stepErr = installCmd.GetSteps(ctx, &host)
postvalidation(false, false, installCmdSteps[0], stepErr, models.HostRoleMaster)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host.ID, sdb.ID, []string{sda.ID, sdc.ID}, models.ClusterHighAvailabilityModeFull, true)
validateInstallCommand(installCmd, installCmdSteps[0], models.HostRoleMaster, infraEnvId, clusterId, *host.ID, sdb.ID, []string{sda.ID, sdc.ID}, models.ClusterHighAvailabilityModeFull, false, common.TestDefaultConfig.OpenShiftVersion)
hostFromDb := hostutil.GetHostFromDB(*host.ID, infraEnvId, db)
Expect(hostFromDb.InstallerVersion).Should(Equal(DefaultInstructionConfig.InstallerImage))
verifyDiskFormatCommand(installCmdSteps[0], sda.ID, true)
Expand Down Expand Up @@ -1187,7 +1190,7 @@ func postvalidation(isstepreplynil bool, issteperrnil bool, expectedstepreply *m
}

func validateInstallCommand(installCmd *installCmd, reply *models.Step, role models.HostRole, infraEnvId, clusterId, hostId strfmt.UUID,
bootDevice string, bootableDisks []string, haMode string, enableSkipMcoReboot bool) {
bootDevice string, bootableDisks []string, haMode string, enableSkipMcoReboot bool, version string) {
ExpectWithOffset(1, reply.StepType).To(Equal(models.StepTypeInstall))
mustGatherImage, _ := installCmd.getMustGatherArgument(defaultMustGatherVersion)
request := models.InstallCmdRequest{}
Expand All @@ -1197,7 +1200,7 @@ func validateInstallCommand(installCmd *installCmd, reply *models.Step, role mod
Expect(request.ClusterID.String()).To(Equal(clusterId.String()))
Expect(request.HostID.String()).To(Equal(hostId.String()))
Expect(swag.StringValue(request.HighAvailabilityMode)).To(Equal(haMode))
Expect(request.OpenshiftVersion).To(Equal(common.TestDefaultConfig.OpenShiftVersion))
Expect(request.OpenshiftVersion).To(Equal(version))
Expect(*request.Role).To(Equal(role))
Expect(swag.StringValue(request.BootDevice)).To(Equal(bootDevice))
Expect(request.McoImage).To(Equal(defaultMCOImage))
Expand Down

0 comments on commit 1535cec

Please sign in to comment.