Use QoS constants definitions

Some of the QoS API extensions definitions were using literal string
constants when defining attributes, instead of commonly predefined
constants. This patch fixes that situation.

In addition, modules related to the metering extension are also
updated to re-use the DIRECTION constant.

Change-Id: Ib1c272f6ce11864bd461bb8c29ee8cad0e91945d
This commit is contained in:
Miguel Lavalle 2018-10-15 11:27:48 -05:00
parent 8225a6b6a3
commit 3e44497d15
9 changed files with 30 additions and 23 deletions

View File

@ -15,6 +15,7 @@
from neutron_lib.api import converters
from neutron_lib import constants
from neutron_lib.db import constants as db_const
from neutron_lib.services.qos import constants as qos_consts
METERING_LABELS = 'metering_labels'
@ -76,11 +77,11 @@ RESOURCE_ATTRIBUTE_MAP = {
'is_filter': True, 'is_sort_key': True,
'is_visible': True, 'required_by_policy': True
},
'direction': {
qos_consts.DIRECTION: {
'allow_post': True, 'allow_put': False,
'is_visible': True, 'is_filter': True,
'is_sort_key': True,
'validate': {'type:values': ['ingress', 'egress']}
'validate': {'type:values': constants.VALID_DIRECTIONS}
},
'excluded': {
'allow_post': True, 'allow_put': False,

View File

@ -116,7 +116,7 @@ SUB_RESOURCE_ATTRIBUTE_MAP = {
'parent': _PARENT,
'parameters': dict(
_QOS_RULE_COMMON_FIELDS,
**{'max_kbps': {
**{qos_const.MAX_KBPS: {
'allow_post': True, 'allow_put': True,
'convert_to': converters.convert_to_int,
'is_visible': True,
@ -125,7 +125,7 @@ SUB_RESOURCE_ATTRIBUTE_MAP = {
'validate': {
'type:range': [0, db_const.DB_INTEGER_MAX_VALUE]}
},
'max_burst_kbps': {
qos_const.MAX_BURST: {
'allow_post': True, 'allow_put': True,
'is_visible': True, 'default': 0,
'is_filter': True,
@ -138,7 +138,7 @@ SUB_RESOURCE_ATTRIBUTE_MAP = {
'parent': _PARENT,
'parameters': dict(
_QOS_RULE_COMMON_FIELDS,
**{'dscp_mark': {
**{qos_const.DSCP_MARK: {
'allow_post': True, 'allow_put': True,
'convert_to': converters.convert_to_int,
'is_visible': True,
@ -151,7 +151,7 @@ SUB_RESOURCE_ATTRIBUTE_MAP = {
'parent': _PARENT,
'parameters': dict(
_QOS_RULE_COMMON_FIELDS,
**{'min_kbps': {
**{qos_const.MIN_KBPS: {
'allow_post': True, 'allow_put': True,
'is_visible': True,
'is_filter': True,
@ -159,7 +159,7 @@ SUB_RESOURCE_ATTRIBUTE_MAP = {
'convert_to': converters.convert_to_int,
'validate': {
'type:range': [0, db_const.DB_INTEGER_MAX_VALUE]}},
'direction': {
qos_const.DIRECTION: {
'allow_post': True, 'allow_put': True,
'is_visible': True, 'default': constants.EGRESS_DIRECTION,
'is_filter': True,

View File

@ -15,10 +15,9 @@
from neutron_lib.api.definitions import qos as qos_apidef
from neutron_lib import constants
from neutron_lib.services.qos import constants as qos_const
DIRECTION = 'direction'
ALIAS = 'qos-bw-limit-direction'
LABEL = ''
IS_SHIM_EXTENSION = False
@ -34,7 +33,7 @@ SUB_RESOURCE_ATTRIBUTE_MAP = {
# sub-resource extension itself
qos_apidef.BANDWIDTH_LIMIT_RULES: {
'parameters': {
DIRECTION: {
qos_const.DIRECTION: {
'allow_post': True,
'allow_put': True,
'is_visible': True,

View File

@ -55,7 +55,7 @@ RESOURCE_ATTRIBUTE_MAP = {
'type:range': [0, db_const.DB_INTEGER_MAX_VALUE]
}
},
qos_bw_limit_direction.DIRECTION: {
q_const.DIRECTION: {
'allow_post': False,
'allow_put': True,
'is_visible': True,
@ -100,7 +100,7 @@ RESOURCE_ATTRIBUTE_MAP = {
'type:range': [0, db_const.DB_INTEGER_MAX_VALUE]
}
},
qos_bw_limit_direction.DIRECTION: {
q_const.DIRECTION: {
'allow_post': False, 'allow_put': True,
'is_visible': True, 'default': constants.EGRESS_DIRECTION,
'is_filter': True,

View File

@ -11,6 +11,7 @@
# under the License.
from neutron_lib.api.definitions import metering
from neutron_lib.services.qos import constants as qos_consts
from neutron_lib.tests.unit.api.definitions import base
@ -21,4 +22,4 @@ class MeteringDefinitionTestCase(base.DefinitionBaseTestCase):
extension_attributes = ('remote_ip_prefix',
'excluded',
'metering_label_id',
'direction')
qos_consts.DIRECTION)

View File

@ -11,6 +11,7 @@
# under the License.
from neutron_lib.api.definitions import qos
from neutron_lib.services.qos import constants as q_const
from neutron_lib.tests.unit.api.definitions import base
@ -20,6 +21,6 @@ class QoSDefinitionTestCase(base.DefinitionBaseTestCase):
extension_subresources = (qos.BANDWIDTH_LIMIT_RULES,
qos.DSCP_MARKING_RULES,
qos.MIN_BANDWIDTH_RULES)
extension_attributes = ('direction', 'max_burst_kbps', 'type',
'dscp_mark', 'min_kbps', 'rules', 'max_kbps',
'qos_policy_id')
extension_attributes = (q_const.DIRECTION, q_const.MAX_BURST, 'type',
q_const.DSCP_MARK, q_const.MIN_KBPS, 'rules',
q_const.MAX_KBPS, q_const.QOS_POLICY_ID)

View File

@ -15,10 +15,11 @@
from neutron_lib.api.definitions import qos
from neutron_lib.api.definitions import qos_bw_limit_direction
from neutron_lib.services.qos import constants as qos_const
from neutron_lib.tests.unit.api.definitions import base
class QoSBwLimitDirectionDefinitionTestCase(base.DefinitionBaseTestCase):
extension_module = qos_bw_limit_direction
extension_subresources = (qos.BANDWIDTH_LIMIT_RULES,)
extension_attributes = (qos_bw_limit_direction.DIRECTION,)
extension_attributes = (qos_const.DIRECTION,)

View File

@ -11,7 +11,6 @@
# under the License.
from neutron_lib.api.definitions import qos
from neutron_lib.api.definitions import qos_bw_limit_direction
from neutron_lib.api.definitions import qos_rules_alias
from neutron_lib.services.qos import constants as q_const
from neutron_lib.tests.unit.api.definitions import base
@ -22,7 +21,7 @@ class QoSRulesAliasDefinitionTestCase(base.DefinitionBaseTestCase):
extension_resources = (qos.BANDWIDTH_LIMIT_RULES,
qos.DSCP_MARKING_RULES,
qos.MIN_BANDWIDTH_RULES)
extension_attributes = (qos_bw_limit_direction.DIRECTION,
extension_attributes = (q_const.DIRECTION,
q_const.MAX_BURST,
q_const.DSCP_MARK,
q_const.MIN_KBPS,

View File

@ -15,6 +15,7 @@
import mock
from neutron_lib.api.definitions import portbindings
from neutron_lib import constants
from neutron_lib.services.qos import base as qos_base
from neutron_lib.services.qos import constants as qos_consts
from neutron_lib.tests import _base
@ -22,8 +23,8 @@ from neutron_lib.tests import _base
SUPPORTED_RULES = {
qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH: {
"min_kbps": {'type:values': None},
'direction': {'type:values': ['egress']}
qos_consts.MIN_KBPS: {'type:values': None},
qos_consts.DIRECTION: {'type:values': ['egress']}
}
}
@ -73,9 +74,13 @@ class TestDriverBase(_base.BaseTestCase):
_make_driver().is_rule_supported(
_make_rule(
rule_type=qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
params={'min_kbps': None, 'direction': 'egress'})))
params={qos_consts.MIN_KBPS: None,
qos_consts.DIRECTION:
constants.EGRESS_DIRECTION})))
self.assertFalse(
_make_driver().is_rule_supported(
_make_rule(
rule_type=qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
params={'min_kbps': None, 'direction': 'ingress'})))
params={qos_consts.MIN_KBPS: None,
qos_consts.DIRECTION:
constants.INGRESS_DIRECTION})))