libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [3/4] git commit: Issue LIBCLOUD-365: change ec2 ex_blockdevicemappings to support all possible key/values
Date Thu, 25 Jul 2013 07:21:26 GMT
Issue LIBCLOUD-365: change ec2 ex_blockdevicemappings to support all possible key/values

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


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

Branch: refs/heads/0.13.x
Commit: d56f0c065099b30dc260775aabed30ec3fb57491
Parents: ac7c6ad
Author: joe miller <joeym@joeym.net>
Authored: Sun Jul 21 07:48:23 2013 -0700
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Thu Jul 25 09:21:03 2013 +0200

----------------------------------------------------------------------
 libcloud/compute/drivers/ec2.py   | 18 ++++++++++++------
 libcloud/test/compute/test_ec2.py | 30 +++++++++++++++++++++++++++---
 2 files changed, 39 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/d56f0c06/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 26018ac..1f4db0b 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -1291,7 +1291,8 @@ class BaseEC2NodeDriver(NodeDriver):
 
         @keyword    ex_blockdevicemappings: C{list} of C{dict} block device
                     mappings. Example:
-                    [{'DeviceName': '/dev/sdb', 'VirtualName': 'ephemeral0'}]
+                    [{'DeviceName': '/dev/sda1', 'Ebs.VolumeSize': 10},
+                     {'DeviceName': '/dev/sdb', 'VirtualName': 'ephemeral0'}]
         @type       ex_blockdevicemappings: C{list} of C{dict}
         """
         image = kwargs["image"]
@@ -1331,11 +1332,16 @@ class BaseEC2NodeDriver(NodeDriver):
             params['ClientToken'] = kwargs['ex_clienttoken']
 
         if 'ex_blockdevicemappings' in kwargs:
-            for index, mapping in enumerate(kwargs['ex_blockdevicemappings']):
-                params['BlockDeviceMapping.%d.DeviceName' % (index + 1)] = \
-                    mapping['DeviceName']
-                params['BlockDeviceMapping.%d.VirtualName' % (index + 1)] = \
-                    mapping['VirtualName']
+            if not isinstance(kwargs['ex_blockdevicemappings'], (list, tuple)):
+                raise AttributeError('ex_blockdevicemappings not list or tuple')
+
+            for idx, mapping in enumerate(kwargs['ex_blockdevicemappings'],
+                                          start=1):
+                if not isinstance(mapping, dict):
+                    raise AttributeError('mapping %s in ex_blockdevicemappings '
+                                         'not a dict' % mapping)
+                for k, v in mapping.items():
+                    params['BlockDeviceMapping.%d.%s' % (idx, k)] = str(v)
 
         object = self.connection.request(self.path, params=params).object
         nodes = self._to_nodes(object, 'instancesSet/item')

http://git-wip-us.apache.org/repos/asf/libcloud/blob/d56f0c06/libcloud/test/compute/test_ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index d0e2c8a..b9de7cc 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -185,6 +185,7 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
         size = NodeSize('m1.small', 'Small Instance', None, None, None, None,
                         driver=self.driver)
         mappings = [
+            {'DeviceName': '/dev/sda1', 'Ebs.VolumeSize': 10},
             {'DeviceName': '/dev/sdb', 'VirtualName': 'ephemeral0'},
             {'DeviceName': '/dev/sdc', 'VirtualName': 'ephemeral1'}
         ]
@@ -192,6 +193,25 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
                                        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)
@@ -440,12 +460,16 @@ class EC2MockHttp(MockHttpTestCase):
     def _create_ex_blockdevicemappings_RunInstances(self, method, url, body, headers):
         parameters = dict(parse_qsl(url))
         self.assertEqual(parameters['BlockDeviceMapping.1.DeviceName'],
+                         '/dev/sda1')
+        self.assertEqual(parameters['BlockDeviceMapping.1.Ebs.VolumeSize'],
+                         '10')
+        self.assertEqual(parameters['BlockDeviceMapping.2.DeviceName'],
                          '/dev/sdb')
-        self.assertEqual(parameters['BlockDeviceMapping.1.VirtualName'],
+        self.assertEqual(parameters['BlockDeviceMapping.2.VirtualName'],
                          'ephemeral0')
-        self.assertEqual(parameters['BlockDeviceMapping.2.DeviceName'],
+        self.assertEqual(parameters['BlockDeviceMapping.3.DeviceName'],
                          '/dev/sdc')
-        self.assertEqual(parameters['BlockDeviceMapping.2.VirtualName'],
+        self.assertEqual(parameters['BlockDeviceMapping.3.VirtualName'],
                          'ephemeral1')
 
         body = self.fixtures.load('run_instances.xml')


Mime
View raw message