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 2014/01/14 15:02:28 UTC

[2/3] git commit: [LIBCLOUD-492] Fix delete_key_pair method in the EC2 driver.

[LIBCLOUD-492] Fix delete_key_pair method in the EC2 driver.

The API expects a key pair name and not a key pair object.

Signed-off-by: Tomaz Muraus <to...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/05252f65
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/05252f65
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/05252f65

Branch: refs/heads/trunk
Commit: 05252f652d05ab1eb4e0425ec45dfc569ae33124
Parents: 4403766
Author: gigimon <gi...@gmail.com>
Authored: Tue Jan 14 14:18:43 2014 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Tue Jan 14 14:55:26 2014 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/ec2.py                 |  6 +++--
 .../fixtures/ec2/associate_vpc_address.xml      |  2 +-
 .../compute/fixtures/ec2/delete_key_pair.xml    |  4 ++++
 libcloud/test/compute/test_ec2.py               | 23 +++++++++++---------
 4 files changed, 22 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/05252f65/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 164fd88..c96d1e9 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -1549,7 +1549,7 @@ class BaseEC2NodeDriver(NodeDriver):
     def delete_key_pair(self, key_pair):
         params = {
             'Action': 'DeleteKeyPair',
-            'KeyName': key_pair
+            'KeyName': key_pair.name
         }
         result = self.connection.request(self.path, params=params).object
         element = findtext(element=result, xpath='return',
@@ -2955,7 +2955,9 @@ class BaseEC2NodeDriver(NodeDriver):
         warnings.warn('This method has been deprecated in favor of '
                       'delete_key_pair method')
 
-        return self.delete_key_pair(name=keypair)
+        keypair = KeyPair(name=keypair, driver=self, public_key='', fingerprint='')
+
+        return self.delete_key_pair(keypair)
 
     def ex_import_keypair_from_string(self, name, key_material):
         """

http://git-wip-us.apache.org/repos/asf/libcloud/blob/05252f65/libcloud/test/compute/fixtures/ec2/associate_vpc_address.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ec2/associate_vpc_address.xml b/libcloud/test/compute/fixtures/ec2/associate_vpc_address.xml
index 46433e2..21348ed 100644
--- a/libcloud/test/compute/fixtures/ec2/associate_vpc_address.xml
+++ b/libcloud/test/compute/fixtures/ec2/associate_vpc_address.xml
@@ -1,5 +1,5 @@
 <AssociateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
-    <requestId>1b3bf0d9-6c51-4443-a218-f25ecdc98c2a</requestId>
+    <requestId>s132fsz2-6cdg-4ox3-a148-lpqnvdc98c2a</requestId>
     <return>true</return>
     <associationId>eipassoc-167a8073</associationId>
 </AssociateAddressResponse>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/05252f65/libcloud/test/compute/fixtures/ec2/delete_key_pair.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ec2/delete_key_pair.xml b/libcloud/test/compute/fixtures/ec2/delete_key_pair.xml
new file mode 100644
index 0000000..3e605b0
--- /dev/null
+++ b/libcloud/test/compute/fixtures/ec2/delete_key_pair.xml
@@ -0,0 +1,4 @@
+<DeleteKeyPairResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
+    <requestId>59dbff89-35bd-4eac-99ed-be587</requestId>
+    <return>true</return>
+</DeleteKeyPairResponse>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/05252f65/libcloud/test/compute/test_ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index e0af93d..2a8fd6e 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -524,23 +524,26 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
         keys = self.driver.ex_describe_all_keypairs()
         self.assertEqual(keys, ['gsg-keypair'])
 
-    def test_ex_describe_keypairs(self):
-        keypair1 = self.driver.ex_describe_keypair('gsg-keypair')
+    def test_list_key_pairs(self):
+        keypair1 = self.driver.list_key_pairs()[0]
+
+        self.assertEqual(keypair1.name, 'gsg-keypair')
+        self.assertEqual(keypair1.fingerprint, null_fingerprint)
 
         # Test backward compatibility
         keypair2 = self.driver.ex_describe_keypairs('gsg-keypair')
 
-        self.assertEqual(keypair1['keyName'], 'gsg-keypair')
-        self.assertEqual(keypair1['keyFingerprint'], null_fingerprint)
         self.assertEqual(keypair2['keyName'], 'gsg-keypair')
         self.assertEqual(keypair2['keyFingerprint'], null_fingerprint)
 
-    def ex_delete_key_pair(self):
-        success = self.driver.delete_key_pair('testkey')
+    def test_delete_key_pair(self):
+        keypair = self.driver.list_key_pairs()[0]
+        success = self.driver.delete_key_pair(keypair)
+
         self.assertTrue(success)
 
         # Test old and deprecated method
-        resp = self.driver.ex_delete_keypair('testkey')
+        resp = self.driver.ex_delete_keypair('gsg-keypair')
         self.assertTrue(resp)
 
     def test_ex_describe_tags(self):
@@ -1256,10 +1259,10 @@ class EC2MockHttp(MockHttpTestCase):
         body = self.fixtures.load('deregister_image.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
-    def _DeleteKeypair(self, method, url, body, headers):
-        self.assertUrlContainsQueryParams(url, {'KeyPair': 'testkey'})
+    def _DeleteKeyPair(self, method, url, body, headers):
+        self.assertUrlContainsQueryParams(url, {'KeyName': 'gsg-keypair'})
 
-        body = self.fixtures.load('delete_keypair.xml')
+        body = self.fixtures.load('delete_key_pair.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
     def _ModifyImageAttribute(self, method, url, body, headers):