Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
Issue LIBCLOUD-365. check types
Browse files Browse the repository at this point in the history
  • Loading branch information
joemiller committed Jul 21, 2013
1 parent 04a7c6d commit 6d36811
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
11 changes: 9 additions & 2 deletions libcloud/compute/drivers/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,10 +1332,17 @@ def create_node(self, **kwargs):
params['ClientToken'] = kwargs['ex_clienttoken']

if 'ex_blockdevicemappings' in kwargs:
if not isinstance(kwargs['ex_blockdevicemappings'], list):
raise AttributeError('ex_blockdevicemappings is not a list')

for idx, mapping in enumerate(kwargs['ex_blockdevicemappings'],
start=1):
for k, v in mapping.iteritems():
params['BlockDeviceMapping.%d.%s' % (idx, k)] = str(v)
for k, v in mapping.items():
if not isinstance(mapping, dict):
raise AttributeError('mapping %s in '\
'ex_blockdevicemappings is not '\
'a dict' % mapping)
params['BlockDeviceMapping.%d.%s' % (idx, k)] = str(v)

object = self.connection.request(self.path, params=params).object
nodes = self._to_nodes(object, 'instancesSet/item')
Expand Down
19 changes: 19 additions & 0 deletions libcloud/test/compute/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,25 @@ def test_ex_create_node_with_ex_blockdevicemappings(self):
ex_blockdevicemappings=mappings)
self.assertEqual(node.id, 'i-2ba64342')

def test_ex_create_node_with_ex_blockdevicemappings_attribute_error(self):
EC2MockHttp.type = 'create_ex_blockdevicemappings'

image = NodeImage(id='ami-be3adfd7',
name=self.image_name,
driver=self.driver)
size = NodeSize('m1.small', 'Small Instance', None, None, None, None,
driver=self.driver)

mappings = 'this should be a list'
self.assertRaises(AttributeError, self.driver.create_node, name='foo',
image=image, size=size,
ex_blockdevicemappings=mappings)

mappings = ['this should be a dict']
self.assertRaises(AttributeError, self.driver.create_node, name='foo',
image=image, size=size,
ex_blockdevicemappings=mappings)

def test_destroy_node(self):
node = Node('i-4382922a', None, None, None, None, self.driver)
ret = self.driver.destroy_node(node)
Expand Down

0 comments on commit 6d36811

Please sign in to comment.