1# Copyright 2013 Red Hat, Inc.
2# All Rights Reserved.
3#
4#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5#    not use this file except in compliance with the License. You may obtain
6#    a copy of the License at
7#
8#         http://www.apache.org/licenses/LICENSE-2.0
9#
10#    Unless required by applicable law or agreed to in writing, software
11#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13#    License for the specific language governing permissions and limitations
14#    under the License.
15
16from cinderclient.tests.unit.fixture_data import client
17from cinderclient.tests.unit.fixture_data import snapshots
18from cinderclient.tests.unit import utils
19
20
21class SnapshotActionsTest(utils.FixturedTestCase):
22
23    client_fixture_class = client.V2
24    data_fixture_class = snapshots.Fixture
25
26    def test_update_snapshot_status(self):
27        snap = self.cs.volume_snapshots.get('1234')
28        self._assert_request_id(snap)
29        stat = {'status': 'available'}
30        stats = self.cs.volume_snapshots.update_snapshot_status(snap, stat)
31        self.assert_called('POST', '/snapshots/1234/action')
32        self._assert_request_id(stats)
33
34    def test_update_snapshot_status_with_progress(self):
35        s = self.cs.volume_snapshots.get('1234')
36        self._assert_request_id(s)
37        stat = {'status': 'available', 'progress': '73%'}
38        stats = self.cs.volume_snapshots.update_snapshot_status(s, stat)
39        self.assert_called('POST', '/snapshots/1234/action')
40        self._assert_request_id(stats)
41
42    def test_list_snapshots_with_marker_limit(self):
43        lst = self.cs.volume_snapshots.list(marker=1234, limit=2)
44        self.assert_called('GET', '/snapshots/detail?limit=2&marker=1234')
45        self._assert_request_id(lst)
46
47    def test_list_snapshots_with_sort(self):
48        lst = self.cs.volume_snapshots.list(sort="id")
49        self.assert_called('GET', '/snapshots/detail?sort=id')
50        self._assert_request_id(lst)
51
52    def test_snapshot_unmanage(self):
53        s = self.cs.volume_snapshots.get('1234')
54        self._assert_request_id(s)
55        snap = self.cs.volume_snapshots.unmanage(s)
56        self.assert_called('POST', '/snapshots/1234/action',
57                           {'os-unmanage': None})
58        self._assert_request_id(snap)
59