blob: 1f4071fc560e96e5ac2558eecb122fcf6fe218a3 [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
Masayuki Igawa209fd502014-02-17 14:46:43 +090020from tempest.common.utils.linux import remote_client
Sean Dague86bd8422013-12-20 09:56:44 -050021from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080022from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080023from tempest.lib import decorators
Masayuki Igawa209fd502014-02-17 14:46:43 +090024from tempest import test
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):
ivan-zhua5141d92013-03-06 23:12:43 +080030 disk_config = 'AUTO'
Andrea Frittoli9958b172017-07-13 11:24:59 +010031 volume_backed = False
Daryl Walleck6b9b2882012-04-08 21:43:39 -050032
Attila Fazekas19044d52013-02-16 07:35:06 +010033 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053034 def setup_credentials(cls):
Attila Fazekas423834d2014-03-14 17:33:13 +010035 cls.prepare_instance_network()
Rohan Kanade60b73092015-02-04 17:58:19 +053036 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 Kanade60b73092015-02-04 17:58:19 +053042
43 @classmethod
44 def resource_setup(cls):
nithya-ganesan222efd72015-01-22 12:20:27 +000045 cls.set_validation_resources()
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010046 super(ServersTestJSON, cls).resource_setup()
Daryl Walleck6b9b2882012-04-08 21:43:39 -050047 cls.meta = {'hello': 'world'}
48 cls.accessIPv4 = '1.1.1.1'
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050049 cls.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2'
zhuflc6ce5392016-08-17 14:34:37 +080050 cls.name = data_utils.rand_name(cls.__name__ + '-server')
Ghanshyam3390d9f2015-12-25 12:48:02 +090051 cls.password = data_utils.rand_password()
David Kranz0fb14292015-02-11 15:55:20 -050052 disk_config = cls.disk_config
zhufl7e0c9b62017-02-16 11:25:34 +080053 server_initial = cls.create_test_server(
Joseph Lanouxb3e1f872015-01-30 11:13:07 +000054 validatable=True,
55 wait_until='ACTIVE',
56 name=cls.name,
Ken'ichi Ohmichif2d436e2015-09-03 01:13:16 +000057 metadata=cls.meta,
Joseph Lanouxb3e1f872015-01-30 11:13:07 +000058 accessIPv4=cls.accessIPv4,
59 accessIPv6=cls.accessIPv6,
Ghanshyam3390d9f2015-12-25 12:48:02 +090060 disk_config=disk_config,
Andrea Frittoli9958b172017-07-13 11:24:59 +010061 adminPass=cls.password,
62 volume_backed=cls.volume_backed)
zhufl7e0c9b62017-02-16 11:25:34 +080063 cls.server = (cls.client.show_server(server_initial['id'])
ghanshyam0f825252015-08-25 16:02:50 +090064 ['server'])
Daryl Walleck6b9b2882012-04-08 21:43:39 -050065
Jordan Pittier3b46d272017-04-12 16:17:28 +020066 @decorators.attr(type='smoke')
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080067 @decorators.idempotent_id('5de47127-9977-400a-936f-abcfbec1218f')
Daryl Wallecked97dca2012-07-04 23:25:45 -050068 def test_verify_server_details(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050069 # Verify the specified server attributes are set correctly
Daryl Walleck6b9b2882012-04-08 21:43:39 -050070 self.assertEqual(self.accessIPv4, self.server['accessIPv4'])
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050071 # NOTE(maurosr): See http://tools.ietf.org/html/rfc5952 (section 4)
72 # Here we compare directly with the canonicalized format.
73 self.assertEqual(self.server['accessIPv6'],
74 str(netaddr.IPAddress(self.accessIPv6)))
Daryl Walleck6b9b2882012-04-08 21:43:39 -050075 self.assertEqual(self.name, self.server['name'])
Andrea Frittoli9958b172017-07-13 11:24:59 +010076 if self.volume_backed:
77 # Image is an empty string as per documentation
78 self.assertEqual("", self.server['image'])
79 else:
80 self.assertEqual(self.image_ref, self.server['image']['id'])
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +090081 self.assertEqual(self.flavor_ref, self.server['flavor']['id'])
Daryl Walleck6b9b2882012-04-08 21:43:39 -050082 self.assertEqual(self.meta, self.server['metadata'])
83
Jordan Pittier3b46d272017-04-12 16:17:28 +020084 @decorators.attr(type='smoke')
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080085 @decorators.idempotent_id('9a438d88-10c6-4bcd-8b5b-5b6e25e1346f')
Daryl Wallecked97dca2012-07-04 23:25:45 -050086 def test_list_servers(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050087 # The created server should be in the list of all servers
David Kranzae99b9a2015-02-16 13:37:01 -050088 body = self.client.list_servers()
Daryl Wallecked97dca2012-07-04 23:25:45 -050089 servers = body['servers']
zhufl63f059e2017-06-12 13:56:18 +080090 found = [i for i in servers if i['id'] == self.server['id']]
91 self.assertNotEmpty(found)
Daryl Wallecked97dca2012-07-04 23:25:45 -050092
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080093 @decorators.idempotent_id('585e934c-448e-43c4-acbf-d06a9b899997')
Daryl Wallecked97dca2012-07-04 23:25:45 -050094 def test_list_servers_with_detail(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050095 # The created server should be in the detailed list of all servers
Ken'ichi Ohmichicbc26a82015-07-03 08:18:04 +000096 body = self.client.list_servers(detail=True)
Daryl Wallecked97dca2012-07-04 23:25:45 -050097 servers = body['servers']
zhufl63f059e2017-06-12 13:56:18 +080098 found = [i for i in servers if i['id'] == self.server['id']]
99 self.assertNotEmpty(found)
Daryl Wallecked97dca2012-07-04 23:25:45 -0500100
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800101 @decorators.idempotent_id('cbc0f52f-05aa-492b-bdc1-84b575ca294b')
Matthew Treinishe5cca002015-05-11 15:36:50 -0400102 @testtools.skipUnless(CONF.validation.run_validation,
Matt Riedemann6c668202014-03-24 09:17:10 -0700103 'Instance validation tests are disabled.')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500104 def test_verify_created_server_vcpus(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500105 # Verify that the number of vcpus reported by the instance matches
106 # the amount stated by the flavor
ghanshyam19973be2015-08-18 15:46:42 +0900107 flavor = self.flavors_client.show_flavor(self.flavor_ref)['flavor']
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000108 linux_client = remote_client.RemoteClient(
109 self.get_server_ip(self.server),
110 self.ssh_user,
111 self.password,
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -0500112 self.validation_resources['keypair']['private_key'],
113 server=self.server,
114 servers_client=self.client)
Ken'ichi Ohmichi326a6b32017-03-01 14:35:30 -0800115 output = linux_client.exec_command('grep -c ^processor /proc/cpuinfo')
116 self.assertEqual(flavor['vcpus'], int(output))
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500117
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800118 @decorators.idempotent_id('ac1ad47f-984b-4441-9274-c9079b7a0666')
Matthew Treinishe5cca002015-05-11 15:36:50 -0400119 @testtools.skipUnless(CONF.validation.run_validation,
Matt Riedemann6c668202014-03-24 09:17:10 -0700120 'Instance validation tests are disabled.')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500121 def test_host_name_is_same_as_server_name(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500122 # Verify the instance host name is the same as the server name
Joseph Lanouxffe09dd2015-03-18 16:45:33 +0000123 linux_client = remote_client.RemoteClient(
124 self.get_server_ip(self.server),
125 self.ssh_user,
126 self.password,
Andrea Frittoli (andreaf)2a70a612016-04-29 16:09:13 -0500127 self.validation_resources['keypair']['private_key'],
128 server=self.server,
129 servers_client=self.client)
Ken'ichi Ohmichi326a6b32017-03-01 14:35:30 -0800130 hostname = linux_client.exec_command("hostname").rstrip()
imran malikcdf20382016-06-16 00:43:57 -0700131 msg = ('Failed while verifying servername equals hostname. Expected '
132 'hostname "%s" but got "%s".' % (self.name, hostname))
obutenko149feaf2016-08-31 16:14:45 +0300133 self.assertEqual(self.name.lower(), hostname, msg)
Dan Smith4307f992012-08-16 09:23:20 -0700134
135
Attila Fazekas19044d52013-02-16 07:35:06 +0100136class ServersTestManualDisk(ServersTestJSON):
137 disk_config = 'MANUAL'
138
Daryl Walleck0aea0032012-12-04 00:53:28 -0600139 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +0530140 def skip_checks(cls):
141 super(ServersTestManualDisk, cls).skip_checks()
Sean Dague86bd8422013-12-20 09:56:44 -0500142 if not CONF.compute_feature_enabled.disk_config:
Daryl Walleck0aea0032012-12-04 00:53:28 -0600143 msg = "DiskConfig extension not enabled."
ivan-zhu1feeb382013-01-24 10:14:39 +0800144 raise cls.skipException(msg)
Andrea Frittoli9958b172017-07-13 11:24:59 +0100145
146
147class ServersTestBootFromVolume(ServersTestJSON):
148 """Run the `ServersTestJSON` tests with a volume backed VM"""
149 volume_backed = True
150
151 @classmethod
152 def skip_checks(cls):
153 super(ServersTestBootFromVolume, cls).skip_checks()
154 if not test.get_service_list()['volume']:
155 msg = "Volume service not enabled."
156 raise cls.skipException(msg)