def delete_security_group_rule(self, context, id):
with context.session.begin(subtransactions=True):
- rule = self._get_security_group_rule(context, id)
- context.session.delete(rule)
+ query = self._model_query(context, SecurityGroupRule)
+ if query.filter(SecurityGroupRule.id == id).delete() == 0:
+ raise ext_sg.SecurityGroupRuleNotFound(id=id)
def _extend_port_dict_security_group(self, port_res, port_db):
# Security group bindings will be retrieved from the sqlalchemy
--- /dev/null
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import testtools
+
+from neutron import context
+from neutron.db import common_db_mixin
+from neutron.db import securitygroups_db
+from neutron.extensions import securitygroup
+from neutron.tests.unit import testlib_api
+
+
+class SecurityGroupDbMixinImpl(securitygroups_db.SecurityGroupDbMixin,
+ common_db_mixin.CommonDbMixin):
+ pass
+
+
+class SecurityGroupDbMixinTestCase(testlib_api.SqlTestCase):
+
+ def setUp(self):
+ super(SecurityGroupDbMixinTestCase, self).setUp()
+ self.ctx = context.get_admin_context()
+ self.mixin = SecurityGroupDbMixinImpl()
+
+ def test_delete_security_group_rule_raise_error_on_not_found(self):
+ with testtools.ExpectedException(
+ securitygroup.SecurityGroupRuleNotFound):
+ self.mixin.delete_security_group_rule(self.ctx, 'foo_rule')