コード例 #1
0
 def _create_minimum_bandwidth_rule_obj(self):
     rule_obj = rule.QosMinimumBandwidthRule()
     rule_obj.id = uuidutils.generate_uuid()
     rule_obj.min_kbps = 200
     rule_obj.direction = constants.EGRESS_DIRECTION
     rule_obj.obj_reset_changes()
     return rule_obj
コード例 #2
0
    def _test_validate_rule_for_port(self, port, expected_result):
        driver_manager = self._create_manager_with_drivers({
            'driver-A': {
                'is_loaded': True,
                'rules': {
                    qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH: {
                        "min_kbps": {'type:values': None},
                        'direction': {
                            'type:values': constants.VALID_DIRECTIONS}
                    }
                },
                'vif_types': [portbindings.VIF_TYPE_OVS],
                'vnic_types': [portbindings.VNIC_NORMAL]
            }
        })
        rule = rule_object.QosMinimumBandwidthRule(
            self.ctxt, id=uuidutils.generate_uuid())

        is_rule_supported_mock = mock.Mock()
        if expected_result:
            is_rule_supported_mock.return_value = expected_result
        driver_manager._drivers[0].is_rule_supported = is_rule_supported_mock

        self.assertEqual(expected_result,
                         driver_manager.validate_rule_for_port(rule, port))
        if expected_result:
            is_rule_supported_mock.assert_called_once_with(rule)
        else:
            is_rule_supported_mock.assert_not_called()
コード例 #3
0
ファイル: test_qos.py プロジェクト: younkun/neutron
 def test__qos_rules(self, mock_get_rules, mock_warning):
     rules = [
         rule_obj.QosBandwidthLimitRule(
             direction=constants.EGRESS_DIRECTION, **QOS_RULE_BW_1),
         rule_obj.QosBandwidthLimitRule(
             direction=constants.INGRESS_DIRECTION, **QOS_RULE_BW_2),
         rule_obj.QosDscpMarkingRule(**QOS_RULE_DSCP_1),
         rule_obj.QosMinimumBandwidthRule(**QOS_RULE_MINBW_1)
     ]
     mock_get_rules.return_value = rules
     expected = {
         constants.EGRESS_DIRECTION: {
             qos_constants.RULE_TYPE_BANDWIDTH_LIMIT: QOS_RULE_BW_1,
             qos_constants.RULE_TYPE_DSCP_MARKING: QOS_RULE_DSCP_1
         },
         constants.INGRESS_DIRECTION: {
             qos_constants.RULE_TYPE_BANDWIDTH_LIMIT: QOS_RULE_BW_2
         }
     }
     self.assertEqual(expected,
                      self.qos_driver._qos_rules(mock.ANY, 'policy_id1'))
     msg = ('Rule type %(rule_type)s from QoS policy %(policy_id)s is not '
            'supported in OVN')
     mock_warning.assert_called_once_with(
         msg, {
             'rule_type': qos_constants.RULE_TYPE_MINIMUM_BANDWIDTH,
             'policy_id': 'policy_id1'
         })
コード例 #4
0
 def test_duplicate_rules(self):
     policy_id = uuidutils.generate_uuid()
     ingress_rule_1 = rule.QosMinimumPacketRateRule(
         self.context,
         qos_policy_id=policy_id,
         min_kpps=1000,
         direction=constants.INGRESS_DIRECTION)
     ingress_rule_2 = rule.QosMinimumPacketRateRule(
         self.context,
         qos_policy_id=policy_id,
         min_kpps=2000,
         direction=constants.INGRESS_DIRECTION)
     egress_rule = rule.QosMinimumPacketRateRule(
         self.context,
         qos_policy_id=policy_id,
         min_kpps=1000,
         direction=constants.EGRESS_DIRECTION)
     directionless_rule = rule.QosMinimumPacketRateRule(
         self.context,
         qos_policy_id=policy_id,
         min_kpps=1000,
         direction=constants.ANY_DIRECTION)
     min_bw_rule = rule.QosMinimumBandwidthRule(
         self.context,
         qos_policy_id=policy_id,
         min_kbps=1000,
         direction=constants.INGRESS_DIRECTION)
     self.assertTrue(ingress_rule_1.duplicates(ingress_rule_2))
     self.assertFalse(ingress_rule_1.duplicates(egress_rule))
     self.assertFalse(ingress_rule_1.duplicates(directionless_rule))
     self.assertFalse(ingress_rule_1.duplicates(min_bw_rule))
コード例 #5
0
 def _create_min_bw_rule_obj(self):
     rule_obj = rule.QosMinimumBandwidthRule()
     rule_obj.id = uuidutils.generate_uuid()
     rule_obj.min_kbps = self.RULE_MAX
     rule_obj.direction = self.RULE_DIRECTION_EGRESS
     rule_obj.obj_reset_changes()
     return rule_obj
コード例 #6
0
ファイル: test_rule.py プロジェクト: stackhpc/neutron
 def test_duplicate_rules(self):
     policy_id = uuidutils.generate_uuid()
     ingress_rule_1 = rule.QosMinimumBandwidthRule(
         self.context, qos_policy_id=policy_id,
         min_kbps=1000, direction=constants.INGRESS_DIRECTION)
     ingress_rule_2 = rule.QosMinimumBandwidthRule(
         self.context, qos_policy_id=policy_id,
         min_kbps=2000, direction=constants.INGRESS_DIRECTION)
     egress_rule = rule.QosMinimumBandwidthRule(
         self.context, qos_policy_id=policy_id,
         min_kbps=1000, direction=constants.EGRESS_DIRECTION)
     dscp_rule = rule.QosDscpMarkingRule(
         self.context, qos_policy_id=policy_id, dscp_mark=16)
     self.assertTrue(ingress_rule_1.duplicates(ingress_rule_2))
     self.assertFalse(ingress_rule_1.duplicates(egress_rule))
     self.assertFalse(ingress_rule_1.duplicates(dscp_rule))
コード例 #7
0
    def test_validate_rule_for_network(self):
        driver_manager = self._create_manager_with_drivers({
            'driver-A': {
                'is_loaded': True,
                'rules': {
                    qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH: {
                        "min_kbps": {
                            'type:values': None
                        },
                        'direction': {
                            'type:values': lib_consts.VALID_DIRECTIONS
                        }
                    }
                }
            }
        })
        rule = rule_object.QosMinimumBandwidthRule(
            self.ctxt, id=uuidutils.generate_uuid())

        is_rule_supported_mock = mock.Mock()
        is_rule_supported_mock.return_value = True
        driver_manager._drivers[0].is_rule_supported = is_rule_supported_mock
        self.assertTrue(
            driver_manager.validate_rule_for_network(mock.Mock(), rule,
                                                     mock.Mock()))
        is_rule_supported_mock.assert_called_once_with(rule)
コード例 #8
0
 def setUp(self):
     super(TestDriverBase, self).setUp()
     self.driver = FakeDriver.create()
     self.rule_data = {
         'minimum_bandwidth_rule': {
             'id': uuidutils.generate_uuid(),
             'min_kbps': 100,
             'direction': constants.EGRESS_DIRECTION
         },
         'dscp_marking_rule': {
             'id': uuidutils.generate_uuid(),
             'dscp_mark': 16
         }
     }
     ctxt = context.Context('fake_user', 'fake_tenant')
     self.minimum_bandwidth_rule = rule_object.QosMinimumBandwidthRule(
         ctxt, **self.rule_data['minimum_bandwidth_rule'])
     self.dscp_rule = rule_object.QosDscpMarkingRule(
         ctxt, **self.rule_data['dscp_marking_rule'])
コード例 #9
0
    def test__extend_port_resource_request_mixed_rules(self):
        self.min_rule.direction = lib_constants.EGRESS_DIRECTION

        min_rule_ingress_data = {
            'id': uuidutils.generate_uuid(),
            'min_kbps': 20,
            'direction': lib_constants.INGRESS_DIRECTION
        }
        min_rule_ingress = rule_object.QosMinimumBandwidthRule(
            self.ctxt, **min_rule_ingress_data)

        port = self._create_and_extend_port([self.min_rule, min_rule_ingress])
        self.assertEqual(['CUSTOM_PHYSNET_PUBLIC', 'CUSTOM_VNIC_TYPE_NORMAL'],
                         port['resource_request']['required'])
        self.assertEqual(
            {
                pl_constants.CLASS_NET_BW_EGRESS_KBPS: 10,
                pl_constants.CLASS_NET_BW_INGRESS_KBPS: 20
            },
            port['resource_request']['resources'],
        )
コード例 #10
0
 def test__qos_rules(self, mock_get_rules, mock_warning):
     rules = [
         rule_obj.QosBandwidthLimitRule(
             direction=constants.EGRESS_DIRECTION, **QOS_RULE_BW_1),
         rule_obj.QosBandwidthLimitRule(
             direction=constants.INGRESS_DIRECTION, **QOS_RULE_BW_2),
         rule_obj.QosDscpMarkingRule(**QOS_RULE_DSCP_1),
         rule_obj.QosMinimumBandwidthRule(**QOS_RULE_MINBW_1)
     ]
     mock_get_rules.return_value = rules
     expected = {
         constants.EGRESS_DIRECTION: {
             qos_constants.RULE_TYPE_BANDWIDTH_LIMIT: QOS_RULE_BW_1,
             qos_constants.RULE_TYPE_DSCP_MARKING: QOS_RULE_DSCP_1
         },
         constants.INGRESS_DIRECTION: {
             qos_constants.RULE_TYPE_BANDWIDTH_LIMIT: QOS_RULE_BW_2
         }
     }
     self.assertEqual(expected,
                      self.qos_driver._qos_rules(mock.ANY, 'policy_id1'))
     mock_warning.assert_not_called()
コード例 #11
0
    def test_min_bw_object_version_degradation(self):
        min_bw_rule = rule.QosMinimumBandwidthRule()

        for version in ['1.0', '1.1']:
            self.assertRaises(exception.IncompatibleObjectVersion,
                              min_bw_rule.obj_to_primitive, version)
コード例 #12
0
 def test_object_version_degradation_less_than_1_3(self):
     rule_obj = rule.QosMinimumBandwidthRule()
     self.assertRaises(exception.IncompatibleObjectVersion,
                       rule_obj.obj_to_primitive, '1.2')
コード例 #13
0
    def setUp(self):
        super(TestQosPlugin, self).setUp()
        self.setup_coreplugin(load_plugins=False)

        mock.patch('neutron.objects.db.api.create_object').start()
        mock.patch('neutron.objects.db.api.update_object').start()
        mock.patch('neutron.objects.db.api.delete_object').start()
        mock.patch('neutron.objects.db.api.get_object').start()
        _mock_qos_load_attr = mock.patch(
            'neutron.objects.qos.policy.QosPolicy.obj_load_attr')
        self.mock_qos_load_attr = _mock_qos_load_attr.start()
        # We don't use real models as per mocks above. We also need to mock-out
        # methods that work with real data types
        mock.patch('neutron.objects.base.NeutronDbObject.modify_fields_from_db'
                   ).start()
        mock.patch.object(policy_object.QosPolicy, 'unset_default').start()
        mock.patch.object(policy_object.QosPolicy, 'set_default').start()

        cfg.CONF.set_override("core_plugin", DB_PLUGIN_KLASS)
        cfg.CONF.set_override("service_plugins", ["qos"])

        manager.init()
        self.qos_plugin = directory.get_plugin(constants.QOS)

        self.qos_plugin.driver_manager = mock.Mock()

        self.rpc_push = mock.patch('neutron.api.rpc.handlers.resources_rpc'
                                   '.ResourcesPushRpcApi.push').start()

        self.ctxt = context.Context('fake_user', 'fake_tenant')
        mock.patch.object(self.ctxt.session, 'refresh').start()
        mock.patch.object(self.ctxt.session, 'expunge').start()

        self.policy_data = {
            'policy': {
                'id': uuidutils.generate_uuid(),
                'project_id': uuidutils.generate_uuid(),
                'name': 'test-policy',
                'description': 'Test policy description',
                'shared': True,
                'is_default': False
            }
        }

        self.rule_data = {
            'bandwidth_limit_rule': {
                'id': uuidutils.generate_uuid(),
                'max_kbps': 100,
                'max_burst_kbps': 150
            },
            'dscp_marking_rule': {
                'id': uuidutils.generate_uuid(),
                'dscp_mark': 16
            },
            'minimum_bandwidth_rule': {
                'id': uuidutils.generate_uuid(),
                'min_kbps': 10
            }
        }

        self.policy = policy_object.QosPolicy(self.ctxt,
                                              **self.policy_data['policy'])

        self.rule = rule_object.QosBandwidthLimitRule(
            self.ctxt, **self.rule_data['bandwidth_limit_rule'])

        self.dscp_rule = rule_object.QosDscpMarkingRule(
            self.ctxt, **self.rule_data['dscp_marking_rule'])

        self.min_rule = rule_object.QosMinimumBandwidthRule(
            self.ctxt, **self.rule_data['minimum_bandwidth_rule'])
コード例 #14
0
ファイル: test_rule.py プロジェクト: vinayakhegdev/neutron
    def test_min_bw_object_version(self):
        min_bw_rule = rule.QosMinimumBandwidthRule()

        prim = min_bw_rule.obj_to_primitive('1.2')

        self.assertTrue(prim)