Debian Codegraph @

neutron_lib/tests/unit/services/qos/test_base.py

raw
1 # 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.
14
15 from unittest import mock
16
17 from neutron_lib.api.definitions import portbindings
18 from neutron_lib import constants
19 from neutron_lib.services.qos import base as qos_base
20 from neutron_lib.services.qos import constants as qos_consts
21 from neutron_lib.tests import _base
22
23
24 SUPPORTED_RULES = {
25 qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH: {
26 qos_consts.MIN_KBPS: {'type:values': None},
27 qos_consts.DIRECTION: {'type:values': ['egress']}
28 }
29 }
30
31
32 def _make_rule(rule_type='fake-rule-type', params=None):
33 mock_rule = mock.MagicMock()
34 mock_rule.rule_type = rule_type
35 params = params or {}
36 mock_rule.get = params.get
37 return mock_rule
38
39
40 def _make_driver(name='fake-driver',
41 vif_types=None,
42 vnic_types=None,
43 supported_rules=None,
44 requires_rpc_notifications=False):
45 vif_types = vif_types or [portbindings.VIF_TYPE_OVS]
46 vnic_types = vnic_types or [portbindings.VNIC_NORMAL]
47 supported_rules = supported_rules or SUPPORTED_RULES
48 return qos_base.DriverBase(
49 name, vif_types, vnic_types, supported_rules,
50 requires_rpc_notifications=requires_rpc_notifications)
51
52
53 class TestDriverBase(_base.BaseTestCase):
54
55 def test_is_loaded(self):
56 self.assertTrue(_make_driver().is_loaded())
57
58 def test_is_vif_type_compatible(self):
59 self.assertTrue(
60 _make_driver().is_vif_type_compatible(
61 portbindings.VIF_TYPE_OVS))
62 self.assertFalse(
63 _make_driver().is_vif_type_compatible(
64 portbindings.VIF_TYPE_BRIDGE))
65
66 def test_is_vnic_compatible(self):
67 self.assertTrue(
68 _make_driver().is_vnic_compatible(portbindings.VNIC_NORMAL))
69 self.assertFalse(
70 _make_driver().is_vnic_compatible(portbindings.VNIC_BAREMETAL))
71
72 def test_is_rule_supported_with_unsupported_rule(self):
73 self.assertFalse(_make_driver().is_rule_supported(_make_rule()))
74
75 def test_is_rule_supported(self):
76 self.assertTrue(
77 _make_driver().is_rule_supported(
78 _make_rule(
79 rule_type=qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
80 params={qos_consts.MIN_KBPS: None,
81 qos_consts.DIRECTION:
82 constants.EGRESS_DIRECTION})))
83 self.assertFalse(
84 _make_driver().is_rule_supported(
85 _make_rule(
86 rule_type=qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
87 params={qos_consts.MIN_KBPS: None,
88 qos_consts.DIRECTION:
89 constants.INGRESS_DIRECTION})))