]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix error raising in security groups method
authorKevin Benton <blak111@gmail.com>
Sat, 28 Mar 2015 06:18:08 +0000 (23:18 -0700)
committerKevin Benton <blak111@gmail.com>
Sat, 28 Mar 2015 11:20:20 +0000 (04:20 -0700)
In case there were security groups not belonging to tenant on port
_get_security_groups_on_port would try to raise exception but fail
trying to index set.

This patch simply joins the whole set as a string and inserts it
into the standard SecurityGroupNotFound exception.

No new exception types, no string freeze violations.

Co-Author: watanabe.isao <zou.yun@jp.fujitsu.com>
Co-Author: Jacek Swiderski <jacek.swiderski@codilime.com>

Change-Id: I039ea57269dc53ced8dece0985f33ce9ae7eab17
Closes-Bug: #1373816

neutron/db/securitygroups_db.py
neutron/tests/unit/test_extension_security_group.py

index 6fdbd0c3a99d38df2fd7a58dcb75f86555314c86..f14ed9cc515bc67b0cf3e058d82bc8eac30e6410 100644 (file)
@@ -575,7 +575,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
         requested_groups = set(port_sg)
         port_sg_missing = requested_groups - valid_groups
         if port_sg_missing:
-            raise ext_sg.SecurityGroupNotFound(id=str(port_sg_missing[0]))
+            raise ext_sg.SecurityGroupNotFound(id=', '.join(port_sg_missing))
 
         return requested_groups
 
index f13c19a978cf58dfcb19adb6e5ef9289068be10c..2a401bcc9eb81e7dc09a7c04afd75c91b3632b5c 100644 (file)
@@ -17,6 +17,7 @@ import contextlib
 
 import mock
 import oslo_db.exception as exc
+import testtools
 import webob.exc
 
 from neutron.api.v2 import attributes as attr
@@ -26,6 +27,7 @@ from neutron import context
 from neutron.db import db_base_plugin_v2
 from neutron.db import securitygroups_db
 from neutron.extensions import securitygroup as ext_sg
+from neutron import manager
 from neutron.tests import base
 from neutron.tests.unit import test_db_plugin
 
@@ -577,6 +579,21 @@ class TestSecurityGroups(SecurityGroupDBTestCase):
                 for k, v, in keys:
                     self.assertEqual(sg_rule[0][k], v)
 
+    def test_get_security_group_on_port_from_wrong_tenant(self):
+        plugin = manager.NeutronManager.get_plugin()
+        if not hasattr(plugin, '_get_security_groups_on_port'):
+            self.skipTest("plugin doesn't use the mixin with this method")
+        neutron_context = context.get_admin_context()
+        res = self._create_security_group(self.fmt, 'webservers', 'webservers',
+                                          tenant_id='bad_tenant')
+        sg1 = self.deserialize(self.fmt, res)
+        with testtools.ExpectedException(ext_sg.SecurityGroupNotFound):
+            plugin._get_security_groups_on_port(
+                neutron_context,
+                {'port': {'security_groups': [sg1['security_group']['id']],
+                          'tenant_id': 'tenant'}}
+            )
+
     def test_delete_security_group(self):
         name = 'webservers'
         description = 'my webservers'