Skip to content

Commit

Permalink
Merge a94ee91 into 9df2320
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanpm committed Mar 26, 2020
2 parents 9df2320 + a94ee91 commit 90f0ae2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
7 changes: 5 additions & 2 deletions cloudimg/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class PublishingMetadata(object):
Args:
image_path (str): A file path or URL to the image
image_name (str): The name of the image. Used as a primary identifier.
snapshot_name (str): The name of the snapshot. Derived from the image
filename by default.
description (str, optional): The description of the image
container (str, optional): The name of the storage container for
uploads
Expand All @@ -28,9 +30,10 @@ class PublishingMetadata(object):
def __init__(self, image_path, image_name, description=None,
container=None, arch=None, virt_type=None,
root_device_name=None, volume_type=None,
accounts=[], groups=[]):
accounts=[], groups=[], snapshot_name=None):
self.image_path = image_path
self.image_name = image_name
self.snapshot_name = snapshot_name or self._default_snapshot_name
self.description = description
self.container = container
self.arch = arch
Expand All @@ -41,7 +44,7 @@ def __init__(self, image_path, image_name, description=None,
self.groups = groups

@property
def snapshot_name(self):
def _default_snapshot_name(self):
return os.path.splitext(self.object_name)[0]

@property
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='cloudimg',
version='1.0.0',
version='1.1.0',
author='Alex Misstear',
author_email='amisstea@redhat.com',
description=('Services for building and releasing products in cloud '
Expand Down
22 changes: 22 additions & 0 deletions tests/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ def test_container_not_defined(self):
image_path='/some/fake/path/to/image.raw',
image_name='fakeimagename')

def test_default_snapshot_name(self):
"""
Test that a snapshot name by default is derived from the image
filename.
"""
metadata = AWSPublishingMetadata(image_path='/somedir/some-image.raw',
image_name='fakeimagename',
container='abcdef')

self.assertEqual(metadata.snapshot_name, 'some-image')

def test_explicit_snapshot_name(self):
"""
Test that a snapshot name can be provided explicitly.
"""
metadata = AWSPublishingMetadata(image_path='/somedir/some-image.raw',
image_name='fakeimagename',
snapshot_name='mysnapshot',
container='abcdef')

self.assertEqual(metadata.snapshot_name, 'mysnapshot')


class TestAWSService(unittest.TestCase):

Expand Down

0 comments on commit 90f0ae2

Please sign in to comment.