blob: a5b5a1ba29d75b8c80cd9587c4ac45a94c8e221c [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
Jordan Pittier7cf64762015-10-14 15:01:12 +020061 def nova_boot(self, keypair):
62 create_kwargs = {'key_name': keypair['name']}
63 return self.create_server(image=self.image,
64 create_kwargs=create_kwargs)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090065
66 def nova_list(self):
David Kranzae99b9a2015-02-16 13:37:01 -050067 servers = self.servers_client.list_servers()
Andrea Frittoli247058f2014-07-16 16:09:22 +010068 # The list servers in the compute client is inconsistent...
Jordan Pittier7cf64762015-10-14 15:01:12 +020069 return servers['servers']
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090070
Jordan Pittier7cf64762015-10-14 15:01:12 +020071 def nova_show(self, server):
72 got_server = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +090073 ['server'])
Jordan Pittier5d367152015-08-19 12:03:49 +020074 excluded_keys = ['OS-EXT-AZ:availability_zone']
75 # Exclude these keys because of LP:#1486475
76 excluded_keys.extend(['OS-EXT-STS:power_state', 'updated'])
Andrea Frittoli247058f2014-07-16 16:09:22 +010077 self.assertThat(
Jordan Pittier7cf64762015-10-14 15:01:12 +020078 server, custom_matchers.MatchesDictExceptForKeys(
Jordan Pittier5d367152015-08-19 12:03:49 +020079 got_server, excluded_keys=excluded_keys))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090080
81 def cinder_create(self):
Jordan Pittier7cf64762015-10-14 15:01:12 +020082 return self.create_volume()
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090083
84 def cinder_list(self):
Jordan Pittier7cf64762015-10-14 15:01:12 +020085 return self.volumes_client.list_volumes()['volumes']
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090086
Jordan Pittier7cf64762015-10-14 15:01:12 +020087 def cinder_show(self, volume):
88 got_volume = self.volumes_client.show_volume(volume['id'])['volume']
89 self.assertEqual(volume, got_volume)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090090
Jordan Pittier7cf64762015-10-14 15:01:12 +020091 def nova_reboot(self, server):
92 self.servers_client.reboot_server(server['id'], 'SOFT')
93 self._wait_for_server_status(server, 'ACTIVE')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090094
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090095 def check_partitions(self):
Andrea Frittoli247058f2014-07-16 16:09:22 +010096 # NOTE(andreaf) The device name may be different on different guest OS
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090097 partitions = self.linux_client.get_partitions()
Alessandro Pilottib4aa55d2014-08-17 13:57:16 +030098 self.assertEqual(1, partitions.count(CONF.compute.volume_device_name))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090099
Jordan Pittier7cf64762015-10-14 15:01:12 +0200100 def create_and_add_security_group_to_server(self, server):
Yair Fried1fc32a12014-08-04 09:11:30 +0300101 secgroup = self._create_security_group()
Jordan Pittier7cf64762015-10-14 15:01:12 +0200102 self.servers_client.add_security_group(server['id'],
Andrea Frittoli247058f2014-07-16 16:09:22 +0100103 secgroup['name'])
104 self.addCleanup(self.servers_client.remove_security_group,
Jordan Pittier7cf64762015-10-14 15:01:12 +0200105 server['id'], secgroup['name'])
Grishkin0f1e11c2014-05-04 20:44:52 +0400106
Clark Boylanff31bcc2014-11-04 13:44:04 -0800107 def wait_for_secgroup_add():
Jordan Pittier7cf64762015-10-14 15:01:12 +0200108 body = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +0900109 ['server'])
Clark Boylanff31bcc2014-11-04 13:44:04 -0800110 return {'name': secgroup['name']} in body['security_groups']
111
112 if not test.call_until_true(wait_for_secgroup_add,
113 CONF.compute.build_timeout,
114 CONF.compute.build_interval):
115 msg = ('Timed out waiting for adding security group %s to server '
Jordan Pittier7cf64762015-10-14 15:01:12 +0200116 '%s' % (secgroup['id'], server['id']))
Clark Boylanff31bcc2014-11-04 13:44:04 -0800117 raise exceptions.TimeoutException(msg)
118
Chris Hoge7579c1a2015-02-26 14:12:15 -0800119 @test.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8')
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900120 @test.services('compute', 'volume', 'image', 'network')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900121 def test_minimum_basic_scenario(self):
122 self.glance_image_create()
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900123
Jordan Pittier7cf64762015-10-14 15:01:12 +0200124 keypair = self.create_keypair()
JordanP3fe2dc32014-11-17 13:06:01 +0100125
Jordan Pittier7cf64762015-10-14 15:01:12 +0200126 server = self.nova_boot(keypair)
127 servers = self.nova_list()
128 self.assertIn(server['id'], [x['id'] for x in servers])
JordanP3fe2dc32014-11-17 13:06:01 +0100129
Jordan Pittier7cf64762015-10-14 15:01:12 +0200130 self.nova_show(server)
131
132 volume = self.cinder_create()
133 volumes = self.cinder_list()
134 self.assertIn(volume['id'], [x['id'] for x in volumes])
135
136 self.cinder_show(volume)
137
138 volume = self.nova_volume_attach(server, volume)
139 self.addCleanup(self.nova_volume_detach, server, volume)
140 self.cinder_show(volume)
141
142 floating_ip = self.create_floating_ip(server)
143 self.create_and_add_security_group_to_server(server)
144
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200145 # check that we can SSH to the server before reboot
Jordan Pittier7cf64762015-10-14 15:01:12 +0200146 self.linux_client = self.get_remote_client(
147 floating_ip['ip'], private_key=keypair['private_key'])
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200148
Jordan Pittier7cf64762015-10-14 15:01:12 +0200149 self.nova_reboot(server)
150
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200151 # check that we can SSH to the server after reboot
152 # (both connections are part of the scenario)
Jordan Pittier7cf64762015-10-14 15:01:12 +0200153 self.linux_client = self.get_remote_client(
154 floating_ip['ip'], private_key=keypair['private_key'])
Alexander Gubanova5ab12e2015-11-17 18:18:46 +0200155
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900156 self.check_partitions()