Currently, if we invoke the API for 'show rule' but the rule does not
exist, an exception is raised from deep within Neutron. This in turns
causes an uncaught exception and the user will see 'ServerFault'. This
patch proposes a fix for this scenario - the case where the rule does
not exist is handled and a NeutronException is caused, causing a proper
'NotFound' error on the client side instead.
Partially-Implements: blueprint quantum-qos-api
Change-Id: Ic703a0865d1cfa057ab1ad5290b793b22df06af6
message = _("QoS policy %(policy_id)s could not be found")
+class QosRuleNotFound(NotFound):
+ message = _("QoS rule %(rule_id)s for policy %(policy_id)s "
+ "could not be found")
+
+
class PortNotFoundOnNetwork(NotFound):
message = _("Port %(port_id)s could not be found "
"on network %(net_id)s")
policy_id, fields=None):
# validate that we have access to the policy
self._get_policy_obj(context, policy_id)
- return rule_object.QosBandwidthLimitRule.get_by_id(context,
- rule_id)
+ rule = rule_object.QosBandwidthLimitRule.get_by_id(context, rule_id)
+ if not rule:
+ raise n_exc.QosRuleNotFound(policy_id=policy_id, rule_id=rule_id)
+ return rule
@db_base_plugin_common.filter_fields
@db_base_plugin_common.convert_result_to_dict
self.assertEqual(rule['id'], retrieved_policy['id'])
self.admin_client.delete_bandwidth_limit_rule(policy['id'], rule['id'])
- self.assertRaises(exceptions.ServerFault,
+ self.assertRaises(exceptions.NotFound,
self.admin_client.show_bandwidth_limit_rule,
policy['id'], rule['id'])