blob: d9918f31fa71ba740df6e6869a4161237fa3a2df [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016from oslo_log import log as logging
17
Matthew Treinish6c072292014-01-29 19:15:52 +000018from tempest import config
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
Ghanshyam5a305c42014-08-27 14:24:58 +090030class TestServerBasicOps(manager.ScenarioTest):
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
ghanshyam416c94c2014-10-02 13:47:25 +090039 * Perform ssh to instance
Jay Pipes051075a2012-04-28 17:39:37 -040040 * Terminate the instance
41 """
42
Andrea Frittolif5da28b2013-12-06 07:08:07 +000043 def setUp(self):
44 super(TestServerBasicOps, self).setUp()
45 # Setup image and flavor the test instance
46 # Support both configured and injected values
47 if not hasattr(self, 'image_ref'):
Matthew Treinish6c072292014-01-29 19:15:52 +000048 self.image_ref = CONF.compute.image_ref
Andrea Frittolif5da28b2013-12-06 07:08:07 +000049 if not hasattr(self, 'flavor_ref'):
Matthew Treinish6c072292014-01-29 19:15:52 +000050 self.flavor_ref = CONF.compute.flavor_ref
Matthew Treinish96cadf42015-05-14 19:45:59 -040051 self.image_utils = test_utils.ImageUtils(self.manager)
Andrea Frittolif5da28b2013-12-06 07:08:07 +000052 if not self.image_utils.is_flavor_enough(self.flavor_ref,
53 self.image_ref):
54 raise self.skipException(
55 '{image} does not fit in {flavor}'.format(
56 image=self.image_ref, flavor=self.flavor_ref
57 )
58 )
Matthew Treinishe5cca002015-05-11 15:36:50 -040059 self.run_ssh = CONF.validation.run_validation and \
Andrea Frittolif5da28b2013-12-06 07:08:07 +000060 self.image_utils.is_sshable_image(self.image_ref)
61 self.ssh_user = self.image_utils.ssh_user(self.image_ref)
62 LOG.debug('Starting test for i:{image}, f:{flavor}. '
63 'Run ssh: {ssh}, user: {ssh_user}'.format(
64 image=self.image_ref, flavor=self.flavor_ref,
65 ssh=self.run_ssh, ssh_user=self.ssh_user))
66
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +090067 def add_keypair(self):
68 self.keypair = self.create_keypair()
Jay Pipes051075a2012-04-28 17:39:37 -040069
ivan-zhu19977392013-01-12 21:57:55 +080070 def boot_instance(self):
Andrea Frittolif5da28b2013-12-06 07:08:07 +000071 # Create server with image and flavor from input scenario
Ken'ichi Ohmichi1b3461e2014-12-02 03:41:07 +000072 security_groups = [{'name': self.security_group['name']}]
Jay Pipes051075a2012-04-28 17:39:37 -040073 create_kwargs = {
Ghanshyam5a305c42014-08-27 14:24:58 +090074 'key_name': self.keypair['name'],
Grishkin0f1e11c2014-05-04 20:44:52 +040075 'security_groups': security_groups
Jay Pipes051075a2012-04-28 17:39:37 -040076 }
Matthew Treinishb7144eb2013-12-13 22:57:35 +000077 self.instance = self.create_server(image=self.image_ref,
78 flavor=self.flavor_ref,
79 create_kwargs=create_kwargs)
ivan-zhu19977392013-01-12 21:57:55 +080080
Andrea Frittolif5da28b2013-12-06 07:08:07 +000081 def verify_ssh(self):
82 if self.run_ssh:
83 # Obtain a floating IP
David Kranze4e3b412015-02-10 10:50:42 -050084 floating_ip = self.floating_ips_client.create_floating_ip()
Ghanshyam5a305c42014-08-27 14:24:58 +090085 self.addCleanup(self.delete_wrapper,
86 self.floating_ips_client.delete_floating_ip,
87 floating_ip['id'])
Andrea Frittolif5da28b2013-12-06 07:08:07 +000088 # Attach a floating IP
Ghanshyam5a305c42014-08-27 14:24:58 +090089 self.floating_ips_client.associate_floating_ip_to_server(
90 floating_ip['ip'], self.instance['id'])
Andrea Frittolif5da28b2013-12-06 07:08:07 +000091 # Check ssh
JordanP3fe2dc32014-11-17 13:06:01 +010092 self.get_remote_client(
93 server_or_ip=floating_ip['ip'],
94 username=self.image_utils.ssh_user(self.image_ref),
95 private_key=self.keypair['private_key'])
Andrea Frittolif5da28b2013-12-06 07:08:07 +000096
Chris Hoge7579c1a2015-02-26 14:12:15 -080097 @test.idempotent_id('7fff3fb3-91d8-4fd0-bd7d-0204f1f180ba')
Sean Dague3c634d12015-04-27 12:09:19 -040098 @test.attr(type='smoke')
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090099 @test.services('compute', 'network')
ivan-zhu19977392013-01-12 21:57:55 +0800100 def test_server_basicops(self):
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +0900101 self.add_keypair()
Yair Fried1fc32a12014-08-04 09:11:30 +0300102 self.security_group = self._create_security_group()
ivan-zhu19977392013-01-12 21:57:55 +0800103 self.boot_instance()
Andrea Frittolif5da28b2013-12-06 07:08:07 +0000104 self.verify_ssh()
Ghanshyam5a305c42014-08-27 14:24:58 +0900105 self.servers_client.delete_server(self.instance['id'])