Skip to content

Commit

Permalink
Updating yum install to support multi architecture based packages
Browse files Browse the repository at this point in the history
  • Loading branch information
darthmelonder committed Jun 25, 2024
1 parent d09da8e commit 2d44675
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
11 changes: 10 additions & 1 deletion ospatch/yum_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ func YumDryRun(dryrun bool) YumUpdateOption {
}
}

// fullPackageName returns the package name with architecture if present.
func fullPackageName(pkgInfo *packages.PkgInfo) string {
pkgName := pkgInfo.Name
if len(pkgInfo.RawArch) > 0 {
pkgName = pkgName + "." + pkgInfo.RawArch
}
return pkgName
}

// RunYumUpdate runs yum update.
func RunYumUpdate(ctx context.Context, opts ...YumUpdateOption) error {
yumOpts := &yumUpdateOpts{
Expand Down Expand Up @@ -108,7 +117,7 @@ func RunYumUpdate(ctx context.Context, opts ...YumUpdateOption) error {

var pkgNames []string
for _, pkg := range fPkgs {
pkgNames = append(pkgNames, pkg.Name)
pkgNames = append(pkgNames, fullPackageName(pkg))
}

msg := fmt.Sprintf("%d packages: %q", len(pkgNames), fPkgs)
Expand Down
4 changes: 2 additions & 2 deletions ospatch/yum_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestRunYumUpdateWithSecurity(t *testing.T) {
packages.SetCommandRunner(mockCommandRunner)
checkUpdateCall := mockCommandRunner.EXPECT().Run(ctx, utilmocks.EqCmd(exec.Command("/usr/bin/yum", []string{"check-update", "--assumeyes"}...))).Return([]byte("stdout"), []byte("stderr"), err).Times(1)
// yum install call to install package
mockCommandRunner.EXPECT().Run(ctx, utilmocks.EqCmd(exec.Command("/usr/bin/yum", []string{"install", "--assumeyes", "foo"}...))).After(checkUpdateCall).Return([]byte("stdout"), []byte("stderr"), nil).Times(1)
mockCommandRunner.EXPECT().Run(ctx, utilmocks.EqCmd(exec.Command("/usr/bin/yum", []string{"install", "--assumeyes", "foo.noarch"}...))).After(checkUpdateCall).Return([]byte("stdout"), []byte("stderr"), nil).Times(1)

packages.SetPtyCommandRunner(mockCommandRunner)
mockCommandRunner.EXPECT().Run(ctx, utilmocks.EqCmd(exec.Command("/usr/bin/yum", []string{"update", "--assumeno", "--cacheonly", "--color=never", "--security"}...))).Return(data, []byte("stderr"), nil).Times(1)
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestRunYumUpdateWithSecurityWithExclusives(t *testing.T) {
packages.SetCommandRunner(mockCommandRunner)
checkUpdateCall := mockCommandRunner.EXPECT().Run(ctx, utilmocks.EqCmd(exec.Command("/usr/bin/yum", []string{"check-update", "--assumeyes"}...))).Return([]byte("stdout"), []byte("stderr"), err).Times(1)
// yum install call to install package, make sure only 2 packages are installed.
mockCommandRunner.EXPECT().Run(ctx, utilmocks.EqCmd(exec.Command("/usr/bin/yum", []string{"install", "--assumeyes", "foo", "bar"}...))).After(checkUpdateCall).Return([]byte("stdout"), []byte("stderr"), nil).Times(1)
mockCommandRunner.EXPECT().Run(ctx, utilmocks.EqCmd(exec.Command("/usr/bin/yum", []string{"install", "--assumeyes", "foo.noarch", "bar.x86_64"}...))).After(checkUpdateCall).Return([]byte("stdout"), []byte("stderr"), nil).Times(1)

packages.SetPtyCommandRunner(mockCommandRunner)
mockCommandRunner.EXPECT().Run(ctx, utilmocks.EqCmd(exec.Command("/usr/bin/yum", []string{"update", "--assumeno", "--cacheonly", "--color=never", "--security"}...))).Return(data, []byte("stderr"), nil).Times(1)
Expand Down
2 changes: 1 addition & 1 deletion packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type Packages struct {

// PkgInfo describes a package.
type PkgInfo struct {
Name, Arch, Version string
Name, Arch, RawArch, Version string

Source Source
}
Expand Down
2 changes: 1 addition & 1 deletion packages/yum.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func parseYumUpdates(data []byte) []*PkgInfo {
}
break
}
pkgs = append(pkgs, &PkgInfo{Name: string(pkg[0]), Arch: osinfo.Architecture(string(pkg[1])), Version: string(pkg[2])})
pkgs = append(pkgs, &PkgInfo{Name: string(pkg[0]), Arch: osinfo.Architecture(string(pkg[1])), RawArch: string(pkg[1]), Version: string(pkg[2])})
}
return pkgs
}
Expand Down
4 changes: 2 additions & 2 deletions packages/yum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func TestParseYumUpdates(t *testing.T) {
data []byte
want []*PkgInfo
}{
{"NormalCase", data, []*PkgInfo{{Name: "kernel", Arch: "x86_64", Version: "2.6.32-754.24.3.el6"}, {Name: "foo", Arch: "all", Version: "2.0.0-1"}, {Name: "bar", Arch: "x86_64", Version: "2.0.0-1"}}},
{"NormalCase", data, []*PkgInfo{{Name: "kernel", Arch: "x86_64", RawArch: "x86_64", Version: "2.6.32-754.24.3.el6"}, {Name: "foo", Arch: "all", RawArch: "noarch", Version: "2.0.0-1"}, {Name: "bar", Arch: "x86_64", RawArch: "x86_64", Version: "2.0.0-1"}}},
{"NoPackages", []byte("nothing here"), nil},
{"nil", nil, nil},
}
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestParseYumUpdatesWithInstallingDependenciesKeywords(t *testing.T) {
data []byte
want []*PkgInfo
}{
{"NormalCase", data, []*PkgInfo{{Name: "kernel", Arch: "x86_64", Version: "2.6.32-754.24.3.el6"}, {Name: "foo", Arch: "all", Version: "2.0.0-1"}, {Name: "bar", Arch: "x86_64", Version: "2.0.0-1"}}},
{"NormalCase", data, []*PkgInfo{{Name: "kernel", Arch: "x86_64", RawArch: "x86_64", Version: "2.6.32-754.24.3.el6"}, {Name: "foo", Arch: "all", RawArch: "noarch", Version: "2.0.0-1"}, {Name: "bar", Arch: "x86_64", RawArch: "x86_64", Version: "2.0.0-1"}}},
{"NoPackages", []byte("nothing here"), nil},
{"nil", nil, nil},
}
Expand Down

0 comments on commit 2d44675

Please sign in to comment.