ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 2 | # 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 Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 16 | from oslo_log import log as logging |
| 17 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 18 | from tempest import config |
Yaroslav Lobankov | 117a48f | 2015-08-11 11:40:44 +0300 | [diff] [blame] | 19 | from tempest import exceptions |
Sean Dague | 6dbc6da | 2013-05-08 17:49:46 -0400 | [diff] [blame] | 20 | from tempest.scenario import manager |
Matthew Treinish | d75edef | 2014-04-11 15:57:16 -0400 | [diff] [blame] | 21 | from tempest.scenario import utils as test_utils |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 22 | from tempest import test |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 23 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 24 | CONF = config.CONF |
| 25 | |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 26 | LOG = logging.getLogger(__name__) |
| 27 | |
Matthew Treinish | a0048cb | 2014-04-08 17:44:42 -0400 | [diff] [blame] | 28 | load_tests = test_utils.load_tests_input_scenario_utils |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 29 | |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 30 | |
Ghanshyam | 5a305c4 | 2014-08-27 14:24:58 +0900 | [diff] [blame] | 31 | class TestServerBasicOps(manager.ScenarioTest): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 32 | |
| 33 | """ |
| 34 | This smoke test case follows this basic set of operations: |
| 35 | |
| 36 | * Create a keypair for use in launching an instance |
| 37 | * Create a security group to control network access in instance |
| 38 | * Add simple permissive rules to the security group |
| 39 | * Launch an instance |
ghanshyam | 416c94c | 2014-10-02 13:47:25 +0900 | [diff] [blame] | 40 | * Perform ssh to instance |
YAMAMOTO Takashi | 1f62af2 | 2015-06-16 03:29:50 +0900 | [diff] [blame] | 41 | * Verify metadata service |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 42 | * Terminate the instance |
| 43 | """ |
| 44 | |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 45 | def setUp(self): |
| 46 | super(TestServerBasicOps, self).setUp() |
| 47 | # Setup image and flavor the test instance |
| 48 | # Support both configured and injected values |
| 49 | if not hasattr(self, 'image_ref'): |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 50 | self.image_ref = CONF.compute.image_ref |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 51 | if not hasattr(self, 'flavor_ref'): |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 52 | self.flavor_ref = CONF.compute.flavor_ref |
Matthew Treinish | 96cadf4 | 2015-05-14 19:45:59 -0400 | [diff] [blame] | 53 | self.image_utils = test_utils.ImageUtils(self.manager) |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 54 | if not self.image_utils.is_flavor_enough(self.flavor_ref, |
| 55 | self.image_ref): |
| 56 | raise self.skipException( |
| 57 | '{image} does not fit in {flavor}'.format( |
| 58 | image=self.image_ref, flavor=self.flavor_ref |
| 59 | ) |
| 60 | ) |
Matthew Treinish | e5cca00 | 2015-05-11 15:36:50 -0400 | [diff] [blame] | 61 | self.run_ssh = CONF.validation.run_validation and \ |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 62 | self.image_utils.is_sshable_image(self.image_ref) |
| 63 | self.ssh_user = self.image_utils.ssh_user(self.image_ref) |
| 64 | LOG.debug('Starting test for i:{image}, f:{flavor}. ' |
| 65 | 'Run ssh: {ssh}, user: {ssh_user}'.format( |
| 66 | image=self.image_ref, flavor=self.flavor_ref, |
| 67 | ssh=self.run_ssh, ssh_user=self.ssh_user)) |
| 68 | |
Ken'ichi Ohmichi | 599d1b8 | 2013-08-19 18:48:37 +0900 | [diff] [blame] | 69 | def add_keypair(self): |
| 70 | self.keypair = self.create_keypair() |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 71 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 72 | def boot_instance(self): |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 73 | # Create server with image and flavor from input scenario |
Ken'ichi Ohmichi | 1b3461e | 2014-12-02 03:41:07 +0000 | [diff] [blame] | 74 | security_groups = [{'name': self.security_group['name']}] |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 75 | create_kwargs = { |
Ghanshyam | 5a305c4 | 2014-08-27 14:24:58 +0900 | [diff] [blame] | 76 | 'key_name': self.keypair['name'], |
Grishkin | 0f1e11c | 2014-05-04 20:44:52 +0400 | [diff] [blame] | 77 | 'security_groups': security_groups |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 78 | } |
Matthew Treinish | b7144eb | 2013-12-13 22:57:35 +0000 | [diff] [blame] | 79 | self.instance = self.create_server(image=self.image_ref, |
| 80 | flavor=self.flavor_ref, |
| 81 | create_kwargs=create_kwargs) |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 82 | |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 83 | def verify_ssh(self): |
| 84 | if self.run_ssh: |
| 85 | # Obtain a floating IP |
YAMAMOTO Takashi | 1f62af2 | 2015-06-16 03:29:50 +0900 | [diff] [blame] | 86 | self.floating_ip = self.floating_ips_client.create_floating_ip() |
Ghanshyam | 5a305c4 | 2014-08-27 14:24:58 +0900 | [diff] [blame] | 87 | self.addCleanup(self.delete_wrapper, |
| 88 | self.floating_ips_client.delete_floating_ip, |
YAMAMOTO Takashi | 1f62af2 | 2015-06-16 03:29:50 +0900 | [diff] [blame] | 89 | self.floating_ip['id']) |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 90 | # Attach a floating IP |
Ghanshyam | 5a305c4 | 2014-08-27 14:24:58 +0900 | [diff] [blame] | 91 | self.floating_ips_client.associate_floating_ip_to_server( |
YAMAMOTO Takashi | 1f62af2 | 2015-06-16 03:29:50 +0900 | [diff] [blame] | 92 | self.floating_ip['ip'], self.instance['id']) |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 93 | # Check ssh |
YAMAMOTO Takashi | 1f62af2 | 2015-06-16 03:29:50 +0900 | [diff] [blame] | 94 | self.ssh_client = self.get_remote_client( |
| 95 | server_or_ip=self.floating_ip['ip'], |
JordanP | 3fe2dc3 | 2014-11-17 13:06:01 +0100 | [diff] [blame] | 96 | username=self.image_utils.ssh_user(self.image_ref), |
| 97 | private_key=self.keypair['private_key']) |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 98 | |
YAMAMOTO Takashi | 1f62af2 | 2015-06-16 03:29:50 +0900 | [diff] [blame] | 99 | def verify_metadata(self): |
| 100 | if self.run_ssh and CONF.compute_feature_enabled.metadata_service: |
| 101 | # Verify metadata service |
Yaroslav Lobankov | 117a48f | 2015-08-11 11:40:44 +0300 | [diff] [blame] | 102 | md_url = 'http://169.254.169.254/latest/meta-data/public-ipv4' |
| 103 | |
| 104 | def exec_cmd_and_verify_output(): |
| 105 | cmd = 'curl ' + md_url |
| 106 | floating_ip = self.floating_ip['ip'] |
| 107 | result = self.ssh_client.exec_command(cmd) |
| 108 | if result: |
| 109 | msg = ('Failed while verifying metadata on server. Result ' |
| 110 | 'of command "%s" is NOT "%s".' % (cmd, floating_ip)) |
| 111 | self.assertEqual(floating_ip, result, msg) |
| 112 | return 'Verification is successful!' |
| 113 | |
| 114 | if not test.call_until_true(exec_cmd_and_verify_output, |
| 115 | CONF.compute.build_timeout, |
| 116 | CONF.compute.build_interval): |
| 117 | raise exceptions.TimeoutException('Timed out while waiting to ' |
| 118 | 'verify metadata on server. ' |
| 119 | '%s is empty.' % md_url) |
YAMAMOTO Takashi | 1f62af2 | 2015-06-16 03:29:50 +0900 | [diff] [blame] | 120 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 121 | @test.idempotent_id('7fff3fb3-91d8-4fd0-bd7d-0204f1f180ba') |
Sean Dague | 3c634d1 | 2015-04-27 12:09:19 -0400 | [diff] [blame] | 122 | @test.attr(type='smoke') |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 123 | @test.services('compute', 'network') |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 124 | def test_server_basicops(self): |
Ken'ichi Ohmichi | 599d1b8 | 2013-08-19 18:48:37 +0900 | [diff] [blame] | 125 | self.add_keypair() |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 126 | self.security_group = self._create_security_group() |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 127 | self.boot_instance() |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 128 | self.verify_ssh() |
YAMAMOTO Takashi | 1f62af2 | 2015-06-16 03:29:50 +0900 | [diff] [blame] | 129 | self.verify_metadata() |
Ghanshyam | 5a305c4 | 2014-08-27 14:24:58 +0900 | [diff] [blame] | 130 | self.servers_client.delete_server(self.instance['id']) |