summaryrefslogtreecommitdiff
path: root/openstackclient/tests/functional/compute
diff options
context:
space:
mode:
authorRui Chen <chenrui.momo@gmail.com>2017-05-03 15:17:10 +0800
committerDean Troyer <dtroyer@gmail.com>2017-05-22 20:32:01 +0000
commit45496feee6ae781dc0c1df4a0e5bd71b05653748 (patch)
tree752980b8d6c52810381049b2feceacf2ed801d06 /openstackclient/tests/functional/compute
parent411cda722b082bc9274dd23f7e6b0c47e2cc9765 (diff)
downloadpython-openstackclient-45496feee6ae781dc0c1df4a0e5bd71b05653748.tar.gz
Create server with security group ID and name
Both resource ID and name are supported to identify an object in openstackclient to make user easy to input, for security group, nova only support security group name in API when launch a new server, this patch convert ID to name, then pass name to nova API, and check the security group exist before creating server. Change-Id: I1ed4a967fb9de3f91c8945a1ef63f6c7b6b2dfb2 Closes-Bug: #1687814
Diffstat (limited to 'openstackclient/tests/functional/compute')
-rw-r--r--openstackclient/tests/functional/compute/v2/test_server.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/openstackclient/tests/functional/compute/v2/test_server.py b/openstackclient/tests/functional/compute/v2/test_server.py
index 7d54b6a6..f4ffe961 100644
--- a/openstackclient/tests/functional/compute/v2/test_server.py
+++ b/openstackclient/tests/functional/compute/v2/test_server.py
@@ -410,6 +410,52 @@ class ServerTests(common.ComputeTestCase):
self.assertIsNotNone(server['addresses'])
self.assertEqual('', server['addresses'])
+ def test_server_create_with_security_group(self):
+ """Test server create with security group ID and name"""
+ if not self.haz_network:
+ # NOTE(dtroyer): As of Ocata release Nova forces nova-network to
+ # run in a cells v1 configuration. Security group
+ # and network functions currently do not work in
+ # the gate jobs so we have to skip this. It is
+ # known to work tested against a Mitaka nova-net
+ # DevStack without cells.
+ self.skipTest("No Network service present")
+ # Create two security group, use name and ID to create server
+ sg_name1 = uuid.uuid4().hex
+ security_group1 = json.loads(self.openstack(
+ 'security group create -f json ' + sg_name1
+ ))
+ self.addCleanup(self.openstack, 'security group delete ' + sg_name1)
+ sg_name2 = uuid.uuid4().hex
+ security_group2 = json.loads(self.openstack(
+ 'security group create -f json ' + sg_name2
+ ))
+ self.addCleanup(self.openstack, 'security group delete ' + sg_name2)
+
+ server_name = uuid.uuid4().hex
+ server = json.loads(self.openstack(
+ 'server create -f json ' +
+ '--flavor ' + self.flavor_name + ' ' +
+ '--image ' + self.image_name + ' ' +
+ # Security group id is integer in nova-network, convert to string
+ '--security-group ' + str(security_group1['id']) + ' ' +
+ '--security-group ' + security_group2['name'] + ' ' +
+ self.network_arg + ' ' +
+ server_name
+ ))
+ self.addCleanup(self.openstack, 'server delete --wait ' + server_name)
+
+ self.assertIsNotNone(server['id'])
+ self.assertEqual(server_name, server['name'])
+ self.assertIn(str(security_group1['id']), server['security_groups'])
+ self.assertIn(str(security_group2['id']), server['security_groups'])
+ self.wait_for_status(server_name, 'ACTIVE')
+ server = json.loads(self.openstack(
+ 'server show -f json ' + server_name
+ ))
+ self.assertIn(sg_name1, server['security_groups'])
+ self.assertIn(sg_name2, server['security_groups'])
+
def test_server_create_with_empty_network_option_latest(self):
"""Test server create with empty network option in nova 2.latest."""
server_name = uuid.uuid4().hex