Skip to content

Commit

Permalink
Use unique names for the bootc images (#3419)
Browse files Browse the repository at this point in the history
Rename default disk file name, disk.qcow, to a unique name for
each plan run

Resolve: #3414

Signed-off-by: Xiaofeng Wang <henrywangxf@me.com>
  • Loading branch information
henrywang authored Jan 13, 2025
1 parent ba6756b commit 46de3f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
6 changes: 0 additions & 6 deletions tests/provision/bootc/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
IMAGE_NEEDS_DEPS="localhost/tmt-bootc-needs-deps"
IMAGE_INCLUDES_DEPS="localhost/tmt-bootc-includes-deps"

TESTCLOUD_IMAGE="/var/tmp/tmt/testcloud/images/disk.qcow2"


rlJournalStart
rlPhaseStartSetup
Expand All @@ -19,23 +17,19 @@ rlJournalStart
rlPhaseStartTest "Image that needs dependencies"
rlRun "podman build . -f needs-deps.containerfile -t $IMAGE_NEEDS_DEPS"
rlRun "tmt -vvv run --scratch -i $run plan --name /plans/image/needs-deps"
rlRun "rm -rf $TESTCLOUD_IMAGE"
rlPhaseEnd

rlPhaseStartTest "Image that already includes dependencies"
rlRun "podman build . -f includes-deps.containerfile -t $IMAGE_INCLUDES_DEPS"
rlRun "tmt -vvv run --scratch -i $run plan --name /plans/image/includes-deps"
rlRun "rm -rf $TESTCLOUD_IMAGE"
rlPhaseEnd

rlPhaseStartTest "Containerfile that needs dependencies"
rlRun "tmt -vvv run --scratch -i $run plan --name /plans/containerfile/needs-deps"
rlRun "rm -rf $TESTCLOUD_IMAGE"
rlPhaseEnd

rlPhaseStartTest "Containerfile that already includes dependencies"
rlRun "tmt -vvv run --scratch -i $run plan --name /plans/containerfile/includes-deps"
rlRun "rm -rf $TESTCLOUD_IMAGE"
rlPhaseEnd

rlPhaseStartCleanup
Expand Down
21 changes: 19 additions & 2 deletions tmt/steps/provision/bootc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import tmt.steps.provision.testcloud
import tmt.utils
from tmt.steps.provision.testcloud import GuestTestcloud
from tmt.utils import field
from tmt.utils import Path, field
from tmt.utils.templates import render_template

if TYPE_CHECKING:
Expand Down Expand Up @@ -329,7 +329,6 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
self._check_if_podman_is_rootless()

data = BootcData.from_plugin(self)
data.image = f"file://{self.workdir}/qcow2/disk.qcow2"
data.show(verbose=self.verbosity_level, logger=self._logger)

if self._rootless:
Expand All @@ -355,6 +354,24 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
raise tmt.utils.ProvisionError(
"Either 'container-file' or 'container-image' must be specified.")

# Set unique disk file name, each plan will have its own disk file
disk_file_name = Path(render_template(
'disk-{{ PHASE.parent.plan.my_run.unique_id }}'
'-{{ PHASE.parent.plan.pathless_safe_name }}'
'-{{ PHASE.safe_name }}.qcow2',
PHASE=self))

assert self.workdir is not None

image_dir = self.workdir / 'qcow2'

# Rename disk file name to unique file name
built_image = image_dir / 'disk.qcow2'
renamed_image = image_dir / disk_file_name

built_image.rename(renamed_image)
data.image = f"file://{renamed_image}"

self._guest = GuestBootc(
logger=self._logger,
data=data,
Expand Down

0 comments on commit 46de3f9

Please sign in to comment.