From dd6e0f281be412fe667e7ee68ec3d13fcf15a47c Mon Sep 17 00:00:00 2001 From: Andrew Clay Shafer Date: Tue, 14 Feb 2012 01:44:37 -0500 Subject: [PATCH] Prevent Duplicate VLAN IDs Addresses Bug 708278 Add check for duplicates in api.py Add DuplicateVlan to exception.py Add test to raise DuplicateVlan in test_db_api.py Add to Authors Change-Id: I9d68d7b7c886071e38df3c9d7d53724758bdd84c --- Authors | 1 + nova/exception.py | 4 ++++ nova/tests/test_db_api.py | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/Authors b/Authors index 9995e58ac..3a7e16d3c 100644 --- a/Authors +++ b/Authors @@ -7,6 +7,7 @@ Alex Meade Alexander Sakhnov Alvaro Lopez Garcia Andrew Bogott +Andrew Clay Shafer Andrey Brindeyev Andy Smith Andy Southgate diff --git a/nova/exception.py b/nova/exception.py index 9bb39b2f4..979703072 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -984,3 +984,7 @@ class SolidFireAPIStatusException(SolidFireAPIException): class SolidFireAPIDataException(SolidFireAPIException): message = _("Error in SolidFire API response: data=%(data)s") + + +class DuplicateVlan(Duplicate): + message = _("Detected existing vlan with id %(vlan)") diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 121120dbf..3353ea737 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -146,6 +146,14 @@ class DbApiTestCase(test.TestCase): db_network = db.network_get(ctxt, network.id) self.assertEqual(network.uuid, db_network.uuid) + def test_network_create_with_duplicate_vlan(self): + ctxt = context.get_admin_context() + values1 = {'host': 'localhost', 'project_id': 'project1', 'vlan': 1} + values2 = {'host': 'something', 'project_id': 'project1', 'vlan': 1} + db.network_create_safe(ctxt, values1) + self.assertRaises(exception.DuplicateVlan, + db.network_create_safe, ctxt, values2) + def test_instance_update_with_instance_id(self): """ test instance_update() works when an instance id is passed """ ctxt = context.get_admin_context()