Fix adding identical metering rules on two labels
Fixes: Bug #1229075 Change-Id: Id86c83ec9c7af78fc08e662bb0a9202f0f759c0c
This commit is contained in:
parent
ed8b85e6d6
commit
dec1e329c2
@ -144,9 +144,12 @@ class MeteringDbMixin(metering.MeteringPluginBase,
|
|||||||
|
|
||||||
return self._make_metering_label_rule_dict(metering_label_rule, fields)
|
return self._make_metering_label_rule_dict(metering_label_rule, fields)
|
||||||
|
|
||||||
def _validate_cidr(self, context, remote_ip_prefix, direction, excluded):
|
def _validate_cidr(self, context, label_id, remote_ip_prefix,
|
||||||
|
direction, excluded):
|
||||||
r_ips = self.get_metering_label_rules(context,
|
r_ips = self.get_metering_label_rules(context,
|
||||||
filters={'direction':
|
filters={'metering_label_id':
|
||||||
|
label_id,
|
||||||
|
'direction':
|
||||||
[direction],
|
[direction],
|
||||||
'excluded':
|
'excluded':
|
||||||
[excluded]},
|
[excluded]},
|
||||||
@ -166,7 +169,8 @@ class MeteringDbMixin(metering.MeteringPluginBase,
|
|||||||
direction = m['direction']
|
direction = m['direction']
|
||||||
excluded = m['excluded']
|
excluded = m['excluded']
|
||||||
|
|
||||||
self._validate_cidr(context, ip_prefix, direction, excluded)
|
self._validate_cidr(context, label_id, ip_prefix, direction,
|
||||||
|
excluded)
|
||||||
metering_db = MeteringLabelRule(id=uuidutils.generate_uuid(),
|
metering_db = MeteringLabelRule(id=uuidutils.generate_uuid(),
|
||||||
metering_label_id=label_id,
|
metering_label_id=label_id,
|
||||||
direction=direction,
|
direction=direction,
|
||||||
|
@ -263,6 +263,34 @@ class MeteringPluginDbTestCase(test_db_plugin.NeutronDbPluginV2TestCase,
|
|||||||
self._test_list_resources('metering-label-rule',
|
self._test_list_resources('metering-label-rule',
|
||||||
metering_label_rule)
|
metering_label_rule)
|
||||||
|
|
||||||
|
def test_create_metering_label_rule_two_labels(self):
|
||||||
|
name1 = 'my label 1'
|
||||||
|
name2 = 'my label 2'
|
||||||
|
description = 'my metering label'
|
||||||
|
|
||||||
|
with self.metering_label(name1, description) as metering_label1:
|
||||||
|
metering_label_id1 = metering_label1['metering_label']['id']
|
||||||
|
|
||||||
|
with self.metering_label(name2, description) as metering_label2:
|
||||||
|
metering_label_id2 = metering_label2['metering_label']['id']
|
||||||
|
|
||||||
|
direction = 'egress'
|
||||||
|
remote_ip_prefix = '192.168.0.0/24'
|
||||||
|
excluded = True
|
||||||
|
|
||||||
|
with contextlib.nested(
|
||||||
|
self.metering_label_rule(metering_label_id1,
|
||||||
|
direction,
|
||||||
|
remote_ip_prefix,
|
||||||
|
excluded),
|
||||||
|
self.metering_label_rule(metering_label_id2,
|
||||||
|
direction,
|
||||||
|
remote_ip_prefix,
|
||||||
|
excluded)) as metering_label_rule:
|
||||||
|
|
||||||
|
self._test_list_resources('metering-label-rule',
|
||||||
|
metering_label_rule)
|
||||||
|
|
||||||
|
|
||||||
class TestMeteringDbXML(MeteringPluginDbTestCase):
|
class TestMeteringDbXML(MeteringPluginDbTestCase):
|
||||||
fmt = 'xml'
|
fmt = 'xml'
|
||||||
|
Loading…
Reference in New Issue
Block a user