summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Kearney <josh@jk0.org>2011-06-24 11:55:43 -0500
committerJosh Kearney <josh@jk0.org>2011-06-24 11:55:43 -0500
commitcbf9f1bef113d54be57e2bb9a79990226afcd90f (patch)
treefbdec79d7174106fa920122bb737e66c7d010a21
parent4a32c971893a22a6451eed7e618291ad86c24510 (diff)
downloadnova-cbf9f1bef113d54be57e2bb9a79990226afcd90f.tar.gz
nova-cbf9f1bef113d54be57e2bb9a79990226afcd90f.tar.xz
nova-cbf9f1bef113d54be57e2bb9a79990226afcd90f.zip
Adding tests for backup no rotation, invalid image type
-rw-r--r--nova/api/openstack/images.py6
-rw-r--r--nova/tests/api/openstack/test_images.py29
2 files changed, 34 insertions, 1 deletions
diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py
index d8dbd2360..2287ca0f7 100644
--- a/nova/api/openstack/images.py
+++ b/nova/api/openstack/images.py
@@ -122,13 +122,17 @@ class Controller(object):
image_name = get_param("name")
image = self._compute_service.snapshot(context, server_id,
image_name)
- else:
+ elif image_type in ("daily", "weekly"):
if not FLAGS.allow_admin_api:
raise webob.exc.HTTPBadRequest()
rotation = int(get_param("rotation"))
image = self._compute_service.backup(context, server_id,
image_type, rotation)
+ else:
+ LOG.error(_("Invalid image_type '%s' passed" % image_type))
+ raise webob.exc.HTTPBadRequest()
+
return dict(image=self.get_builder(req).build(image, detail=True))
diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py
index 036e510c9..0fad044f1 100644
--- a/nova/tests/api/openstack/test_images.py
+++ b/nova/tests/api/openstack/test_images.py
@@ -1018,6 +1018,35 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
response = req.get_response(fakes.wsgi_app())
self.assertEqual(200, response.status_int)
+ def test_create_backup_no_rotation(self):
+ """Rotation is required for backup requests"""
+ # FIXME(sirp): teardown needed?
+ FLAGS.allow_admin_api = True
+
+ # FIXME(sirp): should the fact that backups are admin_only be a FLAG
+ body = dict(image=dict(serverId='123', image_type='daily'))
+ req = webob.Request.blank('/v1.0/images')
+ req.method = 'POST'
+ req.body = json.dumps(body)
+ req.headers["content-type"] = "application/json"
+ response = req.get_response(fakes.wsgi_app())
+ self.assertEqual(400, response.status_int)
+
+ def test_create_image_with_invalid_image_type(self):
+ """Valid image_types are snapshot | daily | weekly"""
+ # FIXME(sirp): teardown needed?
+ FLAGS.allow_admin_api = True
+
+ # FIXME(sirp): should the fact that backups are admin_only be a FLAG
+ body = dict(image=dict(serverId='123', image_type='monthly',
+ rotation=1))
+ req = webob.Request.blank('/v1.0/images')
+ req.method = 'POST'
+ req.body = json.dumps(body)
+ req.headers["content-type"] = "application/json"
+ response = req.get_response(fakes.wsgi_app())
+ self.assertEqual(400, response.status_int)
+
def test_create_image_no_server_id(self):
body = dict(image=dict(name='Snapshot 1'))