summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Authors1
-rw-r--r--nova/db/sqlalchemy/api.py7
-rw-r--r--nova/exception.py4
-rw-r--r--nova/tests/test_db_api.py8
4 files changed, 20 insertions, 0 deletions
diff --git a/Authors b/Authors
index e8f539653..8de5e3ca8 100644
--- a/Authors
+++ b/Authors
@@ -7,6 +7,7 @@ Alex Meade <alex.meade@rackspace.com>
Alexander Sakhnov <asakhnov@mirantis.com>
Alvaro Lopez Garcia <aloga@ifca.unican.es>
Andrew Bogott <abogott@wikimedia.org>
+Andrew Clay Shafer <acs@parvuscaptus.com>
Andrey Brindeyev <abrindeyev@griddynamics.com>
Andy Smith <code@term.ie>
Andy Southgate <andy.southgate@citrix.com>
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index ed9286eff..1f4f2f88c 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -1984,9 +1984,16 @@ def network_count_reserved_ips(context, network_id):
@require_admin_context
def network_create_safe(context, values):
+ if values.get('vlan'):
+ if model_query(context, models.Network, read_deleted="no")\
+ .filter_by(vlan=values['vlan'])\
+ .first():
+ raise exception.DuplicateVlan(vlan=values['vlan'])
+
network_ref = models.Network()
network_ref['uuid'] = str(utils.gen_uuid())
network_ref.update(values)
+
try:
network_ref.save()
return network_ref
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()