blob: d369f12576966d3e2203cacab484ef8953bc3525 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes051075a2012-04-28 17:39:37 -04002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Masayuki Igawa259c1132013-10-31 17:48:44 +090016from tempest.common.utils import data_utils
Andrea Frittolif5da28b2013-12-06 07:08:07 +000017from tempest.common.utils import test_utils
Matthew Treinish6c072292014-01-29 19:15:52 +000018from tempest import config
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
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090021from tempest import test
Jay Pipes051075a2012-04-28 17:39:37 -040022
Andrea Frittolif5da28b2013-12-06 07:08:07 +000023import testscenarios
24
Matthew Treinish6c072292014-01-29 19:15:52 +000025CONF = config.CONF
26
Jay Pipes051075a2012-04-28 17:39:37 -040027LOG = logging.getLogger(__name__)
28
Andrea Frittolif5da28b2013-12-06 07:08:07 +000029load_tests = testscenarios.load_tests_apply_scenarios
30
Jay Pipes051075a2012-04-28 17:39:37 -040031
Sean Dague6dbc6da2013-05-08 17:49:46 -040032class TestServerBasicOps(manager.OfficialClientTest):
Jay Pipes051075a2012-04-28 17:39:37 -040033
34 """
35 This smoke test case follows this basic set of operations:
36
37 * Create a keypair for use in launching an instance
38 * Create a security group to control network access in instance
39 * Add simple permissive rules to the security group
40 * Launch an instance
41 * Pause/unpause the instance
42 * Suspend/resume the instance
43 * Terminate the instance
44 """
45
Andrea Frittolif5da28b2013-12-06 07:08:07 +000046 scenario_utils = test_utils.InputScenarioUtils()
47 scenario_flavor = scenario_utils.scenario_flavors
48 scenario_image = scenario_utils.scenario_images
49
50 scenarios = testscenarios.multiply_scenarios(scenario_image,
51 scenario_flavor)
52
53 def setUp(self):
54 super(TestServerBasicOps, self).setUp()
55 # Setup image and flavor the test instance
56 # Support both configured and injected values
57 if not hasattr(self, 'image_ref'):
Matthew Treinish6c072292014-01-29 19:15:52 +000058 self.image_ref = CONF.compute.image_ref
Andrea Frittolif5da28b2013-12-06 07:08:07 +000059 if not hasattr(self, 'flavor_ref'):
Matthew Treinish6c072292014-01-29 19:15:52 +000060 self.flavor_ref = CONF.compute.flavor_ref
Andrea Frittolif5da28b2013-12-06 07:08:07 +000061 self.image_utils = test_utils.ImageUtils()
62 if not self.image_utils.is_flavor_enough(self.flavor_ref,
63 self.image_ref):
64 raise self.skipException(
65 '{image} does not fit in {flavor}'.format(
66 image=self.image_ref, flavor=self.flavor_ref
67 )
68 )
Matthew Treinish6c072292014-01-29 19:15:52 +000069 self.run_ssh = CONF.compute.run_ssh and \
Andrea Frittolif5da28b2013-12-06 07:08:07 +000070 self.image_utils.is_sshable_image(self.image_ref)
71 self.ssh_user = self.image_utils.ssh_user(self.image_ref)
72 LOG.debug('Starting test for i:{image}, f:{flavor}. '
73 'Run ssh: {ssh}, user: {ssh_user}'.format(
74 image=self.image_ref, flavor=self.flavor_ref,
75 ssh=self.run_ssh, ssh_user=self.ssh_user))
76
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +090077 def add_keypair(self):
78 self.keypair = self.create_keypair()
Jay Pipes051075a2012-04-28 17:39:37 -040079
ivan-zhu19977392013-01-12 21:57:55 +080080 def create_security_group(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +090081 sg_name = data_utils.rand_name('secgroup-smoke')
Jay Pipes051075a2012-04-28 17:39:37 -040082 sg_desc = sg_name + " description"
Maru Newbydec13ec2012-08-30 11:19:17 -070083 self.secgroup = self.compute_client.security_groups.create(sg_name,
84 sg_desc)
Giulio Fidente92f77192013-08-26 17:13:28 +020085 self.assertEqual(self.secgroup.name, sg_name)
86 self.assertEqual(self.secgroup.description, sg_desc)
87 self.set_resource('secgroup', self.secgroup)
Jay Pipes051075a2012-04-28 17:39:37 -040088
89 # Add rules to the security group
Yair Friedeb69f3f2013-10-10 13:18:16 +030090 self._create_loginable_secgroup_rule_nova(secgroup_id=self.secgroup.id)
Jay Pipes051075a2012-04-28 17:39:37 -040091
ivan-zhu19977392013-01-12 21:57:55 +080092 def boot_instance(self):
Andrea Frittolif5da28b2013-12-06 07:08:07 +000093 # Create server with image and flavor from input scenario
Jay Pipes051075a2012-04-28 17:39:37 -040094 create_kwargs = {
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +090095 'key_name': self.keypair.id
Jay Pipes051075a2012-04-28 17:39:37 -040096 }
Andrea Frittolif5da28b2013-12-06 07:08:07 +000097 instance = self.create_server(image=self.image_ref,
98 flavor=self.flavor_ref,
99 create_kwargs=create_kwargs)
Ken'ichi Ohmichi61f272b2013-08-15 15:58:53 +0900100 self.set_resource('instance', instance)
Jay Pipes051075a2012-04-28 17:39:37 -0400101
ivan-zhu19977392013-01-12 21:57:55 +0800102 def pause_server(self):
Jay Pipes051075a2012-04-28 17:39:37 -0400103 instance = self.get_resource('instance')
104 instance_id = instance.id
105 LOG.debug("Pausing instance %s. Current status: %s",
106 instance_id, instance.status)
107 instance.pause()
Sean Dague35a7caf2013-05-10 10:38:22 -0400108 self.status_timeout(
109 self.compute_client.servers, instance_id, 'PAUSED')
Jay Pipes051075a2012-04-28 17:39:37 -0400110
ivan-zhu19977392013-01-12 21:57:55 +0800111 def unpause_server(self):
Jay Pipes051075a2012-04-28 17:39:37 -0400112 instance = self.get_resource('instance')
113 instance_id = instance.id
114 LOG.debug("Unpausing instance %s. Current status: %s",
115 instance_id, instance.status)
116 instance.unpause()
Sean Dague35a7caf2013-05-10 10:38:22 -0400117 self.status_timeout(
118 self.compute_client.servers, instance_id, 'ACTIVE')
Jay Pipes051075a2012-04-28 17:39:37 -0400119
ivan-zhu19977392013-01-12 21:57:55 +0800120 def suspend_server(self):
Jay Pipes051075a2012-04-28 17:39:37 -0400121 instance = self.get_resource('instance')
122 instance_id = instance.id
123 LOG.debug("Suspending instance %s. Current status: %s",
124 instance_id, instance.status)
125 instance.suspend()
Sean Dague35a7caf2013-05-10 10:38:22 -0400126 self.status_timeout(self.compute_client.servers,
Maru Newbydec13ec2012-08-30 11:19:17 -0700127 instance_id, 'SUSPENDED')
Jay Pipes051075a2012-04-28 17:39:37 -0400128
ivan-zhu19977392013-01-12 21:57:55 +0800129 def resume_server(self):
Jay Pipes051075a2012-04-28 17:39:37 -0400130 instance = self.get_resource('instance')
131 instance_id = instance.id
132 LOG.debug("Resuming instance %s. Current status: %s",
133 instance_id, instance.status)
134 instance.resume()
Sean Dague35a7caf2013-05-10 10:38:22 -0400135 self.status_timeout(
136 self.compute_client.servers, instance_id, 'ACTIVE')
Jay Pipes051075a2012-04-28 17:39:37 -0400137
ivan-zhu19977392013-01-12 21:57:55 +0800138 def terminate_instance(self):
Jay Pipes051075a2012-04-28 17:39:37 -0400139 instance = self.get_resource('instance')
140 instance.delete()
141 self.remove_resource('instance')
ivan-zhu19977392013-01-12 21:57:55 +0800142
Andrea Frittolif5da28b2013-12-06 07:08:07 +0000143 def verify_ssh(self):
144 if self.run_ssh:
145 # Obtain a floating IP
146 floating_ip = self.compute_client.floating_ips.create()
147 # Attach a floating IP
148 instance = self.get_resource('instance')
149 instance.add_floating_ip(floating_ip)
150 # Check ssh
Nachi Ueno95b41282014-01-15 06:54:21 -0800151 try:
152 self.get_remote_client(
153 server_or_ip=floating_ip.ip,
154 username=self.image_utils.ssh_user(self.image_ref),
155 private_key=self.keypair.private)
156 except Exception:
157 LOG.exception('ssh to server failed')
158 self._log_console_output()
159 raise
Andrea Frittolif5da28b2013-12-06 07:08:07 +0000160
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900161 @test.services('compute', 'network')
ivan-zhu19977392013-01-12 21:57:55 +0800162 def test_server_basicops(self):
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +0900163 self.add_keypair()
ivan-zhu19977392013-01-12 21:57:55 +0800164 self.create_security_group()
165 self.boot_instance()
ivan-zhu19977392013-01-12 21:57:55 +0800166 self.pause_server()
167 self.unpause_server()
168 self.suspend_server()
169 self.resume_server()
Andrea Frittolif5da28b2013-12-06 07:08:07 +0000170 self.verify_ssh()
ivan-zhu19977392013-01-12 21:57:55 +0800171 self.terminate_instance()