builder: don't use DibImageFile to construct dib image path

This refactors the _buildImage function to not use DibImageFile to
construct the path to the dib output files.

DibImageFile represents one on-disk image.  The dib build argument is
different -- you give it the basename in "-o" and the output types,
and it creates "basename.ext" where "ext" represents the varioius
output types it produced.

This converts _buildImage to the simple thing and makes it a bit
clearer this is a basename.

Change-Id: I214581ad80b7740e7ca749b574672d2c33b92474
This commit is contained in:
Ian Wienand 2021-12-21 16:05:38 +11:00
parent e0a16431d3
commit 5704ce75fc
1 changed files with 9 additions and 6 deletions

View File

@ -789,13 +789,15 @@ class BuildWorker(BaseWorker):
:raises: BuilderError if we failed to execute the build command.
'''
base = "-".join([diskimage.name, build_id])
image_file = DibImageFile(base)
filename = image_file.to_path(self._config.images_dir, False)
image_filename = Path(self._config.images_dir) / base
env = os.environ.copy()
env['DIB_RELEASE'] = diskimage.release
env['DIB_IMAGE_NAME'] = diskimage.name
env['DIB_IMAGE_FILENAME'] = filename
# This is just the basename. DIB may create multiple images
# here based on img_types; each will produce a final output
# file image_filename.<type>
env['DIB_IMAGE_FILENAME'] = image_filename
# Note we use a reference to the nodepool config here so
# that whenever the config is updated we get up to date
@ -820,7 +822,7 @@ class BuildWorker(BaseWorker):
cmd = ('%s -x -t %s --checksum --no-tmpfs %s -o %s %s' %
(dib_cmd, img_types, qemu_img_options,
filename, img_elements))
image_filename, img_elements))
self._pruneBuildLogs(diskimage.name)
log_fn = self._getBuildLog(diskimage.name, build_id)
@ -957,9 +959,10 @@ class BuildWorker(BaseWorker):
# purposes of watching if we've added too much stuff
# into the image. Note that st_blocks is defined as
# 512-byte blocks by stat(2)
size = os.stat("%s.%s" % (filename, ext)).st_blocks * 512
size = os.stat("%s.%s" %
(image_filename, ext)).st_blocks * 512
self.log.debug("%s created image %s.%s (size: %d) " %
(diskimage.name, filename, ext, size))
(diskimage.name, image_filename, ext, size))
pipeline.gauge(key, size)
if self._statsd: