Skip to content

feat: Pre-requiste sanity checks for installation of SUSE Manager#741

Open
katara-Jayprakash wants to merge 9 commits into
uyuni-project:mainfrom
katara-Jayprakash:Pre-requiste-sanity-checks
Open

feat: Pre-requiste sanity checks for installation of SUSE Manager#741
katara-Jayprakash wants to merge 9 commits into
uyuni-project:mainfrom
katara-Jayprakash:Pre-requiste-sanity-checks

Conversation

@katara-Jayprakash
Copy link
Copy Markdown

@katara-Jayprakash katara-Jayprakash commented Mar 10, 2026

What does this PR change?

add description
this pr try to add prerequisite sanity checks before podman installation for both mgradm and mgrpxy. its include minimum memory and disk space, required network port availability, and detection of conflicting running containers on the uyuni network.

Codespace

Check if you already have a running container clicking on Running CodeSpace

Create CodeSpace About billing for Github Codespaces CodeSpace Billing Summary CodeSpace Limit

Test coverage

  • No tests: add explanation

  • No tests: already covered

  • Unit tests were added

  • DONE

Links

Issue(s): #355

  • DONE

Changelogs

Make sure the changelogs entries you are adding are compliant with https://github.com/uyuni-project/uyuni/wiki/Contributing#changelogs and https://github.com/uyuni-project/uyuni/wiki/Contributing#uyuni-projectuyuni-repository

If you don't need a changelog check, please mark this checkbox:

  • No changelog needed

If you uncheck the checkbox after the PR is created, you will need to re-run changelog_test (see below)

Before you merge

Check How to branch and merge properly!

@sonarqubecloud
Copy link
Copy Markdown

Comment thread mgradm/cmd/install/utils.go
Comment thread mgradm/cmd/install/utils.go
Comment thread mgradm/cmd/install/utils.go Outdated
}

func checkPrerequisites() error {
if err := utils.CheckMemory(8); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The memory, and storage minimums should be extracted as constants.
8GB is also a bit tight for production environment thought most of the devs use this… Getting a proper value here is not easy.

Comment thread mgradm/cmd/install/utils.go Outdated
if err := utils.CheckMemory(8); err != nil {
return err
}
if err := utils.CheckStorage("/var/lib", 50); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/var/lib is too large to check. You should find the podman storage root instead. Note that this shouldn't be hard coded as users can configure it in podman's config files.

Comment thread mgradm/cmd/install/utils.go Outdated
return err
}

for _, port := range []int{80, 443, 4505, 4506} {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ports are already defined in the shared/utils module. Please use it instead of hardcoding them here again. The ports list is also a bit too short…

Comment thread mgrpxy/cmd/install/utils.go Outdated
}

func checkPrerequisites() error {
if err := shared_utils.CheckMemory(4); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here about the magic numbers

Comment thread shared/utils/prerequisites_other.go Outdated

// CheckPort checks if a given port is available.
func CheckPort(port int) error {
l, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to a file that is built for all OSes instead of duplicating it.

Comment thread shared/utils/prerequisites_other.go
Comment thread shared/utils/prerequisites_other.go
Comment thread shared/utils/prerequisites_test.go Outdated
@@ -0,0 +1,51 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright issue again

Comment thread shared/utils/prerequisites_test.go Outdated
)

func getFreePort() (int, error) {
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such a test highly depends on where it is running: mock or drop the test!

@katara-Jayprakash katara-Jayprakash force-pushed the Pre-requiste-sanity-checks branch from 0d82af8 to 0e7ad4f Compare April 24, 2026 05:25
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
Signed-off-by: katara-Jayprakash <katarajayprakash@icloud.com>
@katara-Jayprakash
Copy link
Copy Markdown
Author

@cbosdo i think its done now! could you review it. sir

@katara-Jayprakash katara-Jayprakash force-pushed the Pre-requiste-sanity-checks branch from 0e7ad4f to 69f79e3 Compare April 24, 2026 05:37
@sonarqubecloud
Copy link
Copy Markdown

Comment on lines +120 to +125
if err != nil {
// binary is not installed, skip
return nil
}
// the binary is installed
return utils.Error(utils.RunCmdStdMapping(zerolog.DebugLevel, path), L("failed to extract payg data"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code is not behaving as before and would lead to issues. This would be correct and more readable:

Suggested change
if err != nil {
// binary is not installed, skip
return nil
}
// the binary is installed
return utils.Error(utils.RunCmdStdMapping(zerolog.DebugLevel, path), L("failed to extract payg data"))
if err == nil {
if utils.RunCmdStdMapping(zerolog.DebugLevel, path) != nil {
return utils.Error(err, L("failed to extract payg data"))
}
}
return nil

}

const (
minMemoryGB = 16 // Minimum memory in GB for production
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to be able to bypass that for dev environments: some run with less memory than that.


storageRoot, err := shared_podman.GetPodmanVolumeBasePath()
if err != nil || storageRoot == "" {
storageRoot = "/var/lib" // fallback if detection fails
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would fit the default path on several distros:

Suggested change
storageRoot = "/var/lib" // fallback if detection fails
storageRoot = "/var/lib/containers/storage" // fallback if detection fails


storageRoot, err := shared_podman.GetPodmanVolumeBasePath()
if err != nil || storageRoot == "" {
storageRoot = "/var/lib" // fallback if detection fails
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be shared with the code for the server. The default path should rather be `/var/lib/containers/storage' too.

Comment on lines +127 to +131
for _, portMap := range shared_utils.GetProxyPorts() {
if err := shared_utils.CheckPort(portMap.Exposed); err != nil {
return err
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could share the loop with the server code too.

}

if len(strings.TrimSpace(string(out))) > 0 {
return errors.New(L("there are running containers on the uyuni network. Please stop them before installing or upgrading (see issue #323)."))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stopping the containers before the upgrade is not needed. Only before install is that needed.
Don't mention the issue in user-facing messages: they wouldn't care and it can only confuse them.

oldRunner := runner
defer func() { runner = oldRunner }()

runner = testutils.FakeRunnerGenerator("", nil)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use data-driven tests here: this test and the next are the same with different initialization of the fake runner. You can find examples of how to do this in https://github.com/uyuni-project/uyuni-tools/blob/main/mgradm/shared/templates/templates_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants