You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2013/11/14 23:55:20 UTC
[3/3] git commit: Fix an issue with the ex_list_keypairs and
ex_list_security_groups method in the CloudStack driver which caused an
exception to be thrown if the API returned no keypairs / security groups.
Fix an issue with the ex_list_keypairs and ex_list_security_groups method
in the CloudStack driver which caused an exception to be thrown if the API
returned no keypairs / security groups.
Reported by Carlos Reategui, part of LIBCLOUD-432.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/d988c473
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/d988c473
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/d988c473
Branch: refs/heads/trunk
Commit: d988c473dabdc91712ab0653fe71606d7254f2bc
Parents: b8195a1
Author: Tomaz Muraus <to...@apache.org>
Authored: Thu Nov 14 23:51:13 2013 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Nov 14 23:51:13 2013 +0100
----------------------------------------------------------------------
CHANGES | 6 ++++++
libcloud/compute/drivers/cloudstack.py | 9 ++++++---
.../fixtures/cloudstack/listSSHKeyPairs_no_keys.json | 1 +
.../cloudstack/listSecurityGroups_no_groups.json | 1 +
libcloud/test/compute/test_cloudstack.py | 11 +++++++++++
5 files changed, 25 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/d988c473/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 5294705..839f5af 100644
--- a/CHANGES
+++ b/CHANGES
@@ -86,6 +86,12 @@ Changes with Apache Libcloud in development
- Add new c3 instance types to the EC2 driver.
[Tomaz Muraus]
+ - Fix an issue with the ex_list_keypairs and ex_list_security_groups method
+ in the CloudStack driver which caused an exception to be thrown if the API
+ returned no keypairs / security groups.
+ (LIBCLOUD-432)
+ [Carlos Reategui, Tomaz Muraus]
+
*) Storage
- Add a new driver for KT UCloud based on the OpenStack Swift driver.
http://git-wip-us.apache.org/repos/asf/libcloud/blob/d988c473/libcloud/compute/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudstack.py b/libcloud/compute/drivers/cloudstack.py
index e116155..84073b7 100644
--- a/libcloud/compute/drivers/cloudstack.py
+++ b/libcloud/compute/drivers/cloudstack.py
@@ -904,7 +904,8 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
extra_args = kwargs.copy()
res = self._sync_request('listSSHKeyPairs', **extra_args)
- return res['sshkeypair']
+ keypairs = res.get('sshkeypair', [])
+ return keypairs
def ex_create_keypair(self, name, **kwargs):
"""
@@ -1050,8 +1051,10 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
:rtype ``list``
"""
extra_args = kwargs
- return self._sync_request('listSecurityGroups',
- **extra_args)['securitygroup']
+ res = self._sync_request('listSecurityGroups', **extra_args)
+
+ security_groups = res.get('securitygroup', [])
+ return security_groups
def ex_create_security_group(self, name, **kwargs):
"""
http://git-wip-us.apache.org/repos/asf/libcloud/blob/d988c473/libcloud/test/compute/fixtures/cloudstack/listSSHKeyPairs_no_keys.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/listSSHKeyPairs_no_keys.json b/libcloud/test/compute/fixtures/cloudstack/listSSHKeyPairs_no_keys.json
new file mode 100644
index 0000000..ccc9283
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/listSSHKeyPairs_no_keys.json
@@ -0,0 +1 @@
+{"listsshkeypairsresponse":{}}
http://git-wip-us.apache.org/repos/asf/libcloud/blob/d988c473/libcloud/test/compute/fixtures/cloudstack/listSecurityGroups_no_groups.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/listSecurityGroups_no_groups.json b/libcloud/test/compute/fixtures/cloudstack/listSecurityGroups_no_groups.json
new file mode 100644
index 0000000..d3c6a01
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/listSecurityGroups_no_groups.json
@@ -0,0 +1 @@
+{ "listsecuritygroupsresponse" : {} }
http://git-wip-us.apache.org/repos/asf/libcloud/blob/d988c473/libcloud/test/compute/test_cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_cloudstack.py b/libcloud/test/compute/test_cloudstack.py
index 546b182..dde40db 100644
--- a/libcloud/test/compute/test_cloudstack.py
+++ b/libcloud/test/compute/test_cloudstack.py
@@ -284,6 +284,11 @@ class CloudStackNodeDriverTest(unittest.TestCase, TestCaseMixin):
self.assertEqual(keypairs[0]['name'], 'cs-keypair')
self.assertEqual(keypairs[0]['fingerprint'], fingerprint)
+ def test_ex_list_keypairs_no_keypair_key(self):
+ CloudStackMockHttp.fixture_tag = 'no_keys'
+ keypairs = self.driver.ex_list_keypairs()
+ self.assertEqual(keypairs, [])
+
def test_ex_create_keypair(self):
self.assertRaises(
LibcloudError,
@@ -322,6 +327,12 @@ class CloudStackNodeDriverTest(unittest.TestCase, TestCaseMixin):
self.assertEqual(groups[0]['name'], 'default')
self.assertEqual(groups[1]['name'], 'mongodb')
+ def test_ex_list_security_groups_no_securitygroup_key(self):
+ CloudStackMockHttp.fixture_tag = 'no_groups'
+
+ groups = self.driver.ex_list_security_groups()
+ self.assertEqual(groups, [])
+
def test_ex_create_security_group(self):
group = self.driver.ex_create_security_group(name='MySG')
self.assertEqual(group['name'], 'MySG')