Merge "Remove QoS related objects unneeded compatibility conversions"

changes/07/683207/5
Zuul 3 years ago committed by Gerrit Code Review
commit 88683b76ae
  1. 50
      neutron/objects/qos/policy.py
  2. 29
      neutron/objects/qos/rule.py
  3. 5
      neutron/objects/qos/rule_type.py
  4. 108
      neutron/tests/unit/objects/qos/test_policy.py
  5. 41
      neutron/tests/unit/objects/qos/test_rule.py
  6. 29
      neutron/tests/unit/objects/qos/test_rule_type.py

@ -15,7 +15,6 @@
import itertools
from neutron_lib import constants as n_const
from neutron_lib.exceptions import qos as qos_exc
from oslo_db import exception as db_exc
from oslo_utils import versionutils
@ -393,53 +392,10 @@ class QosPolicy(rbac_db.NeutronRbacObject):
return set(bound_tenants)
def obj_make_compatible(self, primitive, target_version):
def filter_rules(obj_names, rules):
return [rule for rule in rules if
rule['versioned_object.name'] in obj_names]
def filter_ingress_bandwidth_limit_rules(rules):
bwlimit_obj_name = rule_obj_impl.QosBandwidthLimitRule.obj_name()
filtered_rules = []
for rule in rules:
if rule['versioned_object.name'] == bwlimit_obj_name:
direction = rule['versioned_object.data'].get("direction")
if direction == n_const.EGRESS_DIRECTION:
rule['versioned_object.data'].pop('direction')
filtered_rules.append(rule)
else:
filtered_rules.append(rule)
return filtered_rules
_target_version = versionutils.convert_version_to_tuple(target_version)
names = []
if _target_version >= (1, 0):
names.append(rule_obj_impl.QosBandwidthLimitRule.obj_name())
if _target_version >= (1, 1):
names.append(rule_obj_impl.QosDscpMarkingRule.obj_name())
if _target_version >= (1, 2):
names.append(rule_obj_impl.QosMinimumBandwidthRule.obj_name())
if 'rules' in primitive and names:
primitive['rules'] = filter_rules(names, primitive['rules'])
if _target_version < (1, 3):
standard_fields = ['revision_number', 'created_at', 'updated_at']
for f in standard_fields:
primitive.pop(f)
if primitive['description'] is None:
# description was not nullable before
raise exception.IncompatibleObjectVersion(
objver=target_version, objname='QosPolicy')
if _target_version < (1, 4):
primitive['tenant_id'] = primitive.pop('project_id')
if _target_version < (1, 5):
if 'rules' in primitive:
primitive['rules'] = filter_ingress_bandwidth_limit_rules(
primitive['rules'])
if _target_version < (1, 6):
primitive.pop('is_default', None)
if _target_version < (1, 8):
raise exception.IncompatibleObjectVersion(
objver=target_version, objname=self.__class__.__name__)
@base_db.NeutronObjectRegistry.register

@ -117,6 +117,12 @@ class QosRule(base.NeutronDbObject):
((is_router_gw or not is_network_device_port) and
is_network_policy_only))
def obj_make_compatible(self, primitive, target_version):
_target_version = versionutils.convert_version_to_tuple(target_version)
if _target_version < (1, 3):
raise exception.IncompatibleObjectVersion(
objver=target_version, objtype=self.__class__.__name__)
@base.NeutronObjectRegistry.register
class QosBandwidthLimitRule(QosRule):
@ -134,15 +140,6 @@ class QosBandwidthLimitRule(QosRule):
rule_type = qos_consts.RULE_TYPE_BANDWIDTH_LIMIT
def obj_make_compatible(self, primitive, target_version):
_target_version = versionutils.convert_version_to_tuple(target_version)
if _target_version < (1, 3) and 'direction' in primitive:
direction = primitive.pop('direction')
if direction == constants.INGRESS_DIRECTION:
raise exception.IncompatibleObjectVersion(
objver=target_version,
objtype="QosBandwidthLimitRule")
@base.NeutronObjectRegistry.register
class QosDscpMarkingRule(QosRule):
@ -155,13 +152,6 @@ class QosDscpMarkingRule(QosRule):
rule_type = qos_consts.RULE_TYPE_DSCP_MARKING
def obj_make_compatible(self, primitive, target_version):
_target_version = versionutils.convert_version_to_tuple(target_version)
if _target_version < (1, 1):
raise exception.IncompatibleObjectVersion(
objver=target_version,
objname="QosDscpMarkingRule")
@base.NeutronObjectRegistry.register
class QosMinimumBandwidthRule(QosRule):
@ -176,10 +166,3 @@ class QosMinimumBandwidthRule(QosRule):
duplicates_compare_fields = ['direction']
rule_type = qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH
def obj_make_compatible(self, primitive, target_version):
_target_version = versionutils.convert_version_to_tuple(target_version)
if _target_version < (1, 2):
raise exception.IncompatibleObjectVersion(
objver=target_version,
objname="QosMinimumBandwidthRule")

@ -14,6 +14,7 @@ from neutron_lib.plugins import constants
from neutron_lib.plugins import directory
from neutron_lib.services.qos import constants as qos_consts
from oslo_utils import versionutils
from oslo_versionedobjects import exception
from oslo_versionedobjects import fields as obj_fields
from neutron.objects import base
@ -75,9 +76,9 @@ class QosRuleType(base.NeutronObject):
def obj_make_compatible(self, primitive, target_version):
_target_version = versionutils.convert_version_to_tuple(target_version)
if _target_version < (1, 3):
primitive.pop('drivers', None)
raise exception.IncompatibleObjectVersion(
objver=target_version, objtype=self.__class__.__name__)
@base.NeutronObjectRegistry.register

@ -13,12 +13,10 @@
import random
import mock
from neutron_lib import constants as n_const
from neutron_lib.exceptions import qos as qos_exc
from neutron_lib.services.qos import constants as qos_consts
from oslo_utils import uuidutils
from oslo_versionedobjects import exception
import testtools
from neutron.objects.db import api as db_api
from neutron.objects import network as net_obj
@ -453,110 +451,10 @@ class QosPolicyDbObjectTestCase(test_base.BaseDbObjectTestCase,
obj.detach_port(self._port['id'])
obj.delete()
@staticmethod
def _policy_through_version(obj, version):
primitive = obj.obj_to_primitive(target_version=version)
return policy.QosPolicy.clean_obj_from_primitive(primitive)
def test_object_version(self):
policy_obj, rule_objs = self._create_test_policy_with_rules(
RULE_OBJ_CLS.keys(), reload_rules=True)
policy_obj_v1_5 = self._policy_through_version(
policy_obj, policy.QosPolicy.VERSION)
for rule_obj in rule_objs:
self.assertIn(rule_obj, policy_obj_v1_5.rules)
def test_object_version_degradation_1_3_to_1_2_null_description(self):
def test_object_version_degradation_less_than_1_8(self):
policy_obj = self._create_test_policy()
policy_obj.description = None
with testtools.ExpectedException(exception.IncompatibleObjectVersion):
policy_obj.obj_to_primitive('1.2')
def test_object_version_degradation_to_1_0(self):
# NOTE(mangelajo): we should not check .VERSION, since that's the
# local version on the class definition
policy_obj, rule_objs = self._create_test_policy_with_rules(
[qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
qos_consts.RULE_TYPE_DSCP_MARKING,
qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH],
reload_rules=True, bwlimit_direction=n_const.EGRESS_DIRECTION)
policy_obj_v1_0 = self._policy_through_version(policy_obj, '1.0')
self.assertIn(rule_objs[0], policy_obj_v1_0.rules)
self.assertNotIn(rule_objs[1], policy_obj_v1_0.rules)
self.assertNotIn(rule_objs[2], policy_obj_v1_0.rules)
def test_object_version_degradation_1_2_to_1_1(self):
# NOTE(mangelajo): we should not check .VERSION, since that's the
# local version on the class definition
policy_obj, rule_objs = self._create_test_policy_with_rules(
[qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
qos_consts.RULE_TYPE_DSCP_MARKING,
qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH],
reload_rules=True, bwlimit_direction=n_const.EGRESS_DIRECTION)
policy_obj_v1_1 = self._policy_through_version(policy_obj, '1.1')
self.assertIn(rule_objs[0], policy_obj_v1_1.rules)
self.assertIn(rule_objs[1], policy_obj_v1_1.rules)
self.assertNotIn(rule_objs[2], policy_obj_v1_1.rules)
def test_object_version_degradation_1_3_to_1_2(self):
# NOTE(mangelajo): we should not check .VERSION, since that's the
# local version on the class definition
policy_obj, rule_objs = self._create_test_policy_with_rules(
[qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
qos_consts.RULE_TYPE_DSCP_MARKING,
qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH],
reload_rules=True, bwlimit_direction=n_const.EGRESS_DIRECTION)
policy_obj_v1_2 = self._policy_through_version(policy_obj, '1.2')
self.assertIn(rule_objs[0], policy_obj_v1_2.rules)
self.assertIn(rule_objs[1], policy_obj_v1_2.rules)
self.assertIn(rule_objs[2], policy_obj_v1_2.rules)
def test_v1_4_to_v1_3_drops_project_id(self):
policy_new = self._create_test_policy()
policy_v1_3 = policy_new.obj_to_primitive(target_version='1.3')
self.assertNotIn('project_id', policy_v1_3['versioned_object.data'])
self.assertIn('tenant_id', policy_v1_3['versioned_object.data'])
def test_object_version_degradation_1_5_to_1_4_ingress_direction(self):
policy_obj, rule_objs = self._create_test_policy_with_rules(
[qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
qos_consts.RULE_TYPE_DSCP_MARKING,
qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH],
reload_rules=True, bwlimit_direction=n_const.INGRESS_DIRECTION)
policy_obj_v1_4 = self._policy_through_version(policy_obj, '1.4')
self.assertNotIn(rule_objs[0], policy_obj_v1_4.rules)
self.assertIn(rule_objs[1], policy_obj_v1_4.rules)
self.assertIn(rule_objs[2], policy_obj_v1_4.rules)
def test_object_version_degradation_1_5_to_1_4_egress_direction(self):
policy_obj, rule_objs = self._create_test_policy_with_rules(
[qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
qos_consts.RULE_TYPE_DSCP_MARKING,
qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH],
reload_rules=True, bwlimit_direction=n_const.EGRESS_DIRECTION)
policy_obj_v1_4 = self._policy_through_version(policy_obj, '1.4')
self.assertIn(rule_objs[0], policy_obj_v1_4.rules)
self.assertIn(rule_objs[1], policy_obj_v1_4.rules)
self.assertIn(rule_objs[2], policy_obj_v1_4.rules)
def test_v1_6_to_v1_5_drops_is_default(self):
policy_new = self._create_test_policy()
policy_v1_5 = policy_new.obj_to_primitive(target_version='1.5')
self.assertNotIn('is_default', policy_v1_5['versioned_object.data'])
self.assertRaises(exception.IncompatibleObjectVersion,
policy_obj.obj_to_primitive, '1.7')
@mock.patch.object(policy.QosPolicy, 'unset_default')
def test_filter_by_shared(self, *mocks):

@ -118,25 +118,6 @@ class QosBandwidthLimitRuleObjectTestCase(test_base.BaseObjectIfaceTestCase):
dict_ = obj.to_dict()
self.assertEqual(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT, dict_['type'])
def test_bandwidth_limit_object_version_degradation(self):
self.db_objs[0]['direction'] = constants.EGRESS_DIRECTION
rule_obj = rule.QosBandwidthLimitRule(self.context, **self.db_objs[0])
primitive_rule = rule_obj.obj_to_primitive('1.2')
self.assertNotIn(
"direction", primitive_rule['versioned_object.data'].keys())
self.assertEqual(
self.db_objs[0]['max_kbps'],
primitive_rule['versioned_object.data']['max_kbps'])
self.assertEqual(
self.db_objs[0]['max_burst_kbps'],
primitive_rule['versioned_object.data']['max_burst_kbps'])
self.db_objs[0]['direction'] = constants.INGRESS_DIRECTION
rule_obj = rule.QosBandwidthLimitRule(self.context, **self.db_objs[0])
self.assertRaises(
exception.IncompatibleObjectVersion,
rule_obj.obj_to_primitive, '1.2')
def test_duplicate_rules(self):
policy_id = uuidutils.generate_uuid()
ingress_rule_1 = rule.QosBandwidthLimitRule(
@ -157,6 +138,11 @@ class QosBandwidthLimitRuleObjectTestCase(test_base.BaseObjectIfaceTestCase):
self.assertFalse(ingress_rule_1.duplicates(egress_rule))
self.assertFalse(ingress_rule_1.duplicates(dscp_rule))
def test_object_version_degradation_less_than_1_3(self):
rule_obj = rule.QosBandwidthLimitRule()
self.assertRaises(exception.IncompatibleObjectVersion,
rule_obj.obj_to_primitive, '1.2')
class QosBandwidthLimitRuleDbObjectTestCase(test_base.BaseDbObjectTestCase,
testlib_api.SqlTestCase):
@ -179,11 +165,10 @@ class QosDscpMarkingRuleObjectTestCase(test_base.BaseObjectIfaceTestCase):
_test_class = rule.QosDscpMarkingRule
def test_dscp_object_version_degradation(self):
dscp_rule = rule.QosDscpMarkingRule()
def test_object_version_degradation_less_than_1_3(self):
rule_obj = rule.QosDscpMarkingRule()
self.assertRaises(exception.IncompatibleObjectVersion,
dscp_rule.obj_to_primitive, '1.0')
rule_obj.obj_to_primitive, '1.2')
def test_duplicate_rules(self):
policy_id = uuidutils.generate_uuid()
@ -219,12 +204,10 @@ class QosMinimumBandwidthRuleObjectTestCase(test_base.BaseObjectIfaceTestCase):
_test_class = rule.QosMinimumBandwidthRule
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)
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')
def test_duplicate_rules(self):
policy_id = uuidutils.generate_uuid()

@ -18,6 +18,7 @@ from neutron_lib import constants as lib_consts
from neutron_lib.db import constants as db_consts
from neutron_lib.services.qos import constants as qos_consts
from oslo_config import cfg
from oslo_versionedobjects import exception
from neutron import manager
from neutron.objects.qos import rule_type
@ -87,29 +88,7 @@ class QosRuleTypeObjectTestCase(test_base.BaseTestCase):
def test_wrong_type(self):
self.assertRaises(ValueError, rule_type.QosRuleType, type='bad_type')
@staticmethod
def _policy_through_version(obj, version):
primitive = obj.obj_to_primitive(target_version=version)
return rule_type.QosRuleType.clean_obj_from_primitive(primitive)
def test_object_version(self):
def test_object_version_degradation_less_than_1_3(self):
qos_rule_type = rule_type.QosRuleType()
rule_type_v1_1 = self._policy_through_version(qos_rule_type, '1.1')
self.assertIn(qos_consts.RULE_TYPE_BANDWIDTH_LIMIT,
tuple(rule_type_v1_1.fields['type'].AUTO_TYPE.
_valid_values))
self.assertIn(qos_consts.RULE_TYPE_DSCP_MARKING,
tuple(rule_type_v1_1.fields['type'].AUTO_TYPE.
_valid_values))
def test_object_version_degradation_1_3_to_1_2(self):
drivers_obj = rule_type.QosRuleTypeDriver(
name="backend_driver", supported_parameters=[{}]
)
qos_rule_type = rule_type.QosRuleType(
type=qos_consts.RULE_TYPE_BANDWIDTH_LIMIT, drivers=[drivers_obj])
rule_type_v1_2 = self._policy_through_version(qos_rule_type, '1.2')
self.assertNotIn("drivers", rule_type_v1_2)
self.assertIn("type", rule_type_v1_2)
self.assertRaises(exception.IncompatibleObjectVersion,
qos_rule_type.obj_to_primitive, '1.2')

Loading…
Cancel
Save