libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [1/2] libcloud git commit: OS create_snapshot posts optional keywords only when needed
Date Mon, 26 Sep 2016 06:03:56 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk a29f8fba6 -> 93c467c3e


OS create_snapshot posts optional keywords only when needed


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

Branch: refs/heads/trunk
Commit: 46647ea4af9d72e140cf3e4577ea9b08296eaba2
Parents: a29f8fb
Author: Allard Hoeve <allardhoeve@gmail.com>
Authored: Fri Sep 23 12:23:52 2016 +0200
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Mon Sep 26 16:02:22 2016 +1000

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py   | 15 +++++++++------
 libcloud/test/compute/test_openstack.py | 13 +++++++++++++
 2 files changed, 22 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/46647ea4/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 0c17774..0a34866 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -1672,10 +1672,10 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
         :type  volume: `StorageVolume`
 
         :param name: Name of snapshot (optional)
-        :type  name: `str`
+        :type  name: `str` | `NoneType`
 
         :param ex_description: Description of the snapshot (optional)
-        :type  ex_description: `str`
+        :type  ex_description: `str` | `NoneType`
 
         :param ex_force: Specifies if we create a snapshot that is not in
                          state `available`. For example `in-use`. Defaults
@@ -1684,10 +1684,13 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
 
         :rtype: :class:`VolumeSnapshot`
         """
-        data = {'snapshot': {'display_name': name,
-                             'display_description': ex_description,
-                             'volume_id': volume.id,
-                             'force': ex_force}}
+        data = {'snapshot': {'volume_id': volume.id, 'force': ex_force}}
+
+        if name is not None:
+            data['snapshot']['display_name'] = name
+
+        if ex_description is not None:
+            data['snapshot']['display_description'] = ex_description
 
         return self._to_snapshot(self.connection.request('/os-snapshots',
                                                          method='POST',

http://git-wip-us.apache.org/repos/asf/libcloud/blob/46647ea4/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index ec6a00e..71a2fab 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1521,6 +1521,19 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin):
                                              force=True)
         self.assertEqual(ret.id, '3fbbcccf-d058-4502-8844-6feeffdf4cb5')
 
+    def test_ex_create_snapshot_does_not_post_optional_parameters_if_none(self):
+        volume = self.driver.list_volumes()[0]
+        with patch.object(self.driver, '_to_snapshot'):
+            with patch.object(self.driver.connection, 'request') as mock_request:
+                self.driver.create_volume_snapshot(volume,
+                                                   name=None,
+                                                   ex_description=None,
+                                                   ex_force=True)
+
+        name, args, kwargs = mock_request.mock_calls[0]
+        self.assertFalse("display_name" in kwargs["data"]["snapshot"])
+        self.assertFalse("display_description" in kwargs["data"]["snapshot"])
+
     def test_destroy_volume_snapshot(self):
         if self.driver_type.type == 'rackspace':
             self.conn_classes[0].type = 'RACKSPACE'


Mime
View raw message