File: test_scheduler_stats.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 (81 lines) | stat: -rw-r--r-- 2,962 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
# Copyright (c) 2015 Clinton Knight.  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

from manilaclient.tests.unit import utils
from manilaclient.tests.unit.v2 import fakes
from manilaclient.v2 import scheduler_stats


class PoolTest(utils.TestCase):

    def setUp(self):
        super(PoolTest, self).setUp()

        self.name = 'fake_host@fake_backend#fake_pool'
        info = {
            'name': self.name,
            'host': 'fake_host',
            'backend': 'fake_backend',
            'pool': 'fake_pool',
        }
        self.resource_class = scheduler_stats.Pool(manager=self, info=info)

    def test_get_repr_of_share_server(self):
        self.assertEqual('<Pool: %s>' % self.name, repr(self.resource_class))


class PoolManagerTest(utils.TestCase):

    def setUp(self):
        super(PoolManagerTest, self).setUp()
        self.manager = scheduler_stats.PoolManager(fakes.FakeClient())

    @mock.patch.object(scheduler_stats.PoolManager, '_list', mock.Mock())
    def test_list(self):
        self.manager.list(detailed=False)
        self.manager._list.assert_called_once_with(
            scheduler_stats.RESOURCES_PATH,
            scheduler_stats.RESOURCES_NAME)

    @mock.patch.object(scheduler_stats.PoolManager, '_list', mock.Mock())
    def test_list_detail(self):
        self.manager.list()
        self.manager._list.assert_called_once_with(
            scheduler_stats.RESOURCES_PATH + '/detail',
            scheduler_stats.RESOURCES_NAME)

    @mock.patch.object(scheduler_stats.PoolManager, '_list', mock.Mock())
    def test_list_with_one_search_opt(self):
        host = 'fake_host'
        query_string = "?host=%s" % host

        self.manager.list(detailed=False, search_opts={'host': host})

        self.manager._list.assert_called_once_with(
            scheduler_stats.RESOURCES_PATH + query_string,
            scheduler_stats.RESOURCES_NAME)

    @mock.patch.object(scheduler_stats.PoolManager, '_list', mock.Mock())
    def test_list_detail_with_two_search_opts(self):
        host = 'fake_host'
        backend = 'fake_backend'
        query_string = "?backend=%s&host=%s" % (backend, host)

        self.manager.list(search_opts={'host': host, 'backend': backend})

        self.manager._list.assert_called_once_with(
            scheduler_stats.RESOURCES_PATH + '/detail' + query_string,
            scheduler_stats.RESOURCES_NAME)