From e6e33b72604e337bf5317dbea573703cbdc3b983 Mon Sep 17 00:00:00 2001 From: Allard Hoeve Date: Fri, 23 Sep 2016 12:23:52 +0200 Subject: [PATCH 1/2] OS create_snapshot posts optional keywords only when needed --- libcloud/compute/drivers/openstack.py | 15 +++++++++------ libcloud/test/compute/test_openstack.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py index 88622d29c4..e85f19beda 100644 --- a/libcloud/compute/drivers/openstack.py +++ b/libcloud/compute/drivers/openstack.py @@ -1668,10 +1668,10 @@ def create_volume_snapshot(self, volume, name=None, ex_description=None, :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 @@ -1680,10 +1680,13 @@ def create_volume_snapshot(self, volume, name=None, ex_description=None, :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', diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py index 1a0cdabc54..c34b93672d 100644 --- a/libcloud/test/compute/test_openstack.py +++ b/libcloud/test/compute/test_openstack.py @@ -1509,6 +1509,19 @@ def test_ex_create_snapshot(self): 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' From a0afc5422ec1a509ab5a9dd91cdc5ff3bd0758d7 Mon Sep 17 00:00:00 2001 From: Allard Hoeve Date: Fri, 23 Sep 2016 12:26:29 +0200 Subject: [PATCH 2/2] Docs for #866 --- CHANGES.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index eb027dad64..e4e7b32146 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,6 +13,12 @@ Compute (GITHUB-857) [Allard Hoeve] +- When creating volume snapshot, the arguments `name` and `description` are truely + optional when working with newer OpenStack versions. The OpenStack driver will now + only post thost arguments if they are non-`NoneType`. + (GITHUB-866) + [Allard Hoeve] + Container ~~~~~~~~~