Skip to content

Commit

Permalink
fix rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
mbussolotto committed Apr 18, 2024
1 parent 45297c6 commit 115c505
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 30 deletions.
1 change: 0 additions & 1 deletion mgradm/cmd/inspect/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package inspect
import (
"encoding/json"
"fmt"
"os"

"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand Down
23 changes: 3 additions & 20 deletions mgradm/cmd/upgrade/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,14 @@ package shared
import (
"errors"
"fmt"
"regexp"
"strconv"
"strings"

"github.com/rs/zerolog/log"

"github.com/uyuni-project/uyuni-tools/shared"
. "github.com/uyuni-project/uyuni-tools/shared/l10n"
"github.com/uyuni-project/uyuni-tools/shared/utils"
)

// 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...)
Expand Down Expand Up @@ -74,7 +57,7 @@ func SanityCheck(cnx *shared.Connection, inspectedValues map[string]string, serv
return fmt.Errorf(L("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 {
if utils.CompareVersion(inspectedValues["uyuni_release"], string(current_uyuni_release)) < 0 {
return fmt.Errorf(L("cannot downgrade from version %s to %s"), string(current_uyuni_release), inspectedValues["uyuni_release"])
}
} else {
Expand All @@ -88,7 +71,7 @@ func SanityCheck(cnx *shared.Connection, inspectedValues map[string]string, serv
return fmt.Errorf(L("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 {
if utils.CompareVersion(inspectedValues["suse_manager_release"], string(current_suse_manager_release)) < 0 {
return fmt.Errorf(L("cannot downgrade from version %s to %s"), string(current_suse_manager_release), inspectedValues["suse_manager_release"])
}
}
Expand Down
Binary file removed mgradm/shared/podman/.podman.go.swp
Binary file not shown.
14 changes: 7 additions & 7 deletions mgradm/shared/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func Upgrade(image types.ImageFlags, migrationImage types.ImageFlags, args []str
err = podman.StartService(podman.ServerService)
}()
if inspectedValues["image_pg_version"] > inspectedValues["current_pg_version"] {
log.Info().Msgf("Previous postgresql is %s, instead new one is %s. Performing a DB version upgrade...", inspectedValues["current_pg_version"], inspectedValues["image_pg_version"])
log.Info().Msgf(L("Previous postgresql is %s, instead new one is %s. Performing a DB version upgrade..."), inspectedValues["current_pg_version"], inspectedValues["image_pg_version"])
if err := RunPgsqlVersionUpgrade(image, migrationImage, inspectedValues["current_pg_version"], inspectedValues["image_pg_version"]); err != nil {
return fmt.Errorf(L("cannot run PostgreSQL version upgrade script: %s"), err)
}
Expand Down Expand Up @@ -357,7 +357,7 @@ func Inspect(serverImage string, pullPolicy string) (map[string]string, error) {
return map[string]string{}, fmt.Errorf(L("failed to create temporary directory %s"), err)
}

inspectedHostValues, err := adm_utils.InspectHost()
inspectedHostValues, err := utils.InspectHost()
if err != nil {
return map[string]string{}, fmt.Errorf(L("cannot inspect host values: %s"), err)
}
Expand All @@ -374,22 +374,22 @@ func Inspect(serverImage string, pullPolicy string) (map[string]string, error) {
return map[string]string{}, err
}

if err := adm_utils.GenerateInspectContainerScript(scriptDir); err != nil {
if err := utils.GenerateInspectContainerScript(scriptDir); err != nil {
return map[string]string{}, err
}

podmanArgs := []string{
"-v", scriptDir + ":" + adm_utils.InspectOutputFile.Directory,
"-v", scriptDir + ":" + utils.InspectOutputFile.Directory,
"--security-opt", "label:disable",
}

err = RunContainer("uyuni-inspect", preparedImage, podmanArgs,
[]string{adm_utils.InspectOutputFile.Directory + "/" + adm_utils.InspectScriptFilename})
err = podman.RunContainer("uyuni-inspect", preparedImage, podmanArgs,
[]string{utils.InspectOutputFile.Directory + "/" + utils.InspectScriptFilename})
if err != nil {
return map[string]string{}, err
}

inspectResult, err := adm_utils.ReadInspectData(scriptDir)
inspectResult, err := utils.ReadInspectData(scriptDir)
if err != nil {
return map[string]string{}, fmt.Errorf(L("cannot inspect data. %s"), err)
}
Expand Down
4 changes: 2 additions & 2 deletions mgradm/shared/utils/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func SanityCheck(cnx *shared.Connection, inspectedValues map[string]string, serv
return fmt.Errorf(L("cannot fetch release from image %s"), serverImage)
}
log.Debug().Msgf(L("Image %s is %s"), serverImage, inspectedValues["uyuni_release"])
if CompareVersion(inspectedValues["uyuni_release"], string(current_uyuni_release)) < 0 {
if utils.CompareVersion(inspectedValues["uyuni_release"], string(current_uyuni_release)) < 0 {
return fmt.Errorf(L("cannot downgrade from version %s to %s"), string(current_uyuni_release), inspectedValues["uyuni_release"])
}
} else {
Expand All @@ -224,7 +224,7 @@ func SanityCheck(cnx *shared.Connection, inspectedValues map[string]string, serv
return fmt.Errorf(L("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 {
if utils.CompareVersion(inspectedValues["suse_manager_release"], string(current_suse_manager_release)) < 0 {
return fmt.Errorf(L("cannot downgrade from version %s to %s"), string(current_suse_manager_release), inspectedValues["suse_manager_release"])
}
}
Expand Down

0 comments on commit 115c505

Please sign in to comment.