Merge "builder: Remove optional extension from DibImageFile"

changes/49/828649/1
Zuul 12 months ago committed by Gerrit Code Review
commit 11aae9bce4

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

@ -19,7 +19,7 @@ import fixtures
import mock
import time
from nodepool import builder, exceptions, tests
from nodepool import builder, tests
from nodepool.driver.fake import provider as fakeprovider
from nodepool import zk
from nodepool.config import Config
@ -61,11 +61,6 @@ class TestNodepoolBuilderDibImage(tests.BaseTestCase):
'/imagedir/myid1234.qcow2')
self.assertEqual(image.to_path('/imagedir/'),
'/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):

Loading…
Cancel
Save