Coverage for manila/tests/api/views/test_scheduler_stats.py: 100%
21 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright (c) 2015 Clinton Knight. All rights reserved.
2#
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
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
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
13# under the License.
15import copy
17from manila.api.views import scheduler_stats
18from manila import test
21POOL1 = {
22 'name': 'host1@backend1#pool1',
23 'host': 'host1',
24 'backend': 'backend1',
25 'pool': 'pool1',
26 'other': 'junk',
27 'capabilities': {
28 'pool_name': 'pool1',
29 'driver_handles_share_servers': False,
30 'qos': 'False',
31 'timestamp': '2015-03-15T19:15:42.611690',
32 'allocated_capacity_gb': 5,
33 'total_capacity_gb': 10,
34 },
35}
36POOL2 = {
37 'name': 'host1@backend1#pool2',
38 'host': 'host1',
39 'backend': 'backend1',
40 'pool': 'pool2',
41 'capabilities': {
42 'pool_name': 'pool2',
43 'driver_handles_share_servers': False,
44 'qos': 'False',
45 'timestamp': '2015-03-15T19:15:42.611690',
46 'allocated_capacity_gb': 15,
47 'total_capacity_gb': 20,
48 },
49}
50POOLS = [POOL1, POOL2]
52POOLS_DETAIL_VIEW = {
53 'pools': [
54 {
55 'name': 'host1@backend1#pool1',
56 'host': 'host1',
57 'backend': 'backend1',
58 'pool': 'pool1',
59 'capabilities': {
60 'pool_name': 'pool1',
61 'driver_handles_share_servers': False,
62 'qos': 'False',
63 'timestamp': '2015-03-15T19:15:42.611690',
64 'allocated_capacity_gb': 5,
65 'total_capacity_gb': 10,
66 },
67 }, {
68 'name': 'host1@backend1#pool2',
69 'host': 'host1',
70 'backend': 'backend1',
71 'pool': 'pool2',
72 'capabilities': {
73 'pool_name': 'pool2',
74 'driver_handles_share_servers': False,
75 'qos': 'False',
76 'timestamp': '2015-03-15T19:15:42.611690',
77 'allocated_capacity_gb': 15,
78 'total_capacity_gb': 20,
79 }
80 }
81 ]
82}
85class ViewBuilderTestCase(test.TestCase):
87 def setUp(self):
88 super(ViewBuilderTestCase, self).setUp()
89 self.builder = scheduler_stats.ViewBuilder()
91 def test_pools(self):
93 result = self.builder.pools(POOLS)
95 # Remove capabilities for summary view
96 expected = copy.deepcopy(POOLS_DETAIL_VIEW)
97 for pool in expected['pools']:
98 del pool['capabilities']
100 self.assertDictEqual(expected, result)
102 def test_pools_with_details(self):
104 result = self.builder.pools(POOLS, detail=True)
106 expected = POOLS_DETAIL_VIEW
107 self.assertDictEqual(expected, result)