blob: ff9dabf991c6ffcd570cca8829ae53931b8bf5b6 [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
Clark Boylanff31bcc2014-11-04 13:44:04 -080019from tempest import exceptions
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090020from tempest.scenario import manager
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090021from tempest import test
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090022
Matthew Treinish6c072292014-01-29 19:15:52 +000023CONF = config.CONF
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090024
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090025
Andrea Frittoli247058f2014-07-16 16:09:22 +010026class TestMinimumBasicScenario(manager.ScenarioTest):
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090027
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000028 """This is a basic minimum scenario test.
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090029
30 This test below:
31 * across the multiple components
32 * as a regular user
33 * with and without optional parameters
34 * check command outputs
35
Alexander Gubanova5ab12e2015-11-17 18:18:46 +020036 Steps:
37 1. Create image
38 2. Create keypair
39 3. Boot instance with keypair and get list of instances
40 4. Create volume and show list of volumes
41 5. Attach volume to instance and getlist of volumes
42 6. Add IP to instance
43 7. Create and add security group to instance
44 8. Check SSH connection to instance
45 9. Reboot instance
46 10. Check SSH connection to instance after reboot
47
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090048 """
49
Jordan Pittier7cf64762015-10-14 15:01:12 +020050 def _wait_for_server_status(self, server, status):
51 server_id = server['id']
Andrea Frittoli247058f2014-07-16 16:09:22 +010052 # Raise on error defaults to True, which is consistent with the
53 # original function from scenario tests here
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000054 waiters.wait_for_server_status(self.servers_client,
55 server_id, status)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090056
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090057 def nova_list(self):
David Kranzae99b9a2015-02-16 13:37:01 -050058 servers = self.servers_client.list_servers()
Andrea Frittoli247058f2014-07-16 16:09:22 +010059 # The list servers in the compute client is inconsistent...
Jordan Pittier7cf64762015-10-14 15:01:12 +020060 return servers['servers']
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090061
Jordan Pittier7cf64762015-10-14 15:01:12 +020062 def nova_show(self, server):
63 got_server = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +090064 ['server'])
Jordan Pittier5d367152015-08-19 12:03:49 +020065 excluded_keys = ['OS-EXT-AZ:availability_zone']
66 # Exclude these keys because of LP:#1486475
67 excluded_keys.extend(['OS-EXT-STS:power_state', 'updated'])
Andrea Frittoli247058f2014-07-16 16:09:22 +010068 self.assertThat(
Jordan Pittier7cf64762015-10-14 15:01:12 +020069 server, custom_matchers.MatchesDictExceptForKeys(
Jordan Pittier5d367152015-08-19 12:03:49 +020070 got_server, excluded_keys=excluded_keys))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090071
72 def cinder_create(self):
Jordan Pittier7cf64762015-10-14 15:01:12 +020073 return self.create_volume()
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090074
75 def cinder_list(self):
Jordan Pittier7cf64762015-10-14 15:01:12 +020076 return self.volumes_client.list_volumes()['volumes']
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090077
Jordan Pittier7cf64762015-10-14 15:01:12 +020078 def cinder_show(self, volume):
79 got_volume = self.volumes_client.show_volume(volume['id'])['volume']
80 self.assertEqual(volume, got_volume)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090081
Jordan Pittier7cf64762015-10-14 15:01:12 +020082 def nova_reboot(self, server):
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +000083 self.servers_client.reboot_server(server['id'], type='SOFT')
Jordan Pittier7cf64762015-10-14 15:01:12 +020084 self._wait_for_server_status(server, 'ACTIVE')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090085
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090086 def check_partitions(self):
Andrea Frittoli247058f2014-07-16 16:09:22 +010087 # NOTE(andreaf) The device name may be different on different guest OS
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090088 partitions = self.linux_client.get_partitions()
Alessandro Pilottib4aa55d2014-08-17 13:57:16 +030089 self.assertEqual(1, partitions.count(CONF.compute.volume_device_name))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090090
Jordan Pittier7cf64762015-10-14 15:01:12 +020091 def create_and_add_security_group_to_server(self, server):
Yair Fried1fc32a12014-08-04 09:11:30 +030092 secgroup = self._create_security_group()
Jordan Pittier7cf64762015-10-14 15:01:12 +020093 self.servers_client.add_security_group(server['id'],
Ken'ichi Ohmichie6349f32015-12-09 06:47:54 +000094 name=secgroup['name'])
Andrea Frittoli247058f2014-07-16 16:09:22 +010095 self.addCleanup(self.servers_client.remove_security_group,
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +000096 server['id'], name=secgroup['name'])
Grishkin0f1e11c2014-05-04 20:44:52 +040097
Clark Boylanff31bcc2014-11-04 13:44:04 -080098 def wait_for_secgroup_add():
Jordan Pittier7cf64762015-10-14 15:01:12 +020099 body = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +0900100 ['server'])
Clark Boylanff31bcc2014-11-04 13:44:04 -0800101 return {'name': secgroup['name']} in body['security_groups']
102
103 if not test.call_until_true(wait_for_secgroup_add,
104 CONF.compute.build_timeout,
105 CONF.compute.build_interval):
106 msg = ('Timed out waiting for adding security group %s to server '
Jordan Pittier7cf64762015-10-14 15:01:12 +0200107 '%s' % (secgroup['id'], server['id']))
Clark Boylanff31bcc2014-11-04 13:44:04 -0800108 raise exceptions.TimeoutException(msg)
109
Chris Hoge7579c1a2015-02-26 14:12:15 -0800110 @test.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8')
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900111 @test.services('compute', 'volume', 'image', 'network')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900112 def test_minimum_basic_scenario(self):
Jordan Pittier1e443ec2015-11-20 16:15:58 +0100113 image = self.glance_image_create()
Jordan Pittier7cf64762015-10-14 15:01:12 +0200114 keypair = self.create_keypair()
JordanP3fe2dc32014-11-17 13:06:01 +0100115
lanoux5fc14522015-09-21 08:17:35 +0000116 server = self.create_server(image_id=image,
117 key_name=keypair['name'],
118 wait_until='ACTIVE')
Jordan Pittier7cf64762015-10-14 15:01:12 +0200119 servers = self.nova_list()
120 self.assertIn(server['id'], [x['id'] for x in servers])
JordanP3fe2dc32014-11-17 13:06:01 +0100121
Jordan Pittier7cf64762015-10-14 15:01:12 +0200122 self.nova_show(server)
123
124 volume = self.cinder_create()
125 volumes = self.cinder_list()
126 self.assertIn(volume['id'], [x['id'] for x in volumes])
127
128 self.cinder_show(volume)
129
130 volume = self.nova_volume_attach(server, volume)
131 self.addCleanup(self.nova_volume_detach, server, volume)
132 self.cinder_show(volume)
133
134 floating_ip = self.create_floating_ip(server)
135 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()