Convert network security group functional tests to JSON
Change-Id: Icb63aa0dfbce9016fb824f97915a660cf130d120
This commit is contained in:
parent
5cc4d5b530
commit
95e279176b
openstackclient/tests/functional/network/v2
@ -10,6 +10,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from openstackclient.tests.functional.network.v2 import common
|
from openstackclient.tests.functional.network.v2 import common
|
||||||
@ -17,44 +18,6 @@ from openstackclient.tests.functional.network.v2 import common
|
|||||||
|
|
||||||
class SecurityGroupTests(common.NetworkTests):
|
class SecurityGroupTests(common.NetworkTests):
|
||||||
"""Functional tests for security group"""
|
"""Functional tests for security group"""
|
||||||
HEADERS = ['Name']
|
|
||||||
FIELDS = ['name']
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def setUpClass(cls):
|
|
||||||
common.NetworkTests.setUpClass()
|
|
||||||
if cls.haz_network:
|
|
||||||
cls.NAME = uuid.uuid4().hex
|
|
||||||
cls.OTHER_NAME = uuid.uuid4().hex
|
|
||||||
|
|
||||||
opts = cls.get_opts(cls.FIELDS)
|
|
||||||
raw_output = cls.openstack(
|
|
||||||
'security group create ' +
|
|
||||||
cls.NAME +
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
expected = cls.NAME + '\n'
|
|
||||||
cls.assertOutput(expected, raw_output)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
try:
|
|
||||||
if cls.haz_network:
|
|
||||||
# Rename test
|
|
||||||
raw_output = cls.openstack(
|
|
||||||
'security group set --name ' +
|
|
||||||
cls.OTHER_NAME + ' ' +
|
|
||||||
cls.NAME
|
|
||||||
)
|
|
||||||
cls.assertOutput('', raw_output)
|
|
||||||
# Delete test
|
|
||||||
raw_output = cls.openstack(
|
|
||||||
'security group delete ' +
|
|
||||||
cls.OTHER_NAME
|
|
||||||
)
|
|
||||||
cls.assertOutput('', raw_output)
|
|
||||||
finally:
|
|
||||||
super(SecurityGroupTests, cls).tearDownClass()
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(SecurityGroupTests, self).setUp()
|
super(SecurityGroupTests, self).setUp()
|
||||||
@ -62,22 +25,33 @@ class SecurityGroupTests(common.NetworkTests):
|
|||||||
if not self.haz_network:
|
if not self.haz_network:
|
||||||
self.skipTest("No Network service present")
|
self.skipTest("No Network service present")
|
||||||
|
|
||||||
|
self.NAME = uuid.uuid4().hex
|
||||||
|
self.OTHER_NAME = uuid.uuid4().hex
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'security group create -f json ' +
|
||||||
|
self.NAME
|
||||||
|
))
|
||||||
|
self.addCleanup(self.openstack,
|
||||||
|
'security group delete ' + cmd_output['id'])
|
||||||
|
self.assertEqual(self.NAME, cmd_output['name'])
|
||||||
|
|
||||||
def test_security_group_list(self):
|
def test_security_group_list(self):
|
||||||
opts = self.get_opts(self.HEADERS)
|
cmd_output = json.loads(self.openstack('security group list -f json'))
|
||||||
raw_output = self.openstack('security group list' + opts)
|
self.assertIn(self.NAME, [sg['Name'] for sg in cmd_output])
|
||||||
self.assertIn(self.NAME, raw_output)
|
|
||||||
|
|
||||||
def test_security_group_set(self):
|
def test_security_group_set(self):
|
||||||
|
other_name = uuid.uuid4().hex
|
||||||
raw_output = self.openstack(
|
raw_output = self.openstack(
|
||||||
'security group set --description NSA ' + self.NAME
|
'security group set --description NSA --name ' +
|
||||||
|
other_name + ' ' + self.NAME
|
||||||
)
|
)
|
||||||
self.assertEqual('', raw_output)
|
self.assertEqual('', raw_output)
|
||||||
|
|
||||||
opts = self.get_opts(['description'])
|
cmd_output = json.loads(self.openstack(
|
||||||
raw_output = self.openstack('security group show ' + self.NAME + opts)
|
'security group show -f json ' + other_name))
|
||||||
self.assertEqual("NSA\n", raw_output)
|
self.assertEqual('NSA', cmd_output['description'])
|
||||||
|
|
||||||
def test_security_group_show(self):
|
def test_security_group_show(self):
|
||||||
opts = self.get_opts(self.FIELDS)
|
cmd_output = json.loads(self.openstack(
|
||||||
raw_output = self.openstack('security group show ' + self.NAME + opts)
|
'security group show -f json ' + self.NAME))
|
||||||
self.assertEqual(self.NAME + "\n", raw_output)
|
self.assertEqual(self.NAME, cmd_output['name'])
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from openstackclient.tests.functional.network.v2 import common
|
from openstackclient.tests.functional.network.v2 import common
|
||||||
@ -17,54 +18,6 @@ from openstackclient.tests.functional.network.v2 import common
|
|||||||
|
|
||||||
class SecurityGroupRuleTests(common.NetworkTests):
|
class SecurityGroupRuleTests(common.NetworkTests):
|
||||||
"""Functional tests for security group rule"""
|
"""Functional tests for security group rule"""
|
||||||
SECURITY_GROUP_RULE_ID = None
|
|
||||||
NAME_FIELD = ['name']
|
|
||||||
ID_FIELD = ['id']
|
|
||||||
ID_HEADER = ['ID']
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def setUpClass(cls):
|
|
||||||
common.NetworkTests.setUpClass()
|
|
||||||
if cls.haz_network:
|
|
||||||
cls.SECURITY_GROUP_NAME = uuid.uuid4().hex
|
|
||||||
|
|
||||||
# Create the security group to hold the rule
|
|
||||||
opts = cls.get_opts(cls.NAME_FIELD)
|
|
||||||
raw_output = cls.openstack(
|
|
||||||
'security group create ' +
|
|
||||||
cls.SECURITY_GROUP_NAME +
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
expected = cls.SECURITY_GROUP_NAME + '\n'
|
|
||||||
cls.assertOutput(expected, raw_output)
|
|
||||||
|
|
||||||
# Create the security group rule.
|
|
||||||
opts = cls.get_opts(cls.ID_FIELD)
|
|
||||||
raw_output = cls.openstack(
|
|
||||||
'security group rule create ' +
|
|
||||||
cls.SECURITY_GROUP_NAME + ' ' +
|
|
||||||
'--protocol tcp --dst-port 80:80 ' +
|
|
||||||
'--ingress --ethertype IPv4 ' +
|
|
||||||
opts
|
|
||||||
)
|
|
||||||
cls.SECURITY_GROUP_RULE_ID = raw_output.strip('\n')
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
try:
|
|
||||||
if cls.haz_network:
|
|
||||||
raw_output = cls.openstack(
|
|
||||||
'security group rule delete ' +
|
|
||||||
cls.SECURITY_GROUP_RULE_ID
|
|
||||||
)
|
|
||||||
cls.assertOutput('', raw_output)
|
|
||||||
raw_output = cls.openstack(
|
|
||||||
'security group delete ' +
|
|
||||||
cls.SECURITY_GROUP_NAME
|
|
||||||
)
|
|
||||||
cls.assertOutput('', raw_output)
|
|
||||||
finally:
|
|
||||||
super(SecurityGroupRuleTests, cls).tearDownClass()
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(SecurityGroupRuleTests, self).setUp()
|
super(SecurityGroupRuleTests, self).setUp()
|
||||||
@ -72,16 +25,35 @@ class SecurityGroupRuleTests(common.NetworkTests):
|
|||||||
if not self.haz_network:
|
if not self.haz_network:
|
||||||
self.skipTest("No Network service present")
|
self.skipTest("No Network service present")
|
||||||
|
|
||||||
|
self.SECURITY_GROUP_NAME = uuid.uuid4().hex
|
||||||
|
|
||||||
|
# Create the security group to hold the rule
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'security group create -f json ' +
|
||||||
|
self.SECURITY_GROUP_NAME
|
||||||
|
))
|
||||||
|
self.addCleanup(self.openstack,
|
||||||
|
'security group delete ' + self.SECURITY_GROUP_NAME)
|
||||||
|
self.assertEqual(self.SECURITY_GROUP_NAME, cmd_output['name'])
|
||||||
|
|
||||||
|
# Create the security group rule.
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'security group rule create -f json ' +
|
||||||
|
self.SECURITY_GROUP_NAME + ' ' +
|
||||||
|
'--protocol tcp --dst-port 80:80 ' +
|
||||||
|
'--ingress --ethertype IPv4 '
|
||||||
|
))
|
||||||
|
self.addCleanup(self.openstack,
|
||||||
|
'security group rule delete ' + cmd_output['id'])
|
||||||
|
self.SECURITY_GROUP_RULE_ID = cmd_output['id']
|
||||||
|
|
||||||
def test_security_group_rule_list(self):
|
def test_security_group_rule_list(self):
|
||||||
opts = self.get_opts(self.ID_HEADER)
|
cmd_output = json.loads(self.openstack(
|
||||||
raw_output = self.openstack('security group rule list ' +
|
'security group rule list -f json ' + self.SECURITY_GROUP_NAME))
|
||||||
self.SECURITY_GROUP_NAME +
|
self.assertIn(self.SECURITY_GROUP_RULE_ID,
|
||||||
opts)
|
[rule['ID'] for rule in cmd_output])
|
||||||
self.assertIn(self.SECURITY_GROUP_RULE_ID, raw_output)
|
|
||||||
|
|
||||||
def test_security_group_rule_show(self):
|
def test_security_group_rule_show(self):
|
||||||
opts = self.get_opts(self.ID_FIELD)
|
cmd_output = json.loads(self.openstack(
|
||||||
raw_output = self.openstack('security group rule show ' +
|
'security group rule show -f json ' + self.SECURITY_GROUP_RULE_ID))
|
||||||
self.SECURITY_GROUP_RULE_ID +
|
self.assertEqual(self.SECURITY_GROUP_RULE_ID, cmd_output['id'])
|
||||||
opts)
|
|
||||||
self.assertEqual(self.SECURITY_GROUP_RULE_ID + "\n", raw_output)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user