Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel check on verify is not passing when version is 3.10 which is greater than 3.2, because of float check #8288

Merged
merged 6 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"
"strings"

semver "github.com/Masterminds/semver/v3"
"github.com/chef/automate/components/automate-cli/pkg/verifyserver/constants"
"github.com/chef/automate/components/automate-cli/pkg/verifyserver/models"
"github.com/chef/automate/components/automate-cli/pkg/verifyserver/utils/fiberutils"
Expand Down Expand Up @@ -41,14 +42,14 @@ const (
OSFILEPATH = "/etc/os-release"
KERNELFILEPATH = "/proc/sys/kernel/osrelease"
LINUX_VERSION_CHECK = "Linux Version Check"
KERNAL_VERSION_CHECK = "Kernal Version Check"
KERNEL_VERSION_CHECK = "Kernel Version Check"
UBUNTU = "Ubuntu"
RED_HAT = "Red Hat"
AMAZON_LINUX = "Amazon Linux"
SUSE_LINUX = "SUSE Linux"
RED_HAT_SUPPORTED_VERSION = 7
KERNAL_SUPPORTED_VERSION = 3.2
KERNAL_SUPPORTED_VERSION_AMAZON_LINUX = 5.10
KERNEL_SUPPORTED_VERSION = "3.2"
KERNEL_SUPPORTED_VERSION_AMAZON_LINUX = 5.10
)

var cmdCheckArray = []string{"mkdir", "useradd", "usermod", "groupadd", "chown", "chmod",
Expand Down Expand Up @@ -94,7 +95,7 @@ func (sv *SoftwareVersionService) GetSoftwareVersionDetails(query string) (*mode
}
kernelResponse, err := sv.checkKernelVersion(sv.kernelFilePath, osName)
if err != nil {
sv.logger.Error("Error while getting the Kernal Version: ", kernelResponse.ErrorMsg)
sv.logger.Error("Error while getting the Kernel Version: ", kernelResponse.ErrorMsg)
}
if !kernelResponse.Passed {
serviceResponse.Passed = false
Expand Down Expand Up @@ -183,20 +184,31 @@ func (sv *SoftwareVersionService) checkKernelVersion(kernelFilePath, osName stri
kernelVersion, err := getosutils.GetKernelVersion(kernelFilePath)
if err != nil {
sv.logger.Error("Enable to get OS Version as the file on the path does not exit: ", err)
return failureResponse(KERNAL_VERSION_CHECK, "Its not feasible to determine the Kernal version of the system", "Please run automate on the supported platforms."), err
return failureResponse(KERNEL_VERSION_CHECK, "Its not feasible to determine the Kernel version of the system", "Please run automate on the supported platforms."), err
}
sv.logger.Debug("Got the kernal version:", kernelVersion)
checkVersion, _ := strconv.ParseFloat(kernelVersion, 64)
sv.logger.Debug("Got the kernel version:", kernelVersion)
if strings.Contains(strings.ToLower(osName), strings.ToLower(AMAZON_LINUX)) {
if checkVersion == KERNAL_SUPPORTED_VERSION_AMAZON_LINUX {
return successResponse(KERNAL_VERSION_CHECK, "Linux kernal version is "+fmt.Sprintf("%.2f", checkVersion)), nil
checkVersion, _ := strconv.ParseFloat(kernelVersion, 64)
if checkVersion == KERNEL_SUPPORTED_VERSION_AMAZON_LINUX {
return successResponse(KERNEL_VERSION_CHECK, "Linux kernel version is "+fmt.Sprintf("%.2f", checkVersion)), nil
}
return failureResponse(KERNAL_VERSION_CHECK, "Linux kernel version is not equal to 5.10", "Use a linux version whose kernel version is equal to 5.10"), nil
return failureResponse(KERNEL_VERSION_CHECK, "Linux kernel version is "+kernelVersion+" which is lower than 5.10", "Use a linux version whose kernel version is greater than or equals to 5.10"), nil
}
if checkVersion >= KERNAL_SUPPORTED_VERSION {
return successResponse(KERNAL_VERSION_CHECK, "Linux kernal version is "+fmt.Sprintf("%.2f", checkVersion)), nil
userVersion, err := semver.NewVersion(kernelVersion)
if err != nil {
sv.logger.Errorf("Error parsing user kernel version: %v", err)
return failureResponse(KERNEL_VERSION_CHECK, "Failed while getting the kernel version", "Check your kernel version."), err
}
minimumVersion, err := semver.NewVersion(KERNEL_SUPPORTED_VERSION)
if err != nil {
sv.logger.Errorf("Error parsing minimum required kernel version: %v", err)
return failureResponse(KERNEL_VERSION_CHECK, "Failed while getting minimum supported kernel version", "Check your kernel version."), err
}

if userVersion.Compare(minimumVersion) >= 0 {
return successResponse(KERNEL_VERSION_CHECK, "Linux kernel version is "+kernelVersion), nil
}
return failureResponse(KERNAL_VERSION_CHECK, "Linux kernel version is lower than 3.2", "Use a linux version whose kernel version is greater than 3.2"), nil
return failureResponse(KERNEL_VERSION_CHECK, "Linux kernel version is "+kernelVersion+" which is lower than 3.2", "Use a linux version whose kernel version is greater than or equals to 3.2"), nil
}

func successResponse(title string, successMsg string) *models.Checks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,30 @@ var osTestVersion = map[string][]string{
}

const (
osReleaseRedHatFail = "./testfiles/os_release_red_hat_failure.txt"
osReleaseUbuntuFail = "./testfiles/os_release_ubuntu_failure.txt"
osReleaseDebian = "./testfiles/os_release_debian.txt"
osReleaseSuse = "./testfiles/os_release_suse.txt"
osReleaseAmazonLinux = "./testfiles/os_release_amazon_linux.txt"
osReleaseRedHat = "./testfiles/os_release_red_hat.txt"
osReleaseCentos = "./testfiles/os_release_centos.txt"
successfile = "./testfiles/os_release_ubuntu.txt"
failurefile = "./testfiles/failure.txt"
versionfile = "./testfiles/os_release_suse_failure.txt"
failfilepath = "./failfilepath"
LinuxVersionTitle = "Linux Version Check"
KernalVersionTitle = "Kernal Version Check"
MkdirTitle = "mkdir availability"
OpensslTitle = "openssl availability"
StatTitle = "stat availability"
MkdirIsAvailable = "mkdir is available"
OpensslIsAvailable = "openssl is available"
StatIsAvailable = "stat is available"
successKernelfile = "./testfiles/successkernel.txt"
failureKernelfile = "./testfiles/failurekernel.txt"
osReleaseRedHatFail = "./testfiles/os_release_red_hat_failure.txt"
osReleaseUbuntuFail = "./testfiles/os_release_ubuntu_failure.txt"
osReleaseDebian = "./testfiles/os_release_debian.txt"
osReleaseSuse = "./testfiles/os_release_suse.txt"
osReleaseAmazonLinux = "./testfiles/os_release_amazon_linux.txt"
osReleaseRedHat = "./testfiles/os_release_red_hat.txt"
osReleaseCentos = "./testfiles/os_release_centos.txt"
successfile = "./testfiles/os_release_ubuntu.txt"
failurefile = "./testfiles/failure.txt"
versionfile = "./testfiles/os_release_suse_failure.txt"
failfilepath = "./failfilepath"
LinuxVersionTitle = "Linux Version Check"
KernelVersionTitle = "Kernel Version Check"
MkdirTitle = "mkdir availability"
OpensslTitle = "openssl availability"
StatTitle = "stat availability"
MkdirIsAvailable = "mkdir is available"
OpensslIsAvailable = "openssl is available"
StatIsAvailable = "stat is available"
successKernelfile = "./testfiles/successkernel.txt"
testKernelfile = "./testfiles/testkernel.txt"
failKernelfile = "./testfiles/failkernel.txt"
failureParsingKernelfile = "./testfiles/failureparsingkernel.txt"
failureKernelfile = "./testfiles/failurekernel.txt"
)

var (
Expand Down Expand Up @@ -88,9 +91,9 @@ func TestGetSoftwareVersionDetails(t *testing.T) {
ResolutionMsg: "",
},
{
Title: KernalVersionTitle,
Title: KernelVersionTitle,
Passed: true,
SuccessMsg: "Linux kernal version is 5.10",
SuccessMsg: "Linux kernel version is 5.10",
ErrorMsg: "",
ResolutionMsg: "",
},
Expand Down Expand Up @@ -130,9 +133,9 @@ func TestGetSoftwareVersionDetails(t *testing.T) {
ResolutionMsg: "",
},
{
Title: KernalVersionTitle,
Title: KernelVersionTitle,
Passed: true,
SuccessMsg: "Linux kernal version is 5.10",
SuccessMsg: "Linux kernel version is 5.10",
ErrorMsg: "",
ResolutionMsg: "",
},
Expand Down Expand Up @@ -165,9 +168,9 @@ func TestGetSoftwareVersionDetails(t *testing.T) {
ResolutionMsg: "",
},
{
Title: KernalVersionTitle,
Title: KernelVersionTitle,
Passed: true,
SuccessMsg: "Linux kernal version is 5.10",
SuccessMsg: "Linux kernel version is 5.10",
ErrorMsg: "",
ResolutionMsg: "",
},
Expand Down Expand Up @@ -207,9 +210,9 @@ func TestGetSoftwareVersionDetails(t *testing.T) {
ResolutionMsg: "Ensure wrong-cammand is available in $PATH on the node",
},
{
Title: KernalVersionTitle,
Title: KernelVersionTitle,
Passed: true,
SuccessMsg: "Linux kernal version is 5.10",
SuccessMsg: "Linux kernel version is 5.10",
ErrorMsg: "",
ResolutionMsg: "",
},
Expand Down Expand Up @@ -249,9 +252,9 @@ func TestGetSoftwareVersionDetails(t *testing.T) {
ResolutionMsg: "",
},
{
Title: KernalVersionTitle,
Title: KernelVersionTitle,
Passed: true,
SuccessMsg: "Linux kernal version is 5.10",
SuccessMsg: "Linux kernel version is 5.10",
ErrorMsg: "",
ResolutionMsg: "",
},
Expand Down Expand Up @@ -291,9 +294,9 @@ func TestGetSoftwareVersionDetails(t *testing.T) {
ResolutionMsg: "",
},
{
Title: KernalVersionTitle,
Title: KernelVersionTitle,
Passed: true,
SuccessMsg: "Linux kernal version is 5.10",
SuccessMsg: "Linux kernel version is 5.10",
ErrorMsg: "",
ResolutionMsg: "",
},
Expand All @@ -308,7 +311,7 @@ func TestGetSoftwareVersionDetails(t *testing.T) {
},
},
{
description: "If the kernal version is not supported by automate",
description: "If the kernel version is not supported by automate",
args: args{
query: "postgresql",
checkarray: checktrue,
Expand All @@ -333,11 +336,11 @@ func TestGetSoftwareVersionDetails(t *testing.T) {
ResolutionMsg: "",
},
{
Title: KernalVersionTitle,
Title: KernelVersionTitle,
Passed: false,
SuccessMsg: "",
ErrorMsg: "Linux kernel version is lower than 3.2",
ResolutionMsg: "Use a linux version whose kernel version is greater than 3.2",
ErrorMsg: "Linux kernel version is 2.15 which is lower than 3.2",
ResolutionMsg: "Use a linux version whose kernel version is greater than or equals to 3.2",
},
{
Title: LinuxVersionTitle,
Expand All @@ -350,7 +353,7 @@ func TestGetSoftwareVersionDetails(t *testing.T) {
},
},
{
description: "If file is not present for reading the kernal version",
description: "If file is not present for reading the kernel version",
args: args{
query: "postgresql",
checkarray: checktrue,
Expand All @@ -375,10 +378,10 @@ func TestGetSoftwareVersionDetails(t *testing.T) {
ResolutionMsg: "",
},
{
Title: KernalVersionTitle,
Title: KernelVersionTitle,
Passed: false,
SuccessMsg: "",
ErrorMsg: "Its not feasible to determine the Kernal version of the system",
ErrorMsg: "Its not feasible to determine the Kernel version of the system",
ResolutionMsg: "Please run automate on the supported platforms.",
},
{
Expand Down Expand Up @@ -412,6 +415,7 @@ func TestGetSoftwareVersionDetails(t *testing.T) {
})
}
}

func TestCheckOs(t *testing.T) {
log, _ := logger.NewLogger("text", "debug")
sv := NewSoftwareVersionService(log, func(cmd string) (string, error) {
Expand Down Expand Up @@ -740,54 +744,102 @@ func TestCheckKernelVersion(t *testing.T) {
expectedErr string
}{
{
description: "If the Kernal version is supported",
description: "If the Kernel version is supported",
args: args{
kernelFilePath: successKernelfile,
osname: AMAZON_LINUX,
},
expectedBody: &models.Checks{
Title: "Kernal Version Check",
Title: "Kernel Version Check",
Passed: true,
SuccessMsg: "Linux kernal version is 5.10",
SuccessMsg: "Linux kernel version is 5.10",
ErrorMsg: "",
ResolutionMsg: "",
},
wantErr: false,
expectedErr: "",
},
{
description: "If the Kernal Version entered is not supported suse linux",
description: "If the Kernel Version entered is not supported suse linux",
args: args{
kernelFilePath: failureKernelfile,
osname: SUSE_LINUX,
},
expectedBody: &models.Checks{
Title: KernalVersionTitle,
Title: KernelVersionTitle,
Passed: false,
SuccessMsg: "",
ErrorMsg: "Linux kernel version is lower than 3.2",
ResolutionMsg: "Use a linux version whose kernel version is greater than 3.2",
ErrorMsg: "Linux kernel version is 2.15 which is lower than 3.2",
ResolutionMsg: "Use a linux version whose kernel version is greater than or equals to 3.2",
},
wantErr: false,
expectedErr: "",
},
{
description: "If the Kernel Version entered is not supported suse linux",
args: args{
kernelFilePath: failKernelfile,
osname: SUSE_LINUX,
},
expectedBody: &models.Checks{
Title: KernelVersionTitle,
Passed: false,
SuccessMsg: "",
ErrorMsg: "Linux kernel version is 3.1 which is lower than 3.2",
ResolutionMsg: "Use a linux version whose kernel version is greater than or equals to 3.2",
},
wantErr: false,
expectedErr: "",
},
{
description: "If the Kernel Version entered is 3.10 suse linux",
args: args{
kernelFilePath: testKernelfile,
osname: SUSE_LINUX,
},
expectedBody: &models.Checks{
Title: KernelVersionTitle,
Passed: true,
SuccessMsg: "Linux kernel version is 3.10",
ErrorMsg: "",
ResolutionMsg: "",
},
wantErr: false,
expectedErr: "",
},
{
description: "If the Kernal Version entered is not supported Amazon linux",
description: "Failure while passing the user kernel version",
args: args{
kernelFilePath: failureParsingKernelfile,
osname: SUSE_LINUX,
},
expectedBody: &models.Checks{
Title: KernelVersionTitle,
Passed: false,
SuccessMsg: "",
ErrorMsg: "Failed while getting the kernel version",
ResolutionMsg: "Check your kernel version.",
},
wantErr: true,
expectedErr: "Invalid Semantic Version",
},
{
description: "If the Kernel Version entered is not supported Amazon linux",
args: args{
kernelFilePath: failureKernelfile,
osname: AMAZON_LINUX,
},
expectedBody: &models.Checks{
Title: "Kernal Version Check",
Title: "Kernel Version Check",
Passed: false, SuccessMsg: "",
ErrorMsg: "Linux kernel version is not equal to 5.10",
ResolutionMsg: "Use a linux version whose kernel version is equal to 5.10",
ErrorMsg: "Linux kernel version is 2.15 which is lower than 5.10",
ResolutionMsg: "Use a linux version whose kernel version is greater than or equals to 5.10",
},
wantErr: false,
expectedErr: "",
},
{
description: "If not able to get the kernal Version",
description: "If not able to get the kernel Version",
args: args{
kernelFilePath: failfilepath,
osname: AMAZON_LINUX,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.1.0-1036-aws
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.10.0-1036-aws
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.0-1036-aws
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ require (
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/Masterminds/semver/v3 v3.2.1
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/OneOfOne/xxhash v1.2.7 // indirect
github.com/agext/levenshtein v1.2.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20190129172621-c8b1d7a94ddf/go.mod h1:aJ4qN3TfrelA6NZ6AXsXRfmEVaYin3EDbSPJrKS8OXo=
github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20191009163259-e802c2cb94ae/go.mod h1:mjwGPas4yKduTyubHvD1Atl9r1rUq8DfVy+gkVvZ+oo=
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Masterminds/squirrel v1.1.0 h1:baP1qLdoQCeTw3ifCdOq2dkYc6vGcmRdaociKLbEJXs=
github.com/Masterminds/squirrel v1.1.0/go.mod h1:yaPeOnPG5ZRwL9oKdTsO/prlkPbXWZlRVMQ/gGlzIuA=
github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU=
Expand Down
Loading