feat: Pre-requiste sanity checks for installation of SUSE Manager#741
feat: Pre-requiste sanity checks for installation of SUSE Manager#741katara-Jayprakash wants to merge 9 commits into
Conversation
|
| } | ||
|
|
||
| func checkPrerequisites() error { | ||
| if err := utils.CheckMemory(8); err != nil { |
There was a problem hiding this comment.
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.
| if err := utils.CheckMemory(8); err != nil { | ||
| return err | ||
| } | ||
| if err := utils.CheckStorage("/var/lib", 50); err != nil { |
There was a problem hiding this comment.
/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.
| return err | ||
| } | ||
|
|
||
| for _, port := range []int{80, 443, 4505, 4506} { |
There was a problem hiding this comment.
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…
| } | ||
|
|
||
| func checkPrerequisites() error { | ||
| if err := shared_utils.CheckMemory(4); err != nil { |
There was a problem hiding this comment.
Same here about the magic numbers
|
|
||
| // CheckPort checks if a given port is available. | ||
| func CheckPort(port int) error { | ||
| l, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) |
There was a problem hiding this comment.
This should be moved to a file that is built for all OSes instead of duplicating it.
| @@ -0,0 +1,51 @@ | |||
| // SPDX-FileCopyrightText: 2024 SUSE LLC | |||
| ) | ||
|
|
||
| func getFreePort() (int, error) { | ||
| addr, err := net.ResolveTCPAddr("tcp", "localhost:0") |
There was a problem hiding this comment.
Such a test highly depends on where it is running: mock or drop the test!
0d82af8 to
0e7ad4f
Compare
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>
|
@cbosdo i think its done now! could you review it. sir |
0e7ad4f to
69f79e3
Compare
|
| 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")) |
There was a problem hiding this comment.
Your code is not behaving as before and would lead to issues. This would be correct and more readable:
| 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
This would fit the default path on several distros:
| 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 |
There was a problem hiding this comment.
This could be shared with the code for the server. The default path should rather be `/var/lib/containers/storage' too.
| for _, portMap := range shared_utils.GetProxyPorts() { | ||
| if err := shared_utils.CheckPort(portMap.Exposed); err != nil { | ||
| return err | ||
| } | ||
| } |
There was a problem hiding this comment.
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).")) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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



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
Test coverage
No tests: add explanation
No tests: already covered
Unit tests were added
DONE
Links
Issue(s): #355
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:
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!