File: test_share_snapshot_instances.py

package info (click to toggle)
python-manilaclient 5.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,768 kB
  • sloc: python: 49,541; makefile: 99; sh: 2
file content (96 lines) | stat: -rw-r--r-- 3,612 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Copyright 2016 Huawei inc.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from unittest import mock

import ddt

from manilaclient import api_versions
from manilaclient import exceptions
from manilaclient import extension
from manilaclient.tests.unit import utils
from manilaclient.tests.unit.v2 import fakes
from manilaclient.v2 import share_snapshot_instances


extensions = [
    extension.Extension('share_snapshot_instances', share_snapshot_instances),
]
cs = fakes.FakeClient(extensions=extensions)


@ddt.ddt
class SnapshotInstancesTest(utils.TestCase):

    def setUp(self):
        super(SnapshotInstancesTest, self).setUp()
        microversion = api_versions.APIVersion("2.19")
        mock_microversion = mock.Mock(api_version=microversion)
        self.manager = share_snapshot_instances.ShareSnapshotInstanceManager(
            api=mock_microversion)

    @ddt.data(True, False)
    def test_list(self, detailed):
        if detailed:
            url = '/snapshot-instances/detail'
        else:
            url = '/snapshot-instances'
        self.mock_object(self.manager, '_list', mock.Mock())
        self.manager.list(detailed=detailed, search_opts=None)
        self.manager._list.assert_called_once_with(url, 'snapshot_instances')

    @ddt.data(True, False)
    def test_list_with_snapshot(self, detailed):
        if detailed:
            url = '/snapshot-instances/detail'
        else:
            url = '/snapshot-instances'
        self.mock_object(self.manager, '_list', mock.Mock())
        self.manager.list(detailed=detailed, snapshot='snapshot_id')
        self.manager._list.assert_called_once_with(
            (url + '?snapshot_id=snapshot_id'), 'snapshot_instances',)

    def test_get(self):
        self.mock_object(self.manager, '_get', mock.Mock())
        self.manager.get('fake_snapshot_instance')
        self.manager._get.assert_called_once_with(
            '/snapshot-instances/' + 'fake_snapshot_instance',
            'snapshot_instance')

    def test_reset_instance_state(self):
        state = 'available'

        self.mock_object(self.manager, '_action', mock.Mock())
        self.manager.reset_state('fake_instance', state)
        self.manager._action.assert_called_once_with(
            "reset_status", 'fake_instance', {"status": state})

    @ddt.data('get', 'list', 'reset_state')
    def test_upsupported_microversion(self, method_name):
        unsupported_microversions = ('1.0', '2.18')
        arguments = {
            'instance': 'FAKE_INSTANCE',
        }
        if method_name in ('list'):
            arguments.clear()

        for microversion in unsupported_microversions:
            microversion = api_versions.APIVersion(microversion)
            mock_microversion = mock.Mock(api_version=microversion)
            manager = share_snapshot_instances.ShareSnapshotInstanceManager(
                api=mock_microversion)
            method = getattr(manager, method_name)
            self.assertRaises(exceptions.UnsupportedVersion,
                              method, **arguments)