From 7001102867f3b5459fbe6b7bca7aafc470ce6b3f Mon Sep 17 00:00:00 2001 From: bhagyashris Date: Mon, 17 Oct 2016 16:36:26 +0530 Subject: [PATCH] Change backup rotation min value from 0 to 1 If you backup an instance by passing rotation as 0 to the backup api, then nova creates an image in glance and takes a snapshot of an instance and then deletes it immediately. Creation of an image and snapshot is an unnecessary step. This patch changes the 'rotation' parameter min value from 0 to 1. Caveat: The last backup of an instance should be deleted by user explicitly. APIImpact: For backup instance API, it will return 400 error if user passes rotation parameter value as 0. DocImpact: Minimum value for the rotation parameter should 1. Closes-Bug: #1627597 Change-Id: Ie95f5c39c478ae69b697414347ae5272a205fb07 --- .../api/openstack/compute/schemas/create_backup.py | 2 +- .../api/openstack/compute/test_create_backup.py | 23 +++++++--------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/nova/api/openstack/compute/schemas/create_backup.py b/nova/api/openstack/compute/schemas/create_backup.py index 29401c8..3c3e3b2 100644 --- a/nova/api/openstack/compute/schemas/create_backup.py +++ b/nova/api/openstack/compute/schemas/create_backup.py @@ -27,7 +27,7 @@ create_backup = { 'backup_type': { 'type': 'string', }, - 'rotation': parameter_types.non_negative_integer, + 'rotation': parameter_types.positive_integer, 'metadata': parameter_types.metadata, }, 'required': ['name', 'backup_type', 'rotation'], diff --git a/nova/tests/unit/api/openstack/compute/test_create_backup.py b/nova/tests/unit/api/openstack/compute/test_create_backup.py index d3fca0d..80cc909 100644 --- a/nova/tests/unit/api/openstack/compute/test_create_backup.py +++ b/nova/tests/unit/api/openstack/compute/test_create_backup.py @@ -129,7 +129,7 @@ class CreateBackupTestsV21(admin_only_action_common.CommonMixin, self.req, fakes.FAKE_UUID, body=body) def test_create_backup_negative_rotation(self): - """Rotation must be greater than or equal to zero + """Rotation must be greater than zero for backup requests """ body = { @@ -187,7 +187,9 @@ class CreateBackupTestsV21(admin_only_action_common.CommonMixin, self.req, fakes.FAKE_UUID, body=body) def test_create_backup_rotation_is_zero(self): - # The happy path for creating backups if rotation is zero. + """Rotation must be greater than zero + for backup requests + """ body = { 'createBackup': { 'name': 'Backup 1', @@ -196,20 +198,9 @@ class CreateBackupTestsV21(admin_only_action_common.CommonMixin, }, } - image = dict(id='fake-image-id', status='ACTIVE', name='Backup 1', - properties={}) - common.check_img_metadata_properties_quota(self.context, {}) - instance = self._stub_instance_get() - self.compute_api.backup(self.context, instance, 'Backup 1', - 'daily', 0, - extra_properties={}).AndReturn(image) - - self.mox.ReplayAll() - - res = self.controller._create_backup(self.req, instance.uuid, - body=body) - self.assertEqual(202, res.status_int) - self.assertNotIn('Location', res.headers) + self.assertRaises(self.validation_error, + self.controller._create_backup, + self.req, fakes.FAKE_UUID, body=body) def test_create_backup_rotation_is_positive(self): # The happy path for creating backups if rotation is positive. -- 1.9.1