blob: 29f17430fa06dc32e8ed103847fac5d1c15fe7d6 [file] [log] [blame]
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +09001# 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
zhufl6b7040a2017-01-18 16:38:34 +080016import testtools
17
Andrea Frittoli247058f2014-07-16 16:09:22 +010018from tempest.common import custom_matchers
Andrea Frittolicd368412017-08-14 21:37:56 +010019from tempest.common import utils
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000020from tempest.common import waiters
Matthew Treinish6c072292014-01-29 19:15:52 +000021from tempest import config
Jordan Pittier35a63752016-08-30 13:09:12 +020022from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080023from tempest.lib import decorators
guo yunxian7383a6f2016-12-05 18:56:51 +080024from tempest.lib import exceptions
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090025from tempest.scenario import manager
26
Matthew Treinish6c072292014-01-29 19:15:52 +000027CONF = config.CONF
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090028
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090029
Andrea Frittoli247058f2014-07-16 16:09:22 +010030class TestMinimumBasicScenario(manager.ScenarioTest):
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090031
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000032 """This is a basic minimum scenario test.
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090033
34 This test below:
35 * across the multiple components
36 * as a regular user
37 * with and without optional parameters
38 * check command outputs
39
Alexander Gubanova5ab12e2015-11-17 18:18:46 +020040 Steps:
41 1. Create image
42 2. Create keypair
43 3. Boot instance with keypair and get list of instances
44 4. Create volume and show list of volumes
45 5. Attach volume to instance and getlist of volumes
46 6. Add IP to instance
47 7. Create and add security group to instance
48 8. Check SSH connection to instance
49 9. Reboot instance
50 10. Check SSH connection to instance after reboot
51
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090052 """
Jordan Pittier7cf64762015-10-14 15:01:12 +020053 def nova_show(self, server):
54 got_server = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +090055 ['server'])
Jordan Pittier5d367152015-08-19 12:03:49 +020056 excluded_keys = ['OS-EXT-AZ:availability_zone']
57 # Exclude these keys because of LP:#1486475
58 excluded_keys.extend(['OS-EXT-STS:power_state', 'updated'])
Andrea Frittoli247058f2014-07-16 16:09:22 +010059 self.assertThat(
Jordan Pittier7cf64762015-10-14 15:01:12 +020060 server, custom_matchers.MatchesDictExceptForKeys(
Jordan Pittier5d367152015-08-19 12:03:49 +020061 got_server, excluded_keys=excluded_keys))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090062
Jordan Pittier7cf64762015-10-14 15:01:12 +020063 def cinder_show(self, volume):
64 got_volume = self.volumes_client.show_volume(volume['id'])['volume']
65 self.assertEqual(volume, got_volume)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090066
Jordan Pittier7cf64762015-10-14 15:01:12 +020067 def nova_reboot(self, server):
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +000068 self.servers_client.reboot_server(server['id'], type='SOFT')
Masayuki Igawa8bf68672016-01-15 14:43:10 +090069 waiters.wait_for_server_status(self.servers_client,
70 server['id'], 'ACTIVE')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090071
Evgeny Antyshev4894a912016-11-21 12:17:18 +000072 def check_disks(self):
Andrea Frittoli247058f2014-07-16 16:09:22 +010073 # NOTE(andreaf) The device name may be different on different guest OS
Evgeny Antyshev4894a912016-11-21 12:17:18 +000074 disks = self.linux_client.get_disks()
75 self.assertEqual(1, disks.count(CONF.compute.volume_device_name))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090076
Jordan Pittier7cf64762015-10-14 15:01:12 +020077 def create_and_add_security_group_to_server(self, server):
Yair Fried1fc32a12014-08-04 09:11:30 +030078 secgroup = self._create_security_group()
Jordan Pittier7cf64762015-10-14 15:01:12 +020079 self.servers_client.add_security_group(server['id'],
Ken'ichi Ohmichie6349f32015-12-09 06:47:54 +000080 name=secgroup['name'])
Andrea Frittoli247058f2014-07-16 16:09:22 +010081 self.addCleanup(self.servers_client.remove_security_group,
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +000082 server['id'], name=secgroup['name'])
Grishkin0f1e11c2014-05-04 20:44:52 +040083
Clark Boylanff31bcc2014-11-04 13:44:04 -080084 def wait_for_secgroup_add():
Jordan Pittier7cf64762015-10-14 15:01:12 +020085 body = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +090086 ['server'])
Clark Boylanff31bcc2014-11-04 13:44:04 -080087 return {'name': secgroup['name']} in body['security_groups']
88
Jordan Pittier35a63752016-08-30 13:09:12 +020089 if not test_utils.call_until_true(wait_for_secgroup_add,
90 CONF.compute.build_timeout,
91 CONF.compute.build_interval):
Clark Boylanff31bcc2014-11-04 13:44:04 -080092 msg = ('Timed out waiting for adding security group %s to server '
Jordan Pittier7cf64762015-10-14 15:01:12 +020093 '%s' % (secgroup['id'], server['id']))
Clark Boylanff31bcc2014-11-04 13:44:04 -080094 raise exceptions.TimeoutException(msg)
95
Matt Riedemann8ca50562016-08-16 14:46:01 -040096 def _get_floating_ip_in_server_addresses(self, floating_ip, server):
Béla Vancsicsb6dfa082017-03-01 10:44:58 +010097 for addresses in server['addresses'].values():
Matt Riedemann8ca50562016-08-16 14:46:01 -040098 for address in addresses:
99 if (address['OS-EXT-IPS:type'] == 'floating' and
100 address['addr'] == floating_ip['ip']):
101 return address
102
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -0800103 @decorators.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8')
zhufl6b7040a2017-01-18 16:38:34 +0800104 @testtools.skipUnless(CONF.network.public_network_id,
105 'The public_network_id option must be specified.')
Matthew Treinish3312de32017-05-19 12:08:17 -0400106 @testtools.skipUnless(CONF.network_feature_enabled.floating_ips,
107 'Floating ips are not available')
Andrea Frittolicd368412017-08-14 21:37:56 +0100108 @utils.services('compute', 'volume', 'image', 'network')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900109 def test_minimum_basic_scenario(self):
Jordan Pittier1e443ec2015-11-20 16:15:58 +0100110 image = self.glance_image_create()
Jordan Pittier7cf64762015-10-14 15:01:12 +0200111 keypair = self.create_keypair()
JordanP3fe2dc32014-11-17 13:06:01 +0100112
zhufl13c9c892017-02-10 12:04:07 +0800113 server = self.create_server(image_id=image, key_name=keypair['name'])
Jordan Pittier93dffb72016-09-16 15:12:31 +0200114 servers = self.servers_client.list_servers()['servers']
Jordan Pittier7cf64762015-10-14 15:01:12 +0200115 self.assertIn(server['id'], [x['id'] for x in servers])
JordanP3fe2dc32014-11-17 13:06:01 +0100116
Jordan Pittier7cf64762015-10-14 15:01:12 +0200117 self.nova_show(server)
118
Jordan Pittierbbb17122016-01-26 17:10:55 +0100119 volume = self.create_volume()
120 volumes = self.volumes_client.list_volumes()['volumes']
Jordan Pittier7cf64762015-10-14 15:01:12 +0200121 self.assertIn(volume['id'], [x['id'] for x in volumes])
122
123 self.cinder_show(volume)
124
125 volume = self.nova_volume_attach(server, volume)
126 self.addCleanup(self.nova_volume_detach, server, volume)
127 self.cinder_show(volume)
128
129 floating_ip = self.create_floating_ip(server)
Matt Riedemann8ca50562016-08-16 14:46:01 -0400130 # fetch the server again to make sure the addresses were refreshed
131 # after associating the floating IP
132 server = self.servers_client.show_server(server['id'])['server']
133 address = self._get_floating_ip_in_server_addresses(
134 floating_ip, server)
135 self.assertIsNotNone(
136 address,
137 "Failed to find floating IP '%s' in server addresses: %s" %
138 (floating_ip['ip'], server['addresses']))
139
Jordan Pittier7cf64762015-10-14 15:01:12 +0200140 self.create_and_add_security_group_to_server(server)
141
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200142 # check that we can SSH to the server before reboot
Jordan Pittier7cf64762015-10-14 15:01:12 +0200143 self.linux_client = self.get_remote_client(
zhuflf52c7592017-05-25 13:55:24 +0800144 floating_ip['ip'], private_key=keypair['private_key'],
145 server=server)
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200146
Jordan Pittier7cf64762015-10-14 15:01:12 +0200147 self.nova_reboot(server)
148
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200149 # check that we can SSH to the server after reboot
150 # (both connections are part of the scenario)
Jordan Pittier7cf64762015-10-14 15:01:12 +0200151 self.linux_client = self.get_remote_client(
zhuflf52c7592017-05-25 13:55:24 +0800152 floating_ip['ip'], private_key=keypair['private_key'],
153 server=server)
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200154
Evgeny Antyshev4894a912016-11-21 12:17:18 +0000155 self.check_disks()
Matt Riedemann8ca50562016-08-16 14:46:01 -0400156
157 # delete the floating IP, this should refresh the server addresses
158 self.compute_floating_ips_client.delete_floating_ip(floating_ip['id'])
zhuflc310b8d2016-09-27 11:33:23 +0800159
160 def is_floating_ip_detached_from_server():
161 server_info = self.servers_client.show_server(
162 server['id'])['server']
163 address = self._get_floating_ip_in_server_addresses(
164 floating_ip, server_info)
165 return (not address)
166
167 if not test_utils.call_until_true(
168 is_floating_ip_detached_from_server,
169 CONF.compute.build_timeout,
170 CONF.compute.build_interval):
171 msg = ("Floating IP '%s' should not be in server addresses: %s" %
172 (floating_ip['ip'], server['addresses']))
173 raise exceptions.TimeoutException(msg)