Skip to content

Commit

Permalink
suma changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbussolotto committed Feb 20, 2024
1 parent f6ce254 commit a80c6a2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
1 change: 1 addition & 0 deletions mgradm/cmd/inspect/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions mgradm/cmd/upgrade/podman/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""
Expand Down Expand Up @@ -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)
Expand Down
63 changes: 53 additions & 10 deletions mgradm/cmd/upgrade/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
package shared

import (
"errors"
"fmt"
"regexp"
"strconv"
"strings"

Expand All @@ -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)
}
Expand Down

0 comments on commit a80c6a2

Please sign in to comment.