1
# Copyright 2013, Red Hat, Inc.
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
# not use this file except in compliance with the License. You may obtain
5
# a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
# License for the specific language governing permissions and limitations
20
from cinder import exception
21
from cinder.openstack.common import jsonutils
22
from cinder.openstack.common.rpc import common as rpc_common
23
from cinder import test
24
from cinder.tests.api import fakes
25
from cinder.tests.api.v2 import stubs
26
from cinder import volume
27
from cinder.volume import api as volume_api
30
class SnapshotActionsTest(test.TestCase):
33
super(SnapshotActionsTest, self).setUp()
35
def test_update_snapshot_status(self):
36
self.stubs.Set(db, 'snapshot_get', stub_snapshot_get)
37
self.stubs.Set(db, 'snapshot_update', stub_snapshot_update)
39
body = {'os-update_snapshot_status': {'status': 'available'}}
40
req = webob.Request.blank('/v2/fake/snapshots/1/action')
42
req.body = jsonutils.dumps(body)
43
req.headers["content-type"] = "application/json"
45
res = req.get_response(fakes.wsgi_app())
46
self.assertEqual(res.status_int, 202)
48
def test_update_snapshot_status_invalid_status(self):
49
self.stubs.Set(db, 'snapshot_get', stub_snapshot_get)
50
body = {'os-update_snapshot_status': {'status': 'in-use'}}
51
req = webob.Request.blank('/v2/fake/snapshots/1/action')
53
req.body = jsonutils.dumps(body)
54
req.headers["content-type"] = "application/json"
56
res = req.get_response(fakes.wsgi_app())
57
self.assertEqual(res.status_int, 400)
60
def stub_snapshot_get(context, snapshot_id):
61
snapshot = stubs.stub_snapshot(snapshot_id)
63
snapshot['status'] = 'error'
64
elif snapshot_id == 1:
65
snapshot['status'] = 'creating'
66
elif snapshot_id == 7:
67
snapshot['status'] = 'available'
69
snapshot['status'] = 'creating'
74
def stub_snapshot_update(self, context, id, **kwargs):