blob: 48f32a81336121039a692e5c30ee946cc8c7d734 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04002# 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. Rodrigues54110362013-02-15 13:14:04 -050016import netaddr
ivan-zhu1feeb382013-01-24 10:14:39 +080017import testtools
Jay Pipes13b479b2012-06-11 14:52:27 -040018
Sean Dague1937d092013-05-17 16:36:38 -040019from tempest.api.compute import base
Andrea Frittolicd368412017-08-14 21:37:56 +010020from tempest.common import utils
Masayuki Igawa209fd502014-02-17 14:46:43 +090021from tempest.common.utils.linux import remote_client
Sean Dague86bd8422013-12-20 09:56:44 -050022from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080023from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080024from tempest.lib import decorators
Daryl Walleck6b9b2882012-04-08 21:43:39 -050025
Sean Dague86bd8422013-12-20 09:56:44 -050026CONF = config.CONF
27
Daryl Walleck6b9b2882012-04-08 21:43:39 -050028
ivan-zhuf2b00502013-10-18 10:06:52 +080029class ServersTestJSON(base.BaseV2ComputeTest):
zhufl67b3d382020-05-25 13:35:12 +080030 """Test creating server and verifying the server attributes
31
32 This is to create server booted from image and with disk_config 'AUTO'
33 """
34
ivan-zhua5141d92013-03-06 23:12:43 +080035 disk_config = 'AUTO'
Andrea Frittoli9958b172017-07-13 11:24:59 +010036 volume_backed = False
Daryl Walleck6b9b2882012-04-08 21:43:39 -050037
Attila Fazekas19044d52013-02-16 07:35:06 +010038 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053039 def setup_credentials(cls):
Attila Fazekas423834d2014-03-14 17:33:13 +010040 cls.prepare_instance_network()
Rohan Kanade60b73092015-02-04 17:58:19 +053041 super(ServersTestJSON, cls).setup_credentials()
42
43 @classmethod
44 def setup_clients(cls):
45 super(ServersTestJSON, cls).setup_clients()
46 cls.client = cls.servers_client
Rohan Kanade60b73092015-02-04 17:58:19 +053047
48 @classmethod
49 def resource_setup(cls):
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010050 super(ServersTestJSON, cls).resource_setup()
Andrea Frittoli9f416dd2017-08-10 15:38:00 +010051 validation_resources = cls.get_class_validation_resources(
52 cls.os_primary)
Daryl Walleck6b9b2882012-04-08 21:43:39 -050053 cls.meta = {'hello': 'world'}
54 cls.accessIPv4 = '1.1.1.1'
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050055 cls.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2'
zhuflc6ce5392016-08-17 14:34:37 +080056 cls.name = data_utils.rand_name(cls.__name__ + '-server')
Ghanshyam3390d9f2015-12-25 12:48:02 +090057 cls.password = data_utils.rand_password()
David Kranz0fb14292015-02-11 15:55:20 -050058 disk_config = cls.disk_config
zhufl7e0c9b62017-02-16 11:25:34 +080059 server_initial = cls.create_test_server(
Joseph Lanouxb3e1f872015-01-30 11:13:07 +000060 validatable=True,
Andrea Frittoli9f416dd2017-08-10 15:38:00 +010061 validation_resources=validation_resources,
Joseph Lanouxb3e1f872015-01-30 11:13:07 +000062 wait_until='ACTIVE',
63 name=cls.name,
Ken'ichi Ohmichif2d436e2015-09-03 01:13:16 +000064 metadata=cls.meta,
Joseph Lanouxb3e1f872015-01-30 11:13:07 +000065 accessIPv4=cls.accessIPv4,
66 accessIPv6=cls.accessIPv6,
Ghanshyam3390d9f2015-12-25 12:48:02 +090067 disk_config=disk_config,
Andrea Frittoli9958b172017-07-13 11:24:59 +010068 adminPass=cls.password,
69 volume_backed=cls.volume_backed)
zhufl67b3d382020-05-25 13:35:12 +080070 cls.server = cls.client.show_server(server_initial['id'])['server']
Daryl Walleck6b9b2882012-04-08 21:43:39 -050071
Jordan Pittier3b46d272017-04-12 16:17:28 +020072 @decorators.attr(type='smoke')
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080073 @decorators.idempotent_id('5de47127-9977-400a-936f-abcfbec1218f')
Daryl Wallecked97dca2012-07-04 23:25:45 -050074 def test_verify_server_details(self):
zhufl67b3d382020-05-25 13:35:12 +080075 """Verify the specified server attributes are set correctly"""
Daryl Walleck6b9b2882012-04-08 21:43:39 -050076 self.assertEqual(self.accessIPv4, self.server['accessIPv4'])
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050077 # NOTE(maurosr): See http://tools.ietf.org/html/rfc5952 (section 4)
78 # Here we compare directly with the canonicalized format.
79 self.assertEqual(self.server['accessIPv6'],
80 str(netaddr.IPAddress(self.accessIPv6)))
Daryl Walleck6b9b2882012-04-08 21:43:39 -050081 self.assertEqual(self.name, self.server['name'])
Andrea Frittoli9958b172017-07-13 11:24:59 +010082 if self.volume_backed:
83 # Image is an empty string as per documentation
84 self.assertEqual("", self.server['image'])
85 else:
86 self.assertEqual(self.image_ref, self.server['image']['id'])
zhuflbcb71172018-03-29 13:49:31 +080087 self.assert_flavor_equal(self.flavor_ref, self.server['flavor'])
Daryl Walleck6b9b2882012-04-08 21:43:39 -050088 self.assertEqual(self.meta, self.server['metadata'])
89
Jordan Pittier3b46d272017-04-12 16:17:28 +020090 @decorators.attr(type='smoke')
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080091 @decorators.idempotent_id('9a438d88-10c6-4bcd-8b5b-5b6e25e1346f')
Daryl Wallecked97dca2012-07-04 23:25:45 -050092 def test_list_servers(self):
zhufl67b3d382020-05-25 13:35:12 +080093 """The created server should be in the list of all servers"""
David Kranzae99b9a2015-02-16 13:37:01 -050094 body = self.client.list_servers()
Daryl Wallecked97dca2012-07-04 23:25:45 -050095 servers = body['servers']
zhufl63f059e2017-06-12 13:56:18 +080096 found = [i for i in servers if i['id'] == self.server['id']]
97 self.assertNotEmpty(found)
Daryl Wallecked97dca2012-07-04 23:25:45 -050098
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080099 @decorators.idempotent_id('585e934c-448e-43c4-acbf-d06a9b899997')
Daryl Wallecked97dca2012-07-04 23:25:45 -0500100 def test_list_servers_with_detail(self):
zhufl67b3d382020-05-25 13:35:12 +0800101 """The created server should be in the detailed list of all servers"""
Ken'ichi Ohmichicbc26a82015-07-03 08:18:04 +0000102 body = self.client.list_servers(detail=True)
Daryl Wallecked97dca2012-07-04 23:25:45 -0500103 servers = body['servers']
zhufl63f059e2017-06-12 13:56:18 +0800104 found = [i for i in servers if i['id'] == self.server['id']]
105 self.assertNotEmpty(found)
Daryl Wallecked97dca2012-07-04 23:25:45 -0500106
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800107 @decorators.idempotent_id('cbc0f52f-05aa-492b-bdc1-84b575ca294b')
Matthew Treinishe5cca002015-05-11 15:36:50 -0400108 @testtools.skipUnless(CONF.validation.run_validation,
Matt Riedemann6c668202014-03-24 09:17:10 -0700109 'Instance validation tests are disabled.')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500110 def test_verify_created_server_vcpus(self):
zhufl67b3d382020-05-25 13:35:12 +0800111 """The created server should have the same specification as the flavor
112
113 Verify that the number of vcpus reported by the instance matches
114 the amount stated by the flavor
115 """
ghanshyam19973be2015-08-18 15:46:42 +0900116 flavor = self.flavors_client.show_flavor(self.flavor_ref)['flavor']
Andrea Frittoli9f416dd2017-08-10 15:38:00 +0100117 validation_resources = self.get_class_validation_resources(
118 self.os_primary)
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000119 linux_client = remote_client.RemoteClient(
Andrea Frittoli9f416dd2017-08-10 15:38:00 +0100120 self.get_server_ip(self.server, validation_resources),
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000121 self.ssh_user,
122 self.password,
Andrea Frittoli9f416dd2017-08-10 15:38:00 +0100123 validation_resources['keypair']['private_key'],
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -0500124 server=self.server,
125 servers_client=self.client)
Ken'ichi Ohmichi326a6b32017-03-01 14:35:30 -0800126 output = linux_client.exec_command('grep -c ^processor /proc/cpuinfo')
127 self.assertEqual(flavor['vcpus'], int(output))
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500128
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800129 @decorators.idempotent_id('ac1ad47f-984b-4441-9274-c9079b7a0666')
Matthew Treinishe5cca002015-05-11 15:36:50 -0400130 @testtools.skipUnless(CONF.validation.run_validation,
Matt Riedemann6c668202014-03-24 09:17:10 -0700131 'Instance validation tests are disabled.')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500132 def test_host_name_is_same_as_server_name(self):
zhufl67b3d382020-05-25 13:35:12 +0800133 """Verify the instance host name is the same as the server name"""
Andrea Frittoli9f416dd2017-08-10 15:38:00 +0100134 validation_resources = self.get_class_validation_resources(
135 self.os_primary)
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000136 linux_client = remote_client.RemoteClient(
Andrea Frittoli9f416dd2017-08-10 15:38:00 +0100137 self.get_server_ip(self.server, validation_resources),
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000138 self.ssh_user,
139 self.password,
Andrea Frittoli9f416dd2017-08-10 15:38:00 +0100140 validation_resources['keypair']['private_key'],
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -0500141 server=self.server,
142 servers_client=self.client)
Ken'ichi Ohmichi326a6b32017-03-01 14:35:30 -0800143 hostname = linux_client.exec_command("hostname").rstrip()
imran malikcdf20382016-06-16 00:43:57 -0700144 msg = ('Failed while verifying servername equals hostname. Expected '
zhufl4b1b9df2018-03-13 16:02:50 +0800145 'hostname "%s" but got "%s".' %
146 (self.name, hostname.split(".")[0]))
147 # NOTE(zhufl): Some images will add postfix for the hostname, e.g.,
148 # if hostname is "aaa", postfix ".novalocal" may be added to it, and
149 # the hostname will be "aaa.novalocal" then, so we should ignore the
150 # postfix when checking whether hostname equals self.name.
151 self.assertEqual(self.name.lower(), hostname.split(".")[0], msg)
Dan Smith4307f992012-08-16 09:23:20 -0700152
153
Attila Fazekas19044d52013-02-16 07:35:06 +0100154class ServersTestManualDisk(ServersTestJSON):
zhufl67b3d382020-05-25 13:35:12 +0800155 """Test creating server and verifying the server attributes
156
157 This is to create server booted from image and with disk_config 'MANUAL'
158 """
Attila Fazekas19044d52013-02-16 07:35:06 +0100159 disk_config = 'MANUAL'
160
Daryl Walleck0aea0032012-12-04 00:53:28 -0600161 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +0530162 def skip_checks(cls):
163 super(ServersTestManualDisk, cls).skip_checks()
Sean Dague86bd8422013-12-20 09:56:44 -0500164 if not CONF.compute_feature_enabled.disk_config:
Daryl Walleck0aea0032012-12-04 00:53:28 -0600165 msg = "DiskConfig extension not enabled."
ivan-zhu1feeb382013-01-24 10:14:39 +0800166 raise cls.skipException(msg)
Andrea Frittoli9958b172017-07-13 11:24:59 +0100167
168
169class ServersTestBootFromVolume(ServersTestJSON):
zhufl67b3d382020-05-25 13:35:12 +0800170 """Test creating server and verifying the server attributes
171
172 This is to create server booted from volume and with disk_config 'AUTO'
173 """
174 # Run the `ServersTestJSON` tests with a volume backed VM
Andrea Frittoli9958b172017-07-13 11:24:59 +0100175 volume_backed = True
176
177 @classmethod
178 def skip_checks(cls):
179 super(ServersTestBootFromVolume, cls).skip_checks()
Andrea Frittolicd368412017-08-14 21:37:56 +0100180 if not utils.get_service_list()['volume']:
Andrea Frittoli9958b172017-07-13 11:24:59 +0100181 msg = "Volume service not enabled."
182 raise cls.skipException(msg)