Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2012 OpenStack, LLC |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 18 | from tempest.common.utils.data_utils import rand_name |
Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 19 | from tempest.openstack.common import log as logging |
Sean Dague | 6dbc6da | 2013-05-08 17:49:46 -0400 | [diff] [blame] | 20 | from tempest.scenario import manager |
Matthew Treinish | 2153ec0 | 2013-09-09 20:57:30 +0000 | [diff] [blame] | 21 | from tempest.test import services |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 22 | |
| 23 | LOG = logging.getLogger(__name__) |
| 24 | |
| 25 | |
Sean Dague | 6dbc6da | 2013-05-08 17:49:46 -0400 | [diff] [blame] | 26 | class TestServerAdvancedOps(manager.OfficialClientTest): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 27 | |
| 28 | """ |
| 29 | This test case stresses some advanced server instance operations: |
| 30 | |
| 31 | * Resizing an instance |
Tatyana Leontovich | 58ab531 | 2013-04-22 16:48:33 +0300 | [diff] [blame] | 32 | * Sequence suspend resume |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 33 | """ |
| 34 | |
| 35 | @classmethod |
| 36 | def setUpClass(cls): |
| 37 | super(TestServerAdvancedOps, cls).setUpClass() |
| 38 | |
| 39 | if not cls.config.compute.resize_available: |
| 40 | msg = "Skipping test - resize not available on this host" |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 41 | raise cls.skipException(msg) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 42 | |
| 43 | resize_flavor = cls.config.compute.flavor_ref_alt |
| 44 | |
| 45 | if resize_flavor == cls.config.compute.flavor_ref: |
| 46 | msg = "Skipping test - flavor_ref and flavor_ref_alt are identical" |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 47 | raise cls.skipException(msg) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 48 | |
Matthew Treinish | 2153ec0 | 2013-09-09 20:57:30 +0000 | [diff] [blame] | 49 | @services('compute') |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 50 | def test_resize_server_confirm(self): |
| 51 | # We create an instance for use in this test |
| 52 | i_name = rand_name('instance') |
| 53 | flavor_id = self.config.compute.flavor_ref |
| 54 | base_image_id = self.config.compute.image_ref |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 55 | self.instance = self.compute_client.servers.create( |
Sean Dague | 14c6818 | 2013-04-14 15:34:30 -0400 | [diff] [blame] | 56 | i_name, base_image_id, flavor_id) |
Tatyana Leontovich | 58ab531 | 2013-04-22 16:48:33 +0300 | [diff] [blame] | 57 | self.assertEqual(self.instance.name, i_name) |
| 58 | self.set_resource('instance', self.instance) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 59 | self.assertEqual(self.instance.status, 'BUILD') |
| 60 | instance_id = self.get_resource('instance').id |
Sean Dague | 35a7caf | 2013-05-10 10:38:22 -0400 | [diff] [blame] | 61 | self.status_timeout( |
| 62 | self.compute_client.servers, instance_id, 'ACTIVE') |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 63 | instance = self.get_resource('instance') |
| 64 | instance_id = instance.id |
| 65 | resize_flavor = self.config.compute.flavor_ref_alt |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 66 | LOG.debug("Resizing instance %s from flavor %s to flavor %s", |
| 67 | instance.id, instance.flavor, resize_flavor) |
| 68 | instance.resize(resize_flavor) |
Sean Dague | 35a7caf | 2013-05-10 10:38:22 -0400 | [diff] [blame] | 69 | self.status_timeout(self.compute_client.servers, instance_id, |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 70 | 'VERIFY_RESIZE') |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 71 | |
| 72 | LOG.debug("Confirming resize of instance %s", instance_id) |
| 73 | instance.confirm_resize() |
Tatyana Leontovich | 58ab531 | 2013-04-22 16:48:33 +0300 | [diff] [blame] | 74 | |
Sean Dague | 35a7caf | 2013-05-10 10:38:22 -0400 | [diff] [blame] | 75 | self.status_timeout( |
| 76 | self.compute_client.servers, instance_id, 'ACTIVE') |
Tatyana Leontovich | 58ab531 | 2013-04-22 16:48:33 +0300 | [diff] [blame] | 77 | |
Matthew Treinish | 2153ec0 | 2013-09-09 20:57:30 +0000 | [diff] [blame] | 78 | @services('compute') |
Tatyana Leontovich | 58ab531 | 2013-04-22 16:48:33 +0300 | [diff] [blame] | 79 | def test_server_sequence_suspend_resume(self): |
| 80 | # We create an instance for use in this test |
| 81 | i_name = rand_name('instance') |
| 82 | flavor_id = self.config.compute.flavor_ref |
| 83 | base_image_id = self.config.compute.image_ref |
| 84 | self.instance = self.compute_client.servers.create( |
| 85 | i_name, base_image_id, flavor_id) |
| 86 | self.assertEqual(self.instance.name, i_name) |
| 87 | self.set_resource('instance', self.instance) |
| 88 | self.assertEqual(self.instance.status, 'BUILD') |
| 89 | instance_id = self.get_resource('instance').id |
| 90 | self.status_timeout( |
| 91 | self.compute_client.servers, instance_id, 'ACTIVE') |
| 92 | instance = self.get_resource('instance') |
| 93 | instance_id = instance.id |
| 94 | LOG.debug("Suspending instance %s. Current status: %s", |
| 95 | instance_id, instance.status) |
| 96 | instance.suspend() |
| 97 | self.status_timeout(self.compute_client.servers, instance_id, |
| 98 | 'SUSPENDED') |
| 99 | LOG.debug("Resuming instance %s. Current status: %s", |
| 100 | instance_id, instance.status) |
| 101 | instance.resume() |
| 102 | self.status_timeout(self.compute_client.servers, instance_id, |
| 103 | 'ACTIVE') |
| 104 | LOG.debug("Suspending instance %s. Current status: %s", |
| 105 | instance_id, instance.status) |
| 106 | instance.suspend() |
| 107 | self.status_timeout(self.compute_client.servers, instance_id, |
| 108 | 'SUSPENDED') |
| 109 | LOG.debug("Resuming instance %s. Current status: %s", |
| 110 | instance_id, instance.status) |
| 111 | instance.resume() |
| 112 | self.status_timeout(self.compute_client.servers, instance_id, |
| 113 | 'ACTIVE') |