blob: e4d7ecea9c77e9294f9769281b989cec889b6c17 [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
Matthew Treinish6c072292014-01-29 19:15:52 +000017from tempest import config
Clark Boylanff31bcc2014-11-04 13:44:04 -080018from tempest import exceptions
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040019from tempest.openstack.common import log as logging
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
25LOG = logging.getLogger(__name__)
26
27
Andrea Frittoli247058f2014-07-16 16:09:22 +010028class TestMinimumBasicScenario(manager.ScenarioTest):
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090029
30 """
31 This is a basic minimum scenario test.
32
33 This test below:
34 * across the multiple components
35 * as a regular user
36 * with and without optional parameters
37 * check command outputs
38
39 """
40
41 def _wait_for_server_status(self, status):
Andrea Frittoli247058f2014-07-16 16:09:22 +010042 server_id = self.server['id']
43 # Raise on error defaults to True, which is consistent with the
44 # original function from scenario tests here
45 self.servers_client.wait_for_server_status(server_id, status)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090046
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090047 def nova_keypair_add(self):
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +090048 self.keypair = self.create_keypair()
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090049
50 def nova_boot(self):
Andrea Frittoli247058f2014-07-16 16:09:22 +010051 create_kwargs = {'key_name': self.keypair['name']}
Giulio Fidente61cadca2013-09-24 18:33:37 +020052 self.server = self.create_server(image=self.image,
Ken'ichi Ohmichi61f272b2013-08-15 15:58:53 +090053 create_kwargs=create_kwargs)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090054
55 def nova_list(self):
David Kranzae99b9a2015-02-16 13:37:01 -050056 servers = self.servers_client.list_servers()
Andrea Frittoli247058f2014-07-16 16:09:22 +010057 # The list servers in the compute client is inconsistent...
58 servers = servers['servers']
59 self.assertIn(self.server['id'], [x['id'] for x in servers])
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090060
61 def nova_show(self):
David Kranz0fb14292015-02-11 15:55:20 -050062 got_server = self.servers_client.get_server(self.server['id'])
Andrea Frittoli247058f2014-07-16 16:09:22 +010063 self.assertThat(
64 self.server, custom_matchers.MatchesDictExceptForKeys(
65 got_server, excluded_keys=['OS-EXT-AZ:availability_zone']))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090066
67 def cinder_create(self):
Ken'ichi Ohmichi70672df2013-08-19 18:35:19 +090068 self.volume = self.create_volume()
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090069
70 def cinder_list(self):
Joseph Lanoux6809bab2014-12-18 14:57:18 +000071 volumes = self.volumes_client.list_volumes()
Andrea Frittoli247058f2014-07-16 16:09:22 +010072 self.assertIn(self.volume['id'], [x['id'] for x in volumes])
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090073
74 def cinder_show(self):
Joseph Lanoux6809bab2014-12-18 14:57:18 +000075 volume = self.volumes_client.get_volume(self.volume['id'])
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090076 self.assertEqual(self.volume, volume)
77
78 def nova_volume_attach(self):
Alessandro Pilottib4aa55d2014-08-17 13:57:16 +030079 volume_device_path = '/dev/' + CONF.compute.volume_device_name
Joseph Lanoux6809bab2014-12-18 14:57:18 +000080 volume = self.servers_client.attach_volume(
David Kranz3ebc7212015-02-10 12:19:19 -050081 self.server['id'], self.volume['id'], volume_device_path)
Andrea Frittoli247058f2014-07-16 16:09:22 +010082 self.assertEqual(self.volume['id'], volume['id'])
83 self.volumes_client.wait_for_volume_status(volume['id'], 'in-use')
84 # Refresh the volume after the attachment
Joseph Lanoux6809bab2014-12-18 14:57:18 +000085 self.volume = self.volumes_client.get_volume(volume['id'])
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090086
87 def nova_reboot(self):
Andrea Frittoli247058f2014-07-16 16:09:22 +010088 self.servers_client.reboot(self.server['id'], 'SOFT')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090089 self._wait_for_server_status('ACTIVE')
90
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090091 def check_partitions(self):
Andrea Frittoli247058f2014-07-16 16:09:22 +010092 # NOTE(andreaf) The device name may be different on different guest OS
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090093 partitions = self.linux_client.get_partitions()
Alessandro Pilottib4aa55d2014-08-17 13:57:16 +030094 self.assertEqual(1, partitions.count(CONF.compute.volume_device_name))
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090095
96 def nova_volume_detach(self):
Andrea Frittoli247058f2014-07-16 16:09:22 +010097 self.servers_client.detach_volume(self.server['id'], self.volume['id'])
98 self.volumes_client.wait_for_volume_status(self.volume['id'],
99 'available')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900100
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000101 volume = self.volumes_client.get_volume(self.volume['id'])
Andrea Frittoli247058f2014-07-16 16:09:22 +0100102 self.assertEqual('available', volume['status'])
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900103
Grishkin0f1e11c2014-05-04 20:44:52 +0400104 def create_and_add_security_group(self):
Yair Fried1fc32a12014-08-04 09:11:30 +0300105 secgroup = self._create_security_group()
Andrea Frittoli247058f2014-07-16 16:09:22 +0100106 self.servers_client.add_security_group(self.server['id'],
107 secgroup['name'])
108 self.addCleanup(self.servers_client.remove_security_group,
109 self.server['id'], secgroup['name'])
Grishkin0f1e11c2014-05-04 20:44:52 +0400110
Clark Boylanff31bcc2014-11-04 13:44:04 -0800111 def wait_for_secgroup_add():
David Kranz0fb14292015-02-11 15:55:20 -0500112 body = self.servers_client.get_server(self.server['id'])
Clark Boylanff31bcc2014-11-04 13:44:04 -0800113 return {'name': secgroup['name']} in body['security_groups']
114
115 if not test.call_until_true(wait_for_secgroup_add,
116 CONF.compute.build_timeout,
117 CONF.compute.build_interval):
118 msg = ('Timed out waiting for adding security group %s to server '
119 '%s' % (secgroup['id'], self.server['id']))
120 raise exceptions.TimeoutException(msg)
121
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900122 @test.services('compute', 'volume', 'image', 'network')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900123 def test_minimum_basic_scenario(self):
124 self.glance_image_create()
125 self.nova_keypair_add()
126 self.nova_boot()
127 self.nova_list()
128 self.nova_show()
129 self.cinder_create()
130 self.cinder_list()
131 self.cinder_show()
132 self.nova_volume_attach()
john-griffith5462b332013-12-13 10:04:43 -0500133 self.addCleanup(self.nova_volume_detach)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900134 self.cinder_show()
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900135
Yair Friedae0e73d2014-11-24 11:56:26 +0200136 self.floating_ip = self.create_floating_ip(self.server)
Grishkin0f1e11c2014-05-04 20:44:52 +0400137 self.create_and_add_security_group()
JordanP3fe2dc32014-11-17 13:06:01 +0100138
139 self.linux_client = self.get_remote_client(self.floating_ip['ip'])
Attila Fazekas28c25202014-02-08 18:51:38 +0100140 self.nova_reboot()
JordanP3fe2dc32014-11-17 13:06:01 +0100141
142 self.linux_client = self.get_remote_client(self.floating_ip['ip'])
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900143 self.check_partitions()