ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 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 | |
Mauro S. M. Rodrigues | 5411036 | 2013-02-15 13:14:04 -0500 | [diff] [blame] | 16 | import netaddr |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 17 | import testtools |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 18 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 19 | from tempest.api.compute import base |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 20 | from tempest.common import utils |
Masayuki Igawa | 209fd50 | 2014-02-17 14:46:43 +0900 | [diff] [blame] | 21 | from tempest.common.utils.linux import remote_client |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 22 | from tempest import config |
Ken'ichi Ohmichi | 757833a | 2017-03-10 10:30:30 -0800 | [diff] [blame] | 23 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 24 | from tempest.lib import decorators |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 25 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 26 | CONF = config.CONF |
| 27 | |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 28 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 29 | class ServersTestJSON(base.BaseV2ComputeTest): |
ivan-zhu | a5141d9 | 2013-03-06 23:12:43 +0800 | [diff] [blame] | 30 | disk_config = 'AUTO' |
Andrea Frittoli | 9958b17 | 2017-07-13 11:24:59 +0100 | [diff] [blame] | 31 | volume_backed = False |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 32 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 33 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 34 | def setup_credentials(cls): |
Attila Fazekas | 423834d | 2014-03-14 17:33:13 +0100 | [diff] [blame] | 35 | cls.prepare_instance_network() |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 36 | super(ServersTestJSON, cls).setup_credentials() |
| 37 | |
| 38 | @classmethod |
| 39 | def setup_clients(cls): |
| 40 | super(ServersTestJSON, cls).setup_clients() |
| 41 | cls.client = cls.servers_client |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 42 | |
| 43 | @classmethod |
| 44 | def resource_setup(cls): |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 45 | super(ServersTestJSON, cls).resource_setup() |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 46 | validation_resources = cls.get_class_validation_resources( |
| 47 | cls.os_primary) |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 48 | cls.meta = {'hello': 'world'} |
| 49 | cls.accessIPv4 = '1.1.1.1' |
Mauro S. M. Rodrigues | 5411036 | 2013-02-15 13:14:04 -0500 | [diff] [blame] | 50 | cls.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2' |
zhufl | c6ce539 | 2016-08-17 14:34:37 +0800 | [diff] [blame] | 51 | cls.name = data_utils.rand_name(cls.__name__ + '-server') |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 52 | cls.password = data_utils.rand_password() |
David Kranz | 0fb1429 | 2015-02-11 15:55:20 -0500 | [diff] [blame] | 53 | disk_config = cls.disk_config |
zhufl | 7e0c9b6 | 2017-02-16 11:25:34 +0800 | [diff] [blame] | 54 | server_initial = cls.create_test_server( |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 55 | validatable=True, |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 56 | validation_resources=validation_resources, |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 57 | wait_until='ACTIVE', |
| 58 | name=cls.name, |
Ken'ichi Ohmichi | f2d436e | 2015-09-03 01:13:16 +0000 | [diff] [blame] | 59 | metadata=cls.meta, |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 60 | accessIPv4=cls.accessIPv4, |
| 61 | accessIPv6=cls.accessIPv6, |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 62 | disk_config=disk_config, |
Andrea Frittoli | 9958b17 | 2017-07-13 11:24:59 +0100 | [diff] [blame] | 63 | adminPass=cls.password, |
| 64 | volume_backed=cls.volume_backed) |
zhufl | 7e0c9b6 | 2017-02-16 11:25:34 +0800 | [diff] [blame] | 65 | cls.server = (cls.client.show_server(server_initial['id']) |
ghanshyam | 0f82525 | 2015-08-25 16:02:50 +0900 | [diff] [blame] | 66 | ['server']) |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 67 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 68 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 69 | @decorators.idempotent_id('5de47127-9977-400a-936f-abcfbec1218f') |
Daryl Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 70 | def test_verify_server_details(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 71 | # Verify the specified server attributes are set correctly |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 72 | self.assertEqual(self.accessIPv4, self.server['accessIPv4']) |
Mauro S. M. Rodrigues | 5411036 | 2013-02-15 13:14:04 -0500 | [diff] [blame] | 73 | # NOTE(maurosr): See http://tools.ietf.org/html/rfc5952 (section 4) |
| 74 | # Here we compare directly with the canonicalized format. |
| 75 | self.assertEqual(self.server['accessIPv6'], |
| 76 | str(netaddr.IPAddress(self.accessIPv6))) |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 77 | self.assertEqual(self.name, self.server['name']) |
Andrea Frittoli | 9958b17 | 2017-07-13 11:24:59 +0100 | [diff] [blame] | 78 | if self.volume_backed: |
| 79 | # Image is an empty string as per documentation |
| 80 | self.assertEqual("", self.server['image']) |
| 81 | else: |
| 82 | self.assertEqual(self.image_ref, self.server['image']['id']) |
zhufl | bcb7117 | 2018-03-29 13:49:31 +0800 | [diff] [blame] | 83 | self.assert_flavor_equal(self.flavor_ref, self.server['flavor']) |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 84 | self.assertEqual(self.meta, self.server['metadata']) |
| 85 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 86 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 87 | @decorators.idempotent_id('9a438d88-10c6-4bcd-8b5b-5b6e25e1346f') |
Daryl Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 88 | def test_list_servers(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 89 | # The created server should be in the list of all servers |
David Kranz | ae99b9a | 2015-02-16 13:37:01 -0500 | [diff] [blame] | 90 | body = self.client.list_servers() |
Daryl Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 91 | servers = body['servers'] |
zhufl | 63f059e | 2017-06-12 13:56:18 +0800 | [diff] [blame] | 92 | found = [i for i in servers if i['id'] == self.server['id']] |
| 93 | self.assertNotEmpty(found) |
Daryl Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 94 | |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 95 | @decorators.idempotent_id('585e934c-448e-43c4-acbf-d06a9b899997') |
Daryl Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 96 | def test_list_servers_with_detail(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 97 | # The created server should be in the detailed list of all servers |
Ken'ichi Ohmichi | cbc26a8 | 2015-07-03 08:18:04 +0000 | [diff] [blame] | 98 | body = self.client.list_servers(detail=True) |
Daryl Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 99 | servers = body['servers'] |
zhufl | 63f059e | 2017-06-12 13:56:18 +0800 | [diff] [blame] | 100 | found = [i for i in servers if i['id'] == self.server['id']] |
| 101 | self.assertNotEmpty(found) |
Daryl Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 102 | |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 103 | @decorators.idempotent_id('cbc0f52f-05aa-492b-bdc1-84b575ca294b') |
Matthew Treinish | e5cca00 | 2015-05-11 15:36:50 -0400 | [diff] [blame] | 104 | @testtools.skipUnless(CONF.validation.run_validation, |
Matt Riedemann | 6c66820 | 2014-03-24 09:17:10 -0700 | [diff] [blame] | 105 | 'Instance validation tests are disabled.') |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 106 | def test_verify_created_server_vcpus(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 107 | # Verify that the number of vcpus reported by the instance matches |
| 108 | # the amount stated by the flavor |
ghanshyam | 19973be | 2015-08-18 15:46:42 +0900 | [diff] [blame] | 109 | flavor = self.flavors_client.show_flavor(self.flavor_ref)['flavor'] |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 110 | validation_resources = self.get_class_validation_resources( |
| 111 | self.os_primary) |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 112 | linux_client = remote_client.RemoteClient( |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 113 | self.get_server_ip(self.server, validation_resources), |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 114 | self.ssh_user, |
| 115 | self.password, |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 116 | validation_resources['keypair']['private_key'], |
Andrea Frittoli (andreaf) | 2a70a61 | 2016-04-29 16:09:13 -0500 | [diff] [blame] | 117 | server=self.server, |
| 118 | servers_client=self.client) |
Ken'ichi Ohmichi | 326a6b3 | 2017-03-01 14:35:30 -0800 | [diff] [blame] | 119 | output = linux_client.exec_command('grep -c ^processor /proc/cpuinfo') |
| 120 | self.assertEqual(flavor['vcpus'], int(output)) |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 121 | |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 122 | @decorators.idempotent_id('ac1ad47f-984b-4441-9274-c9079b7a0666') |
Matthew Treinish | e5cca00 | 2015-05-11 15:36:50 -0400 | [diff] [blame] | 123 | @testtools.skipUnless(CONF.validation.run_validation, |
Matt Riedemann | 6c66820 | 2014-03-24 09:17:10 -0700 | [diff] [blame] | 124 | 'Instance validation tests are disabled.') |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 125 | def test_host_name_is_same_as_server_name(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 126 | # Verify the instance host name is the same as the server name |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 127 | validation_resources = self.get_class_validation_resources( |
| 128 | self.os_primary) |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 129 | linux_client = remote_client.RemoteClient( |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 130 | self.get_server_ip(self.server, validation_resources), |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 131 | self.ssh_user, |
| 132 | self.password, |
Andrea Frittoli | 9f416dd | 2017-08-10 15:38:00 +0100 | [diff] [blame] | 133 | validation_resources['keypair']['private_key'], |
Andrea Frittoli (andreaf) | 2a70a61 | 2016-04-29 16:09:13 -0500 | [diff] [blame] | 134 | server=self.server, |
| 135 | servers_client=self.client) |
Ken'ichi Ohmichi | 326a6b3 | 2017-03-01 14:35:30 -0800 | [diff] [blame] | 136 | hostname = linux_client.exec_command("hostname").rstrip() |
imran malik | cdf2038 | 2016-06-16 00:43:57 -0700 | [diff] [blame] | 137 | msg = ('Failed while verifying servername equals hostname. Expected ' |
zhufl | 4b1b9df | 2018-03-13 16:02:50 +0800 | [diff] [blame] | 138 | 'hostname "%s" but got "%s".' % |
| 139 | (self.name, hostname.split(".")[0])) |
| 140 | # NOTE(zhufl): Some images will add postfix for the hostname, e.g., |
| 141 | # if hostname is "aaa", postfix ".novalocal" may be added to it, and |
| 142 | # the hostname will be "aaa.novalocal" then, so we should ignore the |
| 143 | # postfix when checking whether hostname equals self.name. |
| 144 | self.assertEqual(self.name.lower(), hostname.split(".")[0], msg) |
Dan Smith | 4307f99 | 2012-08-16 09:23:20 -0700 | [diff] [blame] | 145 | |
| 146 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 147 | class ServersTestManualDisk(ServersTestJSON): |
| 148 | disk_config = 'MANUAL' |
| 149 | |
Daryl Walleck | 0aea003 | 2012-12-04 00:53:28 -0600 | [diff] [blame] | 150 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 151 | def skip_checks(cls): |
| 152 | super(ServersTestManualDisk, cls).skip_checks() |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 153 | if not CONF.compute_feature_enabled.disk_config: |
Daryl Walleck | 0aea003 | 2012-12-04 00:53:28 -0600 | [diff] [blame] | 154 | msg = "DiskConfig extension not enabled." |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 155 | raise cls.skipException(msg) |
Andrea Frittoli | 9958b17 | 2017-07-13 11:24:59 +0100 | [diff] [blame] | 156 | |
| 157 | |
| 158 | class ServersTestBootFromVolume(ServersTestJSON): |
| 159 | """Run the `ServersTestJSON` tests with a volume backed VM""" |
| 160 | volume_backed = True |
| 161 | |
| 162 | @classmethod |
| 163 | def skip_checks(cls): |
| 164 | super(ServersTestBootFromVolume, cls).skip_checks() |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 165 | if not utils.get_service_list()['volume']: |
Andrea Frittoli | 9958b17 | 2017-07-13 11:24:59 +0100 | [diff] [blame] | 166 | msg = "Volume service not enabled." |
| 167 | raise cls.skipException(msg) |