summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJosh Kearney <josh@jk0.org>2011-06-24 15:03:01 -0500
committerJosh Kearney <josh@jk0.org>2011-06-24 15:03:01 -0500
commit594d5c7a98f2b4e6ea2d866f10c67cbdaa88ce0c (patch)
tree75db0f8b25fe08ea6a037cdd8c4f03b8d0abb01a /nova/tests
parent1d3960e3b76e3f75c68f919278a2a227e1f96e48 (diff)
Refactored backup rotate.
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/fakes.py5
-rw-r--r--nova/tests/api/openstack/test_images.py45
2 files changed, 36 insertions, 14 deletions
diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py
index 0a2584910..ad9c5067c 100644
--- a/nova/tests/api/openstack/fakes.py
+++ b/nova/tests/api/openstack/fakes.py
@@ -147,10 +147,11 @@ def stub_out_compute_api_snapshot(stubs):
def stub_out_compute_api_backup(stubs):
- def backup(self, context, instance_id, backup_type, rotation):
+ def backup(self, context, instance_id, name, backup_type, rotation):
return dict(id='123', status='ACTIVE',
properties=dict(instance_id='123',
- image_type=backup_type,
+ name=name,
+ backup_type=backup_type,
rotation=rotation))
stubs.Set(nova.compute.API, 'backup', backup)
diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py
index 0fad044f1..8ad08080a 100644
--- a/nova/tests/api/openstack/test_images.py
+++ b/nova/tests/api/openstack/test_images.py
@@ -983,11 +983,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
self.assertEqual(200, response.status_int)
def test_create_snapshot_no_name(self):
- """Name is required for snapshots
-
- If an image_type isn't passed, we default to image_type=snapshot,
- thus `name` is required
- """
+ """Name is required for snapshots"""
body = dict(image=dict(serverId='123'))
req = webob.Request.blank('/v1.0/images')
req.method = 'POST'
@@ -996,11 +992,19 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
response = req.get_response(fakes.wsgi_app())
self.assertEqual(400, response.status_int)
- def test_create_backup_no_name_with_rotation(self):
- """Name isn't required for backups, but rotation is.
+ def test_create_backup_no_name(self):
+ """Name is also required for backups"""
+ body = dict(image=dict(serverId='123', image_type='backup',
+ backup_type='daily', 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)
- The reason name isn't required is because it defaults to the
- image_type.
+ def test_create_backup_with_rotation_and_backup_type(self):
+ """The happy path for creating backups
Creating a backup is an admin-only operation, as opposed to snapshots
which are available to anybody.
@@ -1009,8 +1013,9 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
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',
- rotation=1))
+ body = dict(image=dict(serverId='123', image_type='backup',
+ name='Backup 1',
+ backup_type='daily', rotation=1))
req = webob.Request.blank('/v1.0/images')
req.method = 'POST'
req.body = json.dumps(body)
@@ -1024,7 +1029,23 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
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'))
+ body = dict(image=dict(serverId='123', name='daily',
+ image_type='backup', backup_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_backup_no_backup_type(self):
+ """Backup Type (daily or weekly) 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', name='daily',
+ image_type='backup', rotation=1))
req = webob.Request.blank('/v1.0/images')
req.method = 'POST'
req.body = json.dumps(body)