blob: f2f17d297c05fc209e993b2f63c1e4bd6c07ad2b [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
Andrea Frittoli247058f2014-07-16 16:09:22 +010016from tempest.common import custom_matchers
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000017from tempest.common import waiters
Matthew Treinish6c072292014-01-29 19:15:52 +000018from tempest import config
Jordan Pittier35a63752016-08-30 13:09:12 +020019from tempest.lib.common.utils import test_utils
guo yunxian7383a6f2016-12-05 18:56:51 +080020from tempest.lib import exceptions
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090021from tempest.scenario import manager
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090022from tempest import test
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090023
Matthew Treinish6c072292014-01-29 19:15:52 +000024CONF = config.CONF
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090025
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090026
Andrea Frittoli247058f2014-07-16 16:09:22 +010027class TestMinimumBasicScenario(manager.ScenarioTest):
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090028
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000029 """This is a basic minimum scenario test.
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090030
31 This test below:
32 * across the multiple components
33 * as a regular user
34 * with and without optional parameters
35 * check command outputs
36
Alexander Gubanova5ab12e2015-11-17 18:18:46 +020037 Steps:
38 1. Create image
39 2. Create keypair
40 3. Boot instance with keypair and get list of instances
41 4. Create volume and show list of volumes
42 5. Attach volume to instance and getlist of volumes
43 6. Add IP to instance
44 7. Create and add security group to instance
45 8. Check SSH connection to instance
46 9. Reboot instance
47 10. Check SSH connection to instance after reboot
48
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090049 """
Jordan Pittier7cf64762015-10-14 15:01:12 +020050 def nova_show(self, server):
51 got_server = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +090052 ['server'])
Jordan Pittier5d367152015-08-19 12:03:49 +020053 excluded_keys = ['OS-EXT-AZ:availability_zone']
54 # Exclude these keys because of LP:#1486475
55 excluded_keys.extend(['OS-EXT-STS:power_state', 'updated'])
Andrea Frittoli247058f2014-07-16 16:09:22 +010056 self.assertThat(
Jordan Pittier7cf64762015-10-14 15:01:12 +020057 server, custom_matchers.MatchesDictExceptForKeys(
Jordan Pittier5d367152015-08-19 12:03:49 +020058 got_server, excluded_keys=excluded_keys))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090059
Jordan Pittier7cf64762015-10-14 15:01:12 +020060 def cinder_show(self, volume):
61 got_volume = self.volumes_client.show_volume(volume['id'])['volume']
62 self.assertEqual(volume, got_volume)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090063
Jordan Pittier7cf64762015-10-14 15:01:12 +020064 def nova_reboot(self, server):
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +000065 self.servers_client.reboot_server(server['id'], type='SOFT')
Masayuki Igawa8bf68672016-01-15 14:43:10 +090066 waiters.wait_for_server_status(self.servers_client,
67 server['id'], 'ACTIVE')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090068
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090069 def check_partitions(self):
Andrea Frittoli247058f2014-07-16 16:09:22 +010070 # NOTE(andreaf) The device name may be different on different guest OS
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090071 partitions = self.linux_client.get_partitions()
Alessandro Pilottib4aa55d2014-08-17 13:57:16 +030072 self.assertEqual(1, partitions.count(CONF.compute.volume_device_name))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090073
Jordan Pittier7cf64762015-10-14 15:01:12 +020074 def create_and_add_security_group_to_server(self, server):
Yair Fried1fc32a12014-08-04 09:11:30 +030075 secgroup = self._create_security_group()
Jordan Pittier7cf64762015-10-14 15:01:12 +020076 self.servers_client.add_security_group(server['id'],
Ken'ichi Ohmichie6349f32015-12-09 06:47:54 +000077 name=secgroup['name'])
Andrea Frittoli247058f2014-07-16 16:09:22 +010078 self.addCleanup(self.servers_client.remove_security_group,
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +000079 server['id'], name=secgroup['name'])
Grishkin0f1e11c2014-05-04 20:44:52 +040080
Clark Boylanff31bcc2014-11-04 13:44:04 -080081 def wait_for_secgroup_add():
Jordan Pittier7cf64762015-10-14 15:01:12 +020082 body = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +090083 ['server'])
Clark Boylanff31bcc2014-11-04 13:44:04 -080084 return {'name': secgroup['name']} in body['security_groups']
85
Jordan Pittier35a63752016-08-30 13:09:12 +020086 if not test_utils.call_until_true(wait_for_secgroup_add,
87 CONF.compute.build_timeout,
88 CONF.compute.build_interval):
Clark Boylanff31bcc2014-11-04 13:44:04 -080089 msg = ('Timed out waiting for adding security group %s to server '
Jordan Pittier7cf64762015-10-14 15:01:12 +020090 '%s' % (secgroup['id'], server['id']))
Clark Boylanff31bcc2014-11-04 13:44:04 -080091 raise exceptions.TimeoutException(msg)
92
Matt Riedemann8ca50562016-08-16 14:46:01 -040093 def _get_floating_ip_in_server_addresses(self, floating_ip, server):
94 for network_name, addresses in server['addresses'].items():
95 for address in addresses:
96 if (address['OS-EXT-IPS:type'] == 'floating' and
97 address['addr'] == floating_ip['ip']):
98 return address
99
Chris Hoge7579c1a2015-02-26 14:12:15 -0800100 @test.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8')
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900101 @test.services('compute', 'volume', 'image', 'network')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900102 def test_minimum_basic_scenario(self):
Jordan Pittier1e443ec2015-11-20 16:15:58 +0100103 image = self.glance_image_create()
Jordan Pittier7cf64762015-10-14 15:01:12 +0200104 keypair = self.create_keypair()
JordanP3fe2dc32014-11-17 13:06:01 +0100105
lanoux5fc14522015-09-21 08:17:35 +0000106 server = self.create_server(image_id=image,
107 key_name=keypair['name'],
108 wait_until='ACTIVE')
Jordan Pittier93dffb72016-09-16 15:12:31 +0200109 servers = self.servers_client.list_servers()['servers']
Jordan Pittier7cf64762015-10-14 15:01:12 +0200110 self.assertIn(server['id'], [x['id'] for x in servers])
JordanP3fe2dc32014-11-17 13:06:01 +0100111
Jordan Pittier7cf64762015-10-14 15:01:12 +0200112 self.nova_show(server)
113
Jordan Pittierbbb17122016-01-26 17:10:55 +0100114 volume = self.create_volume()
115 volumes = self.volumes_client.list_volumes()['volumes']
Jordan Pittier7cf64762015-10-14 15:01:12 +0200116 self.assertIn(volume['id'], [x['id'] for x in volumes])
117
118 self.cinder_show(volume)
119
120 volume = self.nova_volume_attach(server, volume)
121 self.addCleanup(self.nova_volume_detach, server, volume)
122 self.cinder_show(volume)
123
124 floating_ip = self.create_floating_ip(server)
Matt Riedemann8ca50562016-08-16 14:46:01 -0400125 # fetch the server again to make sure the addresses were refreshed
126 # after associating the floating IP
127 server = self.servers_client.show_server(server['id'])['server']
128 address = self._get_floating_ip_in_server_addresses(
129 floating_ip, server)
130 self.assertIsNotNone(
131 address,
132 "Failed to find floating IP '%s' in server addresses: %s" %
133 (floating_ip['ip'], server['addresses']))
134
Jordan Pittier7cf64762015-10-14 15:01:12 +0200135 self.create_and_add_security_group_to_server(server)
136
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200137 # check that we can SSH to the server before reboot
Jordan Pittier7cf64762015-10-14 15:01:12 +0200138 self.linux_client = self.get_remote_client(
139 floating_ip['ip'], private_key=keypair['private_key'])
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200140
Jordan Pittier7cf64762015-10-14 15:01:12 +0200141 self.nova_reboot(server)
142
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200143 # check that we can SSH to the server after reboot
144 # (both connections are part of the scenario)
Jordan Pittier7cf64762015-10-14 15:01:12 +0200145 self.linux_client = self.get_remote_client(
146 floating_ip['ip'], private_key=keypair['private_key'])
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200147
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900148 self.check_partitions()
Matt Riedemann8ca50562016-08-16 14:46:01 -0400149
150 # delete the floating IP, this should refresh the server addresses
151 self.compute_floating_ips_client.delete_floating_ip(floating_ip['id'])
zhuflc310b8d2016-09-27 11:33:23 +0800152
153 def is_floating_ip_detached_from_server():
154 server_info = self.servers_client.show_server(
155 server['id'])['server']
156 address = self._get_floating_ip_in_server_addresses(
157 floating_ip, server_info)
158 return (not address)
159
160 if not test_utils.call_until_true(
161 is_floating_ip_detached_from_server,
162 CONF.compute.build_timeout,
163 CONF.compute.build_interval):
164 msg = ("Floating IP '%s' should not be in server addresses: %s" %
165 (floating_ip['ip'], server['addresses']))
166 raise exceptions.TimeoutException(msg)