You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by qu...@apache.org on 2017/10/19 05:14:23 UTC

[2/3] libcloud git commit: Add EC2Tests.test_create_encrypted_volume

Add EC2Tests.test_create_encrypted_volume


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

Branch: refs/heads/trunk
Commit: 1e87b82590a4fee5349f59361178dc0e2c35d791
Parents: 61c3e50
Author: mermoldy <s....@scalr.com>
Authored: Mon Oct 9 14:57:54 2017 +0300
Committer: Quentin Pradet <qu...@apache.org>
Committed: Thu Oct 19 09:10:36 2017 +0400

----------------------------------------------------------------------
 libcloud/compute/drivers/ec2.py                 |  4 ++++
 .../fixtures/ec2/create_encrypted_volume.xml    | 11 ++++++++++
 .../test/compute/fixtures/ec2/create_volume.xml |  2 ++
 libcloud/test/compute/test_ec2.py               | 22 +++++++++++++++++++-
 4 files changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/1e87b825/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 9b4b218..7ea29fa 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -2978,6 +2978,10 @@ RESOURCE_EXTRA_ATTRIBUTES_MAP = {
             'xpath': 'status',
             'transform_func': str
         },
+        'encrypted': {
+            'xpath': 'encrypted',
+            'transform_func': lambda x: {'true': True, 'false': False}.get(x)
+        },
         'attach_time': {
             'xpath': 'attachmentSet/item/attachTime',
             'transform_func': parse_date

http://git-wip-us.apache.org/repos/asf/libcloud/blob/1e87b825/libcloud/test/compute/fixtures/ec2/create_encrypted_volume.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ec2/create_encrypted_volume.xml b/libcloud/test/compute/fixtures/ec2/create_encrypted_volume.xml
new file mode 100644
index 0000000..bd22e89
--- /dev/null
+++ b/libcloud/test/compute/fixtures/ec2/create_encrypted_volume.xml
@@ -0,0 +1,11 @@
+<CreateVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
+  <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
+  <volumeId>vol-4d826724</volumeId>
+  <size>10</size>
+  <snapshotId/>
+  <availabilityZone>us-east-1a</availabilityZone>
+  <status>creating</status>
+  <createTime>2008-05-07T11:51:50.000Z</createTime>
+  <volumeType>standard</volumeType>
+  <encrypted>true</encrypted>
+</CreateVolumeResponse>

http://git-wip-us.apache.org/repos/asf/libcloud/blob/1e87b825/libcloud/test/compute/fixtures/ec2/create_volume.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ec2/create_volume.xml b/libcloud/test/compute/fixtures/ec2/create_volume.xml
index df7d7c4..40dd556 100644
--- a/libcloud/test/compute/fixtures/ec2/create_volume.xml
+++ b/libcloud/test/compute/fixtures/ec2/create_volume.xml
@@ -6,4 +6,6 @@
   <availabilityZone>us-east-1a</availabilityZone>
   <status>creating</status>
   <createTime>2008-05-07T11:51:50.000Z</createTime>
+  <volumeType>standard</volumeType>
+  <encrypted>false</encrypted>
 </CreateVolumeResponse>

http://git-wip-us.apache.org/repos/asf/libcloud/blob/1e87b825/libcloud/test/compute/test_ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index a36e650..f0409ed 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -907,6 +907,20 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
         self.assertEqual('vol', vol.name)
         self.assertEqual('creating', vol.extra['state'])
         self.assertTrue(isinstance(vol.extra['create_time'], datetime))
+        self.assertEqual(False, vol.extra['encrypted'])
+
+    def test_create_encrypted_volume(self):
+        location = self.driver.list_locations()[0]
+        vol = self.driver.create_volume(
+            10, 'vol', location,
+            ex_encrypted=True,
+            ex_kms_key_id='1234')
+
+        self.assertEqual(10, vol.size)
+        self.assertEqual('vol', vol.name)
+        self.assertEqual('creating', vol.extra['state'])
+        self.assertTrue(isinstance(vol.extra['create_time'], datetime))
+        self.assertEqual(True, vol.extra['encrypted'])
 
     def test_destroy_volume(self):
         vol = StorageVolume(id='vol-4282672b', name='test',
@@ -1531,7 +1545,13 @@ class EC2MockHttp(MockHttp):
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
     def _CreateVolume(self, method, url, body, headers):
-        body = self.fixtures.load('create_volume.xml')
+        if 'KmsKeyId=' in url:
+            assert 'Encrypted=1' in url, "If a KmsKeyId is specified, the " \
+                                         "Encrypted flag must also be set."
+        if 'Encrypted=1' in url:
+            body = self.fixtures.load('create_encrypted_volume.xml')
+        else:
+            body = self.fixtures.load('create_volume.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
     def _DeleteVolume(self, method, url, body, headers):