Skip to content

Commit

Permalink
Add EC2Tests.test_create_encrypted_volume
Browse files Browse the repository at this point in the history
  • Loading branch information
mermoldy authored and pquentin committed Oct 19, 2017
1 parent 61c3e50 commit 1e87b82
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions libcloud/compute/drivers/ec2.py
Expand Up @@ -2978,6 +2978,10 @@ def GiB(value):
'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
Expand Down
11 changes: 11 additions & 0 deletions 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>
2 changes: 2 additions & 0 deletions libcloud/test/compute/fixtures/ec2/create_volume.xml
Expand Up @@ -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>
22 changes: 21 additions & 1 deletion libcloud/test/compute/test_ec2.py
Expand Up @@ -907,6 +907,20 @@ def test_create_volume(self):
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',
Expand Down Expand Up @@ -1531,7 +1545,13 @@ def _ModifySnapshotAttribute(self, method, url, body, headers):
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):
Expand Down

0 comments on commit 1e87b82

Please sign in to comment.