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