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 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 16 | from oslo_log import log as logging |
| 17 | |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 18 | from tempest.common import custom_matchers |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 19 | from tempest.common import waiters |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 20 | from tempest import config |
Clark Boylan | ff31bcc | 2014-11-04 13:44:04 -0800 | [diff] [blame] | 21 | from tempest import exceptions |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 22 | from tempest.scenario import manager |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 23 | from tempest import test |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 24 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 25 | CONF = config.CONF |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 26 | |
| 27 | LOG = logging.getLogger(__name__) |
| 28 | |
| 29 | |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 30 | class TestMinimumBasicScenario(manager.ScenarioTest): |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 31 | |
| 32 | """ |
| 33 | This is a basic minimum scenario test. |
| 34 | |
| 35 | This test below: |
| 36 | * across the multiple components |
| 37 | * as a regular user |
| 38 | * with and without optional parameters |
| 39 | * check command outputs |
| 40 | |
| 41 | """ |
| 42 | |
| 43 | def _wait_for_server_status(self, status): |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 44 | server_id = self.server['id'] |
| 45 | # Raise on error defaults to True, which is consistent with the |
| 46 | # original function from scenario tests here |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 47 | waiters.wait_for_server_status(self.servers_client, |
| 48 | server_id, status) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 49 | |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 50 | def nova_keypair_add(self): |
Ken'ichi Ohmichi | 599d1b8 | 2013-08-19 18:48:37 +0900 | [diff] [blame] | 51 | self.keypair = self.create_keypair() |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 52 | |
| 53 | def nova_boot(self): |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 54 | create_kwargs = {'key_name': self.keypair['name']} |
Giulio Fidente | 61cadca | 2013-09-24 18:33:37 +0200 | [diff] [blame] | 55 | self.server = self.create_server(image=self.image, |
Ken'ichi Ohmichi | 61f272b | 2013-08-15 15:58:53 +0900 | [diff] [blame] | 56 | create_kwargs=create_kwargs) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 57 | |
| 58 | def nova_list(self): |
David Kranz | ae99b9a | 2015-02-16 13:37:01 -0500 | [diff] [blame] | 59 | servers = self.servers_client.list_servers() |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 60 | # The list servers in the compute client is inconsistent... |
| 61 | servers = servers['servers'] |
| 62 | self.assertIn(self.server['id'], [x['id'] for x in servers]) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 63 | |
| 64 | def nova_show(self): |
ghanshyam | 0f82525 | 2015-08-25 16:02:50 +0900 | [diff] [blame^] | 65 | got_server = (self.servers_client.show_server(self.server['id']) |
| 66 | ['server']) |
Jordan Pittier | 5d36715 | 2015-08-19 12:03:49 +0200 | [diff] [blame] | 67 | excluded_keys = ['OS-EXT-AZ:availability_zone'] |
| 68 | # Exclude these keys because of LP:#1486475 |
| 69 | excluded_keys.extend(['OS-EXT-STS:power_state', 'updated']) |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 70 | self.assertThat( |
| 71 | self.server, custom_matchers.MatchesDictExceptForKeys( |
Jordan Pittier | 5d36715 | 2015-08-19 12:03:49 +0200 | [diff] [blame] | 72 | got_server, excluded_keys=excluded_keys)) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 73 | |
| 74 | def cinder_create(self): |
Ken'ichi Ohmichi | 70672df | 2013-08-19 18:35:19 +0900 | [diff] [blame] | 75 | self.volume = self.create_volume() |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 76 | |
| 77 | def cinder_list(self): |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 78 | volumes = self.volumes_client.list_volumes()['volumes'] |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 79 | self.assertIn(self.volume['id'], [x['id'] for x in volumes]) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 80 | |
| 81 | def cinder_show(self): |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 82 | volume = self.volumes_client.show_volume(self.volume['id'])['volume'] |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 83 | self.assertEqual(self.volume, volume) |
| 84 | |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 85 | def nova_reboot(self): |
Ken'ichi Ohmichi | 5271b0f | 2015-08-10 07:53:27 +0000 | [diff] [blame] | 86 | self.servers_client.reboot_server(self.server['id'], 'SOFT') |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 87 | self._wait_for_server_status('ACTIVE') |
| 88 | |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 89 | def check_partitions(self): |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 90 | # NOTE(andreaf) The device name may be different on different guest OS |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 91 | partitions = self.linux_client.get_partitions() |
Alessandro Pilotti | b4aa55d | 2014-08-17 13:57:16 +0300 | [diff] [blame] | 92 | self.assertEqual(1, partitions.count(CONF.compute.volume_device_name)) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 93 | |
Grishkin | 0f1e11c | 2014-05-04 20:44:52 +0400 | [diff] [blame] | 94 | def create_and_add_security_group(self): |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 95 | secgroup = self._create_security_group() |
Andrea Frittoli | 247058f | 2014-07-16 16:09:22 +0100 | [diff] [blame] | 96 | self.servers_client.add_security_group(self.server['id'], |
| 97 | secgroup['name']) |
| 98 | self.addCleanup(self.servers_client.remove_security_group, |
| 99 | self.server['id'], secgroup['name']) |
Grishkin | 0f1e11c | 2014-05-04 20:44:52 +0400 | [diff] [blame] | 100 | |
Clark Boylan | ff31bcc | 2014-11-04 13:44:04 -0800 | [diff] [blame] | 101 | def wait_for_secgroup_add(): |
ghanshyam | 0f82525 | 2015-08-25 16:02:50 +0900 | [diff] [blame^] | 102 | body = (self.servers_client.show_server(self.server['id']) |
| 103 | ['server']) |
Clark Boylan | ff31bcc | 2014-11-04 13:44:04 -0800 | [diff] [blame] | 104 | return {'name': secgroup['name']} in body['security_groups'] |
| 105 | |
| 106 | if not test.call_until_true(wait_for_secgroup_add, |
| 107 | CONF.compute.build_timeout, |
| 108 | CONF.compute.build_interval): |
| 109 | msg = ('Timed out waiting for adding security group %s to server ' |
| 110 | '%s' % (secgroup['id'], self.server['id'])) |
| 111 | raise exceptions.TimeoutException(msg) |
| 112 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 113 | @test.idempotent_id('bdbb5441-9204-419d-a225-b4fdbfb1a1a8') |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 114 | @test.services('compute', 'volume', 'image', 'network') |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 115 | def test_minimum_basic_scenario(self): |
| 116 | self.glance_image_create() |
| 117 | self.nova_keypair_add() |
| 118 | self.nova_boot() |
| 119 | self.nova_list() |
| 120 | self.nova_show() |
| 121 | self.cinder_create() |
| 122 | self.cinder_list() |
| 123 | self.cinder_show() |
| 124 | self.nova_volume_attach() |
john-griffith | 5462b33 | 2013-12-13 10:04:43 -0500 | [diff] [blame] | 125 | self.addCleanup(self.nova_volume_detach) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 126 | self.cinder_show() |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 127 | |
Yair Fried | ae0e73d | 2014-11-24 11:56:26 +0200 | [diff] [blame] | 128 | self.floating_ip = self.create_floating_ip(self.server) |
Grishkin | 0f1e11c | 2014-05-04 20:44:52 +0400 | [diff] [blame] | 129 | self.create_and_add_security_group() |
JordanP | 3fe2dc3 | 2014-11-17 13:06:01 +0100 | [diff] [blame] | 130 | |
| 131 | self.linux_client = self.get_remote_client(self.floating_ip['ip']) |
Attila Fazekas | 28c2520 | 2014-02-08 18:51:38 +0100 | [diff] [blame] | 132 | self.nova_reboot() |
JordanP | 3fe2dc3 | 2014-11-17 13:06:01 +0100 | [diff] [blame] | 133 | |
| 134 | self.linux_client = self.get_remote_client(self.floating_ip['ip']) |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 135 | self.check_partitions() |