Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 1 | # Copyright 2013 NEC Corporation |
| 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 | |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 16 | from tempest.common import custom_matchers |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 17 | from tempest.common import utils |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 18 | from tempest.common import waiters |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 19 | from tempest import config |
Jordan Pittier | 35a6375 | 2016-08-30 13:09:12 +0200 | [diff] [blame] | 20 | from tempest.lib.common.utils import test_utils |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 21 | from tempest.lib import decorators |
guo yunxian | 7383a6f | 2016-12-05 18:56:51 +0800 | [diff] [blame] | 22 | from tempest.lib import exceptions |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 23 | from tempest.scenario import manager |
| 24 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 25 | CONF = config.CONF |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 26 | |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 27 | |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 28 | class TestMinimumBasicScenario(manager.ScenarioTest): |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 29 | |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 30 | """This is a basic minimum scenario test. |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 31 | |
| 32 | This test below: |
| 33 | * across the multiple components |
| 34 | * as a regular user |
| 35 | * with and without optional parameters |
| 36 | * check command outputs |
| 37 | |
Alexander Gubanov | a5ab12e | 2015-11-17 18:18:46 +0200 | [diff] [blame] | 38 | Steps: |
| 39 | 1. Create image |
| 40 | 2. Create keypair |
| 41 | 3. Boot instance with keypair and get list of instances |
| 42 | 4. Create volume and show list of volumes |
| 43 | 5. Attach volume to instance and getlist of volumes |
| 44 | 6. Add IP to instance |
| 45 | 7. Create and add security group to instance |
| 46 | 8. Check SSH connection to instance |
| 47 | 9. Reboot instance |
| 48 | 10. Check SSH connection to instance after reboot |
| 49 | |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 50 | """ |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 51 | def nova_show(self, server): |
| 52 | got_server = (self.servers_client.show_server(server['id']) |
ghanshyam | 0f82525 | 2015-08-25 16:02:50 +0900 | [diff] [blame] | 53 | ['server']) |
Jordan Pittier | 5d36715 | 2015-08-19 12:03:49 +0200 | [diff] [blame] | 54 | excluded_keys = ['OS-EXT-AZ:availability_zone'] |
| 55 | # Exclude these keys because of LP:#1486475 |
| 56 | excluded_keys.extend(['OS-EXT-STS:power_state', 'updated']) |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 57 | self.assertThat( |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 58 | server, custom_matchers.MatchesDictExceptForKeys( |
Jordan Pittier | 5d36715 | 2015-08-19 12:03:49 +0200 | [diff] [blame] | 59 | got_server, excluded_keys=excluded_keys)) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 60 | |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 61 | def cinder_show(self, volume): |
| 62 | got_volume = self.volumes_client.show_volume(volume['id'])['volume'] |
| 63 | self.assertEqual(volume, got_volume) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 64 | |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 65 | def nova_reboot(self, server): |
Ken'ichi Ohmichi | 36b714c | 2015-12-09 08:12:47 +0000 | [diff] [blame] | 66 | self.servers_client.reboot_server(server['id'], type='SOFT') |
Masayuki Igawa | 8bf6867 | 2016-01-15 14:43:10 +0900 | [diff] [blame] | 67 | waiters.wait_for_server_status(self.servers_client, |
| 68 | server['id'], 'ACTIVE') |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 69 | |
Evgeny Antyshev | 4894a91 | 2016-11-21 12:17:18 +0000 | [diff] [blame] | 70 | def check_disks(self): |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 71 | # NOTE(andreaf) The device name may be different on different guest OS |
Evgeny Antyshev | 4894a91 | 2016-11-21 12:17:18 +0000 | [diff] [blame] | 72 | disks = self.linux_client.get_disks() |
| 73 | self.assertEqual(1, disks.count(CONF.compute.volume_device_name)) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 74 | |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 75 | def create_and_add_security_group_to_server(self, server): |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 76 | secgroup = self._create_security_group() |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 77 | self.servers_client.add_security_group(server['id'], |
Ken'ichi Ohmichi | e6349f3 | 2015-12-09 06:47:54 +0000 | [diff] [blame] | 78 | name=secgroup['name']) |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 79 | self.addCleanup(self.servers_client.remove_security_group, |
Ken'ichi Ohmichi | 36b714c | 2015-12-09 08:12:47 +0000 | [diff] [blame] | 80 | server['id'], name=secgroup['name']) |
Grishkin | 0f1e11c | 2014-05-04 20:44:52 +0400 | [diff] [blame] | 81 | |
Clark Boylan | ff31bcc | 2014-11-04 13:44:04 -0800 | [diff] [blame] | 82 | def wait_for_secgroup_add(): |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 83 | body = (self.servers_client.show_server(server['id']) |
ghanshyam | 0f82525 | 2015-08-25 16:02:50 +0900 | [diff] [blame] | 84 | ['server']) |
Clark Boylan | ff31bcc | 2014-11-04 13:44:04 -0800 | [diff] [blame] | 85 | return {'name': secgroup['name']} in body['security_groups'] |
| 86 | |
Jordan Pittier | 35a6375 | 2016-08-30 13:09:12 +0200 | [diff] [blame] | 87 | if not test_utils.call_until_true(wait_for_secgroup_add, |
| 88 | CONF.compute.build_timeout, |
| 89 | CONF.compute.build_interval): |
Clark Boylan | ff31bcc | 2014-11-04 13:44:04 -0800 | [diff] [blame] | 90 | msg = ('Timed out waiting for adding security group %s to server ' |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 91 | '%s' % (secgroup['id'], server['id'])) |
Clark Boylan | ff31bcc | 2014-11-04 13:44:04 -0800 | [diff] [blame] | 92 | raise exceptions.TimeoutException(msg) |
| 93 | |
Matt Riedemann | 8ca5056 | 2016-08-16 14:46:01 -0400 | [diff] [blame] | 94 | def _get_floating_ip_in_server_addresses(self, floating_ip, server): |
Béla Vancsics | b6dfa08 | 2017-03-01 10:44:58 +0100 | [diff] [blame] | 95 | for addresses in server['addresses'].values(): |
Matt Riedemann | 8ca5056 | 2016-08-16 14:46:01 -0400 | [diff] [blame] | 96 | for address in addresses: |
| 97 | if (address['OS-EXT-IPS:type'] == 'floating' and |
| 98 | address['addr'] == floating_ip['ip']): |
| 99 | return address |
| 100 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 101 | @decorators.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 102 | @utils.services('compute', 'volume', 'image', 'network') |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 103 | def test_minimum_basic_scenario(self): |
Jordan Pittier | 1e443ec | 2015-11-20 16:15:58 +0100 | [diff] [blame] | 104 | image = self.glance_image_create() |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 105 | keypair = self.create_keypair() |
JordanP | 3fe2dc3 | 2014-11-17 13:06:01 +0100 | [diff] [blame] | 106 | |
zhufl | 13c9c89 | 2017-02-10 12:04:07 +0800 | [diff] [blame] | 107 | server = self.create_server(image_id=image, key_name=keypair['name']) |
Jordan Pittier | 93dffb7 | 2016-09-16 15:12:31 +0200 | [diff] [blame] | 108 | servers = self.servers_client.list_servers()['servers'] |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 109 | self.assertIn(server['id'], [x['id'] for x in servers]) |
JordanP | 3fe2dc3 | 2014-11-17 13:06:01 +0100 | [diff] [blame] | 110 | |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 111 | self.nova_show(server) |
| 112 | |
Jordan Pittier | bbb1712 | 2016-01-26 17:10:55 +0100 | [diff] [blame] | 113 | volume = self.create_volume() |
| 114 | volumes = self.volumes_client.list_volumes()['volumes'] |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 115 | self.assertIn(volume['id'], [x['id'] for x in volumes]) |
| 116 | |
| 117 | self.cinder_show(volume) |
| 118 | |
| 119 | volume = self.nova_volume_attach(server, volume) |
| 120 | self.addCleanup(self.nova_volume_detach, server, volume) |
| 121 | self.cinder_show(volume) |
| 122 | |
zhufl | 1bdc3e7 | 2018-01-10 14:10:47 +0800 | [diff] [blame] | 123 | floating_ip = None |
Matt Riedemann | 8ca5056 | 2016-08-16 14:46:01 -0400 | [diff] [blame] | 124 | server = self.servers_client.show_server(server['id'])['server'] |
zhufl | 1bdc3e7 | 2018-01-10 14:10:47 +0800 | [diff] [blame] | 125 | if (CONF.network_feature_enabled.floating_ips and |
| 126 | CONF.network.floating_network_name): |
| 127 | floating_ip = self.create_floating_ip(server) |
| 128 | # fetch the server again to make sure the addresses were refreshed |
| 129 | # after associating the floating IP |
Jakub Libosvar | f979a04 | 2018-02-06 11:14:38 +0000 | [diff] [blame] | 130 | server = self.servers_client.show_server(server['id'])['server'] |
zhufl | 1bdc3e7 | 2018-01-10 14:10:47 +0800 | [diff] [blame] | 131 | address = self._get_floating_ip_in_server_addresses( |
| 132 | floating_ip, server) |
| 133 | self.assertIsNotNone( |
| 134 | address, |
| 135 | "Failed to find floating IP '%s' in server addresses: %s" % |
| 136 | (floating_ip['ip'], server['addresses'])) |
| 137 | ssh_ip = floating_ip['ip'] |
| 138 | else: |
| 139 | ssh_ip = self.get_server_ip(server) |
Matt Riedemann | 8ca5056 | 2016-08-16 14:46:01 -0400 | [diff] [blame] | 140 | |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 141 | self.create_and_add_security_group_to_server(server) |
| 142 | |
Alexander Gubanov | a5ab12e | 2015-11-17 18:18:46 +0200 | [diff] [blame] | 143 | # check that we can SSH to the server before reboot |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 144 | self.linux_client = self.get_remote_client( |
zhufl | 1bdc3e7 | 2018-01-10 14:10:47 +0800 | [diff] [blame] | 145 | ssh_ip, private_key=keypair['private_key'], |
zhufl | f52c759 | 2017-05-25 13:55:24 +0800 | [diff] [blame] | 146 | server=server) |
Alexander Gubanov | a5ab12e | 2015-11-17 18:18:46 +0200 | [diff] [blame] | 147 | |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 148 | self.nova_reboot(server) |
| 149 | |
Alexander Gubanov | a5ab12e | 2015-11-17 18:18:46 +0200 | [diff] [blame] | 150 | # check that we can SSH to the server after reboot |
| 151 | # (both connections are part of the scenario) |
Jordan Pittier | 7cf6476 | 2015-10-14 15:01:12 +0200 | [diff] [blame] | 152 | self.linux_client = self.get_remote_client( |
zhufl | 1bdc3e7 | 2018-01-10 14:10:47 +0800 | [diff] [blame] | 153 | ssh_ip, private_key=keypair['private_key'], |
zhufl | f52c759 | 2017-05-25 13:55:24 +0800 | [diff] [blame] | 154 | server=server) |
Alexander Gubanov | a5ab12e | 2015-11-17 18:18:46 +0200 | [diff] [blame] | 155 | |
Evgeny Antyshev | 4894a91 | 2016-11-21 12:17:18 +0000 | [diff] [blame] | 156 | self.check_disks() |
Matt Riedemann | 8ca5056 | 2016-08-16 14:46:01 -0400 | [diff] [blame] | 157 | |
zhufl | 1bdc3e7 | 2018-01-10 14:10:47 +0800 | [diff] [blame] | 158 | if floating_ip: |
| 159 | # delete the floating IP, this should refresh the server addresses |
| 160 | self.compute_floating_ips_client.delete_floating_ip( |
| 161 | floating_ip['id']) |
zhufl | c310b8d | 2016-09-27 11:33:23 +0800 | [diff] [blame] | 162 | |
zhufl | 1bdc3e7 | 2018-01-10 14:10:47 +0800 | [diff] [blame] | 163 | def is_floating_ip_detached_from_server(): |
| 164 | server_info = self.servers_client.show_server( |
| 165 | server['id'])['server'] |
| 166 | address = self._get_floating_ip_in_server_addresses( |
| 167 | floating_ip, server_info) |
| 168 | return (not address) |
zhufl | c310b8d | 2016-09-27 11:33:23 +0800 | [diff] [blame] | 169 | |
zhufl | 1bdc3e7 | 2018-01-10 14:10:47 +0800 | [diff] [blame] | 170 | if not test_utils.call_until_true( |
| 171 | is_floating_ip_detached_from_server, |
| 172 | CONF.compute.build_timeout, |
| 173 | CONF.compute.build_interval): |
| 174 | msg = ("Floating IP '%s' should not be in server addresses: %s" |
| 175 | % (floating_ip['ip'], server['addresses'])) |
| 176 | raise exceptions.TimeoutException(msg) |