blob: cf72cd444deca16a7fd2cc9107fb823216fcf68b [file] [log] [blame]
Jay Pipes051075a2012-04-28 17:39:37 -04001# 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 Pipes051075a2012-04-28 17:39:37 -040018from tempest.common.utils.data_utils import rand_name
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040019from tempest.openstack.common import log as logging
Sean Dague6dbc6da2013-05-08 17:49:46 -040020from tempest.scenario import manager
Matthew Treinish2153ec02013-09-09 20:57:30 +000021from tempest.test import services
Jay Pipes051075a2012-04-28 17:39:37 -040022
23LOG = logging.getLogger(__name__)
24
25
Sean Dague6dbc6da2013-05-08 17:49:46 -040026class TestServerAdvancedOps(manager.OfficialClientTest):
Jay Pipes051075a2012-04-28 17:39:37 -040027
28 """
29 This test case stresses some advanced server instance operations:
30
31 * Resizing an instance
Tatyana Leontovich58ab5312013-04-22 16:48:33 +030032 * Sequence suspend resume
Jay Pipes051075a2012-04-28 17:39:37 -040033 """
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-zhu1feeb382013-01-24 10:14:39 +080041 raise cls.skipException(msg)
Jay Pipes051075a2012-04-28 17:39:37 -040042
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-zhu1feeb382013-01-24 10:14:39 +080047 raise cls.skipException(msg)
Jay Pipes051075a2012-04-28 17:39:37 -040048
Matthew Treinish2153ec02013-09-09 20:57:30 +000049 @services('compute')
Jay Pipes051075a2012-04-28 17:39:37 -040050 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 Newbydec13ec2012-08-30 11:19:17 -070055 self.instance = self.compute_client.servers.create(
Sean Dague14c68182013-04-14 15:34:30 -040056 i_name, base_image_id, flavor_id)
Tatyana Leontovich58ab5312013-04-22 16:48:33 +030057 self.assertEqual(self.instance.name, i_name)
58 self.set_resource('instance', self.instance)
Jay Pipes051075a2012-04-28 17:39:37 -040059 self.assertEqual(self.instance.status, 'BUILD')
60 instance_id = self.get_resource('instance').id
Sean Dague35a7caf2013-05-10 10:38:22 -040061 self.status_timeout(
62 self.compute_client.servers, instance_id, 'ACTIVE')
Jay Pipes051075a2012-04-28 17:39:37 -040063 instance = self.get_resource('instance')
64 instance_id = instance.id
65 resize_flavor = self.config.compute.flavor_ref_alt
Jay Pipes051075a2012-04-28 17:39:37 -040066 LOG.debug("Resizing instance %s from flavor %s to flavor %s",
67 instance.id, instance.flavor, resize_flavor)
68 instance.resize(resize_flavor)
Sean Dague35a7caf2013-05-10 10:38:22 -040069 self.status_timeout(self.compute_client.servers, instance_id,
Maru Newbydec13ec2012-08-30 11:19:17 -070070 'VERIFY_RESIZE')
Jay Pipes051075a2012-04-28 17:39:37 -040071
72 LOG.debug("Confirming resize of instance %s", instance_id)
73 instance.confirm_resize()
Tatyana Leontovich58ab5312013-04-22 16:48:33 +030074
Sean Dague35a7caf2013-05-10 10:38:22 -040075 self.status_timeout(
76 self.compute_client.servers, instance_id, 'ACTIVE')
Tatyana Leontovich58ab5312013-04-22 16:48:33 +030077
Matthew Treinish2153ec02013-09-09 20:57:30 +000078 @services('compute')
Tatyana Leontovich58ab5312013-04-22 16:48:33 +030079 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')