2015-06-10 11:52:52 -06:00
|
|
|
# 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 uuid
|
|
|
|
|
2017-04-28 12:41:57 -05:00
|
|
|
from openstackclient.tests.functional.network.v2 import common
|
2015-06-10 11:52:52 -06:00
|
|
|
|
|
|
|
|
2017-04-28 12:41:57 -05:00
|
|
|
class SecurityGroupTests(common.NetworkTests):
|
|
|
|
"""Functional tests for security group"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(SecurityGroupTests, self).setUp()
|
|
|
|
# Nothing in this class works with Nova Network
|
|
|
|
if not self.haz_network:
|
|
|
|
self.skipTest("No Network service present")
|
2015-06-10 11:52:52 -06:00
|
|
|
|
2017-08-23 21:14:47 +00:00
|
|
|
self.NAME = uuid.uuid4().hex
|
|
|
|
self.OTHER_NAME = uuid.uuid4().hex
|
2022-11-08 11:23:25 +00:00
|
|
|
cmd_output = self.openstack(
|
|
|
|
'security group create ' +
|
|
|
|
self.NAME,
|
|
|
|
parse_output=True,
|
|
|
|
)
|
2017-08-23 21:14:47 +00:00
|
|
|
self.addCleanup(self.openstack,
|
|
|
|
'security group delete ' + cmd_output['id'])
|
|
|
|
self.assertEqual(self.NAME, cmd_output['name'])
|
|
|
|
|
2015-06-10 11:52:52 -06:00
|
|
|
def test_security_group_list(self):
|
2022-11-08 11:23:25 +00:00
|
|
|
cmd_output = self.openstack('security group list', parse_output=True)
|
2017-08-23 21:14:47 +00:00
|
|
|
self.assertIn(self.NAME, [sg['Name'] for sg in cmd_output])
|
2015-06-10 11:52:52 -06:00
|
|
|
|
|
|
|
def test_security_group_set(self):
|
2017-08-23 21:14:47 +00:00
|
|
|
other_name = uuid.uuid4().hex
|
2016-02-17 15:20:36 +08:00
|
|
|
raw_output = self.openstack(
|
2020-03-05 17:54:55 +01:00
|
|
|
'security group set --description NSA --stateless --name ' +
|
2017-08-23 21:14:47 +00:00
|
|
|
other_name + ' ' + self.NAME
|
2016-02-17 15:20:36 +08:00
|
|
|
)
|
|
|
|
self.assertEqual('', raw_output)
|
|
|
|
|
2022-11-08 11:23:25 +00:00
|
|
|
cmd_output = self.openstack(
|
|
|
|
'security group show ' + other_name,
|
|
|
|
parse_output=True,
|
|
|
|
)
|
2017-08-23 21:14:47 +00:00
|
|
|
self.assertEqual('NSA', cmd_output['description'])
|
2020-03-05 17:54:55 +01:00
|
|
|
self.assertFalse(cmd_output['stateful'])
|
2015-06-10 11:52:52 -06:00
|
|
|
|
|
|
|
def test_security_group_show(self):
|
2022-11-08 11:23:25 +00:00
|
|
|
cmd_output = self.openstack(
|
|
|
|
'security group show ' + self.NAME,
|
|
|
|
parse_output=True,
|
|
|
|
)
|
2017-08-23 21:14:47 +00:00
|
|
|
self.assertEqual(self.NAME, cmd_output['name'])
|
2020-03-05 17:54:55 +01:00
|
|
|
self.assertTrue(cmd_output['stateful'])
|