summaryrefslogtreecommitdiff
path: root/openstackclient/tests/functional/compute/v2
diff options
context:
space:
mode:
authorSteve Martinelli <s.martinelli@gmail.com>2016-09-05 20:35:06 -0700
committerSteve Martinelli <s.martinelli@gmail.com>2016-09-09 03:29:47 +0000
commitc14d3efe6162a58cb3cdcb2834ad2508e2525018 (patch)
tree084f7a998a410957299db58a2449dbfb1dce20a9 /openstackclient/tests/functional/compute/v2
parent39839def2e356e8d145be89380c73a71423cf06d (diff)
downloadpython-openstackclient-c14d3efe6162a58cb3cdcb2834ad2508e2525018.tar.gz
move all functional tests to tests module
functional tests should be grouped with other tests (unit and integration tests). as part of this commit the "common" module was renamed to just "base", this was done for simplicity. the post_test_hook.sh file was also copied to the functional module since it should live there. a separate change to the infra repo will be made to call the new location, once that is merged we can remove the old one (a new change will also be posted for that) Needed-By: I49d54f009021d65c1ae49faf6b3f0a7acdadd7b3 Change-Id: Ie8c334f6223373b8e06df8bd8466500d2a2c8ede
Diffstat (limited to 'openstackclient/tests/functional/compute/v2')
-rw-r--r--openstackclient/tests/functional/compute/v2/__init__.py0
-rw-r--r--openstackclient/tests/functional/compute/v2/test_agent.py77
-rw-r--r--openstackclient/tests/functional/compute/v2/test_aggregate.py67
-rw-r--r--openstackclient/tests/functional/compute/v2/test_flavor.py69
-rw-r--r--openstackclient/tests/functional/compute/v2/test_keypair.py168
-rw-r--r--openstackclient/tests/functional/compute/v2/test_server.py308
-rw-r--r--openstackclient/tests/functional/compute/v2/test_server_group.py46
7 files changed, 735 insertions, 0 deletions
diff --git a/openstackclient/tests/functional/compute/v2/__init__.py b/openstackclient/tests/functional/compute/v2/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/openstackclient/tests/functional/compute/v2/__init__.py
diff --git a/openstackclient/tests/functional/compute/v2/test_agent.py b/openstackclient/tests/functional/compute/v2/test_agent.py
new file mode 100644
index 00000000..7115db1f
--- /dev/null
+++ b/openstackclient/tests/functional/compute/v2/test_agent.py
@@ -0,0 +1,77 @@
+# 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 hashlib
+
+from openstackclient.tests.functional import base
+
+
+class ComputeAgentTests(base.TestCase):
+ """Functional tests for compute agent."""
+
+ ID = None
+ MD5HASH = hashlib.md5().hexdigest()
+ URL = "http://localhost"
+ VER = "v1"
+ OS = "TEST_OS"
+ ARCH = "x86_64"
+ HYPER = "kvm"
+
+ HEADERS = ['agent_id', 'md5hash']
+ FIELDS = ['agent_id', 'md5hash']
+
+ @classmethod
+ def setUpClass(cls):
+ opts = cls.get_opts(cls.HEADERS)
+ raw_output = cls.openstack('compute agent create ' +
+ cls.OS + ' ' + cls.ARCH + ' ' +
+ cls.VER + ' ' + cls.URL + ' ' +
+ cls.MD5HASH + ' ' + cls.HYPER + ' ' +
+ opts)
+
+ # Get agent id because agent can only be deleted by ID
+ output_list = raw_output.split('\n', 1)
+ cls.ID = output_list[0]
+
+ cls.assertOutput(cls.MD5HASH + '\n', output_list[1])
+
+ @classmethod
+ def tearDownClass(cls):
+ raw_output = cls.openstack('compute agent delete ' + cls.ID)
+ cls.assertOutput('', raw_output)
+
+ def test_agent_list(self):
+ raw_output = self.openstack('compute agent list')
+ self.assertIn(self.ID, raw_output)
+ self.assertIn(self.OS, raw_output)
+ self.assertIn(self.ARCH, raw_output)
+ self.assertIn(self.VER, raw_output)
+ self.assertIn(self.URL, raw_output)
+ self.assertIn(self.MD5HASH, raw_output)
+ self.assertIn(self.HYPER, raw_output)
+
+ def test_agent_set(self):
+ ver = 'v2'
+ url = "http://openstack"
+ md5hash = hashlib.md5().hexdigest()
+
+ self.openstack('compute agent set '
+ + self.ID
+ + ' --agent-version ' + ver
+ + ' --url ' + url
+ + ' --md5hash ' + md5hash)
+
+ raw_output = self.openstack('compute agent list')
+ self.assertIn(self.ID, raw_output)
+ self.assertIn(ver, raw_output)
+ self.assertIn(url, raw_output)
+ self.assertIn(md5hash, raw_output)
diff --git a/openstackclient/tests/functional/compute/v2/test_aggregate.py b/openstackclient/tests/functional/compute/v2/test_aggregate.py
new file mode 100644
index 00000000..2bc88e7b
--- /dev/null
+++ b/openstackclient/tests/functional/compute/v2/test_aggregate.py
@@ -0,0 +1,67 @@
+# 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
+
+from openstackclient.tests.functional import base
+
+
+class AggregateTests(base.TestCase):
+ """Functional tests for aggregate."""
+
+ NAME = uuid.uuid4().hex
+ HEADERS = ['Name']
+ FIELDS = ['name']
+
+ @classmethod
+ def setUpClass(cls):
+ opts = cls.get_opts(cls.FIELDS)
+ # Use the default 'nova' availability zone for the aggregate.
+ raw_output = cls.openstack(
+ 'aggregate create --zone nova ' + cls.NAME + opts
+ )
+ expected = cls.NAME + '\n'
+ cls.assertOutput(expected, raw_output)
+
+ @classmethod
+ def tearDownClass(cls):
+ raw_output = cls.openstack('aggregate delete ' + cls.NAME)
+ cls.assertOutput('', raw_output)
+
+ def test_aggregate_list(self):
+ opts = self.get_opts(self.HEADERS)
+ raw_output = self.openstack('aggregate list' + opts)
+ self.assertIn(self.NAME, raw_output)
+
+ def test_aggregate_show(self):
+ opts = self.get_opts(self.FIELDS)
+ raw_output = self.openstack('aggregate show ' + self.NAME + opts)
+ self.assertEqual(self.NAME + "\n", raw_output)
+
+ def test_aggregate_properties(self):
+ opts = self.get_opts(['properties'])
+
+ raw_output = self.openstack(
+ 'aggregate set --property a=b --property c=d ' + self.NAME
+ )
+ self.assertEqual('', raw_output)
+
+ raw_output = self.openstack('aggregate show ' + self.NAME + opts)
+ self.assertIn("a='b', c='d'\n", raw_output)
+
+ raw_output = self.openstack(
+ 'aggregate unset --property a ' + self.NAME
+ )
+ self.assertEqual('', raw_output)
+
+ raw_output = self.openstack('aggregate show ' + self.NAME + opts)
+ self.assertIn("c='d'\n", raw_output)
diff --git a/openstackclient/tests/functional/compute/v2/test_flavor.py b/openstackclient/tests/functional/compute/v2/test_flavor.py
new file mode 100644
index 00000000..794a6cc3
--- /dev/null
+++ b/openstackclient/tests/functional/compute/v2/test_flavor.py
@@ -0,0 +1,69 @@
+# 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
+
+from openstackclient.tests.functional import base
+
+
+class FlavorTests(base.TestCase):
+ """Functional tests for flavor."""
+
+ NAME = uuid.uuid4().hex
+ HEADERS = ['Name']
+ FIELDS = ['name']
+
+ @classmethod
+ def setUpClass(cls):
+ opts = cls.get_opts(cls.FIELDS)
+ raw_output = cls.openstack(
+ 'flavor create --property a=b --property c=d ' + cls.NAME + opts)
+ expected = cls.NAME + '\n'
+ cls.assertOutput(expected, raw_output)
+
+ @classmethod
+ def tearDownClass(cls):
+ raw_output = cls.openstack('flavor delete ' + cls.NAME)
+ cls.assertOutput('', raw_output)
+
+ def test_flavor_list(self):
+ opts = self.get_opts(self.HEADERS)
+ raw_output = self.openstack('flavor list' + opts)
+ self.assertIn("small", raw_output)
+ self.assertIn(self.NAME, raw_output)
+
+ def test_flavor_show(self):
+ opts = self.get_opts(self.FIELDS)
+ raw_output = self.openstack('flavor show ' + self.NAME + opts)
+ self.assertEqual(self.NAME + "\n", raw_output)
+
+ def test_flavor_properties(self):
+ opts = self.get_opts(['properties'])
+ # check the properties we added in create command.
+ raw_output = self.openstack('flavor show ' + self.NAME + opts)
+ self.assertEqual("a='b', c='d'\n", raw_output)
+
+ raw_output = self.openstack(
+ 'flavor set --property e=f --property g=h ' + self.NAME
+ )
+ self.assertEqual('', raw_output)
+
+ raw_output = self.openstack('flavor show ' + self.NAME + opts)
+ self.assertEqual("a='b', c='d', e='f', g='h'\n", raw_output)
+
+ raw_output = self.openstack(
+ 'flavor unset --property a --property c ' + self.NAME
+ )
+ self.assertEqual('', raw_output)
+
+ raw_output = self.openstack('flavor show ' + self.NAME + opts)
+ self.assertEqual("e='f', g='h'\n", raw_output)
diff --git a/openstackclient/tests/functional/compute/v2/test_keypair.py b/openstackclient/tests/functional/compute/v2/test_keypair.py
new file mode 100644
index 00000000..01078c61
--- /dev/null
+++ b/openstackclient/tests/functional/compute/v2/test_keypair.py
@@ -0,0 +1,168 @@
+# 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 tempfile
+
+from openstackclient.tests.functional import base
+
+from tempest.lib.common.utils import data_utils
+from tempest.lib import exceptions
+
+
+class KeypairBase(base.TestCase):
+ """Methods for functional tests."""
+
+ def keypair_create(self, name=data_utils.rand_uuid()):
+ """Create keypair and add cleanup."""
+ raw_output = self.openstack('keypair create ' + name)
+ self.addCleanup(self.keypair_delete, name, True)
+ if not raw_output:
+ self.fail('Keypair has not been created!')
+
+ def keypair_list(self, params=''):
+ """Return dictionary with list of keypairs."""
+ raw_output = self.openstack('keypair list')
+ keypairs = self.parse_show_as_object(raw_output)
+ return keypairs
+
+ def keypair_delete(self, name, ignore_exceptions=False):
+ """Try to delete keypair by name."""
+ try:
+ self.openstack('keypair delete ' + name)
+ except exceptions.CommandFailed:
+ if not ignore_exceptions:
+ raise
+
+
+class KeypairTests(KeypairBase):
+ """Functional tests for compute keypairs."""
+
+ PUBLIC_KEY = (
+ 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDWNGczJxNaFUrJJVhta4dWsZY6bU'
+ '5HUMPbyfSMu713ca3mYtG848W4dfDCB98KmSQx2Bl0D6Q2nrOszOXEQWAXNdfMadnW'
+ 'c4mNwhZcPBVohIFoC1KZJC8kcBTvFZcoz3mdIijxJtywZNpGNh34VRJlZeHyYjg8/D'
+ 'esHzdoBVd5c/4R36emQSIV9ukY6PHeZ3scAH4B3K9PxItJBwiFtouSRphQG0bJgOv/'
+ 'gjAjMElAvg5oku98cb4QiHZ8T8WY68id804raHR6pJxpVVJN4TYJmlUs+NOVM+pPKb'
+ 'KJttqrIBTkawGK9pLHNfn7z6v1syvUo/4enc1l0Q/Qn2kWiz67 fake@openstack'
+ )
+
+ def setUp(self):
+ """Create keypair with randomized name for tests."""
+ super(KeypairTests, self).setUp()
+ self.KPName = data_utils.rand_name('TestKeyPair')
+ self.keypair = self.keypair_create(self.KPName)
+
+ def test_keypair_create_duplicate(self):
+ """Try to create duplicate name keypair.
+
+ Test steps:
+ 1) Create keypair in setUp
+ 2) Try to create duplicate keypair with the same name
+ """
+ self.assertRaises(exceptions.CommandFailed,
+ self.openstack, 'keypair create ' + self.KPName)
+
+ def test_keypair_create_noname(self):
+ """Try to create keypair without name.
+
+ Test steps:
+ 1) Try to create keypair without a name
+ """
+ self.assertRaises(exceptions.CommandFailed,
+ self.openstack, 'keypair create')
+
+ def test_keypair_create_public_key(self):
+ """Test for create keypair with --public-key option.
+
+ Test steps:
+ 1) Create keypair with given public key
+ 2) Delete keypair
+ """
+ with tempfile.NamedTemporaryFile() as f:
+ f.write(self.PUBLIC_KEY)
+ f.flush()
+
+ raw_output = self.openstack(
+ 'keypair create --public-key %s tmpkey' % f.name,
+ )
+ self.addCleanup(
+ self.openstack,
+ 'keypair delete tmpkey',
+ )
+ self.assertIn('tmpkey', raw_output)
+
+ def test_keypair_create(self):
+ """Test keypair create command.
+
+ Test steps:
+ 1) Create keypair in setUp
+ 2) Check RSA private key in output
+ 3) Check for new keypair in keypairs list
+ """
+ NewName = data_utils.rand_name('TestKeyPairCreated')
+ raw_output = self.openstack('keypair create ' + NewName)
+ self.addCleanup(self.openstack, 'keypair delete ' + NewName)
+ self.assertInOutput('-----BEGIN RSA PRIVATE KEY-----', raw_output)
+ self.assertRegex(raw_output, "[0-9A-Za-z+/]+[=]{0,3}\n")
+ self.assertInOutput('-----END RSA PRIVATE KEY-----', raw_output)
+ self.assertIn(NewName, self.keypair_list())
+
+ def test_keypair_delete_not_existing(self):
+ """Try to delete keypair with not existing name.
+
+ Test steps:
+ 1) Create keypair in setUp
+ 2) Try to delete not existing keypair
+ """
+ self.assertRaises(exceptions.CommandFailed,
+ self.openstack, 'keypair delete not_existing')
+
+ def test_keypair_delete(self):
+ """Test keypair delete command.
+
+ Test steps:
+ 1) Create keypair in setUp
+ 2) Delete keypair
+ 3) Check that keypair not in keypairs list
+ """
+ self.openstack('keypair delete ' + self.KPName)
+ self.assertNotIn(self.KPName, self.keypair_list())
+
+ def test_keypair_list(self):
+ """Test keypair list command.
+
+ Test steps:
+ 1) Create keypair in setUp
+ 2) List keypairs
+ 3) Check output table structure
+ 4) Check keypair name in output
+ """
+ HEADERS = ['Name', 'Fingerprint']
+ raw_output = self.openstack('keypair list')
+ items = self.parse_listing(raw_output)
+ self.assert_table_structure(items, HEADERS)
+ self.assertIn(self.KPName, raw_output)
+
+ def test_keypair_show(self):
+ """Test keypair show command.
+
+ Test steps:
+ 1) Create keypair in setUp
+ 2) Show keypair
+ 3) Check output table structure
+ 4) Check keypair name in output
+ """
+ HEADERS = ['Field', 'Value']
+ raw_output = self.openstack('keypair show ' + self.KPName)
+ items = self.parse_listing(raw_output)
+ self.assert_table_structure(items, HEADERS)
+ self.assertInOutput(self.KPName, raw_output)
diff --git a/openstackclient/tests/functional/compute/v2/test_server.py b/openstackclient/tests/functional/compute/v2/test_server.py
new file mode 100644
index 00000000..6eedf408
--- /dev/null
+++ b/openstackclient/tests/functional/compute/v2/test_server.py
@@ -0,0 +1,308 @@
+# 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 time
+
+from tempest.lib.common.utils import data_utils
+
+from openstackclient.tests.functional import base
+from tempest.lib import exceptions
+
+
+class ServerTests(base.TestCase):
+ """Functional tests for openstack server commands."""
+
+ @classmethod
+ def get_flavor(cls):
+ # NOTE(rtheis): Get cirros256 or m1.tiny flavors since functional
+ # tests may create other flavors.
+ flavors = cls.openstack('flavor list -c Name -f value').split('\n')
+ server_flavor = None
+ for flavor in flavors:
+ if flavor in ['m1.tiny', 'cirros256']:
+ server_flavor = flavor
+ break
+ return server_flavor
+
+ @classmethod
+ def get_image(cls):
+ # NOTE(rtheis): Get cirros image since functional tests may
+ # create other images.
+ images = cls.openstack('image list -c Name -f value').split('\n')
+ server_image = None
+ for image in images:
+ if image.startswith('cirros-') and image.endswith('-uec'):
+ server_image = image
+ break
+ return server_image
+
+ @classmethod
+ def get_network(cls):
+ try:
+ # NOTE(rtheis): Get private network since functional tests may
+ # create other networks.
+ raw_output = cls.openstack('network show private -c id -f value')
+ except exceptions.CommandFailed:
+ return ''
+ return ' --nic net-id=' + raw_output.strip('\n')
+
+ def server_create(self, name=None):
+ """Create server. Add cleanup."""
+ name = name or data_utils.rand_uuid()
+ opts = self.get_opts(self.FIELDS)
+ flavor = self.get_flavor()
+ image = self.get_image()
+ network = self.get_network()
+ raw_output = self.openstack('--debug server create --flavor ' +
+ flavor +
+ ' --image ' + image + network + ' ' +
+ name + opts)
+ if not raw_output:
+ self.fail('Server has not been created!')
+ self.addCleanup(self.server_delete, name)
+
+ def server_list(self, params=[]):
+ """List servers."""
+ opts = self.get_opts(params)
+ return self.openstack('server list' + opts)
+
+ def server_delete(self, name):
+ """Delete server by name."""
+ self.openstack('server delete ' + name)
+
+ def setUp(self):
+ """Set necessary variables and create server."""
+ super(ServerTests, self).setUp()
+ self.NAME = data_utils.rand_name('TestServer')
+ self.OTHER_NAME = data_utils.rand_name('TestServer')
+ self.HEADERS = ['"Name"']
+ self.FIELDS = ['name']
+ self.IP_POOL = 'public'
+ self.server_create(self.NAME)
+
+ def test_server_rename(self):
+ """Test server rename command.
+
+ Test steps:
+ 1) Boot server in setUp
+ 2) Rename server
+ 3) Check output
+ 4) Rename server back to original name
+ """
+ raw_output = self.openstack('server set --name ' + self.OTHER_NAME +
+ ' ' + self.NAME)
+ self.assertOutput("", raw_output)
+ self.assertNotIn(self.NAME, self.server_list(['Name']))
+ self.assertIn(self.OTHER_NAME, self.server_list(['Name']))
+ self.openstack('server set --name ' + self.NAME + ' ' +
+ self.OTHER_NAME)
+
+ def test_server_list(self):
+ """Test server list command.
+
+ Test steps:
+ 1) Boot server in setUp
+ 2) List servers
+ 3) Check output
+ """
+ opts = self.get_opts(self.HEADERS)
+ raw_output = self.openstack('server list' + opts)
+ self.assertIn(self.NAME, raw_output)
+
+ def test_server_show(self):
+ """Test server show command.
+
+ Test steps:
+ 1) Boot server in setUp
+ 2) Show server
+ 3) Check output
+ """
+ opts = self.get_opts(self.FIELDS)
+ raw_output = self.openstack('server show ' + self.NAME + opts)
+ self.assertEqual(self.NAME + "\n", raw_output)
+
+ def test_server_metadata(self):
+ """Test command to set server metadata.
+
+ Test steps:
+ 1) Boot server in setUp
+ 2) Set properties for server
+ 3) Check server properties in server show output
+ 4) Unset properties for server
+ 5) Check server properties in server show output
+ """
+ self.wait_for_status("ACTIVE")
+ # metadata
+ raw_output = self.openstack(
+ 'server set --property a=b --property c=d ' + self.NAME)
+ opts = self.get_opts(["name", "properties"])
+ raw_output = self.openstack('server show ' + self.NAME + opts)
+ self.assertEqual(self.NAME + "\na='b', c='d'\n", raw_output)
+
+ raw_output = self.openstack(
+ 'server unset --property a ' + self.NAME)
+ opts = self.get_opts(["name", "properties"])
+ raw_output = self.openstack('server show ' + self.NAME + opts)
+ self.assertEqual(self.NAME + "\nc='d'\n", raw_output)
+
+ def test_server_suspend_resume(self):
+ """Test server suspend and resume commands.
+
+ Test steps:
+ 1) Boot server in setUp
+ 2) Suspend server
+ 3) Check for SUSPENDED server status
+ 4) Resume server
+ 5) Check for ACTIVE server status
+ """
+ self.wait_for_status("ACTIVE")
+ # suspend
+ raw_output = self.openstack('server suspend ' + self.NAME)
+ self.assertEqual("", raw_output)
+ self.wait_for_status("SUSPENDED")
+ # resume
+ raw_output = self.openstack('server resume ' + self.NAME)
+ self.assertEqual("", raw_output)
+ self.wait_for_status("ACTIVE")
+
+ def test_server_lock_unlock(self):
+ """Test server lock and unlock commands.
+
+ Test steps:
+ 1) Boot server in setUp
+ 2) Lock server
+ 3) Check output
+ 4) Unlock server
+ 5) Check output
+ """
+ self.wait_for_status("ACTIVE")
+ # lock
+ raw_output = self.openstack('server lock ' + self.NAME)
+ self.assertEqual("", raw_output)
+ # unlock
+ raw_output = self.openstack('server unlock ' + self.NAME)
+ self.assertEqual("", raw_output)
+
+ def test_server_pause_unpause(self):
+ """Test server pause and unpause commands.
+
+ Test steps:
+ 1) Boot server in setUp
+ 2) Pause server
+ 3) Check for PAUSED server status
+ 4) Unpause server
+ 5) Check for ACTIVE server status
+ """
+ self.wait_for_status("ACTIVE")
+ # pause
+ raw_output = self.openstack('server pause ' + self.NAME)
+ self.assertEqual("", raw_output)
+ self.wait_for_status("PAUSED")
+ # unpause
+ raw_output = self.openstack('server unpause ' + self.NAME)
+ self.assertEqual("", raw_output)
+ self.wait_for_status("ACTIVE")
+
+ def test_server_rescue_unrescue(self):
+ """Test server rescue and unrescue commands.
+
+ Test steps:
+ 1) Boot server in setUp
+ 2) Rescue server
+ 3) Check for RESCUE server status
+ 4) Unrescue server
+ 5) Check for ACTIVE server status
+ """
+ self.wait_for_status("ACTIVE")
+ # rescue
+ opts = self.get_opts(["adminPass"])
+ raw_output = self.openstack('server rescue ' + self.NAME + opts)
+ self.assertNotEqual("", raw_output)
+ self.wait_for_status("RESCUE")
+ # unrescue
+ raw_output = self.openstack('server unrescue ' + self.NAME)
+ self.assertEqual("", raw_output)
+ self.wait_for_status("ACTIVE")
+
+ def test_server_attach_detach_floating_ip(self):
+ """Test commands to attach and detach floating IP for server.
+
+ Test steps:
+ 1) Boot server in setUp
+ 2) Create floating IP
+ 3) Add floating IP to server
+ 4) Check for floating IP in server show output
+ 5) Remove floating IP from server
+ 6) Check that floating IP is not in server show output
+ 7) Delete floating IP
+ 8) Check output
+ """
+ self.wait_for_status("ACTIVE")
+ # attach ip
+ opts = self.get_opts(["id", "floating_ip_address"])
+ raw_output = self.openstack('floating ip create ' +
+ self.IP_POOL +
+ opts)
+ ip, ipid, rol = tuple(raw_output.split('\n'))
+ self.assertNotEqual("", ipid)
+ self.assertNotEqual("", ip)
+ raw_output = self.openstack('server add floating ip ' + self.NAME +
+ ' ' + ip)
+ self.assertEqual("", raw_output)
+ raw_output = self.openstack('server show ' + self.NAME)
+ self.assertIn(ip, raw_output)
+
+ # detach ip
+ raw_output = self.openstack('server remove floating ip ' + self.NAME +
+ ' ' + ip)
+ self.assertEqual("", raw_output)
+ raw_output = self.openstack('server show ' + self.NAME)
+ self.assertNotIn(ip, raw_output)
+ raw_output = self.openstack('floating ip delete ' + ipid)
+ self.assertEqual("", raw_output)
+
+ def test_server_reboot(self):
+ """Test server reboot command.
+
+ Test steps:
+ 1) Boot server in setUp
+ 2) Reboot server
+ 3) Check for ACTIVE server status
+ """
+ self.wait_for_status("ACTIVE")
+ # reboot
+ raw_output = self.openstack('server reboot ' + self.NAME)
+ self.assertEqual("", raw_output)
+ self.wait_for_status("ACTIVE")
+
+ def wait_for_status(self, expected_status='ACTIVE', wait=900, interval=30):
+ """Wait until server reaches expected status."""
+ # TODO(thowe): Add a server wait command to osc
+ failures = ['ERROR']
+ total_sleep = 0
+ opts = self.get_opts(['status'])
+ while total_sleep < wait:
+ status = self.openstack('server show ' + self.NAME + opts)
+ status = status.rstrip()
+ print('Waiting for {} current status: {}'.format(expected_status,
+ status))
+ if status == expected_status:
+ break
+ self.assertNotIn(status, failures)
+ time.sleep(interval)
+ total_sleep += interval
+
+ status = self.openstack('server show ' + self.NAME + opts)
+ status = status.rstrip()
+ self.assertEqual(status, expected_status)
+ # give it a little bit more time
+ time.sleep(5)
diff --git a/openstackclient/tests/functional/compute/v2/test_server_group.py b/openstackclient/tests/functional/compute/v2/test_server_group.py
new file mode 100644
index 00000000..3f0a24e5
--- /dev/null
+++ b/openstackclient/tests/functional/compute/v2/test_server_group.py
@@ -0,0 +1,46 @@
+# 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
+
+from openstackclient.tests.functional import base
+
+
+class ServerGroupTests(base.TestCase):
+ """Functional tests for servergroup."""
+
+ NAME = uuid.uuid4().hex
+ HEADERS = ['Name']
+ FIELDS = ['name']
+
+ @classmethod
+ def setUpClass(cls):
+ opts = cls.get_opts(cls.FIELDS)
+ raw_output = cls.openstack('server group create --policy affinity ' +
+ cls.NAME + opts)
+ expected = cls.NAME + '\n'
+ cls.assertOutput(expected, raw_output)
+
+ @classmethod
+ def tearDownClass(cls):
+ raw_output = cls.openstack('server group delete ' + cls.NAME)
+ cls.assertOutput('', raw_output)
+
+ def test_server_group_list(self):
+ opts = self.get_opts(self.HEADERS)
+ raw_output = self.openstack('server group list' + opts)
+ self.assertIn(self.NAME, raw_output)
+
+ def test_server_group_show(self):
+ opts = self.get_opts(self.FIELDS)
+ raw_output = self.openstack('server group show ' + self.NAME + opts)
+ self.assertEqual(self.NAME + "\n", raw_output)