blob: 585b19d4c4de3f177004359e1d70936a20ad0eb4 [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016from oslo_log import log as logging
17
Andrea Frittoli247058f2014-07-16 16:09:22 +010018from tempest.common import custom_matchers
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000019from tempest.common import waiters
Matthew Treinish6c072292014-01-29 19:15:52 +000020from tempest import config
Clark Boylanff31bcc2014-11-04 13:44:04 -080021from tempest import exceptions
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090022from tempest.scenario import manager
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090023from tempest import test
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090024
Matthew Treinish6c072292014-01-29 19:15:52 +000025CONF = config.CONF
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090026
27LOG = logging.getLogger(__name__)
28
29
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 """
53
Jordan Pittier7cf64762015-10-14 15:01:12 +020054 def _wait_for_server_status(self, server, status):
55 server_id = server['id']
Andrea Frittoli247058f2014-07-16 16:09:22 +010056 # Raise on error defaults to True, which is consistent with the
57 # original function from scenario tests here
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000058 waiters.wait_for_server_status(self.servers_client,
59 server_id, status)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090060
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090061 def nova_list(self):
David Kranzae99b9a2015-02-16 13:37:01 -050062 servers = self.servers_client.list_servers()
Andrea Frittoli247058f2014-07-16 16:09:22 +010063 # The list servers in the compute client is inconsistent...
Jordan Pittier7cf64762015-10-14 15:01:12 +020064 return servers['servers']
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090065
Jordan Pittier7cf64762015-10-14 15:01:12 +020066 def nova_show(self, server):
67 got_server = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +090068 ['server'])
Jordan Pittier5d367152015-08-19 12:03:49 +020069 excluded_keys = ['OS-EXT-AZ:availability_zone']
70 # Exclude these keys because of LP:#1486475
71 excluded_keys.extend(['OS-EXT-STS:power_state', 'updated'])
Andrea Frittoli247058f2014-07-16 16:09:22 +010072 self.assertThat(
Jordan Pittier7cf64762015-10-14 15:01:12 +020073 server, custom_matchers.MatchesDictExceptForKeys(
Jordan Pittier5d367152015-08-19 12:03:49 +020074 got_server, excluded_keys=excluded_keys))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090075
76 def cinder_create(self):
Jordan Pittier7cf64762015-10-14 15:01:12 +020077 return self.create_volume()
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090078
79 def cinder_list(self):
Jordan Pittier7cf64762015-10-14 15:01:12 +020080 return self.volumes_client.list_volumes()['volumes']
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090081
Jordan Pittier7cf64762015-10-14 15:01:12 +020082 def cinder_show(self, volume):
83 got_volume = self.volumes_client.show_volume(volume['id'])['volume']
84 self.assertEqual(volume, got_volume)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090085
Jordan Pittier7cf64762015-10-14 15:01:12 +020086 def nova_reboot(self, server):
87 self.servers_client.reboot_server(server['id'], 'SOFT')
88 self._wait_for_server_status(server, 'ACTIVE')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090089
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090090 def check_partitions(self):
Andrea Frittoli247058f2014-07-16 16:09:22 +010091 # NOTE(andreaf) The device name may be different on different guest OS
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090092 partitions = self.linux_client.get_partitions()
Alessandro Pilottib4aa55d2014-08-17 13:57:16 +030093 self.assertEqual(1, partitions.count(CONF.compute.volume_device_name))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090094
Jordan Pittier7cf64762015-10-14 15:01:12 +020095 def create_and_add_security_group_to_server(self, server):
Yair Fried1fc32a12014-08-04 09:11:30 +030096 secgroup = self._create_security_group()
Jordan Pittier7cf64762015-10-14 15:01:12 +020097 self.servers_client.add_security_group(server['id'],
Ken'ichi Ohmichie6349f32015-12-09 06:47:54 +000098 name=secgroup['name'])
Andrea Frittoli247058f2014-07-16 16:09:22 +010099 self.addCleanup(self.servers_client.remove_security_group,
Jordan Pittier7cf64762015-10-14 15:01:12 +0200100 server['id'], secgroup['name'])
Grishkin0f1e11c2014-05-04 20:44:52 +0400101
Clark Boylanff31bcc2014-11-04 13:44:04 -0800102 def wait_for_secgroup_add():
Jordan Pittier7cf64762015-10-14 15:01:12 +0200103 body = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +0900104 ['server'])
Clark Boylanff31bcc2014-11-04 13:44:04 -0800105 return {'name': secgroup['name']} in body['security_groups']
106
107 if not test.call_until_true(wait_for_secgroup_add,
108 CONF.compute.build_timeout,
109 CONF.compute.build_interval):
110 msg = ('Timed out waiting for adding security group %s to server '
Jordan Pittier7cf64762015-10-14 15:01:12 +0200111 '%s' % (secgroup['id'], server['id']))
Clark Boylanff31bcc2014-11-04 13:44:04 -0800112 raise exceptions.TimeoutException(msg)
113
Chris Hoge7579c1a2015-02-26 14:12:15 -0800114 @test.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8')
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900115 @test.services('compute', 'volume', 'image', 'network')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900116 def test_minimum_basic_scenario(self):
Jordan Pittier1e443ec2015-11-20 16:15:58 +0100117 image = self.glance_image_create()
Jordan Pittier7cf64762015-10-14 15:01:12 +0200118 keypair = self.create_keypair()
JordanP3fe2dc32014-11-17 13:06:01 +0100119
lanoux5fc14522015-09-21 08:17:35 +0000120 server = self.create_server(image_id=image,
121 key_name=keypair['name'],
122 wait_until='ACTIVE')
Jordan Pittier7cf64762015-10-14 15:01:12 +0200123 servers = self.nova_list()
124 self.assertIn(server['id'], [x['id'] for x in servers])
JordanP3fe2dc32014-11-17 13:06:01 +0100125
Jordan Pittier7cf64762015-10-14 15:01:12 +0200126 self.nova_show(server)
127
128 volume = self.cinder_create()
129 volumes = self.cinder_list()
130 self.assertIn(volume['id'], [x['id'] for x in volumes])
131
132 self.cinder_show(volume)
133
134 volume = self.nova_volume_attach(server, volume)
135 self.addCleanup(self.nova_volume_detach, server, volume)
136 self.cinder_show(volume)
137
138 floating_ip = self.create_floating_ip(server)
139 self.create_and_add_security_group_to_server(server)
140
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200141 # check that we can SSH to the server before reboot
Jordan Pittier7cf64762015-10-14 15:01:12 +0200142 self.linux_client = self.get_remote_client(
143 floating_ip['ip'], private_key=keypair['private_key'])
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200144
Jordan Pittier7cf64762015-10-14 15:01:12 +0200145 self.nova_reboot(server)
146
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200147 # check that we can SSH to the server after reboot
148 # (both connections are part of the scenario)
Jordan Pittier7cf64762015-10-14 15:01:12 +0200149 self.linux_client = self.get_remote_client(
150 floating_ip['ip'], private_key=keypair['private_key'])
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200151
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900152 self.check_partitions()