Fix the QoSPluginBase methods signature.

rule_obj has been substituted for rule_cls which is more precise,
and the abstract method signature has been fixed to be correct.

Change-Id: I1dd25a346d13da80af4a1ca81f67563a8f9de94d
Closes-bug: #1608921
This commit is contained in:
Miguel Angel Ajo 2016-08-02 14:19:53 +02:00 committed by Nate Johnston
parent 96a371bf50
commit 795f5f1c87
2 changed files with 38 additions and 38 deletions

View File

@ -228,18 +228,18 @@ class QoSPluginBase(service_base.ServicePluginBase):
# "delete_policy_rule". # "delete_policy_rule".
proxy_method = attrib.replace(rule_type + '_', '') proxy_method = attrib.replace(rule_type + '_', '')
rule_obj = self.rule_objects[rule_type] rule_cls = self.rule_objects[rule_type]
return self._call_proxy_method(proxy_method, rule_obj) return self._call_proxy_method(proxy_method, rule_cls)
# If we got here, then either attrib matched no pattern or the # If we got here, then either attrib matched no pattern or the
# rule_type embedded in attrib wasn't in self.rule_objects. # rule_type embedded in attrib wasn't in self.rule_objects.
raise AttributeError(attrib) raise AttributeError(attrib)
def _call_proxy_method(self, method_name, rule_obj): def _call_proxy_method(self, method_name, rule_cls):
"""Call proxy method. We need to add the rule_obj, obtained from the """Call proxy method. We need to add the rule_cls, obtained from the
self.rule_objects dictionary, to the incoming args. The context is self.rule_objects dictionary, to the incoming args. The context is
passed to proxy method as first argument; the remaining args will passed to proxy method as first argument; the remaining args will
follow rule_obj. follow rule_cls.
Some of the incoming method calls have the policy rule name as one of Some of the incoming method calls have the policy rule name as one of
the keys in the kwargs. For instance, the incoming kwargs for the the keys in the kwargs. For instance, the incoming kwargs for the
@ -260,24 +260,24 @@ class QoSPluginBase(service_base.ServicePluginBase):
:param method_name: the name of the method to call :param method_name: the name of the method to call
:type method_name: str :type method_name: str
:param rule_obj: the rule object, which is sent as an argument to the :param rule_cls: the rule class, which is sent as an argument to the
proxy method proxy method
:type rule_obj: a class from the rule_object (qos.objects.rule) module :type rule_cls: a class from the rule_object (qos.objects.rule) module
""" """
def _make_call(method_name, rule_obj, *args, **kwargs): def _make_call(method_name, rule_cls, *args, **kwargs):
context = args[0] context = args[0]
args_list = list(args[1:]) args_list = list(args[1:])
params = kwargs params = kwargs
rule_data_name = rule_obj.rule_type + "_rule" rule_data_name = rule_cls.rule_type + "_rule"
if rule_data_name in params: if rule_data_name in params:
params['rule_data'] = params.pop(rule_data_name) params['rule_data'] = params.pop(rule_data_name)
return getattr(self, method_name)( return getattr(self, method_name)(
context, rule_obj, *args_list, **params context, rule_cls, *args_list, **params
) )
return lambda *args, **kwargs: _make_call( return lambda *args, **kwargs: _make_call(
method_name, rule_obj, *args, **kwargs) method_name, rule_cls, *args, **kwargs)
def get_plugin_description(self): def get_plugin_description(self):
return "QoS Service Plugin for ports and networks" return "QoS Service Plugin for ports and networks"
@ -313,25 +313,25 @@ class QoSPluginBase(service_base.ServicePluginBase):
pass pass
@abc.abstractmethod @abc.abstractmethod
def create_policy_rule(self, context, policy_id, rule_data, rule_obj): def create_policy_rule(self, context, rule_cls, policy_id, rule_data):
pass pass
@abc.abstractmethod @abc.abstractmethod
def update_policy_rule(self, context, rule_id, policy_id, rule_data, def update_policy_rule(self, context, rule_cls, rule_id, policy_id,
rule_obj): rule_data):
pass pass
@abc.abstractmethod @abc.abstractmethod
def delete_policy_rule(self, context, rule_id, policy_id): def delete_policy_rule(self, context, rule_cls, rule_id, policy_id):
pass pass
@abc.abstractmethod @abc.abstractmethod
def get_policy_rule(self, context, rule_id, policy_id, rule_obj, def get_policy_rule(self, context, rule_cls, rule_id, policy_id,
fields=None): fields=None):
pass pass
@abc.abstractmethod @abc.abstractmethod
def get_policy_rules(self, context, policy_id, rule_obj, def get_policy_rules(self, context, rule_cls, policy_id,
filters=None, fields=None, sorts=None, limit=None, filters=None, fields=None, sorts=None, limit=None,
marker=None, page_reverse=False): marker=None, page_reverse=False):
pass pass

View File

@ -149,13 +149,13 @@ class QoSPlugin(qos.QoSPluginBase):
return rule_type_object.QosRuleType.get_objects(**filters) return rule_type_object.QosRuleType.get_objects(**filters)
@db_base_plugin_common.convert_result_to_dict @db_base_plugin_common.convert_result_to_dict
def create_policy_rule(self, context, rule_obj, policy_id, rule_data): def create_policy_rule(self, context, rule_cls, policy_id, rule_data):
"""Create a QoS policy rule. """Create a QoS policy rule.
:param context: neutron api request context :param context: neutron api request context
:type context: neutron.context.Context :type context: neutron.context.Context
:param rule_obj: the rule object :param rule_cls: the rule object class
:type rule_obj: a class from the rule_object (qos.objects.rule) module :type rule_cls: a class from the rule_object (qos.objects.rule) module
:param policy_id: the id of the QosPolicy for which to create the rule :param policy_id: the id of the QosPolicy for which to create the rule
:type policy_id: str uuid :type policy_id: str uuid
:param rule_data: the rule data to be applied :param rule_data: the rule data to be applied
@ -163,27 +163,27 @@ class QoSPlugin(qos.QoSPluginBase):
:returns: a QoS policy rule object :returns: a QoS policy rule object
""" """
rule_type = rule_obj.rule_type rule_type = rule_cls.rule_type
rule_data = rule_data[rule_type + '_rule'] rule_data = rule_data[rule_type + '_rule']
with db_api.autonested_transaction(context.session): with db_api.autonested_transaction(context.session):
# Ensure that we have access to the policy. # Ensure that we have access to the policy.
policy = self._get_policy_obj(context, policy_id) policy = self._get_policy_obj(context, policy_id)
rule = rule_obj(context, qos_policy_id=policy_id, **rule_data) rule = rule_cls(context, qos_policy_id=policy_id, **rule_data)
rule.create() rule.create()
policy.reload_rules() policy.reload_rules()
self.notification_driver_manager.update_policy(context, policy) self.notification_driver_manager.update_policy(context, policy)
return rule return rule
@db_base_plugin_common.convert_result_to_dict @db_base_plugin_common.convert_result_to_dict
def update_policy_rule(self, context, rule_obj, rule_id, policy_id, def update_policy_rule(self, context, rule_cls, rule_id, policy_id,
rule_data): rule_data):
"""Update a QoS policy rule. """Update a QoS policy rule.
:param context: neutron api request context :param context: neutron api request context
:type context: neutron.context.Context :type context: neutron.context.Context
:param rule_obj: the rule object :param rule_cls: the rule object class
:type rule_obj: a class from the rule_object (qos.objects.rule) module :type rule_cls: a class from the rule_object (qos.objects.rule) module
:param rule_id: the id of the QoS policy rule to update :param rule_id: the id of the QoS policy rule to update
:type rule_id: str uuid :type rule_id: str uuid
:param policy_id: the id of the rule's policy :param policy_id: the id of the rule's policy
@ -193,7 +193,7 @@ class QoSPlugin(qos.QoSPluginBase):
:returns: a QoS policy rule object :returns: a QoS policy rule object
""" """
rule_type = rule_obj.rule_type rule_type = rule_cls.rule_type
rule_data = rule_data[rule_type + '_rule'] rule_data = rule_data[rule_type + '_rule']
with db_api.autonested_transaction(context.session): with db_api.autonested_transaction(context.session):
@ -201,20 +201,20 @@ class QoSPlugin(qos.QoSPluginBase):
policy = self._get_policy_obj(context, policy_id) policy = self._get_policy_obj(context, policy_id)
# Ensure the rule belongs to the policy. # Ensure the rule belongs to the policy.
policy.get_rule_by_id(rule_id) policy.get_rule_by_id(rule_id)
rule = rule_obj(context, id=rule_id) rule = rule_cls(context, id=rule_id)
rule.update_fields(rule_data, reset_changes=True) rule.update_fields(rule_data, reset_changes=True)
rule.update() rule.update()
policy.reload_rules() policy.reload_rules()
self.notification_driver_manager.update_policy(context, policy) self.notification_driver_manager.update_policy(context, policy)
return rule return rule
def delete_policy_rule(self, context, rule_obj, rule_id, policy_id): def delete_policy_rule(self, context, rule_cls, rule_id, policy_id):
"""Delete a QoS policy rule. """Delete a QoS policy rule.
:param context: neutron api request context :param context: neutron api request context
:type context: neutron.context.Context :type context: neutron.context.Context
:param rule_obj: the rule object :param rule_cls: the rule object class
:type rule_obj: a class from the rule_object (qos.objects.rule) module :type rule_cls: a class from the rule_object (qos.objects.rule) module
:param rule_id: the id of the QosPolicy Rule to delete :param rule_id: the id of the QosPolicy Rule to delete
:type rule_id: str uuid :type rule_id: str uuid
:param policy_id: the id of the rule's policy :param policy_id: the id of the rule's policy
@ -232,14 +232,14 @@ class QoSPlugin(qos.QoSPluginBase):
@db_base_plugin_common.filter_fields @db_base_plugin_common.filter_fields
@db_base_plugin_common.convert_result_to_dict @db_base_plugin_common.convert_result_to_dict
def get_policy_rule(self, context, rule_obj, rule_id, policy_id, def get_policy_rule(self, context, rule_cls, rule_id, policy_id,
fields=None): fields=None):
"""Get a QoS policy rule. """Get a QoS policy rule.
:param context: neutron api request context :param context: neutron api request context
:type context: neutron.context.Context :type context: neutron.context.Context
:param rule_obj: the rule object :param rule_cls: the rule object class
:type rule_obj: a class from the rule_object (qos.objects.rule) module :type rule_cls: a class from the rule_object (qos.objects.rule) module
:param rule_id: the id of the QoS policy rule to get :param rule_id: the id of the QoS policy rule to get
:type rule_id: str uuid :type rule_id: str uuid
:param policy_id: the id of the rule's policy :param policy_id: the id of the rule's policy
@ -251,7 +251,7 @@ class QoSPlugin(qos.QoSPluginBase):
with db_api.autonested_transaction(context.session): with db_api.autonested_transaction(context.session):
# Ensure we have access to the policy. # Ensure we have access to the policy.
self._get_policy_obj(context, policy_id) self._get_policy_obj(context, policy_id)
rule = rule_obj.get_object(context, id=rule_id) rule = rule_cls.get_object(context, id=rule_id)
if not rule: if not rule:
raise n_exc.QosRuleNotFound(policy_id=policy_id, rule_id=rule_id) raise n_exc.QosRuleNotFound(policy_id=policy_id, rule_id=rule_id)
return rule return rule
@ -259,15 +259,15 @@ class QoSPlugin(qos.QoSPluginBase):
# TODO(QoS): enforce rule types when accessing rule objects # TODO(QoS): enforce rule types when accessing rule objects
@db_base_plugin_common.filter_fields @db_base_plugin_common.filter_fields
@db_base_plugin_common.convert_result_to_dict @db_base_plugin_common.convert_result_to_dict
def get_policy_rules(self, context, rule_obj, policy_id, filters=None, def get_policy_rules(self, context, rule_cls, policy_id, filters=None,
fields=None, sorts=None, limit=None, marker=None, fields=None, sorts=None, limit=None, marker=None,
page_reverse=False): page_reverse=False):
"""Get QoS policy rules. """Get QoS policy rules.
:param context: neutron api request context :param context: neutron api request context
:type context: neutron.context.Context :type context: neutron.context.Context
:param rule_obj: the rule object :param rule_cls: the rule object class
:type rule_obj: a class from the rule_object (qos.objects.rule) module :type rule_cls: a class from the rule_object (qos.objects.rule) module
:param policy_id: the id of the QosPolicy for which to get rules :param policy_id: the id of the QosPolicy for which to get rules
:type policy_id: str uuid :type policy_id: str uuid
@ -279,4 +279,4 @@ class QoSPlugin(qos.QoSPluginBase):
filters = filters or dict() filters = filters or dict()
filters[qos_consts.QOS_POLICY_ID] = policy_id filters[qos_consts.QOS_POLICY_ID] = policy_id
pager = base_obj.Pager(sorts, limit, page_reverse, marker) pager = base_obj.Pager(sorts, limit, page_reverse, marker)
return rule_obj.get_objects(context, _pager=pager, **filters) return rule_cls.get_objects(context, _pager=pager, **filters)