예제 #1
0
 def test_duplicate_rules(self):
     policy_id = uuidutils.generate_uuid()
     dscp_rule_1 = rule.QosDscpMarkingRule(
         self.context, qos_policy_id=policy_id, dscp_mark=16)
     dscp_rule_2 = rule.QosDscpMarkingRule(
         self.context, qos_policy_id=policy_id, dscp_mark=32)
     bw_limit_rule = rule.QosBandwidthLimitRule(
         self.context, qos_policy_id=policy_id,
         max_kbps=1000, max_burst=500,
         direction=constants.EGRESS_DIRECTION)
     self.assertTrue(dscp_rule_1.duplicates(dscp_rule_2))
     self.assertFalse(dscp_rule_1.duplicates(bw_limit_rule))
예제 #2
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'
         })
예제 #3
0
    def setUp(self):
        super(TestQosNsxV3Notification, self).setUp()
        self.setup_coreplugin(PLUGIN_NAME)

        # Add a dummy notification driver that calls our handler directly
        # (to skip the message queue)
        cfg.CONF.set_override("notification_drivers", [
            'vmware_nsx.tests.unit.services.qos.fake_notifier.'
            'DummyNotificationDriver'
        ], "qos")
        self.qos_plugin = qos_plugin.QoSPlugin()
        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(),
                'tenant_id': uuidutils.generate_uuid(),
                'name': 'test-policy',
                'description': 'Test policy description',
                'shared': True
            }
        }
        self.rule_data = {
            'bandwidth_limit_rule': {
                'id': uuidutils.generate_uuid(),
                'max_kbps': 2000,
                'max_burst_kbps': 150
            }
        }
        self.dscp_rule_data = {
            'dscp_marking_rule': {
                'id': uuidutils.generate_uuid(),
                'dscp_mark': 22
            }
        }

        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.dscp_rule_data['dscp_marking_rule'])

        self.fake_profile_id = 'fake_profile'
        self.fake_profile = {'id': self.fake_profile_id}

        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.qos.policy.QosPolicy.obj_load_attr').start()
        mock.patch.object(nsx_db,
                          'get_switch_profile_by_qos_policy',
                          return_value=self.fake_profile_id).start()

        self.peak_bw_multiplier = cfg.CONF.NSX.qos_peak_bw_multiplier

        self.nsxlib = v3_utils.get_nsxlib_wrapper()
예제 #4
0
 def test_duplicate_rules(self):
     policy_id = uuidutils.generate_uuid()
     ingress_rule_1 = rule.QosPacketRateLimitRule(
         self.context,
         qos_policy_id=policy_id,
         max_kpps=2000,
         max_burst=800,
         direction=constants.INGRESS_DIRECTION)
     ingress_rule_2 = rule.QosPacketRateLimitRule(
         self.context,
         qos_policy_id=policy_id,
         max_kpps=3000,
         max_burst=200,
         direction=constants.INGRESS_DIRECTION)
     egress_rule = rule.QosPacketRateLimitRule(
         self.context,
         qos_policy_id=policy_id,
         max_kpps=1000,
         max_burst=500,
         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))
예제 #5
0
    def setUp(self):
        super(TestQosPlugin, self).setUp()
        self.setup_coreplugin()

        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.patch(
            'neutron.objects.qos.policy.QosPolicy.obj_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()

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

        mgr = manager.NeutronManager.get_instance()
        self.qos_plugin = mgr.get_service_plugins().get(constants.QOS)

        self.qos_plugin.notification_driver_manager = mock.Mock()

        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(),
                'tenant_id': uuidutils.generate_uuid(),
                'name': 'test-policy',
                'description': 'Test policy description',
                'shared': True
            }
        }

        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
            }
        }

        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'])
예제 #6
0
    def _initialize_objs(self):
        self.qos_policies = []
        self.ports = []
        self.networks = []
        self.fips = []
        self.router_fips, self.fips_network = self._create_one_router()
        self.fips_ports = []
        self.routers = []
        self.router_networks = []
        fip_cidr = netaddr.IPNetwork('10.10.0.0/24')

        for net_idx in range(2):
            qos_policy = policy_obj.QosPolicy(self.ctx,
                                              id=uuidutils.generate_uuid(),
                                              project_id=self.project_id)
            qos_policy.create()
            self.qos_policies.append(qos_policy)

            # Any QoS policy should have at least one rule, in order to have
            # the port dictionary extended with the QoS policy information; see
            # QoSPlugin._extend_port_resource_request
            qos_rule = rule_obj.QosDscpMarkingRule(
                self.ctx,
                dscp_mark=20,
                id=uuidutils.generate_uuid(),
                qos_policy_id=qos_policy.id)
            qos_rule.create()

            self.fips_ports.append(
                self._create_one_port(1000 + net_idx, self.fips_network.id))
            fip_ip = str(netaddr.IPAddress(fip_cidr.ip + net_idx + 1))
            fip = router_obj.FloatingIP(
                self.ctx,
                id=uuidutils.generate_uuid(),
                project_id=self.project_id,
                floating_ip_address=fip_ip,
                floating_network_id=self.fips_network.id,
                floating_port_id=self.fips_ports[-1].id)
            fip.create()
            self.fips.append(fip)

            network = network_obj.Network(self.ctx,
                                          id=uuidutils.generate_uuid(),
                                          project_id=self.project_id)
            network.create()
            self.networks.append(network)

            for port_idx in range(3):
                self.ports.append(
                    self._create_one_port(net_idx * 16 + port_idx, network.id))

            router, router_network = self._create_one_router()
            self.routers.append(router)
            self.router_networks.append(router_network)
예제 #7
0
    def setUp(self):
        # Reset the drive to re-create it
        qos_driver.DRIVER = None
        super(TestQosNsxV3Notification, self).setUp()
        self.setup_coreplugin(PLUGIN_NAME)

        self.qos_plugin = qos_plugin.QoSPlugin()
        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
            }
        }
        self.rule_data = {
            'bandwidth_limit_rule': {
                'id': uuidutils.generate_uuid(),
                'max_kbps': 2000,
                'max_burst_kbps': 150
            }
        }
        self.dscp_rule_data = {
            'dscp_marking_rule': {
                'id': uuidutils.generate_uuid(),
                'dscp_mark': 22
            }
        }

        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.dscp_rule_data['dscp_marking_rule'])

        self.fake_profile_id = 'fake_profile'
        self.fake_profile = {'id': self.fake_profile_id}

        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.object(nsx_db,
                          'get_switch_profile_by_qos_policy',
                          return_value=self.fake_profile_id).start()

        self.peak_bw_multiplier = cfg.CONF.NSX.qos_peak_bw_multiplier

        self.nsxlib = v3_utils.get_nsxlib_wrapper()
예제 #8
0
    def _create_test_policy_with_bw_and_dscp(self):
        policy_obj, rule_obj_band = self._create_test_policy_with_bwrule()

        rule_fields = self.get_random_fields(obj_cls=rule.QosDscpMarkingRule)
        rule_fields['qos_policy_id'] = policy_obj.id

        rule_obj_dscp = rule.QosDscpMarkingRule(self.context, **rule_fields)
        rule_obj_dscp.create()

        policy_obj.reload_rules()
        return policy_obj, rule_obj_band, rule_obj_dscp
예제 #9
0
 def create_policy_dscp_marking_rule(self, context, policy_id,
                                     dscp_marking_rule):
     with db_api.autonested_transaction(context.session):
         # first, validate that we have access to the policy
         policy = self._get_policy_obj(context, policy_id)
         rule = rule_object.QosDscpMarkingRule(
             context,
             qos_policy_id=policy_id,
             **dscp_marking_rule['dscp_marking_rule'])
         rule.create()
         policy.reload_rules()
     self.notification_driver_manager.update_policy(context, policy)
     return rule
예제 #10
0
 def update_policy_dscp_marking_rule(self, context, rule_id, policy_id,
                                     dscp_marking_rule):
     with db_api.autonested_transaction(context.session):
         # first, validate that we have access to the policy
         policy = self._get_policy_obj(context, policy_id)
         # check if the rule belong to the policy
         policy.get_rule_by_id(rule_id)
         rule = rule_object.QosDscpMarkingRule(context, id=rule_id)
         rule.obj_reset_changes()
         for k, v in dscp_marking_rule['dscp_marking_rule'].items():
             if k != 'id':
                 setattr(rule, k, v)
         rule.update()
         policy.reload_rules()
     self.notification_driver_manager.update_policy(context, policy)
     return rule
예제 #11
0
 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))
예제 #12
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'])
예제 #13
0
    def setUp(self):
        super(TestQosPlugin, self).setUp()
        self.setup_coreplugin()

        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.patch(
            'neutron.objects.qos.policy.QosPolicy.obj_load_attr').start()

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

        mgr = manager.NeutronManager.get_instance()
        self.qos_plugin = mgr.get_service_plugins().get(
            constants.QOS)

        self.qos_plugin.notification_driver_manager = mock.Mock()

        self.ctxt = context.Context('fake_user', 'fake_tenant')
        self.policy_data = {
            'policy': {'id': uuidutils.generate_uuid(),
                       'tenant_id': uuidutils.generate_uuid(),
                       'name': 'test-policy',
                       'description': 'Test policy description',
                       'shared': True}}

        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}}

        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'])
예제 #14
0
파일: test_qos.py 프로젝트: younkun/neutron
    def _initialize_objs(self):
        self.qos_policies = []
        self.ports = []
        self.networks = []
        for net_idx in range(2):
            qos_policy = policy_obj.QosPolicy(self.ctx,
                                              id=uuidutils.generate_uuid(),
                                              project_id=self.project_id)
            qos_policy.create()
            self.qos_policies.append(qos_policy)

            # Any QoS policy should have at least one rule, in order to have
            # the port dictionary extended with the QoS policy information; see
            # QoSPlugin._extend_port_resource_request
            qos_rule = rule_obj.QosDscpMarkingRule(
                self.ctx,
                dscp=20,
                id=uuidutils.generate_uuid(),
                qos_policy_id=qos_policy.id)
            qos_rule.create()

            network = network_obj.Network(self.ctx,
                                          id=uuidutils.generate_uuid(),
                                          project_id=self.project_id)
            network.create()
            self.networks.append(network)

            for port_idx in range(3):
                mac_address = netaddr.EUI(net_idx * 16 + port_idx)
                port = port_obj.Port(self.ctx,
                                     project_id=self.project_id,
                                     network_id=network.id,
                                     device_owner='',
                                     admin_state_up=True,
                                     status='DOWN',
                                     device_id='2',
                                     mac_address=mac_address)
                port.create()
                self.ports.append(port)
예제 #15
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()
예제 #16
0
 def test_object_version_degradation_less_than_1_3(self):
     rule_obj = rule.QosDscpMarkingRule()
     self.assertRaises(exception.IncompatibleObjectVersion,
                       rule_obj.obj_to_primitive, '1.2')
예제 #17
0
    def setUp(self, *args, **kwargs):
        net_type = kwargs.pop('tenant_network_types', None) or ['vlan']
        ml2_options = {
            'mechanism_drivers': ['apic_aim', 'openvswitch'],
            'extension_drivers': ['apic_aim', 'port_security', 'dns', 'qos'],
            'type_drivers': ['opflex', 'local', 'vlan'],
            'tenant_network_types': net_type
        }
        config.cfg.CONF.set_override('network_vlan_ranges',
                                     ['physnet1:100:200'],
                                     group='ml2_type_vlan')
        self._aim_mech_driver = None
        self._qos_driver = None
        super(TestAIMQosBase, self).setUp(*args,
                                          ml2_options=ml2_options,
                                          qos_plugin='qos',
                                          **kwargs)
        self._plugin = directory.get_plugin()
        self._plugin.remove_networks_from_down_agents = mock.Mock()
        self._plugin.is_agent_down = mock.Mock(return_value=False)
        self._ctx = context.get_admin_context()
        self.ctxt = context.Context('fake_user', 'fake_tenant')
        self.admin_ctxt = context.get_admin_context()

        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 = {
            'egress_bandwidth_limit_rule': {
                'id': uuidutils.generate_uuid(),
                'direction': 'egress',
                'max_kbps': 100,
                'max_burst_kbps': 150
            },
            'ingress_bandwidth_limit_rule': {
                'id': uuidutils.generate_uuid(),
                'direction': 'ingress',
                'max_kbps': 101,
                'max_burst_kbps': 1150
            },
            'dscp_marking_rule': {
                'id': uuidutils.generate_uuid(),
                'dscp_mark': 16
            },
        }

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

        self.egress_rule = rule_object.QosBandwidthLimitRule(
            self.ctxt, **self.rule_data['egress_bandwidth_limit_rule'])

        self.ingress_rule = rule_object.QosBandwidthLimitRule(
            self.ctxt, **self.rule_data['ingress_bandwidth_limit_rule'])

        self.dscp_rule = rule_object.QosDscpMarkingRule(
            self.ctxt, **self.rule_data['dscp_marking_rule'])
예제 #18
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'])
class OVSAgentQoSExtensionTestFramework(base.OVSAgentTestFramework):

    test_dscp_marking_rule_1 = rule.QosDscpMarkingRule(
        context=None,
        qos_policy_id=TEST_POLICY_ID1,
        id="9f126d84-551a-4dcf-bb01-0e9c0df0c793",
        dscp_mark=TEST_DSCP_MARK_1)
    test_dscp_marking_rule_2 = rule.QosDscpMarkingRule(
        context=None,
        qos_policy_id=TEST_POLICY_ID2,
        id="7f126d84-551a-4dcf-bb01-0e9c0df0c793",
        dscp_mark=TEST_DSCP_MARK_2)
    test_bw_limit_rule_1 = rule.QosBandwidthLimitRule(
        context=None,
        qos_policy_id=TEST_POLICY_ID1,
        id="5f126d84-551a-4dcf-bb01-0e9c0df0c793",
        max_kbps=1000,
        max_burst_kbps=10)
    test_bw_limit_rule_2 = rule.QosBandwidthLimitRule(
        context=None,
        qos_policy_id=TEST_POLICY_ID2,
        id="fa9128d9-44af-49b2-99bb-96548378ad42",
        max_kbps=900,
        max_burst_kbps=9)

    def setUp(self):
        super(OVSAgentQoSExtensionTestFramework, self).setUp()
        self.config.set_override('extensions', ['qos'], 'agent')
        self._set_pull_mock()
        self.set_test_qos_rules(
            TEST_POLICY_ID1,
            [self.test_bw_limit_rule_1, self.test_dscp_marking_rule_1])
        self.set_test_qos_rules(
            TEST_POLICY_ID2,
            [self.test_bw_limit_rule_2, self.test_dscp_marking_rule_2])

    def _set_pull_mock(self):

        self.qos_policies = {}

        def _pull_mock(context, resource_type, resource_id):
            return self.qos_policies[resource_id]

        self.pull = mock.patch('neutron.api.rpc.handlers.resources_rpc.'
                               'ResourcesPullRpcApi.pull').start()
        self.pull.side_effect = _pull_mock

    def set_test_qos_rules(self, policy_id, policy_rules):
        """This function sets the policy test rules to be exposed."""

        qos_policy = policy.QosPolicy(
            context=None,
            project_id=uuidutils.generate_uuid(),
            id=policy_id,
            name="Test Policy Name",
            description="This is a policy for testing purposes",
            shared=False,
            rules=policy_rules)

        qos_policy.obj_reset_changes()
        self.qos_policies[policy_id] = qos_policy

    def _create_test_port_dict(self, policy_id=None):
        port_dict = super(OVSAgentQoSExtensionTestFramework,
                          self)._create_test_port_dict()
        port_dict['qos_policy_id'] = policy_id
        port_dict['network_qos_policy_id'] = None
        return port_dict

    def _get_device_details(self, port, network):
        dev = super(OVSAgentQoSExtensionTestFramework,
                    self)._get_device_details(port, network)
        dev['qos_policy_id'] = port['qos_policy_id']
        return dev

    def _assert_bandwidth_limit_rule_is_set(self, port, rule):
        if rule.direction == constants.INGRESS_DIRECTION:
            max_rate, burst = (self.agent.int_br.get_ingress_bw_limit_for_port(
                port['vif_name']))
        else:
            max_rate, burst = (self.agent.int_br.get_egress_bw_limit_for_port(
                port['vif_name']))
        self.assertEqual(max_rate, rule.max_kbps)
        self.assertEqual(burst, rule.max_burst_kbps)

    def _assert_bandwidth_limit_rule_not_set(self, port, rule_direction):
        if rule_direction == constants.INGRESS_DIRECTION:
            max_rate, burst = (self.agent.int_br.get_ingress_bw_limit_for_port(
                port['vif_name']))
        else:
            max_rate, burst = (self.agent.int_br.get_egress_bw_limit_for_port(
                port['vif_name']))
        self.assertIsNone(max_rate)
        self.assertIsNone(burst)

    def wait_until_bandwidth_limit_rule_applied(self, port, rule):
        if rule and rule.direction == constants.INGRESS_DIRECTION:
            l2_extensions.wait_until_ingress_bandwidth_limit_rule_applied(
                self.agent.int_br, port['vif_name'], rule)
        else:
            l2_extensions.wait_until_egress_bandwidth_limit_rule_applied(
                self.agent.int_br, port['vif_name'], rule)

    def _assert_dscp_marking_rule_is_set(self, port, dscp_rule):
        port_num = self.agent.int_br._get_port_val(port['vif_name'], 'ofport')

        flows = self.agent.int_br.dump_flows_for(table='0',
                                                 in_port=str(port_num))
        tos_mark = l2_extensions.extract_mod_nw_tos_action(flows)
        self.assertEqual(dscp_rule.dscp_mark << 2, tos_mark)

    def _assert_dscp_marking_rule_not_set(self, port):
        port_num = self.agent.int_br._get_port_val(port['vif_name'], 'ofport')

        flows = self.agent.int_br.dump_flows_for(table='0',
                                                 in_port=str(port_num))

        tos_mark = l2_extensions.extract_mod_nw_tos_action(flows)
        self.assertIsNone(tos_mark)

    def wait_until_dscp_marking_rule_applied(self, port, dscp_mark):
        l2_extensions.wait_until_dscp_marking_rule_applied_ovs(
            self.agent.int_br, port['vif_name'], dscp_mark)

    def _create_port_with_qos(self):
        port_dict = self._create_test_port_dict()
        port_dict['qos_policy_id'] = TEST_POLICY_ID1
        self.setup_agent_and_ports([port_dict])
        self.wait_until_ports_state(self.ports, up=True)
        self.wait_until_bandwidth_limit_rule_applied(port_dict,
                                                     self.test_bw_limit_rule_1)
        return port_dict
예제 #20
0
 def _create_dscp_marking_rule_obj(self):
     rule_obj = rule.QosDscpMarkingRule()
     rule_obj.id = uuidutils.generate_uuid()
     rule_obj.dscp_mark = 32
     rule_obj.obj_reset_changes()
     return rule_obj
예제 #21
0
    def setUp(self, *mocks):
        # init the nsx-v plugin for testing with DVS
        self._init_dvs_config()
        # Reset the drive to re-create it
        qos_driver.DRIVER = None
        super(TestQosNsxVNotification, self).setUp(plugin=CORE_PLUGIN,
                                                   ext_mgr=None)
        self.setup_coreplugin(CORE_PLUGIN)

        plugin_instance = directory.get_plugin()
        self._core_plugin = plugin_instance
        self._core_plugin.init_is_complete = True

        self.qos_plugin = qos_plugin.QoSPlugin()
        mock.patch.object(qos_utils.NsxVQosRule,
                          '_get_qos_plugin',
                          return_value=self.qos_plugin).start()

        # Pre defined QoS data for the tests
        self.ctxt = context.Context('fake_user', 'fake_tenant')

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

        self.rule_data = {
            'bandwidth_limit_rule': {
                'id': uuidutils.generate_uuid(),
                'max_kbps': 100,
                'max_burst_kbps': 150,
                'type': qos_consts.RULE_TYPE_BANDWIDTH_LIMIT
            }
        }
        self.ingress_rule_data = {
            'bandwidth_limit_rule': {
                'id': uuidutils.generate_uuid(),
                'max_kbps': 200,
                'max_burst_kbps': 250,
                'direction': 'ingress',
                'type': qos_consts.RULE_TYPE_BANDWIDTH_LIMIT
            }
        }
        self.dscp_rule_data = {
            'dscp_marking_rule': {
                'id': uuidutils.generate_uuid(),
                'dscp_mark': 22,
                'type': qos_consts.RULE_TYPE_DSCP_MARKING
            }
        }

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

        # egress bw rule
        self.rule = rule_object.QosBandwidthLimitRule(
            self.ctxt, **self.rule_data['bandwidth_limit_rule'])
        # ingress bw rule
        self.ingress_rule = rule_object.QosBandwidthLimitRule(
            self.ctxt, **self.ingress_rule_data['bandwidth_limit_rule'])
        # dscp marking rule
        self.dscp_rule = rule_object.QosDscpMarkingRule(
            self.ctxt, **self.dscp_rule_data['dscp_marking_rule'])

        self._net_data = {
            'network': {
                'name': 'test-qos',
                'tenant_id': 'fake_tenant',
                'qos_policy_id': self.policy.id,
                'port_security_enabled': False,
                'admin_state_up': False,
                'shared': False
            }
        }
        self._rules = [self.rule_data['bandwidth_limit_rule']]
        self._dscp_rules = [self.dscp_rule_data['dscp_marking_rule']]

        mock.patch(
            'neutron.objects.qos.policy.QosPolicy.obj_load_attr').start()
예제 #22
0
    def test_dscp_object_version_degradation(self):
        dscp_rule = rule.QosDscpMarkingRule()

        self.assertRaises(exception.IncompatibleObjectVersion,
                     dscp_rule.obj_to_primitive, '1.0')
    def setUp(self, *mocks):
        # init the nsx-v plugin for testing with DVS
        self._init_dvs_config()
        super(TestQosNsxVNotification, self).setUp(plugin=CORE_PLUGIN,
                                                   ext_mgr=None)
        plugin_instance = manager.NeutronManager.get_plugin()
        self._core_plugin = plugin_instance

        # Setup the QoS plugin:
        # Add a dummy notification driver that calls our handler directly
        # (to skip the message queue)
        cfg.CONF.set_override("notification_drivers", [
            'vmware_nsx.tests.unit.services.qos.fake_nsxv_notifier.'
            'DummyNsxVNotificationDriver'
        ], "qos")
        self.qos_plugin = qos_plugin.QoSPlugin()
        mock.patch.object(qos_utils.NsxVQosRule,
                          '_get_qos_plugin',
                          return_value=self.qos_plugin).start()

        # Pre defined QoS data for the tests
        self.ctxt = context.Context('fake_user', 'fake_tenant')
        self.policy_data = {
            'policy': {
                'id': uuidutils.generate_uuid(),
                'tenant_id': uuidutils.generate_uuid(),
                'name': 'test-policy',
                'description': 'Test policy description',
                'shared': True
            }
        }

        self.rule_data = {
            'bandwidth_limit_rule': {
                'id': uuidutils.generate_uuid(),
                'max_kbps': 100,
                'max_burst_kbps': 150
            }
        }
        self.dscp_rule_data = {
            'dscp_marking_rule': {
                'id': uuidutils.generate_uuid(),
                'dscp_mark': 22
            }
        }

        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.dscp_rule_data['dscp_marking_rule'])

        self._net_data = {
            'network': {
                'name': 'test-qos',
                'tenant_id': 'fake_tenant',
                'qos_policy_id': self.policy.id,
                'port_security_enabled': False,
                'admin_state_up': False,
                'shared': False
            }
        }
        self._rules = [self.rule_data['bandwidth_limit_rule']]
        self._dscp_rules = [self.dscp_rule_data['dscp_marking_rule']]

        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.patch(
            'neutron.objects.qos.policy.QosPolicy.obj_load_attr').start()
from neutron.api.rpc.callbacks.consumer import registry as consumer_reg
from neutron.api.rpc.callbacks import events
from neutron.api.rpc.callbacks import resources
from neutron.objects.qos import policy
from neutron.objects.qos import rule
from neutron.tests.common.agents import l2_extensions
from neutron.tests.functional.agent.l2 import base

TEST_POLICY_ID1 = "a2d72369-4246-4f19-bd3c-af51ec8d70cd"
TEST_POLICY_ID2 = "46ebaec0-0570-43ac-82f6-60d2b03168c5"
TEST_DSCP_MARK_1 = 14
TEST_DSCP_MARK_2 = 30
TEST_DSCP_MARKING_RULE_1 = rule.QosDscpMarkingRule(
    context=None,
    qos_policy_id=TEST_POLICY_ID1,
    id="9f126d84-551a-4dcf-bb01-0e9c0df0c793",
    dscp_mark=TEST_DSCP_MARK_1)
TEST_DSCP_MARKING_RULE_2 = rule.QosDscpMarkingRule(
    context=None,
    qos_policy_id=TEST_POLICY_ID2,
    id="7f126d84-551a-4dcf-bb01-0e9c0df0c793",
    dscp_mark=TEST_DSCP_MARK_2)
TEST_BW_LIMIT_RULE_1 = rule.QosBandwidthLimitRule(
    context=None,
    qos_policy_id=TEST_POLICY_ID1,
    id="5f126d84-551a-4dcf-bb01-0e9c0df0c793",
    max_kbps=1000,
    max_burst_kbps=10)
TEST_BW_LIMIT_RULE_2 = rule.QosBandwidthLimitRule(
    context=None,
예제 #25
0
    def setUp(self):
        super(QosExtensionBaseTestCase, self).setUp()

        self.fip_qos_ext = fip_qos.FipQosAgentExtension()
        self.context = context.get_admin_context()
        self.connection = mock.Mock()

        self.policy = policy.QosPolicy(context=None, name='test1', id=_uuid())
        self.ingress_rule = (rule.QosBandwidthLimitRule(
            context=None,
            id=_uuid(),
            qos_policy_id=self.policy.id,
            max_kbps=1111,
            max_burst_kbps=2222,
            direction=lib_const.INGRESS_DIRECTION))
        self.egress_rule = (rule.QosBandwidthLimitRule(
            context=None,
            id=_uuid(),
            qos_policy_id=self.policy.id,
            max_kbps=3333,
            max_burst_kbps=4444,
            direction=lib_const.EGRESS_DIRECTION))
        self.policy.rules = [self.ingress_rule, self.egress_rule]

        self.new_ingress_rule = (rule.QosBandwidthLimitRule(
            context=None,
            id=_uuid(),
            qos_policy_id=self.policy.id,
            max_kbps=5555,
            max_burst_kbps=6666,
            direction=lib_const.INGRESS_DIRECTION))
        self.ingress_rule_only_has_max_kbps = (rule.QosBandwidthLimitRule(
            context=None,
            id=_uuid(),
            qos_policy_id=self.policy.id,
            max_kbps=5555,
            max_burst_kbps=0,
            direction=lib_const.INGRESS_DIRECTION))

        self.policy2 = policy.QosPolicy(context=None, name='test2', id=_uuid())
        self.policy2.rules = [self.ingress_rule]

        self.policy3 = policy.QosPolicy(context=None, name='test3', id=_uuid())
        self.policy3.rules = [self.egress_rule]

        self.policy4 = policy.QosPolicy(context=None, name='test4', id=_uuid())
        self.dscp = rule.QosDscpMarkingRule(context=None,
                                            id=_uuid(),
                                            qos_policy_id=self.policy4.id,
                                            dscp_mark=32)
        self.dscp.obj_reset_changes()
        self.policy4.rules = [self.dscp]

        self.qos_policies = {
            self.policy.id: self.policy,
            self.policy2.id: self.policy2,
            self.policy3.id: self.policy3,
            self.policy4.id: self.policy4
        }

        self.agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
        self.ex_gw_port = {'id': _uuid()}
        self.fip = {
            'id': _uuid(),
            'floating_ip_address': TEST_QOS_FIP,
            'fixed_ip_address': '192.168.0.1',
            'floating_network_id': _uuid(),
            'port_id': _uuid(),
            'host': HOSTNAME,
            'qos_policy_id': self.policy.id
        }
        self.router = {
            'id': _uuid(),
            'gw_port': self.ex_gw_port,
            'ha': False,
            'distributed': False,
            lib_const.FLOATINGIP_KEY: [self.fip]
        }
        self.router_info = l3router.RouterInfo(self.agent, _uuid(),
                                               self.router, **self.ri_kwargs)
        self.router_info.ex_gw_port = self.ex_gw_port
        self.agent.router_info[self.router['id']] = self.router_info

        def _mock_get_router_info(router_id):
            return self.router_info

        self.get_router_info = mock.patch(
            'neutron.agent.l3.l3_agent_extension_api.'
            'L3AgentExtensionAPI.get_router_info').start()
        self.get_router_info.side_effect = _mock_get_router_info

        self.agent_api = l3_ext_api.L3AgentExtensionAPI(None)
        self.fip_qos_ext.consume_api(self.agent_api)
예제 #26
0
    def test_dscp_object_version(self):
        dscp_rule = rule.QosDscpMarkingRule()

        prim = dscp_rule.obj_to_primitive('1.1')

        self.assertTrue(prim)