Make list_volume_snapshot method in the EC2 driver conform to the base API.
Closes #451 Signed-off-by: Tomaz Muraus <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/6a281fda Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/6a281fda Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/6a281fda Branch: refs/heads/trunk Commit: 6a281fda51b405354e0264ab5e20357dfe5863e1 Parents: 56882ff Author: Allard Hoeve <[email protected]> Authored: Thu Feb 12 14:49:15 2015 +0100 Committer: Tomaz Muraus <[email protected]> Committed: Fri Feb 20 21:12:02 2015 +0100 ---------------------------------------------------------------------- CHANGES.rst | 5 ++++ libcloud/common/linode.py | 4 ++-- libcloud/common/types.py | 20 ++++++++-------- libcloud/compute/drivers/ec2.py | 5 ++-- libcloud/compute/drivers/rimuhosting.py | 4 ++-- libcloud/compute/drivers/vcloud.py | 6 ++--- libcloud/storage/drivers/s3.py | 2 +- libcloud/test/compute/__init__.py | 5 ++-- .../compute/fixtures/ec2/describe_snapshots.xml | 24 +++++++++++++++++++- libcloud/test/compute/test_ec2.py | 10 +++++++- libcloud/utils/dist.py | 3 +-- 11 files changed, 62 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/6a281fda/CHANGES.rst ---------------------------------------------------------------------- diff --git a/CHANGES.rst b/CHANGES.rst index b2be624..bfb8a38 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -20,6 +20,11 @@ Compute (GITHUB-398, LIBCLOUD-637) [Allard Hoeve] +- Fix ``list_volume_snapshots`` method in the EC2 driver so it comforms to the + base API. + (LIBCLOUD-664, GITHUB-451) + [Allard Hoeve] + Changes with Apache Libcloud 0.17.0 ----------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/6a281fda/libcloud/common/linode.py ---------------------------------------------------------------------- diff --git a/libcloud/common/linode.py b/libcloud/common/linode.py index fb6ea2b..aba75f0 100644 --- a/libcloud/common/linode.py +++ b/libcloud/common/linode.py @@ -127,8 +127,8 @@ class LinodeResponse(JsonResponse): ret = [] errs = [] for obj in js: - if ("DATA" not in obj or "ERRORARRAY" not in obj - or "ACTION" not in obj): + if ("DATA" not in obj or "ERRORARRAY" not in obj or + "ACTION" not in obj): ret.append(None) errs.append(self.invalid) continue http://git-wip-us.apache.org/repos/asf/libcloud/blob/6a281fda/libcloud/common/types.py ---------------------------------------------------------------------- diff --git a/libcloud/common/types.py b/libcloud/common/types.py index 6020440..b5ff512 100644 --- a/libcloud/common/types.py +++ b/libcloud/common/types.py @@ -37,10 +37,10 @@ class LibcloudError(Exception): return self.__repr__() def __repr__(self): - return ("<LibcloudError in " - + repr(self.driver) - + " " - + repr(self.value) + ">") + return ("<LibcloudError in " + + repr(self.driver) + + " " + + repr(self.value) + ">") class MalformedResponseError(LibcloudError): @@ -57,12 +57,12 @@ class MalformedResponseError(LibcloudError): return self.__repr__() def __repr__(self): - return ("<MalformedResponseException in " - + repr(self.driver) - + " " - + repr(self.value) - + ">: " - + repr(self.body)) + return ("<MalformedResponseException in " + + repr(self.driver) + + " " + + repr(self.value) + + ">: " + + repr(self.body)) class ProviderError(LibcloudError): http://git-wip-us.apache.org/repos/asf/libcloud/blob/6a281fda/libcloud/compute/drivers/ec2.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py index df71eb6..fd7c98c 100644 --- a/libcloud/compute/drivers/ec2.py +++ b/libcloud/compute/drivers/ec2.py @@ -2407,8 +2407,9 @@ class BaseEC2NodeDriver(NodeDriver): return snapshot - def list_volume_snapshots(self, snapshot): - return self.list_snapshots(snapshot) + def list_volume_snapshots(self, volume): + return [snapshot for snapshot in self.list_snapshots(owner='self') + if snapshot.extra["volume_id"] == volume.id] def list_snapshots(self, snapshot=None, owner=None): """ http://git-wip-us.apache.org/repos/asf/libcloud/blob/6a281fda/libcloud/compute/drivers/rimuhosting.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/rimuhosting.py b/libcloud/compute/drivers/rimuhosting.py index acde574..f7cfdd7 100644 --- a/libcloud/compute/drivers/rimuhosting.py +++ b/libcloud/compute/drivers/rimuhosting.py @@ -151,8 +151,8 @@ class RimuHostingNodeDriver(NodeDriver): name=order['domain_name'], state=NodeState.RUNNING, public_ips=( - [order['allocated_ips']['primary_ip']] - + order['allocated_ips']['secondary_ips']), + [order['allocated_ips']['primary_ip']] + + order['allocated_ips']['secondary_ips']), private_ips=[], driver=self.connection.driver, extra={ http://git-wip-us.apache.org/repos/asf/libcloud/blob/6a281fda/libcloud/compute/drivers/vcloud.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/vcloud.py b/libcloud/compute/drivers/vcloud.py index d18d390..0ce10b3 100644 --- a/libcloud/compute/drivers/vcloud.py +++ b/libcloud/compute/drivers/vcloud.py @@ -581,9 +581,9 @@ class VCloudNodeDriver(NodeDriver): ) vapps = [ (i.get('name'), i.get('href')) - for i in elms - if i.get('type') == 'application/vnd.vmware.vcloud.vApp+xml' - and i.get('name') + for i in elms if + i.get('type') == 'application/vnd.vmware.vcloud.vApp+xml' and + i.get('name') ] for vapp_name, vapp_href in vapps: http://git-wip-us.apache.org/repos/asf/libcloud/blob/6a281fda/libcloud/storage/drivers/s3.py ---------------------------------------------------------------------- diff --git a/libcloud/storage/drivers/s3.py b/libcloud/storage/drivers/s3.py index 60e5562..eca2910 100644 --- a/libcloud/storage/drivers/s3.py +++ b/libcloud/storage/drivers/s3.py @@ -729,7 +729,7 @@ class BaseS3StorageDriver(StorageDriver): if response.status != httplib.OK: raise LibcloudError('Error fetching multipart uploads. ' - 'Got code: %s' % (response.status), + 'Got code: %s' % response.status, driver=self) body = response.parse_body() http://git-wip-us.apache.org/repos/asf/libcloud/blob/6a281fda/libcloud/test/compute/__init__.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/__init__.py b/libcloud/test/compute/__init__.py index 42e478c..1db7b2d 100644 --- a/libcloud/test/compute/__init__.py +++ b/libcloud/test/compute/__init__.py @@ -38,8 +38,9 @@ class TestCaseMixin(object): self.assertTrue(size.bandwidth is None or isinstance(size.bandwidth, int)) # Check that price values are ints, floats, or None. - self.assertTrue(size.price is None or isinstance(size.price, float) - or isinstance(size.price, int)) + self.assertTrue(size.price is None or + isinstance(size.price, float) or + isinstance(size.price, int)) def test_list_images_response(self): images = self.driver.list_images() http://git-wip-us.apache.org/repos/asf/libcloud/blob/6a281fda/libcloud/test/compute/fixtures/ec2/describe_snapshots.xml ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/ec2/describe_snapshots.xml b/libcloud/test/compute/fixtures/ec2/describe_snapshots.xml index b884c79..2faf38f 100644 --- a/libcloud/test/compute/fixtures/ec2/describe_snapshots.xml +++ b/libcloud/test/compute/fixtures/ec2/describe_snapshots.xml @@ -40,4 +40,26 @@ </tagSet> </item> </snapshotSet> -</DescribeSnapshotsResponse> \ No newline at end of file + <snapshotSet> + <item> + <snapshotId>snap-18349160</snapshotId> + <volumeId>vol-10ae5e2b</volumeId> + <status>pending</status> + <startTime>2014-09-15T16:00:30.000Z</startTime> + <progress>30%</progress> + <ownerId>1938218231</ownerId> + <volumeSize>15</volumeSize> + <description>Weekly backup</description> + <tagSet> + <item> + <key>Name</key> + <value>DB Backup 1</value> + </item> + <item> + <key>Key2</key> + <value>db_backup</value> + </item> + </tagSet> + </item> + </snapshotSet> +</DescribeSnapshotsResponse> http://git-wip-us.apache.org/repos/asf/libcloud/blob/6a281fda/libcloud/test/compute/test_ec2.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py index e156565..1b79781 100644 --- a/libcloud/test/compute/test_ec2.py +++ b/libcloud/test/compute/test_ec2.py @@ -828,7 +828,7 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin): def test_list_snapshots(self): snaps = self.driver.list_snapshots() - self.assertEqual(len(snaps), 2) + self.assertEqual(len(snaps), 3) self.assertEqual('snap-428abd35', snaps[0].id) self.assertEqual('vol-e020df80', snaps[0].extra['volume_id']) @@ -841,6 +841,14 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin): self.assertEqual('Weekly backup', snaps[1].extra['description']) self.assertEqual('DB Backup 1', snaps[1].extra['name']) + def test_list_volume_snapshots(self): + volume = self.driver.list_volumes()[0] + assert volume.id == 'vol-10ae5e2b' + + snapshots = self.driver.list_volume_snapshots(volume) + self.assertEqual(len(snapshots), 1) + self.assertEqual(snapshots[0].id, 'snap-18349160') + def test_destroy_snapshot(self): snap = VolumeSnapshot(id='snap-428abd35', size=10, driver=self.driver) resp = snap.destroy() http://git-wip-us.apache.org/repos/asf/libcloud/blob/6a281fda/libcloud/utils/dist.py ---------------------------------------------------------------------- diff --git a/libcloud/utils/dist.py b/libcloud/utils/dist.py index 4477e2a..01e523e 100644 --- a/libcloud/utils/dist.py +++ b/libcloud/utils/dist.py @@ -36,8 +36,7 @@ def _filter_names(names): # copy (likely a checkout) rather than a pristine export: for pattern in EXCLUDE_PATTERNS: names = [n for n in names - if (not fnmatch.fnmatch(n, pattern)) - and (not n.endswith('.py'))] + if not fnmatch.fnmatch(n, pattern) and not n.endswith('.py')] return names
