blob: ca3035d5ad131b186de2e50eb377473fc3d8fb63 [file] [log] [blame]
Jay Pipes051075a2012-04-28 17:39:37 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Jay Pipes051075a2012-04-28 17:39:37 -04004# 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
Masayuki Igawa259c1132013-10-31 17:48:44 +090018from tempest.common.utils import data_utils
Andrea Frittolif5da28b2013-12-06 07:08:07 +000019from tempest.common.utils import test_utils
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040020from tempest.openstack.common import log as logging
Sean Dague6dbc6da2013-05-08 17:49:46 -040021from tempest.scenario import manager
Matthew Treinish2153ec02013-09-09 20:57:30 +000022from tempest.test import services
Jay Pipes051075a2012-04-28 17:39:37 -040023
Andrea Frittolif5da28b2013-12-06 07:08:07 +000024import testscenarios
25
Jay Pipes051075a2012-04-28 17:39:37 -040026LOG = logging.getLogger(__name__)
27
Andrea Frittolif5da28b2013-12-06 07:08:07 +000028# NOTE(andreaf) - nose does not honour the load_tests protocol
29# however it's test discovery regex will match anything
30# which includes _tests. So nose would require some further
31# investigation to be supported with this
32load_tests = testscenarios.load_tests_apply_scenarios
33
Jay Pipes051075a2012-04-28 17:39:37 -040034
Sean Dague6dbc6da2013-05-08 17:49:46 -040035class TestServerBasicOps(manager.OfficialClientTest):
Jay Pipes051075a2012-04-28 17:39:37 -040036
37 """
38 This smoke test case follows this basic set of operations:
39
40 * Create a keypair for use in launching an instance
41 * Create a security group to control network access in instance
42 * Add simple permissive rules to the security group
43 * Launch an instance
44 * Pause/unpause the instance
45 * Suspend/resume the instance
46 * Terminate the instance
47 """
48
Andrea Frittolif5da28b2013-12-06 07:08:07 +000049 scenario_utils = test_utils.InputScenarioUtils()
50 scenario_flavor = scenario_utils.scenario_flavors
51 scenario_image = scenario_utils.scenario_images
52
53 scenarios = testscenarios.multiply_scenarios(scenario_image,
54 scenario_flavor)
55
56 def setUp(self):
57 super(TestServerBasicOps, self).setUp()
58 # Setup image and flavor the test instance
59 # Support both configured and injected values
60 if not hasattr(self, 'image_ref'):
61 self.image_ref = self.config.compute.image_ref
62 if not hasattr(self, 'flavor_ref'):
63 self.flavor_ref = self.config.compute.flavor_ref
64 self.image_utils = test_utils.ImageUtils()
65 if not self.image_utils.is_flavor_enough(self.flavor_ref,
66 self.image_ref):
67 raise self.skipException(
68 '{image} does not fit in {flavor}'.format(
69 image=self.image_ref, flavor=self.flavor_ref
70 )
71 )
72 self.run_ssh = self.config.compute.run_ssh and \
73 self.image_utils.is_sshable_image(self.image_ref)
74 self.ssh_user = self.image_utils.ssh_user(self.image_ref)
75 LOG.debug('Starting test for i:{image}, f:{flavor}. '
76 'Run ssh: {ssh}, user: {ssh_user}'.format(
77 image=self.image_ref, flavor=self.flavor_ref,
78 ssh=self.run_ssh, ssh_user=self.ssh_user))
79
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +090080 def add_keypair(self):
81 self.keypair = self.create_keypair()
Jay Pipes051075a2012-04-28 17:39:37 -040082
ivan-zhu19977392013-01-12 21:57:55 +080083 def create_security_group(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +090084 sg_name = data_utils.rand_name('secgroup-smoke')
Jay Pipes051075a2012-04-28 17:39:37 -040085 sg_desc = sg_name + " description"
Maru Newbydec13ec2012-08-30 11:19:17 -070086 self.secgroup = self.compute_client.security_groups.create(sg_name,
87 sg_desc)
Giulio Fidente92f77192013-08-26 17:13:28 +020088 self.assertEqual(self.secgroup.name, sg_name)
89 self.assertEqual(self.secgroup.description, sg_desc)
90 self.set_resource('secgroup', self.secgroup)
Jay Pipes051075a2012-04-28 17:39:37 -040091
92 # Add rules to the security group
Yair Friedeb69f3f2013-10-10 13:18:16 +030093 self._create_loginable_secgroup_rule_nova(secgroup_id=self.secgroup.id)
Jay Pipes051075a2012-04-28 17:39:37 -040094
ivan-zhu19977392013-01-12 21:57:55 +080095 def boot_instance(self):
Andrea Frittolif5da28b2013-12-06 07:08:07 +000096 # Create server with image and flavor from input scenario
Jay Pipes051075a2012-04-28 17:39:37 -040097 create_kwargs = {
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +090098 'key_name': self.keypair.id
Jay Pipes051075a2012-04-28 17:39:37 -040099 }
Andrea Frittolif5da28b2013-12-06 07:08:07 +0000100 instance = self.create_server(image=self.image_ref,
101 flavor=self.flavor_ref,
102 create_kwargs=create_kwargs)
Ken'ichi Ohmichi61f272b2013-08-15 15:58:53 +0900103 self.set_resource('instance', instance)
Jay Pipes051075a2012-04-28 17:39:37 -0400104
ivan-zhu19977392013-01-12 21:57:55 +0800105 def pause_server(self):
Jay Pipes051075a2012-04-28 17:39:37 -0400106 instance = self.get_resource('instance')
107 instance_id = instance.id
108 LOG.debug("Pausing instance %s. Current status: %s",
109 instance_id, instance.status)
110 instance.pause()
Sean Dague35a7caf2013-05-10 10:38:22 -0400111 self.status_timeout(
112 self.compute_client.servers, instance_id, 'PAUSED')
Jay Pipes051075a2012-04-28 17:39:37 -0400113
ivan-zhu19977392013-01-12 21:57:55 +0800114 def unpause_server(self):
Jay Pipes051075a2012-04-28 17:39:37 -0400115 instance = self.get_resource('instance')
116 instance_id = instance.id
117 LOG.debug("Unpausing instance %s. Current status: %s",
118 instance_id, instance.status)
119 instance.unpause()
Sean Dague35a7caf2013-05-10 10:38:22 -0400120 self.status_timeout(
121 self.compute_client.servers, instance_id, 'ACTIVE')
Jay Pipes051075a2012-04-28 17:39:37 -0400122
ivan-zhu19977392013-01-12 21:57:55 +0800123 def suspend_server(self):
Jay Pipes051075a2012-04-28 17:39:37 -0400124 instance = self.get_resource('instance')
125 instance_id = instance.id
126 LOG.debug("Suspending instance %s. Current status: %s",
127 instance_id, instance.status)
128 instance.suspend()
Sean Dague35a7caf2013-05-10 10:38:22 -0400129 self.status_timeout(self.compute_client.servers,
Maru Newbydec13ec2012-08-30 11:19:17 -0700130 instance_id, 'SUSPENDED')
Jay Pipes051075a2012-04-28 17:39:37 -0400131
ivan-zhu19977392013-01-12 21:57:55 +0800132 def resume_server(self):
Jay Pipes051075a2012-04-28 17:39:37 -0400133 instance = self.get_resource('instance')
134 instance_id = instance.id
135 LOG.debug("Resuming instance %s. Current status: %s",
136 instance_id, instance.status)
137 instance.resume()
Sean Dague35a7caf2013-05-10 10:38:22 -0400138 self.status_timeout(
139 self.compute_client.servers, instance_id, 'ACTIVE')
Jay Pipes051075a2012-04-28 17:39:37 -0400140
ivan-zhu19977392013-01-12 21:57:55 +0800141 def terminate_instance(self):
Jay Pipes051075a2012-04-28 17:39:37 -0400142 instance = self.get_resource('instance')
143 instance.delete()
144 self.remove_resource('instance')
ivan-zhu19977392013-01-12 21:57:55 +0800145
Andrea Frittolif5da28b2013-12-06 07:08:07 +0000146 def verify_ssh(self):
147 if self.run_ssh:
148 # Obtain a floating IP
149 floating_ip = self.compute_client.floating_ips.create()
150 # Attach a floating IP
151 instance = self.get_resource('instance')
152 instance.add_floating_ip(floating_ip)
153 # Check ssh
154 self.get_remote_client(
155 server_or_ip=floating_ip.ip,
156 username=self.image_utils.ssh_user(self.image_ref),
157 private_key=self.keypair.private)
158
Matthew Treinish2153ec02013-09-09 20:57:30 +0000159 @services('compute', 'network')
ivan-zhu19977392013-01-12 21:57:55 +0800160 def test_server_basicops(self):
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +0900161 self.add_keypair()
ivan-zhu19977392013-01-12 21:57:55 +0800162 self.create_security_group()
163 self.boot_instance()
ivan-zhu19977392013-01-12 21:57:55 +0800164 self.pause_server()
165 self.unpause_server()
166 self.suspend_server()
167 self.resume_server()
Andrea Frittolif5da28b2013-12-06 07:08:07 +0000168 self.verify_ssh()
ivan-zhu19977392013-01-12 21:57:55 +0800169 self.terminate_instance()