blob: eefc624e8326074e5e5ed13ea0690ff9ea7c2ee1 [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
Matthew Treinish6c072292014-01-29 19:15:52 +000017from tempest import config
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040018from tempest.openstack.common import log as logging
Sean Dague6dbc6da2013-05-08 17:49:46 -040019from tempest.scenario import manager
Matthew Treinishd75edef2014-04-11 15:57:16 -040020from tempest.scenario import utils as test_utils
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090021from tempest import test
Jay Pipes051075a2012-04-28 17:39:37 -040022
Matthew Treinish6c072292014-01-29 19:15:52 +000023CONF = config.CONF
24
Jay Pipes051075a2012-04-28 17:39:37 -040025LOG = logging.getLogger(__name__)
26
Matthew Treinisha0048cb2014-04-08 17:44:42 -040027load_tests = test_utils.load_tests_input_scenario_utils
Andrea Frittolif5da28b2013-12-06 07:08:07 +000028
Jay Pipes051075a2012-04-28 17:39:37 -040029
Sean Dague6dbc6da2013-05-08 17:49:46 -040030class TestServerBasicOps(manager.OfficialClientTest):
Jay Pipes051075a2012-04-28 17:39:37 -040031
32 """
33 This smoke test case follows this basic set of operations:
34
35 * Create a keypair for use in launching an instance
36 * Create a security group to control network access in instance
37 * Add simple permissive rules to the security group
38 * Launch an instance
39 * Pause/unpause the instance
40 * Suspend/resume the instance
41 * Terminate the instance
42 """
43
Andrea Frittolif5da28b2013-12-06 07:08:07 +000044 def setUp(self):
45 super(TestServerBasicOps, self).setUp()
46 # Setup image and flavor the test instance
47 # Support both configured and injected values
48 if not hasattr(self, 'image_ref'):
Matthew Treinish6c072292014-01-29 19:15:52 +000049 self.image_ref = CONF.compute.image_ref
Andrea Frittolif5da28b2013-12-06 07:08:07 +000050 if not hasattr(self, 'flavor_ref'):
Matthew Treinish6c072292014-01-29 19:15:52 +000051 self.flavor_ref = CONF.compute.flavor_ref
Andrea Frittolif5da28b2013-12-06 07:08:07 +000052 self.image_utils = test_utils.ImageUtils()
53 if not self.image_utils.is_flavor_enough(self.flavor_ref,
54 self.image_ref):
55 raise self.skipException(
56 '{image} does not fit in {flavor}'.format(
57 image=self.image_ref, flavor=self.flavor_ref
58 )
59 )
Matthew Treinish6c072292014-01-29 19:15:52 +000060 self.run_ssh = CONF.compute.run_ssh and \
Andrea Frittolif5da28b2013-12-06 07:08:07 +000061 self.image_utils.is_sshable_image(self.image_ref)
62 self.ssh_user = self.image_utils.ssh_user(self.image_ref)
63 LOG.debug('Starting test for i:{image}, f:{flavor}. '
64 'Run ssh: {ssh}, user: {ssh_user}'.format(
65 image=self.image_ref, flavor=self.flavor_ref,
66 ssh=self.run_ssh, ssh_user=self.ssh_user))
67
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +090068 def add_keypair(self):
69 self.keypair = self.create_keypair()
Jay Pipes051075a2012-04-28 17:39:37 -040070
ivan-zhu19977392013-01-12 21:57:55 +080071 def create_security_group(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +090072 sg_name = data_utils.rand_name('secgroup-smoke')
Jay Pipes051075a2012-04-28 17:39:37 -040073 sg_desc = sg_name + " description"
Maru Newbydec13ec2012-08-30 11:19:17 -070074 self.secgroup = self.compute_client.security_groups.create(sg_name,
75 sg_desc)
Giulio Fidente92f77192013-08-26 17:13:28 +020076 self.assertEqual(self.secgroup.name, sg_name)
77 self.assertEqual(self.secgroup.description, sg_desc)
78 self.set_resource('secgroup', self.secgroup)
Jay Pipes051075a2012-04-28 17:39:37 -040079
80 # Add rules to the security group
Yair Friedeb69f3f2013-10-10 13:18:16 +030081 self._create_loginable_secgroup_rule_nova(secgroup_id=self.secgroup.id)
Jay Pipes051075a2012-04-28 17:39:37 -040082
ivan-zhu19977392013-01-12 21:57:55 +080083 def boot_instance(self):
Andrea Frittolif5da28b2013-12-06 07:08:07 +000084 # Create server with image and flavor from input scenario
Jay Pipes051075a2012-04-28 17:39:37 -040085 create_kwargs = {
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +090086 'key_name': self.keypair.id
Jay Pipes051075a2012-04-28 17:39:37 -040087 }
Andrea Frittolif5da28b2013-12-06 07:08:07 +000088 instance = self.create_server(image=self.image_ref,
89 flavor=self.flavor_ref,
90 create_kwargs=create_kwargs)
Ken'ichi Ohmichi61f272b2013-08-15 15:58:53 +090091 self.set_resource('instance', instance)
Jay Pipes051075a2012-04-28 17:39:37 -040092
ivan-zhu19977392013-01-12 21:57:55 +080093 def terminate_instance(self):
Jay Pipes051075a2012-04-28 17:39:37 -040094 instance = self.get_resource('instance')
95 instance.delete()
96 self.remove_resource('instance')
ivan-zhu19977392013-01-12 21:57:55 +080097
Andrea Frittolif5da28b2013-12-06 07:08:07 +000098 def verify_ssh(self):
99 if self.run_ssh:
100 # Obtain a floating IP
101 floating_ip = self.compute_client.floating_ips.create()
102 # Attach a floating IP
103 instance = self.get_resource('instance')
104 instance.add_floating_ip(floating_ip)
105 # Check ssh
Nachi Ueno95b41282014-01-15 06:54:21 -0800106 try:
107 self.get_remote_client(
108 server_or_ip=floating_ip.ip,
109 username=self.image_utils.ssh_user(self.image_ref),
110 private_key=self.keypair.private)
111 except Exception:
112 LOG.exception('ssh to server failed')
113 self._log_console_output()
114 raise
Andrea Frittolif5da28b2013-12-06 07:08:07 +0000115
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900116 @test.services('compute', 'network')
ivan-zhu19977392013-01-12 21:57:55 +0800117 def test_server_basicops(self):
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +0900118 self.add_keypair()
ivan-zhu19977392013-01-12 21:57:55 +0800119 self.create_security_group()
120 self.boot_instance()
Andrea Frittolif5da28b2013-12-06 07:08:07 +0000121 self.verify_ssh()
ivan-zhu19977392013-01-12 21:57:55 +0800122 self.terminate_instance()