From a80c6a275dc635b16e26d2680e1fc811b59e8388 Mon Sep 17 00:00:00 2001 From: mbussolotto Date: Tue, 20 Feb 2024 12:09:22 +0100 Subject: [PATCH] suma changes --- mgradm/cmd/inspect/podman.go | 1 + mgradm/cmd/upgrade/podman/utils.go | 2 + mgradm/cmd/upgrade/shared/shared.go | 63 ++++++++++++++++++++++++----- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/mgradm/cmd/inspect/podman.go b/mgradm/cmd/inspect/podman.go index 2e8f66429..9d3d0261f 100644 --- a/mgradm/cmd/inspect/podman.go +++ b/mgradm/cmd/inspect/podman.go @@ -64,6 +64,7 @@ func InspectPodman(serverImage string, pullPolicy string) (map[string]string, er extraArgs := []string{ "-v", scriptDir + ":" + inspect_shared.InspectOutputFile.Directory, + "--security-opt", "label:disable", } err = shared_podman.PrepareImage(serverImage, pullPolicy) diff --git a/mgradm/cmd/upgrade/podman/utils.go b/mgradm/cmd/upgrade/podman/utils.go index 8561305bc..bab3a1bd4 100644 --- a/mgradm/cmd/upgrade/podman/utils.go +++ b/mgradm/cmd/upgrade/podman/utils.go @@ -59,6 +59,7 @@ func upgradePodman(globalFlags *types.GlobalFlags, flags *podmanUpgradeFlags, cm log.Info().Msgf("Previous postgresql is %s, instead new one is %s. Performing a DB migration...", inspectedValues["current_pg_version"], inspectedValues["image_pg_version"]) extraArgs := []string{ "-v", scriptDir + ":/var/lib/uyuni-tools/", + "--security-opt", "label:disable", } migrationImageUrl := "" @@ -99,6 +100,7 @@ func upgradePodman(globalFlags *types.GlobalFlags, flags *podmanUpgradeFlags, cm extraArgs := []string{ "-v", scriptDir + ":/var/lib/uyuni-tools/", + "--security-opt", "label:disable", } scriptName, err := adm_utils.GenerateFinalizePostgresMigrationScript(scriptDir, true, inspectedValues["current_pg_version"] != inspectedValues["image_pg_version"], true, true, false) diff --git a/mgradm/cmd/upgrade/shared/shared.go b/mgradm/cmd/upgrade/shared/shared.go index e9641d402..578480a61 100644 --- a/mgradm/cmd/upgrade/shared/shared.go +++ b/mgradm/cmd/upgrade/shared/shared.go @@ -5,7 +5,9 @@ package shared import ( + "errors" "fmt" + "regexp" "strconv" "strings" @@ -16,29 +18,70 @@ import ( // CompareVersion compare the server image version and the server deployed version. func CompareVersion(imageVersion string, deployedVersion string) int { + re := regexp.MustCompile(`\((.*?)\)`) imageVersionCleaned := strings.ReplaceAll(imageVersion, ".", "") imageVersionCleaned = strings.TrimSpace(imageVersionCleaned) + imageVersionCleaned = re.ReplaceAllString(imageVersionCleaned, "") imageVersionInt, _ := strconv.Atoi(imageVersionCleaned) + deployedVersionCleaned := strings.ReplaceAll(deployedVersion, ".", "") + deployedVersionCleaned = strings.TrimSpace(deployedVersionCleaned) + deployedVersionCleaned = re.ReplaceAllString(deployedVersionCleaned, "") deployedVersionInt, _ := strconv.Atoi(deployedVersionCleaned) return imageVersionInt - deployedVersionInt } +func isUyuni(cnx *shared.Connection) (bool, error) { + cnx_args := []string{"/etc/uyuni-release"} + _, err := cnx.Exec("cat", cnx_args...) + if err != nil { + cnx_args := []string{"/etc/susemanager-release"} + _, err := cnx.Exec("cat", cnx_args...) + if err != nil { + return false, errors.New("cannot find neither /etc/uyuni-release nor /etc/susemanagere-release") + } + return false, nil + } + return true, nil +} + // SanityCheck verifies if an upgrade can be run. func SanityCheck(cnx *shared.Connection, inspectedValues map[string]string, serverImage string) error { - cnx_args := []string{"s/Uyuni release //g", "/etc/uyuni-release"} - current_uyuni_release, err := cnx.Exec("sed", cnx_args...) + isUyuni, err := isUyuni(cnx) if err != nil { - return fmt.Errorf("failed to read current uyuni release: %s", err) - } - log.Debug().Msgf("Current release is %s", string(current_uyuni_release)) - if (len(inspectedValues["uyuni_release"])) <= 0 { - return fmt.Errorf("cannot fetch release from image %s", serverImage) + return fmt.Errorf("cannot check server release: %s", err) } - log.Debug().Msgf("Image %s is %s", serverImage, inspectedValues["uyuni_release"]) - if CompareVersion(inspectedValues["uyuni_release"], string(current_uyuni_release)) <= 0 { - return fmt.Errorf("cannot downgrade from version %s to %s", string(current_uyuni_release), inspectedValues["uyuni_release"]) + + if isUyuni { + cnx_args := []string{"s/Uyuni release //g", "/etc/uyuni-release"} + current_uyuni_release, err := cnx.Exec("sed", cnx_args...) + if err != nil { + return fmt.Errorf("failed to read current uyuni release: %s", err) + } + log.Debug().Msgf("Current release is %s", string(current_uyuni_release)) + if (len(inspectedValues["uyuni_release"])) <= 0 { + return fmt.Errorf("cannot fetch release from image %s", serverImage) + } + log.Debug().Msgf("Image %s is %s", serverImage, inspectedValues["uyuni_release"]) + if CompareVersion(inspectedValues["uyuni_release"], string(current_uyuni_release)) <= 0 { + return fmt.Errorf("cannot downgrade from version %s to %s", string(current_uyuni_release), inspectedValues["uyuni_release"]) + } + } else { + cnx_args := []string{"s/SUSE Manager release //g", "/etc/susemanager-release"} + current_suse_manager_release, err := cnx.Exec("sed", cnx_args...) + if err != nil { + return fmt.Errorf("failed to read current susemanager release: %s", err) + } + log.Debug().Msgf("Current release is %s", string(current_suse_manager_release)) + if (len(inspectedValues["suse_manager_release"])) <= 0 { + return fmt.Errorf("cannot fetch release from image %s", serverImage) + } + log.Debug().Msgf("Image %s is %s", serverImage, inspectedValues["suse_manager_release"]) + if CompareVersion(inspectedValues["suse_manager_release"], string(current_suse_manager_release)) <= 0 { + return fmt.Errorf("cannot downgrade from version %s to %s", string(current_suse_manager_release), inspectedValues["suse_manager_release"]) + } } + if (len(inspectedValues["image_pg_version"])) <= 0 { return fmt.Errorf("cannot fetch postgresql version from %s", serverImage) }