Return-Path: X-Original-To: apmail-libcloud-commits-archive@www.apache.org Delivered-To: apmail-libcloud-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D4BBD10247 for ; Thu, 6 Feb 2014 20:14:06 +0000 (UTC) Received: (qmail 67743 invoked by uid 500); 6 Feb 2014 20:14:05 -0000 Delivered-To: apmail-libcloud-commits-archive@libcloud.apache.org Received: (qmail 67704 invoked by uid 500); 6 Feb 2014 20:14:04 -0000 Mailing-List: contact commits-help@libcloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@libcloud.apache.org Delivered-To: mailing list commits@libcloud.apache.org Received: (qmail 67627 invoked by uid 99); 6 Feb 2014 20:14:02 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Feb 2014 20:14:02 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 946F28A3A97; Thu, 6 Feb 2014 20:14:02 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tomaz@apache.org To: commits@libcloud.apache.org Date: Thu, 06 Feb 2014 20:14:06 -0000 Message-Id: <463005f61c8d4acdbd24d3080d839889@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [5/6] git commit: Fix tests, refactor and clean some things up. Fix tests, refactor and clean some things up. Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/9e90f60c Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/9e90f60c Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/9e90f60c Branch: refs/heads/trunk Commit: 9e90f60cd6d67afb3bc1b1461c11a356925fe7a5 Parents: 1f588a6 Author: Tomaz Muraus Authored: Thu Feb 6 14:22:46 2014 +0100 Committer: Tomaz Muraus Committed: Thu Feb 6 14:31:56 2014 +0100 ---------------------------------------------------------------------- libcloud/compute/drivers/openstack.py | 27 +++++++---------------- libcloud/compute/drivers/rackspace.py | 17 +++++++++++++- libcloud/test/compute/test_openstack.py | 33 ++++++++++++++++++++++------ 3 files changed, 50 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/9e90f60c/libcloud/compute/drivers/openstack.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py index 7889400..610b8f0 100644 --- a/libcloud/compute/drivers/openstack.py +++ b/libcloud/compute/drivers/openstack.py @@ -1644,7 +1644,6 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver): """ resp = self.connection.request('/os-snapshots/%s' % snapshot.id, method='DELETE') - return resp.status == httplib.NO_CONTENT def _to_security_group_rules(self, obj): @@ -2037,25 +2036,15 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver): if 'snapshot' in api_node: api_node = api_node['snapshot'] - if 'rackspace' in self.name.lower(): - extra = {'volume_id': api_node['volumeId'], - 'name': api_node['displayName'], - 'created': api_node['createdAt'], - 'description': api_node['displayDescription'], - 'status': api_node['status']} - - else: - extra = {'volume_id': api_node['volume_id'], - 'name': api_node['display_name'], - 'created': api_node['created_at'], - 'description': api_node['display_description'], - 'status': api_node['status']} + extra = {'volume_id': api_node['volume_id'], + 'name': api_node['display_name'], + 'created': api_node['created_at'], + 'description': api_node['display_description'], + 'status': api_node['status']} - return VolumeSnapshot( - id=api_node['id'], - driver=self, - size=api_node['size'], - extra=extra) + snapshot = VolumeSnapshot(id=api_node['id'], driver=self, + size=api_node['size'], extra=extra) + return snapshot def _to_size(self, api_flavor, price=None, bandwidth=None): # if provider-specific subclasses can get better values for http://git-wip-us.apache.org/repos/asf/libcloud/blob/9e90f60c/libcloud/compute/drivers/rackspace.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/rackspace.py b/libcloud/compute/drivers/rackspace.py index 1aed2ef..367facd 100644 --- a/libcloud/compute/drivers/rackspace.py +++ b/libcloud/compute/drivers/rackspace.py @@ -15,7 +15,7 @@ Rackspace driver """ from libcloud.compute.types import Provider, LibcloudError -from libcloud.compute.base import NodeLocation +from libcloud.compute.base import NodeLocation, VolumeSnapshot from libcloud.compute.drivers.openstack import OpenStack_1_0_Connection,\ OpenStack_1_0_NodeDriver, OpenStack_1_0_Response from libcloud.compute.drivers.openstack import OpenStack_1_1_Connection,\ @@ -207,6 +207,21 @@ class RackspaceNodeDriver(OpenStack_1_1_NodeDriver): region=region, **kwargs) + def _to_snapshot(self, api_node): + if 'snapshot' in api_node: + api_node = api_node['snapshot'] + + extra = {'volume_id': api_node['volumeId'], + 'name': api_node['displayName'], + 'created': api_node['createdAt'], + 'description': api_node['displayDescription'], + 'status': api_node['status']} + + snapshot = VolumeSnapshot(id=api_node['id'], driver=self, + size=api_node['size'], + extra=extra) + return snapshot + def _ex_connection_class_kwargs(self): endpoint_args = ENDPOINT_ARGS_MAP[self.region] kwargs = self.openstack_connection_kwargs() http://git-wip-us.apache.org/repos/asf/libcloud/blob/9e90f60c/libcloud/test/compute/test_openstack.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py index 1386e2b..1bb6487 100644 --- a/libcloud/test/compute/test_openstack.py +++ b/libcloud/test/compute/test_openstack.py @@ -1535,7 +1535,9 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin): def test_ex_list_snapshots(self): if self.driver_type.type == 'rackspace': - OpenStack_2_0_MockHttp.type = 'RACKSPACE' + self.conn_classes[0].type = 'RACKSPACE' + self.conn_classes[1].type = 'RACKSPACE' + snapshots = self.driver.ex_list_snapshots() self.assertEqual(len(snapshots), 2) self.assertEqual(snapshots[0].extra['name'], 'snap-001') @@ -1543,13 +1545,19 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin): def test_ex_create_snapshot(self): volume = self.driver.list_volumes()[0] if self.driver_type.type == 'rackspace': - OpenStack_2_0_MockHttp.type = 'RACKSPACE' + self.conn_classes[0].type = 'RACKSPACE' + self.conn_classes[1].type = 'RACKSPACE' + ret = self.driver.ex_create_snapshot(volume, 'Test Volume', 'This is a test') self.assertEqual(ret.id, '3fbbcccf-d058-4502-8844-6feeffdf4cb5') def test_ex_delete_snapshot(self): + if self.driver_type.type == 'rackspace': + self.conn_classes[0].type = 'RACKSPACE' + self.conn_classes[1].type = 'RACKSPACE' + snapshot = self.driver.ex_list_snapshots()[0] ret = self.driver.ex_delete_snapshot(snapshot) self.assertTrue(ret) @@ -1893,16 +1901,16 @@ class OpenStack_1_1_MockHttp(MockHttpTestCase): return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) def _v1_1_slug_servers_12086_action(self, method, url, body, headers): - if method == "POST": + if method == 'POST': body = self.fixtures.load('_servers_12086_console_output.json') return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK]) else: raise NotImplementedError() def _v1_1_slug_os_snapshots(self, method, url, body, headers): - if method == "GET": + if method == 'GET': body = self.fixtures.load('_os_snapshots.json') - elif method == "POST": + elif method == 'POST': body = self.fixtures.load('_os_snapshots_create.json') else: raise NotImplementedError() @@ -1920,12 +1928,23 @@ class OpenStack_1_1_MockHttp(MockHttpTestCase): return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) def _v1_1_slug_os_snapshots_3fbbcccf_d058_4502_8844_6feeffdf4cb5(self, method, url, body, headers): - if method == "DELETE": + if method == 'DELETE': body = '' + status_code = httplib.NO_CONTENT else: raise NotImplementedError() - return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) + return (status_code, body, self.json_content_headers, httplib.responses[httplib.OK]) + + def _v1_1_slug_os_snapshots_3fbbcccf_d058_4502_8844_6feeffdf4cb5_RACKSPACE(self, method, url, body, headers): + if method == 'DELETE': + body = '' + status_code = httplib.NO_CONTENT + else: + raise NotImplementedError() + + return (status_code, body, self.json_content_headers, httplib.responses[httplib.OK]) + # This exists because the nova compute url in devstack has v2 in there but the v1.1 fixtures # work fine.