Skip to content
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
44 changes: 22 additions & 22 deletions pkg/platform/centos/centos.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,44 @@ func NewCentOS(exec cmdexec.Executor) *CentOS {
func (c *CentOS) Check() []platform.Check {
var checks []platform.Check

result, err := c.removePyCli()
result, err := c.RemovePyCli()
checks = append(checks, platform.Check{"Removal of existing CLI", false, result, err, util.PyCliErr})

result, err = c.CheckExistingInstallation()
checks = append(checks, platform.Check{"Existing Platform9 Packages Check", false, result, err, util.ExisitngInstallationErr})

result, err = c.checkOSPackages()
result, err = c.CheckOSPackages()
checks = append(checks, platform.Check{"Required OS Packages Check", true, result, err, fmt.Sprintf("%s. %s", util.OSPackagesErr, err)})

result, err = c.checkSudo()
result, err = c.CheckSudo()
checks = append(checks, platform.Check{"SudoCheck", true, result, err, util.SudoErr})

result, err = c.checkEnabledRepos()
result, err = c.CheckEnabledRepos()
checks = append(checks, platform.Check{"Required Enabled Repositories Check", true, result, err, fmt.Sprintf("%s", err)})

result, err = c.checkCPU()
result, err = c.CheckCPU()
checks = append(checks, platform.Check{"CPUCheck", false, result, err, fmt.Sprintf("%s %s", util.CPUErr, err)})

result, err = c.checkDisk()
result, err = c.CheckDisk()
checks = append(checks, platform.Check{"DiskCheck", false, result, err, fmt.Sprintf("%s %s", util.DiskErr, err)})

result, err = c.checkMem()
result, err = c.CheckMem()
checks = append(checks, platform.Check{"MemoryCheck", false, result, err, fmt.Sprintf("%s %s", util.MemErr, err)})

result, err = c.checkPort()
result, err = c.CheckPort()
checks = append(checks, platform.Check{"PortCheck", false, result, err, fmt.Sprintf("%s", err)})

result, err = c.CheckKubernetesCluster()
checks = append(checks, platform.Check{"Existing Kubernetes Cluster Check", false, result, err, fmt.Sprintf("%s", err)})

result, err = c.checkPIDofSystemd()
result, err = c.CheckPIDofSystemd()
checks = append(checks, platform.Check{"Check if system is booted with systemd", true, result, err, fmt.Sprintf("%s", err)})

result, err = c.checkFirewalldIsRunning()
result, err = c.CheckFirewalldIsRunning()
checks = append(checks, platform.Check{"Check if firewalld service is not running", false, result, err, fmt.Sprintf("%s", err)})

if !util.SwapOffDisabled {
result, err = c.disableSwap()
result, err = c.DisableSwap()
checks = append(checks, platform.Check{"Disabling swap and removing swap in fstab", true, result, err, fmt.Sprintf("%s", err)})
}

Expand Down Expand Up @@ -129,7 +129,7 @@ func (c *CentOS) CheckExistingInstallation() (bool, error) {
return true, nil
}

func (c *CentOS) checkOSPackages() (bool, error) {
func (c *CentOS) CheckOSPackages() (bool, error) {

var rhel8, rocky9 bool
errLines := []string{packageInstallError}
Expand Down Expand Up @@ -177,7 +177,7 @@ func (c *CentOS) checkOSPackages() (bool, error) {
return true, nil
}

func (c *CentOS) checkEnabledRepos() (bool, error) {
func (c *CentOS) CheckEnabledRepos() (bool, error) {

var centos, rhel8 bool
centos, _ = regexp.MatchString(`.*7\.[3-9]\.*`, string(version))
Expand Down Expand Up @@ -227,7 +227,7 @@ func (c *CentOS) checkEnabledRepos() (bool, error) {
return true, nil
}

func (c *CentOS) checkSudo() (bool, error) {
func (c *CentOS) CheckSudo() (bool, error) {
idS, err := c.exec.RunWithStdout("bash", "-c", "id -u | tr -d '\\n'")
if err != nil {
return false, err
Expand All @@ -241,7 +241,7 @@ func (c *CentOS) checkSudo() (bool, error) {
return id == 0, nil
}

func (c *CentOS) checkCPU() (bool, error) {
func (c *CentOS) CheckCPU() (bool, error) {
cpuS, err := c.exec.RunWithStdout("bash", "-c", "grep -c ^processor /proc/cpuinfo | tr -d '\\n'")
if err != nil {
return false, err
Expand All @@ -260,7 +260,7 @@ func (c *CentOS) checkCPU() (bool, error) {
return false, fmt.Errorf("Number of CPUs found: %d", cpu)
}

func (c *CentOS) checkMem() (bool, error) {
func (c *CentOS) CheckMem() (bool, error) {
memS, err := c.exec.RunWithStdout("bash", "-c", "echo $(($(getconf _PHYS_PAGES) * $(getconf PAGE_SIZE) / (1024 * 1024))) | tr -d '\\n'")
if err != nil {
return false, err
Expand All @@ -279,7 +279,7 @@ func (c *CentOS) checkMem() (bool, error) {
return false, fmt.Errorf("Total memory found: %.0f GB", math.Ceil(mem/1024))
}

func (c *CentOS) checkDisk() (bool, error) {
func (c *CentOS) CheckDisk() (bool, error) {
diskS, err := c.exec.RunWithStdout("bash", "-c", "df -k / --output=size | sed 1d | xargs | tr -d '\\n'")
if err != nil {
return false, err
Expand Down Expand Up @@ -314,7 +314,7 @@ func (c *CentOS) checkDisk() (bool, error) {
return false, fmt.Errorf("Available disk space: %.0f GB", math.Trunc(avail/util.GB))
}

func (c *CentOS) checkPort() (bool, error) {
func (c *CentOS) CheckPort() (bool, error) {
var arg string

// For remote execution the command is wrapped under quotes ("") which creates
Expand Down Expand Up @@ -345,7 +345,7 @@ func (c *CentOS) checkPort() (bool, error) {
return true, nil
}

func (c *CentOS) removePyCli() (bool, error) {
func (c *CentOS) RemovePyCli() (bool, error) {

if _, err := c.exec.RunWithStdout("rm", "-rf", util.PyCliPath); err != nil {
return false, err
Expand Down Expand Up @@ -422,7 +422,7 @@ func (c *CentOS) installOSPackages(p string) error {
return nil
}

func (c *CentOS) disableSwap() (bool, error) {
func (c *CentOS) DisableSwap() (bool, error) {
err := swapoff.SetupNode(c.exec)
if err != nil {
return false, errors.New("error occurred while disabling swap")
Expand All @@ -431,7 +431,7 @@ func (c *CentOS) disableSwap() (bool, error) {
}
}

func (c *CentOS) checkPIDofSystemd() (bool, error) {
func (c *CentOS) CheckPIDofSystemd() (bool, error) {
_, err := c.exec.RunWithStdout("bash", "-c", "ps -p 1 -o comm= | grep systemd")
if err != nil {
return false, errors.New("System is not booted with systemd")
Expand All @@ -440,7 +440,7 @@ func (c *CentOS) checkPIDofSystemd() (bool, error) {
}
}

func (c *CentOS) checkFirewalldIsRunning() (bool, error) {
func (c *CentOS) CheckFirewalldIsRunning() (bool, error) {
_, err := c.exec.RunWithStdout("bash", "-c", "systemctl is-active firewalld")
if err != nil {
return true, nil
Expand Down
30 changes: 15 additions & 15 deletions pkg/platform/centos/centos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type args struct {
exec cmdexec.Executor
}

//CPU check test case
// CPU check test case
func TestCPU(t *testing.T) {
type want struct {
result bool
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestCPU(t *testing.T) {
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
c := &CentOS{exec: tc.exec}
o, err := c.checkCPU()
o, err := c.CheckCPU()

if diff := cmp.Diff(tc.want.result, o); diff != "" {
t.Errorf("r: -want, +got:\n%s", diff)
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestRAM(t *testing.T) {
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
c := &CentOS{exec: tc.exec}
o, err := c.checkMem()
o, err := c.CheckMem()

if diff := cmp.Diff(tc.want.result, o); diff != "" {
t.Errorf("r: -want, +got:\n%s", diff)
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestDisk(t *testing.T) {
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
c := &CentOS{exec: tc.exec}
o, err := c.checkDisk()
o, err := c.CheckDisk()

if diff := cmp.Diff(tc.want.result, o); diff != "" {
t.Errorf("r: -want, +got:\n%s", diff)
Expand All @@ -185,7 +185,7 @@ func TestDisk(t *testing.T) {
}
}

//Sudo check test case
// Sudo check test case
func TestSudo(t *testing.T) {
type want struct {
result bool
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestSudo(t *testing.T) {
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
c := &CentOS{exec: tc.exec}
o, err := c.checkSudo()
o, err := c.CheckSudo()

if diff := cmp.Diff(tc.want.err, err); diff != "" {
t.Errorf("r: -want, +got:\n%s", diff)
Expand All @@ -242,7 +242,7 @@ func TestSudo(t *testing.T) {
}
}

//Port check test case
// Port check test case
func TestPort(t *testing.T) {
type want struct {
result bool
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestPort(t *testing.T) {
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
c := &CentOS{exec: tc.exec}
o, _ := c.checkPort()
o, _ := c.CheckPort()

if diff := cmp.Diff(tc.want.result, o); diff != "" {
t.Errorf("r: -want, +got:\n%s", diff)
Expand All @@ -294,7 +294,7 @@ func TestPort(t *testing.T) {
}
}

//ExistingInstallation check test case
// ExistingInstallation check test case
func TestExistingInstallation(t *testing.T) {
type want struct {
result bool
Expand Down Expand Up @@ -395,7 +395,7 @@ func TestOSPackages(t *testing.T) {
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
c := &CentOS{exec: tc.exec}
o, err := c.checkOSPackages()
o, err := c.CheckOSPackages()

if diff := cmp.Diff(tc.want.result, o); diff != "" {
t.Errorf("r: -want, +got:\n%s", diff)
Expand All @@ -406,7 +406,7 @@ func TestOSPackages(t *testing.T) {
}
}

//Test case for RemovePyCli check
// Test case for RemovePyCli check
func TestRemovePyCli(t *testing.T) {
type want struct {
result bool
Expand Down Expand Up @@ -451,7 +451,7 @@ func TestRemovePyCli(t *testing.T) {
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
c := &CentOS{exec: tc.exec}
result, err := c.removePyCli()
result, err := c.RemovePyCli()

assert.Equal(t, tc.want.err, err)
assert.Equal(t, tc.want.result, result)
Expand Down Expand Up @@ -607,7 +607,7 @@ func TestDisableSwap(t *testing.T) {
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
c := &CentOS{exec: tc.exec}
result, err := c.disableSwap()
result, err := c.DisableSwap()
assert.Equal(t, tc.result, result)
assert.Equal(t, tc.err, err)
})
Expand Down Expand Up @@ -657,7 +657,7 @@ func TestPIDofSystemdCheck(t *testing.T) {
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
c := &CentOS{exec: tc.exec}
result, err := c.checkPIDofSystemd()
result, err := c.CheckPIDofSystemd()
assert.Equal(t, tc.result, result)
assert.Equal(t, tc.err, err)
})
Expand Down Expand Up @@ -707,7 +707,7 @@ func TestCheckFirewalldService(t *testing.T) {
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
c := &CentOS{exec: tc.exec}
result, err := c.checkFirewalldIsRunning()
result, err := c.CheckFirewalldIsRunning()
assert.Equal(t, tc.result, result)
assert.Equal(t, tc.err, err)
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ var (
regexp.MustCompile(`.*/etc/pf9/certs/hostagent/key\.pem`),
regexp.MustCompile(`.*/etc/pf9/certs/ca/cert\.pem`),
regexp.MustCompile(`.*/etc/pf9/hostagent\.conf`),
regexp.MustCompile(`.*pf9-hostagent-.*\.x86_64\.deb`),
regexp.MustCompile(`.*pf9-comms-.*\.x86_64\.deb`),
regexp.MustCompile(`.*pf9-hostagent-.*\.x86_64\.*`),
regexp.MustCompile(`.*pf9-comms-.*\.x86_64\.*`),
regexp.MustCompile(`.*download_nocert_routine executed successfully.*`),
}
HostAgentprogressPercentage = []int{5, 10, 15, 20, 25, 75, 100}
Expand Down
Loading