Skip to content

Commit 023cd26

Browse files
authored
azl4: Use Distro-Aware isPackageInstalled in LiveOS code and TestBaseConfigsFullRun (#723)
Removes isPackageInstalled() which uses tdnf so we can execute these code paths for distros that don't use it. This function is safe to remove. It's a duplicate of `func (pm *tdnfPackageManager) isPackageInstalled`
1 parent 956edd5 commit 023cd26

5 files changed

Lines changed: 15 additions & 20 deletions

File tree

toolkit/tools/pkg/imagecustomizerlib/baseconfigs_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,15 @@ func TestBaseConfigsFullRun(t *testing.T) {
163163
verifyFileContentsSame(t, plantsFileOrigPath, plantsFileNewPath)
164164

165165
// Verify packages
166-
curlInstalled := isPackageInstalled(imageConnection.Chroot(), "curl")
166+
distroHandler, err := NewDistroHandlerFromChroot(imageConnection.Chroot())
167+
if !assert.NoError(t, err) {
168+
return
169+
}
170+
171+
curlInstalled := distroHandler.IsPackageInstalled(imageConnection.Chroot(), "curl")
167172
assert.True(t, curlInstalled)
168173

169-
nginxInstalled := isPackageInstalled(imageConnection.Chroot(), "nginx")
174+
nginxInstalled := distroHandler.IsPackageInstalled(imageConnection.Chroot(), "nginx")
170175
assert.True(t, nginxInstalled)
171176

172177
nginxVersionOutput, err := getPkgVersionFromChroot(imageConnection, "nginx")
@@ -176,7 +181,7 @@ func TestBaseConfigsFullRun(t *testing.T) {
176181
assert.Containsf(t, nginxVersionOutput, nginxExpectedVersion,
177182
"should install nginx version %s, but got: %s", nginxExpectedVersion, nginxVersionOutput)
178183

179-
sshdInstalled := isPackageInstalled(imageConnection.Chroot(), "openssh-server")
184+
sshdInstalled := distroHandler.IsPackageInstalled(imageConnection.Chroot(), "openssh-server")
180185
assert.True(t, sshdInstalled)
181186

182187
systemdBootVersionOutput, err := getPkgVersionFromChroot(imageConnection, "systemd-boot")

toolkit/tools/pkg/imagecustomizerlib/customizepackages.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"github.com/microsoft/azure-linux-image-tools/toolkit/tools/imagecustomizerapi"
1111
"github.com/microsoft/azure-linux-image-tools/toolkit/tools/internal/file"
1212
"github.com/microsoft/azure-linux-image-tools/toolkit/tools/internal/safechroot"
13-
"github.com/microsoft/azure-linux-image-tools/toolkit/tools/internal/shell"
14-
"github.com/sirupsen/logrus"
1513
"go.opentelemetry.io/otel"
1614
"go.opentelemetry.io/otel/attribute"
1715
"go.opentelemetry.io/otel/trace"
@@ -117,17 +115,6 @@ func startCleanPackagesCacheSpan(ctx context.Context) (context.Context, trace.Sp
117115
return otel.GetTracerProvider().Tracer(OtelTracerName).Start(ctx, "clean_package_cache")
118116
}
119117

120-
func isPackageInstalled(imageChroot safechroot.ChrootInterface, packageName string) bool {
121-
err := shell.NewExecBuilder("tdnf", "info", packageName, "--repo", "@system").
122-
LogLevel(logrus.TraceLevel, logrus.DebugLevel).
123-
Chroot(imageChroot.ChrootDir()).
124-
Execute()
125-
if err != nil {
126-
return false
127-
}
128-
return true
129-
}
130-
131118
func needPackageSources(config *imagecustomizerapi.OS) bool {
132119
return len(config.Packages.Install) > 0 || len(config.Packages.Update) > 0 || config.Packages.UpdateExistingPackages
133120
}

toolkit/tools/pkg/imagecustomizerlib/liveosisoartifactstore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func createIsoInfoStoreFromMountedImage(buildDir string, imageRootDir string, di
403403
// Note the MIC allows the user to install other selinux policy packages.
404404
// So, the absence of selinux-policy does not mean that there are no selinux
405405
// policy packages.
406-
if isPackageInstalled(chroot, "selinux-policy") {
406+
if distroHandler.IsPackageInstalled(chroot, "selinux-policy") {
407407
infoStore.selinuxPolicyPackageInfo, err = getPackageInformation(chroot, "selinux-policy")
408408
if err != nil {
409409
return nil, fmt.Errorf("failed to determine package information for selinux-policy under (%s):\n%w", imageRootDir, err)

toolkit/tools/pkg/imagecustomizerlib/liveosisobuilder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ func createLiveOSFromRawHelper(ctx context.Context, buildDir string, inputArtifa
314314
case imagecustomizerapi.InitramfsImageTypeBootstrap:
315315
// Generate the initrd image(s)
316316
for kernelVersion, kernelBootFiles := range artifactsStore.files.kernelBootFiles {
317-
err = createBootstrapInitrdImage(writeableRootfsDir, kernelVersion, kernelBootFiles.initrdImagePath)
317+
err = createBootstrapInitrdImage(writeableRootfsDir, kernelVersion, kernelBootFiles.initrdImagePath,
318+
distroHandler)
318319
if err != nil {
319320
return fmt.Errorf("failed to create initrd image:\n%w", err)
320321
}

toolkit/tools/pkg/imagecustomizerlib/liveosisoimages.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ func createFullOSInitrdImage(writeableRootfsDir string, kernelKdumpFiles *imagec
142142
return nil
143143
}
144144

145-
func createBootstrapInitrdImage(writeableRootfsDir, kernelVersion, outputInitrdPath string) error {
145+
func createBootstrapInitrdImage(writeableRootfsDir, kernelVersion, outputInitrdPath string,
146+
distroHandler DistroHandler,
147+
) error {
146148
logger.Log.Infof("Creating bootstrap initrd for %s", kernelVersion)
147149

148150
dracutConfigFile := filepath.Join(writeableRootfsDir, "/etc/dracut.conf.d/20-live-cd.conf")
@@ -166,7 +168,7 @@ func createBootstrapInitrdImage(writeableRootfsDir, kernelVersion, outputInitrdP
166168
requiredRpms := []string{"squashfs-tools", "tar", "device-mapper", "curl"}
167169
for _, requiredRpm := range requiredRpms {
168170
logger.Log.Debugf("Checking if (%s) is installed", requiredRpm)
169-
if !isPackageInstalled(chroot, requiredRpm) {
171+
if !distroHandler.IsPackageInstalled(chroot, requiredRpm) {
170172
return fmt.Errorf("package (%s) is not installed:\nthe following packages must be installed to generate an iso: %v", requiredRpm, requiredRpms)
171173
}
172174
}

0 commit comments

Comments
 (0)