Merge "api/network/security_groups_negative add testcases"
diff --git a/tempest/api/network/test_security_groups_negative.py b/tempest/api/network/test_security_groups_negative.py
index d321e23..daeb89f 100644
--- a/tempest/api/network/test_security_groups_negative.py
+++ b/tempest/api/network/test_security_groups_negative.py
@@ -16,6 +16,7 @@
# under the License.
from tempest.api.network import test_security_groups as base
+from tempest.common.utils import data_utils
from tempest import exceptions
from tempest.test import attr
import uuid
@@ -37,6 +38,54 @@
self.client.show_security_group_rule,
non_exist_id)
+ @attr(type=['negative', 'smoke'])
+ def test_delete_non_existent_security_group(self):
+ non_exist_id = 'fictional-id'
+ self.assertRaises(exceptions.NotFound,
+ self.client.delete_security_group,
+ non_exist_id
+ )
+
+ @attr(type=['negative', 'smoke'])
+ def test_create_security_group_rule_with_bad_protocol(self):
+ # Create a security group
+ name = data_utils.rand_name('secgroup-')
+ resp, group_create_body = self.client.create_security_group(name)
+ self.assertEqual('201', resp['status'])
+ self.addCleanup(self._delete_security_group,
+ group_create_body['security_group']['id'])
+ self.assertEqual(group_create_body['security_group']['name'], name)
+
+ #Create rule with bad protocol name
+ pname = 'bad_protocol_name'
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group_rule,
+ group_create_body['security_group']['id'],
+ protocol=pname)
+
+ @attr(type=['negative', 'smoke'])
+ def test_create_security_group_rule_with_invalid_ports(self):
+ # Create a security group
+ name = data_utils.rand_name('secgroup-')
+ resp, group_create_body = self.client.create_security_group(name)
+ self.assertEqual('201', resp['status'])
+ self.addCleanup(self._delete_security_group,
+ group_create_body['security_group']['id'])
+ self.assertEqual(group_create_body['security_group']['name'], name)
+
+ #Create rule with invalid ports
+ states = [(-16, 80, 'Invalid value for port -16'),
+ (80, 79, 'port_range_min must be <= port_range_max'),
+ (80, 65536, 'Invalid value for port 65536')]
+ for pmin, pmax, msg in states:
+ ex = self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group_rule,
+ group_create_body['security_group']['id'],
+ protocol='tcp',
+ port_range_min=pmin,
+ port_range_max=pmax)
+ self.assertIn(msg, str(ex))
+
class NegativeSecGroupTestXML(NegativeSecGroupTest):
_interface = 'xml'