blob: 13816e71ac66d575c05a6f8059f44d722cf9ebc6 [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
40 """
41
Jordan Pittier7cf64762015-10-14 15:01:12 +020042 def _wait_for_server_status(self, server, status):
43 server_id = server['id']
Andrea Frittoli247058f2014-07-16 16:09:22 +010044 # Raise on error defaults to True, which is consistent with the
45 # original function from scenario tests here
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000046 waiters.wait_for_server_status(self.servers_client,
47 server_id, status)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090048
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090049 def nova_list(self):
David Kranzae99b9a2015-02-16 13:37:01 -050050 servers = self.servers_client.list_servers()
Andrea Frittoli247058f2014-07-16 16:09:22 +010051 # The list servers in the compute client is inconsistent...
Jordan Pittier7cf64762015-10-14 15:01:12 +020052 return servers['servers']
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090053
Jordan Pittier7cf64762015-10-14 15:01:12 +020054 def nova_show(self, server):
55 got_server = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +090056 ['server'])
Jordan Pittier5d367152015-08-19 12:03:49 +020057 excluded_keys = ['OS-EXT-AZ:availability_zone']
58 # Exclude these keys because of LP:#1486475
59 excluded_keys.extend(['OS-EXT-STS:power_state', 'updated'])
Andrea Frittoli247058f2014-07-16 16:09:22 +010060 self.assertThat(
Jordan Pittier7cf64762015-10-14 15:01:12 +020061 server, custom_matchers.MatchesDictExceptForKeys(
Jordan Pittier5d367152015-08-19 12:03:49 +020062 got_server, excluded_keys=excluded_keys))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090063
64 def cinder_create(self):
Jordan Pittier7cf64762015-10-14 15:01:12 +020065 return self.create_volume()
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090066
67 def cinder_list(self):
Jordan Pittier7cf64762015-10-14 15:01:12 +020068 return self.volumes_client.list_volumes()['volumes']
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090069
Jordan Pittier7cf64762015-10-14 15:01:12 +020070 def cinder_show(self, volume):
71 got_volume = self.volumes_client.show_volume(volume['id'])['volume']
72 self.assertEqual(volume, got_volume)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090073
Jordan Pittier7cf64762015-10-14 15:01:12 +020074 def nova_reboot(self, server):
75 self.servers_client.reboot_server(server['id'], 'SOFT')
76 self._wait_for_server_status(server, 'ACTIVE')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090077
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090078 def check_partitions(self):
Andrea Frittoli247058f2014-07-16 16:09:22 +010079 # NOTE(andreaf) The device name may be different on different guest OS
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090080 partitions = self.linux_client.get_partitions()
Alessandro Pilottib4aa55d2014-08-17 13:57:16 +030081 self.assertEqual(1, partitions.count(CONF.compute.volume_device_name))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090082
Jordan Pittier7cf64762015-10-14 15:01:12 +020083 def create_and_add_security_group_to_server(self, server):
Yair Fried1fc32a12014-08-04 09:11:30 +030084 secgroup = self._create_security_group()
Jordan Pittier7cf64762015-10-14 15:01:12 +020085 self.servers_client.add_security_group(server['id'],
Andrea Frittoli247058f2014-07-16 16:09:22 +010086 secgroup['name'])
87 self.addCleanup(self.servers_client.remove_security_group,
Jordan Pittier7cf64762015-10-14 15:01:12 +020088 server['id'], secgroup['name'])
Grishkin0f1e11c2014-05-04 20:44:52 +040089
Clark Boylanff31bcc2014-11-04 13:44:04 -080090 def wait_for_secgroup_add():
Jordan Pittier7cf64762015-10-14 15:01:12 +020091 body = (self.servers_client.show_server(server['id'])
ghanshyam0f825252015-08-25 16:02:50 +090092 ['server'])
Clark Boylanff31bcc2014-11-04 13:44:04 -080093 return {'name': secgroup['name']} in body['security_groups']
94
95 if not test.call_until_true(wait_for_secgroup_add,
96 CONF.compute.build_timeout,
97 CONF.compute.build_interval):
98 msg = ('Timed out waiting for adding security group %s to server '
Jordan Pittier7cf64762015-10-14 15:01:12 +020099 '%s' % (secgroup['id'], server['id']))
Clark Boylanff31bcc2014-11-04 13:44:04 -0800100 raise exceptions.TimeoutException(msg)
101
Chris Hoge7579c1a2015-02-26 14:12:15 -0800102 @test.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8')
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900103 @test.services('compute', 'volume', 'image', 'network')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900104 def test_minimum_basic_scenario(self):
Jordan Pittier1e443ec2015-11-20 16:15:58 +0100105 image = self.glance_image_create()
Jordan Pittier7cf64762015-10-14 15:01:12 +0200106 keypair = self.create_keypair()
JordanP3fe2dc32014-11-17 13:06:01 +0100107
Jordan Pittier1e443ec2015-11-20 16:15:58 +0100108 create_kwargs = {'key_name': keypair['name']}
109 server = self.create_server(image=image,
110 create_kwargs=create_kwargs)
Jordan Pittier7cf64762015-10-14 15:01:12 +0200111 servers = self.nova_list()
112 self.assertIn(server['id'], [x['id'] for x in servers])
JordanP3fe2dc32014-11-17 13:06:01 +0100113
Jordan Pittier7cf64762015-10-14 15:01:12 +0200114 self.nova_show(server)
115
116 volume = self.cinder_create()
117 volumes = self.cinder_list()
118 self.assertIn(volume['id'], [x['id'] for x in volumes])
119
120 self.cinder_show(volume)
121
122 volume = self.nova_volume_attach(server, volume)
123 self.addCleanup(self.nova_volume_detach, server, volume)
124 self.cinder_show(volume)
125
126 floating_ip = self.create_floating_ip(server)
127 self.create_and_add_security_group_to_server(server)
128
129 self.linux_client = self.get_remote_client(
130 floating_ip['ip'], private_key=keypair['private_key'])
131 self.nova_reboot(server)
132
133 self.linux_client = self.get_remote_client(
134 floating_ip['ip'], private_key=keypair['private_key'])
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900135 self.check_partitions()