Fix adding identical metering rules on two labels

Fixes: Bug #1229075

Change-Id: Id86c83ec9c7af78fc08e662bb0a9202f0f759c0c
This commit is contained in:
Sylvain Afchain 2013-09-09 13:02:19 +02:00
parent ed8b85e6d6
commit dec1e329c2
2 changed files with 35 additions and 3 deletions

View File

@ -144,9 +144,12 @@ class MeteringDbMixin(metering.MeteringPluginBase,
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,
filters={'direction':
filters={'metering_label_id':
label_id,
'direction':
[direction],
'excluded':
[excluded]},
@ -166,7 +169,8 @@ class MeteringDbMixin(metering.MeteringPluginBase,
direction = m['direction']
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_label_id=label_id,
direction=direction,

View File

@ -263,6 +263,34 @@ class MeteringPluginDbTestCase(test_db_plugin.NeutronDbPluginV2TestCase,
self._test_list_resources('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):
fmt = 'xml'