Merge "builder: Remove optional extension from DibImageFile"

This commit is contained in:
Zuul 2022-02-05 18:14:40 +00:00 committed by Gerrit Code Review
commit 11aae9bce4
2 changed files with 6 additions and 17 deletions

View File

@ -56,7 +56,7 @@ class DibImageFile(object):
a unique ID, but can be available in multiple formats (with different a unique ID, but can be available in multiple formats (with different
extensions). extensions).
''' '''
def __init__(self, image_id, extension=None): def __init__(self, image_id, extension):
self.image_id = image_id self.image_id = image_id
self.extension = extension self.extension = extension
self.md5 = None self.md5 = None
@ -79,14 +79,8 @@ class DibImageFile(object):
images.append(image) images.append(image)
return images return images
def to_path(self, images_dir, with_extension=True): def to_path(self, images_dir):
my_path = Path(images_dir) / self.image_id my_path = Path(images_dir) / f'{self.image_id}.{self.extension}'
if with_extension:
if self.extension is None:
raise exceptions.BuilderError(
'Cannot specify image extension of None'
)
my_path = my_path.with_suffix('.' + self.extension)
# Path.with_suffix() will replace an existing suffix, so we create # Path.with_suffix() will replace an existing suffix, so we create
# new Path objects from strings for the checksum files. # new Path objects from strings for the checksum files.
@ -260,7 +254,7 @@ class CleanupWorker(BaseWorker):
manifest_dir = None manifest_dir = None
for f in files: for f in files:
filename = f.to_path(images_dir, True) filename = f.to_path(images_dir)
if not manifest_dir: if not manifest_dir:
path, ext = filename.rsplit('.', 1) path, ext = filename.rsplit('.', 1)
manifest_dir = path + ".d" manifest_dir = path + ".d"
@ -1071,7 +1065,7 @@ class UploadWorker(BaseWorker):
self.log.debug("Found image file of type %s for image id: %s" % self.log.debug("Found image file of type %s for image id: %s" %
(image.extension, image.image_id)) (image.extension, image.image_id))
filename = image.to_path(self._config.images_dir, with_extension=True) filename = image.to_path(self._config.images_dir)
ext_image_name = provider.image_name_format.format( ext_image_name = provider.image_name_format.format(
image_name=image_name, timestamp=str(timestamp) image_name=image_name, timestamp=str(timestamp)

View File

@ -19,7 +19,7 @@ import fixtures
import mock import mock
import time import time
from nodepool import builder, exceptions, tests from nodepool import builder, tests
from nodepool.driver.fake import provider as fakeprovider from nodepool.driver.fake import provider as fakeprovider
from nodepool import zk from nodepool import zk
from nodepool.config import Config from nodepool.config import Config
@ -61,11 +61,6 @@ class TestNodepoolBuilderDibImage(tests.BaseTestCase):
'/imagedir/myid1234.qcow2') '/imagedir/myid1234.qcow2')
self.assertEqual(image.to_path('/imagedir/'), self.assertEqual(image.to_path('/imagedir/'),
'/imagedir/myid1234.qcow2') '/imagedir/myid1234.qcow2')
self.assertEqual(image.to_path('/imagedir/', False),
'/imagedir/myid1234')
image = builder.DibImageFile('myid1234')
self.assertRaises(exceptions.BuilderError, image.to_path, '/imagedir/')
class TestNodepoolBuilderImageInheritance(tests.BaseTestCase): class TestNodepoolBuilderImageInheritance(tests.BaseTestCase):