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

Fix repo #10

Merged
merged 2 commits into from
Mar 16, 2024
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
4 changes: 2 additions & 2 deletions cmd/app/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli"

"github.com/longhorn/longhorn-preflight/pkg/checker"
"github.com/longhorn/longhorn-preflight/pkg/pkgmgr"
"github.com/longhorn/cli/pkg/checker"
"github.com/longhorn/cli/pkg/pkgmgr"
)

func PreflightCheckCmd(pkgMgrType pkgmgr.PackageManagerType) cli.Command {
Expand Down
4 changes: 2 additions & 2 deletions cmd/app/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli"

"github.com/longhorn/longhorn-preflight/pkg/installer"
"github.com/longhorn/longhorn-preflight/pkg/pkgmgr"
"github.com/longhorn/cli/pkg/installer"
"github.com/longhorn/cli/pkg/pkgmgr"
)

func PreflightInstallCmd(pkgMgrType pkgmgr.PackageManagerType) cli.Command {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/longhorn/longhorn-preflight
module github.com/longhorn/cli

go 1.21

Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli"

"github.com/longhorn/longhorn-preflight/cmd/app"
"github.com/longhorn/longhorn-preflight/pkg/utils"
"github.com/longhorn/cli/cmd/app"
"github.com/longhorn/cli/pkg/utils"
)

func main() {
Expand Down
8 changes: 4 additions & 4 deletions pkg/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/longhorn/longhorn-preflight/pkg/pkgmgr"
"github.com/longhorn/longhorn-preflight/pkg/utils"
"github.com/longhorn/cli/pkg/pkgmgr"
"github.com/longhorn/cli/pkg/utils"
)

type Checker struct {
Expand Down Expand Up @@ -183,7 +183,7 @@ func (c *Checker) CheckHugePages() {
}

func (c *Checker) isHugePagesTotalEqualOrLargerThan(requiredHugePages int) (bool, error) {
output, err := c.pkgMgr.Execute("grep", []string{"HugePages_Total", "/proc/meminfo"}, lhtypes.ExecuteNoTimeout)
output, err := c.pkgMgr.Execute([]string{}, "grep", []string{"HugePages_Total", "/proc/meminfo"}, lhtypes.ExecuteNoTimeout)
if err != nil {
return false, errors.Wrap(err, "failed to get total number of HugePages")
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func (c *Checker) CheckCpuInstructionSet(instructionSets map[string][]string) {
}

for _, set := range sets {
_, err := c.pkgMgr.Execute("grep", []string{set, "/proc/cpuinfo"}, lhtypes.ExecuteNoTimeout)
_, err := c.pkgMgr.Execute([]string{}, "grep", []string{set, "/proc/cpuinfo"}, lhtypes.ExecuteNoTimeout)
if err != nil {
logrus.Errorf("CPU instruction set %v is not supported", set)
} else {
Expand Down
4 changes: 2 additions & 2 deletions pkg/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
lhns "github.com/longhorn/go-common-libs/ns"
lhtypes "github.com/longhorn/go-common-libs/types"

"github.com/longhorn/longhorn-preflight/pkg/pkgmgr"
"github.com/longhorn/cli/pkg/pkgmgr"
)

type Installer struct {
Expand All @@ -31,7 +31,7 @@ func NewInstaller(pkgMgrType pkgmgr.PackageManagerType) (*Installer, error) {
return nil, err
}

kernelRelease, err := executor.Execute("uname", []string{"-r"}, lhtypes.ExecuteNoTimeout)
kernelRelease, err := executor.Execute([]string{}, "uname", []string{"-r"}, lhtypes.ExecuteNoTimeout)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/installer/spdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (i *Installer) ConfigureSPDKEnv() error {
// Configure SPDK environment
logrus.Infof("Configuring SPDK environment")
args := getArgsForConfiguringSPDKEnv()
if _, err := i.pkgMgr.Execute("bash", args, lhtypes.ExecuteNoTimeout); err != nil {
if _, err := i.pkgMgr.Execute([]string{}, "bash", args, lhtypes.ExecuteNoTimeout); err != nil {
logrus.WithError(err).Errorf("Failed to configure SPDK environment")
} else {
logrus.Infof("Successfully configured SPDK environment")
Expand Down
22 changes: 11 additions & 11 deletions pkg/pkgmgr/apt.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,51 @@ func NewAptPackageManager(executor *lhns.Executor) *AptPackageManager {

// UpdatePackageList updates list of available packages
func (c *AptPackageManager) UpdatePackageList() (string, error) {
return c.executor.Execute("apt", []string{"update", "-y"}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "apt", []string{"update", "-y"}, lhtypes.ExecuteNoTimeout)
}

// InstallPackage executes the installation command
func (c *AptPackageManager) InstallPackage(name string) (string, error) {
return c.executor.Execute("apt", []string{"install", name, "-y"}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "apt", []string{"install", name, "-y"}, lhtypes.ExecuteNoTimeout)
}

// UninstallPackage executes the uninstallation command
func (c *AptPackageManager) UninstallPackage(name string) (string, error) {
return c.executor.Execute("apt", []string{"remove", name, "-y"}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "apt", []string{"remove", name, "-y"}, lhtypes.ExecuteNoTimeout)
}

// Execute executes the given command with the specified environment variables, binary, and arguments.
func (c *AptPackageManager) Execute(binary string, args []string, timeout time.Duration) (string, error) {
return c.executor.Execute(binary, args, timeout)
func (c *AptPackageManager) Execute(envs []string, binary string, args []string, timeout time.Duration) (string, error) {
return c.executor.Execute(envs, binary, args, timeout)
}

// Modprobe executes the modprobe command
func (c *AptPackageManager) Modprobe(module string) (string, error) {
return c.executor.Execute("modprobe", []string{module}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "modprobe", []string{module}, lhtypes.ExecuteNoTimeout)
}

// CheckModLoaded checks if a module is loaded
func (c *AptPackageManager) CheckModLoaded(module string) error {
_, err := c.executor.Execute("grep", []string{module, "/proc/modules"}, lhtypes.ExecuteNoTimeout)
_, err := c.executor.Execute([]string{}, "grep", []string{module, "/proc/modules"}, lhtypes.ExecuteNoTimeout)
return err
}

// StartService executes the service start command
func (c *AptPackageManager) StartService(name string) (string, error) {
output, err := c.executor.Execute("systemctl", []string{"-q", "enable", name}, lhtypes.ExecuteNoTimeout)
output, err := c.executor.Execute([]string{}, "systemctl", []string{"-q", "enable", name}, lhtypes.ExecuteNoTimeout)
if err != nil {
return output, err
}

return c.executor.Execute("systemctl", []string{"start", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "systemctl", []string{"start", name}, lhtypes.ExecuteNoTimeout)
}

// GetServiceStatus executes the service status command
func (c *AptPackageManager) GetServiceStatus(name string) (string, error) {
return c.executor.Execute("systemctl", []string{"status", "--no-pager", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "systemctl", []string{"status", "--no-pager", name}, lhtypes.ExecuteNoTimeout)
}

// CheckPackageInstalled checks if a package is installed
func (c *AptPackageManager) CheckPackageInstalled(name string) (string, error) {
return c.executor.Execute("dpkg-query", []string{"-l", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "dpkg-query", []string{"-l", name}, lhtypes.ExecuteNoTimeout)
}
22 changes: 11 additions & 11 deletions pkg/pkgmgr/pacman.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,51 @@ func NewPacmanPackageManager(executor *lhns.Executor) *PacmanPackageManager {

// UpdatePackageList updates list of available packages
func (c *PacmanPackageManager) UpdatePackageList() (string, error) {
return c.executor.Execute("pacman", []string{"-Syu", "--noconfirm"}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "pacman", []string{"-Syu", "--noconfirm"}, lhtypes.ExecuteNoTimeout)
}

// InstallPackage executes the installation command
func (c *PacmanPackageManager) InstallPackage(name string) (string, error) {
return c.executor.Execute("pacman", []string{"-S", "--noconfirm", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "pacman", []string{"-S", "--noconfirm", name}, lhtypes.ExecuteNoTimeout)
}

// UninstallPackage executes the uninstallation command
func (c *PacmanPackageManager) UninstallPackage(name string) (string, error) {
return c.executor.Execute("pacman", []string{"-R", "--noconfirm", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "pacman", []string{"-R", "--noconfirm", name}, lhtypes.ExecuteNoTimeout)
}

// Execute executes the given command with the specified environment variables, binary, and arguments.
func (c *PacmanPackageManager) Execute(binary string, args []string, timeout time.Duration) (string, error) {
return c.executor.Execute(binary, args, timeout)
func (c *PacmanPackageManager) Execute(envs []string, binary string, args []string, timeout time.Duration) (string, error) {
return c.executor.Execute(envs, binary, args, timeout)
}

// Modprobe executes the modprobe command
func (c *PacmanPackageManager) Modprobe(module string) (string, error) {
return c.executor.Execute("modprobe", []string{module}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "modprobe", []string{module}, lhtypes.ExecuteNoTimeout)
}

// CheckModLoaded checks if a module is loaded
func (c *PacmanPackageManager) CheckModLoaded(module string) error {
_, err := c.executor.Execute("grep", []string{module, "/proc/modules"}, lhtypes.ExecuteNoTimeout)
_, err := c.executor.Execute([]string{}, "grep", []string{module, "/proc/modules"}, lhtypes.ExecuteNoTimeout)
return err
}

// StartService executes the service start command
func (c *PacmanPackageManager) StartService(name string) (string, error) {
output, err := c.executor.Execute("systemctl", []string{"-q", "enable", name}, lhtypes.ExecuteNoTimeout)
output, err := c.executor.Execute([]string{}, "systemctl", []string{"-q", "enable", name}, lhtypes.ExecuteNoTimeout)
if err != nil {
return output, err
}

return c.executor.Execute("systemctl", []string{"start", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "systemctl", []string{"start", name}, lhtypes.ExecuteNoTimeout)
}

// GetServiceStatus executes the service status command
func (c *PacmanPackageManager) GetServiceStatus(name string) (string, error) {
return c.executor.Execute("systemctl", []string{"status", "--no-pager", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "systemctl", []string{"status", "--no-pager", name}, lhtypes.ExecuteNoTimeout)
}

// CheckPackageInstalled checks if a package is installed
func (c *PacmanPackageManager) CheckPackageInstalled(name string) (string, error) {
return c.executor.Execute("pacman", []string{"-Q", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "pacman", []string{"-Q", name}, lhtypes.ExecuteNoTimeout)
}
2 changes: 1 addition & 1 deletion pkg/pkgmgr/pkgmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type PackageManager interface {
StartService(name string) (string, error)
GetServiceStatus(name string) (string, error)
CheckPackageInstalled(name string) (string, error)
Execute(binary string, args []string, timeout time.Duration) (string, error)
Execute(envs []string, binary string, args []string, timeout time.Duration) (string, error)
}

func New(pkgMgrType PackageManagerType, executor *lhns.Executor) (PackageManager, error) {
Expand Down
22 changes: 11 additions & 11 deletions pkg/pkgmgr/yum.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,51 @@ func NewYumPackageManager(executor *lhns.Executor) *YumPackageManager {

// UpdatePackageList updates list of available packages
func (c *YumPackageManager) UpdatePackageList() (string, error) {
return c.executor.Execute("yum", []string{"update", "-y"}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "yum", []string{"update", "-y"}, lhtypes.ExecuteNoTimeout)
}

// InstallPackage executes the installation command
func (c *YumPackageManager) InstallPackage(name string) (string, error) {
return c.executor.Execute("yum", []string{"install", name, "-y"}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "yum", []string{"install", name, "-y"}, lhtypes.ExecuteNoTimeout)
}

// UninstallPackage executes the uninstallation command
func (c *YumPackageManager) UninstallPackage(name string) (string, error) {
return c.executor.Execute("yum", []string{"remove", name, "-y"}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "yum", []string{"remove", name, "-y"}, lhtypes.ExecuteNoTimeout)
}

// Execute executes the given command with the specified environment variables, binary, and arguments.
func (c *YumPackageManager) Execute(binary string, args []string, timeout time.Duration) (string, error) {
return c.executor.Execute(binary, args, timeout)
func (c *YumPackageManager) Execute(envs []string, binary string, args []string, timeout time.Duration) (string, error) {
return c.executor.Execute(envs, binary, args, timeout)
}

// Modprobe executes the modprobe command
func (c *YumPackageManager) Modprobe(module string) (string, error) {
return c.executor.Execute("modprobe", []string{module}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "modprobe", []string{module}, lhtypes.ExecuteNoTimeout)
}

// CheckModLoaded checks if a module is loaded
func (c *YumPackageManager) CheckModLoaded(module string) error {
_, err := c.executor.Execute("grep", []string{module, "/proc/modules"}, lhtypes.ExecuteNoTimeout)
_, err := c.executor.Execute([]string{}, "grep", []string{module, "/proc/modules"}, lhtypes.ExecuteNoTimeout)
return err
}

// StartService executes the service start command
func (c *YumPackageManager) StartService(name string) (string, error) {
output, err := c.executor.Execute("systemctl", []string{"-q", "enable", name}, lhtypes.ExecuteNoTimeout)
output, err := c.executor.Execute([]string{}, "systemctl", []string{"-q", "enable", name}, lhtypes.ExecuteNoTimeout)
if err != nil {
return output, err
}

return c.executor.Execute("systemctl", []string{"start", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "systemctl", []string{"start", name}, lhtypes.ExecuteNoTimeout)
}

// GetServiceStatus executes the service status command
func (c *YumPackageManager) GetServiceStatus(name string) (string, error) {
return c.executor.Execute("systemctl", []string{"status", "--no-pager", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "systemctl", []string{"status", "--no-pager", name}, lhtypes.ExecuteNoTimeout)
}

// CheckPackageInstalled checks if a package is installed
func (c *YumPackageManager) CheckPackageInstalled(name string) (string, error) {
return c.executor.Execute("rpm", []string{"-q", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "rpm", []string{"-q", name}, lhtypes.ExecuteNoTimeout)
}
22 changes: 11 additions & 11 deletions pkg/pkgmgr/zypper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,51 @@ func NewZypperPackageManager(executor *lhns.Executor) *ZypperPackageManager {

// UpdatePackageList updates list of available packages
func (c *ZypperPackageManager) UpdatePackageList() (string, error) {
return c.executor.Execute("zypper", []string{"update", "-y"}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "zypper", []string{"update", "-y"}, lhtypes.ExecuteNoTimeout)
}

// InstallPackage executes the installation command
func (c *ZypperPackageManager) InstallPackage(name string) (string, error) {
return c.executor.Execute("zypper", []string{"--non-interactive", "install", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "zypper", []string{"--non-interactive", "install", name}, lhtypes.ExecuteNoTimeout)
}

// UninstallPackage executes the uninstallation command
func (c *ZypperPackageManager) UninstallPackage(name string) (string, error) {
return c.executor.Execute("zypper", []string{"--non-interactive", "remove", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "zypper", []string{"--non-interactive", "remove", name}, lhtypes.ExecuteNoTimeout)
}

// Execute executes the given command with the specified environment variables, binary, and arguments.
func (c *ZypperPackageManager) Execute(binary string, args []string, timeout time.Duration) (string, error) {
return c.executor.Execute(binary, args, timeout)
func (c *ZypperPackageManager) Execute(envs []string, binary string, args []string, timeout time.Duration) (string, error) {
return c.executor.Execute(envs, binary, args, timeout)
}

// Modprobe executes the modprobe command
func (c *ZypperPackageManager) Modprobe(module string) (string, error) {
return c.executor.Execute("modprobe", []string{module}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "modprobe", []string{module}, lhtypes.ExecuteNoTimeout)
}

// CheckModLoaded checks if a module is loaded
func (c *ZypperPackageManager) CheckModLoaded(module string) error {
_, err := c.executor.Execute("grep", []string{module, "/proc/modules"}, lhtypes.ExecuteNoTimeout)
_, err := c.executor.Execute([]string{}, "grep", []string{module, "/proc/modules"}, lhtypes.ExecuteNoTimeout)
return err
}

// StartService executes the service start command
func (c *ZypperPackageManager) StartService(name string) (string, error) {
output, err := c.executor.Execute("systemctl", []string{"-q", "enable", name}, lhtypes.ExecuteNoTimeout)
output, err := c.executor.Execute([]string{}, "systemctl", []string{"-q", "enable", name}, lhtypes.ExecuteNoTimeout)
if err != nil {
return output, err
}

return c.executor.Execute("systemctl", []string{"start", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "systemctl", []string{"start", name}, lhtypes.ExecuteNoTimeout)
}

// GetServiceStatus executes the service status command
func (c *ZypperPackageManager) GetServiceStatus(name string) (string, error) {
return c.executor.Execute("systemctl", []string{"status", "--no-pager", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "systemctl", []string{"status", "--no-pager", name}, lhtypes.ExecuteNoTimeout)
}

// CheckPackageInstalled checks if a package is installed
func (c *ZypperPackageManager) CheckPackageInstalled(name string) (string, error) {
return c.executor.Execute("rpm", []string{"-q", name}, lhtypes.ExecuteNoTimeout)
return c.executor.Execute([]string{}, "rpm", []string{"-q", name}, lhtypes.ExecuteNoTimeout)
}
2 changes: 1 addition & 1 deletion pkg/utils/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"regexp"
"strings"

"github.com/longhorn/longhorn-preflight/pkg/pkgmgr"
"github.com/longhorn/cli/pkg/pkgmgr"
)

func GetPackageManagerType(platform string) (pkgmgr.PackageManagerType, error) {
Expand Down