diff --git a/neutron/db/metering/metering_db.py b/neutron/db/metering/metering_db.py index 99e448fc3d..242c76d5b9 100644 --- a/neutron/db/metering/metering_db.py +++ b/neutron/db/metering/metering_db.py @@ -148,7 +148,7 @@ class MeteringDbMixin(metering.MeteringPluginBase, direction, excluded): r_ips = self.get_metering_label_rules(context, filters={'metering_label_id': - label_id, + [label_id], 'direction': [direction], 'excluded': diff --git a/neutron/extensions/metering.py b/neutron/extensions/metering.py index a9c750d01d..5be35a7d4a 100644 --- a/neutron/extensions/metering.py +++ b/neutron/extensions/metering.py @@ -39,7 +39,7 @@ class MeteringLabelRuleNotFound(qexception.NotFound): message = _("Metering label rule %(rule_id)s does not exist") -class MeteringLabelRuleOverlaps(qexception.NotFound): +class MeteringLabelRuleOverlaps(qexception.Conflict): message = _("Metering label rule with remote_ip_prefix " "%(remote_ip_prefix)s overlaps another") diff --git a/neutron/tests/unit/db/metering/test_db_metering.py b/neutron/tests/unit/db/metering/test_db_metering.py index 40dab4d54a..5690f8e84c 100644 --- a/neutron/tests/unit/db/metering/test_db_metering.py +++ b/neutron/tests/unit/db/metering/test_db_metering.py @@ -267,6 +267,29 @@ class TestMetering(MeteringPluginDbTestCase): self._test_list_resources('metering-label-rule', metering_label_rule) + def test_create_overlap_metering_label_rules(self): + name = 'my label' + description = 'my metering label' + + with self.metering_label(name, description) as metering_label: + metering_label_id = metering_label['metering_label']['id'] + + direction = 'egress' + remote_ip_prefix1 = '192.168.0.0/24' + remote_ip_prefix2 = '192.168.0.0/16' + excluded = True + + with self.metering_label_rule(metering_label_id, + direction, + remote_ip_prefix1, + excluded): + res = self._create_metering_label_rule(self.fmt, + metering_label_id, + direction, + remote_ip_prefix2, + excluded) + self.assertEqual(webob.exc.HTTPConflict.code, res.status_int) + def test_create_metering_label_rule_two_labels(self): name1 = 'my label 1' name2 = 'my label 2'