From d051062019f1058a75d6067d81a9f2d658484529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Kap=C5=82o=C5=84ski?= Date: Mon, 10 Apr 2017 14:09:51 +0000 Subject: [PATCH] Make QoS policy object compatible with versions 1.2 and higher For version 1.2 or higher of QoS policy object it can contain QoSMinumumBandwidtLimit rules and appending of such rule type was missing in make_obj_compatible function. Now such rules are appended to QoS policy. Change-Id: I40d699db58c34e83272432376d1d59679a680db2 Closes-Bug: #1681440 (cherry picked from commit 0376d2f6adada320554f247e4c67e15243d01d74) --- neutron/objects/qos/policy.py | 2 ++ neutron/tests/unit/objects/qos/test_policy.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/neutron/objects/qos/policy.py b/neutron/objects/qos/policy.py index 804b214e113..dfb84b85d74 100644 --- a/neutron/objects/qos/policy.py +++ b/neutron/objects/qos/policy.py @@ -228,6 +228,8 @@ class QosPolicy(rbac_db.NeutronRbacObject): 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']) diff --git a/neutron/tests/unit/objects/qos/test_policy.py b/neutron/tests/unit/objects/qos/test_policy.py index b463524fdbf..1b8871f1e0c 100644 --- a/neutron/tests/unit/objects/qos/test_policy.py +++ b/neutron/tests/unit/objects/qos/test_policy.py @@ -397,12 +397,14 @@ class QosPolicyDbObjectTestCase(test_base.BaseDbObjectTestCase, # 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], reload_rules=True) + qos_consts.RULE_TYPE_DSCP_MARKING, + qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH], reload_rules=True) 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 @@ -418,6 +420,19 @@ class QosPolicyDbObjectTestCase(test_base.BaseDbObjectTestCase, 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) + + policy_obj_v1_2 = self._policy_through_version(policy_obj, '1.2') + + for rule_obj in rule_objs: + self.assertIn(rule_obj, policy_obj_v1_2.rules) + def test_v1_4_to_v1_3_drops_project_id(self): policy_new = self._create_test_policy()