Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 1 | # 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 Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 16 | from tempest.common import custom_matchers |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 17 | from tempest import config |
Clark Boylan | ff31bcc | 2014-11-04 13:44:04 -0800 | [diff] [blame] | 18 | from tempest import exceptions |
Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 19 | from tempest.openstack.common import log as logging |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 20 | from tempest.scenario import manager |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 21 | from tempest import test |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 22 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 23 | CONF = config.CONF |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 24 | |
| 25 | LOG = logging.getLogger(__name__) |
| 26 | |
| 27 | |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 28 | class TestMinimumBasicScenario(manager.ScenarioTest): |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 29 | |
| 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 Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 42 | 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 Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 46 | |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 47 | def nova_keypair_add(self): |
Ken'ichi Ohmichi | 599d1b8 | 2013-08-19 18:48:37 +0900 | [diff] [blame] | 48 | self.keypair = self.create_keypair() |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 49 | |
| 50 | def nova_boot(self): |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 51 | create_kwargs = {'key_name': self.keypair['name']} |
Giulio Fidente | 61cadca | 2013-09-24 18:33:37 +0200 | [diff] [blame] | 52 | self.server = self.create_server(image=self.image, |
Ken'ichi Ohmichi | 61f272b | 2013-08-15 15:58:53 +0900 | [diff] [blame] | 53 | create_kwargs=create_kwargs) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 54 | |
| 55 | def nova_list(self): |
David Kranz | ae99b9a | 2015-02-16 13:37:01 -0500 | [diff] [blame^] | 56 | servers = self.servers_client.list_servers() |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 57 | # 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 Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 60 | |
| 61 | def nova_show(self): |
David Kranz | 0fb1429 | 2015-02-11 15:55:20 -0500 | [diff] [blame] | 62 | got_server = self.servers_client.get_server(self.server['id']) |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 63 | self.assertThat( |
| 64 | self.server, custom_matchers.MatchesDictExceptForKeys( |
| 65 | got_server, excluded_keys=['OS-EXT-AZ:availability_zone'])) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 66 | |
| 67 | def cinder_create(self): |
Ken'ichi Ohmichi | 70672df | 2013-08-19 18:35:19 +0900 | [diff] [blame] | 68 | self.volume = self.create_volume() |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 69 | |
| 70 | def cinder_list(self): |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 71 | volumes = self.volumes_client.list_volumes() |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 72 | self.assertIn(self.volume['id'], [x['id'] for x in volumes]) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 73 | |
| 74 | def cinder_show(self): |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 75 | volume = self.volumes_client.get_volume(self.volume['id']) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 76 | self.assertEqual(self.volume, volume) |
| 77 | |
| 78 | def nova_volume_attach(self): |
Alessandro Pilotti | b4aa55d | 2014-08-17 13:57:16 +0300 | [diff] [blame] | 79 | volume_device_path = '/dev/' + CONF.compute.volume_device_name |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 80 | volume = self.servers_client.attach_volume( |
David Kranz | 3ebc721 | 2015-02-10 12:19:19 -0500 | [diff] [blame] | 81 | self.server['id'], self.volume['id'], volume_device_path) |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 82 | 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 Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 85 | self.volume = self.volumes_client.get_volume(volume['id']) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 86 | |
| 87 | def nova_reboot(self): |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 88 | self.servers_client.reboot(self.server['id'], 'SOFT') |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 89 | self._wait_for_server_status('ACTIVE') |
| 90 | |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 91 | def check_partitions(self): |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 92 | # NOTE(andreaf) The device name may be different on different guest OS |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 93 | partitions = self.linux_client.get_partitions() |
Alessandro Pilotti | b4aa55d | 2014-08-17 13:57:16 +0300 | [diff] [blame] | 94 | self.assertEqual(1, partitions.count(CONF.compute.volume_device_name)) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 95 | |
| 96 | def nova_volume_detach(self): |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 97 | 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 Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 100 | |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 101 | volume = self.volumes_client.get_volume(self.volume['id']) |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 102 | self.assertEqual('available', volume['status']) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 103 | |
Grishkin | 0f1e11c | 2014-05-04 20:44:52 +0400 | [diff] [blame] | 104 | def create_and_add_security_group(self): |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 105 | secgroup = self._create_security_group() |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 106 | 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']) |
Grishkin | 0f1e11c | 2014-05-04 20:44:52 +0400 | [diff] [blame] | 110 | |
Clark Boylan | ff31bcc | 2014-11-04 13:44:04 -0800 | [diff] [blame] | 111 | def wait_for_secgroup_add(): |
David Kranz | 0fb1429 | 2015-02-11 15:55:20 -0500 | [diff] [blame] | 112 | body = self.servers_client.get_server(self.server['id']) |
Clark Boylan | ff31bcc | 2014-11-04 13:44:04 -0800 | [diff] [blame] | 113 | 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 Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 122 | @test.services('compute', 'volume', 'image', 'network') |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 123 | 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-griffith | 5462b33 | 2013-12-13 10:04:43 -0500 | [diff] [blame] | 133 | self.addCleanup(self.nova_volume_detach) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 134 | self.cinder_show() |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 135 | |
Yair Fried | ae0e73d | 2014-11-24 11:56:26 +0200 | [diff] [blame] | 136 | self.floating_ip = self.create_floating_ip(self.server) |
Grishkin | 0f1e11c | 2014-05-04 20:44:52 +0400 | [diff] [blame] | 137 | self.create_and_add_security_group() |
JordanP | 3fe2dc3 | 2014-11-17 13:06:01 +0100 | [diff] [blame] | 138 | |
| 139 | self.linux_client = self.get_remote_client(self.floating_ip['ip']) |
Attila Fazekas | 28c2520 | 2014-02-08 18:51:38 +0100 | [diff] [blame] | 140 | self.nova_reboot() |
JordanP | 3fe2dc3 | 2014-11-17 13:06:01 +0100 | [diff] [blame] | 141 | |
| 142 | self.linux_client = self.get_remote_client(self.floating_ip['ip']) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 143 | self.check_partitions() |