blob: 14eb536c1812ed1b5bccf44c2f936b972c977669 [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
Daryl Walleck6b9b2882012-04-08 21:43:39 -050016import base64
Jay Pipes13b479b2012-06-11 14:52:27 -040017
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050018import netaddr
ivan-zhu1feeb382013-01-24 10:14:39 +080019import testtools
Jay Pipes13b479b2012-06-11 14:52:27 -040020
Sean Dague1937d092013-05-17 16:36:38 -040021from tempest.api.compute import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090022from tempest.common.utils import data_utils
Masayuki Igawa209fd502014-02-17 14:46:43 +090023from tempest.common.utils.linux import remote_client
Sean Dague86bd8422013-12-20 09:56:44 -050024from tempest import config
Masayuki Igawa209fd502014-02-17 14:46:43 +090025from tempest import test
Daryl Walleck6b9b2882012-04-08 21:43:39 -050026
Sean Dague86bd8422013-12-20 09:56:44 -050027CONF = config.CONF
28
Daryl Walleck6b9b2882012-04-08 21:43:39 -050029
ivan-zhuf2b00502013-10-18 10:06:52 +080030class ServersTestJSON(base.BaseV2ComputeTest):
ivan-zhua5141d92013-03-06 23:12:43 +080031 disk_config = 'AUTO'
Daryl Walleck6b9b2882012-04-08 21:43:39 -050032
Attila Fazekas19044d52013-02-16 07:35:06 +010033 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010034 def resource_setup(cls):
Attila Fazekas423834d2014-03-14 17:33:13 +010035 cls.prepare_instance_network()
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010036 super(ServersTestJSON, cls).resource_setup()
Daryl Walleck6b9b2882012-04-08 21:43:39 -050037 cls.meta = {'hello': 'world'}
38 cls.accessIPv4 = '1.1.1.1'
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050039 cls.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2'
Masayuki Igawa259c1132013-10-31 17:48:44 +090040 cls.name = data_utils.rand_name('server')
Daryl Walleck6b9b2882012-04-08 21:43:39 -050041 file_contents = 'This is a test file.'
Pádraig Bradyc6081cf2013-01-04 17:43:53 +000042 personality = [{'path': '/test.txt',
Daryl Walleck6b9b2882012-04-08 21:43:39 -050043 'contents': base64.b64encode(file_contents)}]
44 cls.client = cls.servers_client
Joseph Lanoux38edc052014-09-18 14:25:46 +000045 cls.network_client = cls.os.network_client
David Kranz0fb14292015-02-11 15:55:20 -050046 disk_config = cls.disk_config
47 cls.server_initial = cls.create_test_server(name=cls.name,
48 meta=cls.meta,
49 accessIPv4=cls.accessIPv4,
50 accessIPv6=cls.accessIPv6,
51 personality=personality,
52 disk_config=disk_config)
Daryl Walleck6b9b2882012-04-08 21:43:39 -050053 cls.password = cls.server_initial['adminPass']
54 cls.client.wait_for_server_status(cls.server_initial['id'], 'ACTIVE')
David Kranz0fb14292015-02-11 15:55:20 -050055 cls.server = cls.client.get_server(cls.server_initial['id'])
Daryl Walleck6b9b2882012-04-08 21:43:39 -050056
Masayuki Igawa209fd502014-02-17 14:46:43 +090057 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080058 @test.idempotent_id('5de47127-9977-400a-936f-abcfbec1218f')
Daryl Wallecked97dca2012-07-04 23:25:45 -050059 def test_verify_server_details(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050060 # Verify the specified server attributes are set correctly
Daryl Walleck6b9b2882012-04-08 21:43:39 -050061 self.assertEqual(self.accessIPv4, self.server['accessIPv4'])
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050062 # NOTE(maurosr): See http://tools.ietf.org/html/rfc5952 (section 4)
63 # Here we compare directly with the canonicalized format.
64 self.assertEqual(self.server['accessIPv6'],
65 str(netaddr.IPAddress(self.accessIPv6)))
Daryl Walleck6b9b2882012-04-08 21:43:39 -050066 self.assertEqual(self.name, self.server['name'])
67 self.assertEqual(self.image_ref, self.server['image']['id'])
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +090068 self.assertEqual(self.flavor_ref, self.server['flavor']['id'])
Daryl Walleck6b9b2882012-04-08 21:43:39 -050069 self.assertEqual(self.meta, self.server['metadata'])
70
Masayuki Igawa209fd502014-02-17 14:46:43 +090071 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080072 @test.idempotent_id('9a438d88-10c6-4bcd-8b5b-5b6e25e1346f')
Daryl Wallecked97dca2012-07-04 23:25:45 -050073 def test_list_servers(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050074 # The created server should be in the list of all servers
David Kranzae99b9a2015-02-16 13:37:01 -050075 body = self.client.list_servers()
Daryl Wallecked97dca2012-07-04 23:25:45 -050076 servers = body['servers']
77 found = any([i for i in servers if i['id'] == self.server['id']])
78 self.assertTrue(found)
79
Masayuki Igawa209fd502014-02-17 14:46:43 +090080 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080081 @test.idempotent_id('585e934c-448e-43c4-acbf-d06a9b899997')
Daryl Wallecked97dca2012-07-04 23:25:45 -050082 def test_list_servers_with_detail(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050083 # The created server should be in the detailed list of all servers
David Kranzae99b9a2015-02-16 13:37:01 -050084 body = self.client.list_servers_with_detail()
Daryl Wallecked97dca2012-07-04 23:25:45 -050085 servers = body['servers']
86 found = any([i for i in servers if i['id'] == self.server['id']])
87 self.assertTrue(found)
88
Chris Hoge7579c1a2015-02-26 14:12:15 -080089 @test.idempotent_id('cbc0f52f-05aa-492b-bdc1-84b575ca294b')
Matt Riedemann6c668202014-03-24 09:17:10 -070090 @testtools.skipUnless(CONF.compute.run_ssh,
91 'Instance validation tests are disabled.')
Masayuki Igawa209fd502014-02-17 14:46:43 +090092 @test.attr(type='gate')
Daryl Walleck6b9b2882012-04-08 21:43:39 -050093 def test_verify_created_server_vcpus(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050094 # Verify that the number of vcpus reported by the instance matches
95 # the amount stated by the flavor
David Kranz2fa77b22015-02-09 11:39:50 -050096 flavor = self.flavors_client.get_flavor_details(self.flavor_ref)
Masayuki Igawa209fd502014-02-17 14:46:43 +090097 linux_client = remote_client.RemoteClient(self.server, self.ssh_user,
98 self.password)
Daryl Walleck6b9b2882012-04-08 21:43:39 -050099 self.assertEqual(flavor['vcpus'], linux_client.get_number_of_vcpus())
100
Chris Hoge7579c1a2015-02-26 14:12:15 -0800101 @test.idempotent_id('ac1ad47f-984b-4441-9274-c9079b7a0666')
Matt Riedemann6c668202014-03-24 09:17:10 -0700102 @testtools.skipUnless(CONF.compute.run_ssh,
103 'Instance validation tests are disabled.')
Masayuki Igawa209fd502014-02-17 14:46:43 +0900104 @test.attr(type='gate')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500105 def test_host_name_is_same_as_server_name(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500106 # Verify the instance host name is the same as the server name
Masayuki Igawa209fd502014-02-17 14:46:43 +0900107 linux_client = remote_client.RemoteClient(self.server, self.ssh_user,
108 self.password)
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500109 self.assertTrue(linux_client.hostname_equals_servername(self.name))
Dan Smith4307f992012-08-16 09:23:20 -0700110
Ken'ichi Ohmichi60a67f72014-05-20 09:19:50 +0900111 @test.attr(type='gate')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800112 @test.idempotent_id('ed20d3fb-9d1f-4329-b160-543fbd5d9811')
Ken'ichi Ohmichi60a67f72014-05-20 09:19:50 +0900113 def test_create_server_with_scheduler_hint_group(self):
114 # Create a server with the scheduler hint "group".
115 name = data_utils.rand_name('server_group')
116 policies = ['affinity']
David Kranzae99b9a2015-02-16 13:37:01 -0500117 body = self.client.create_server_group(name=name,
118 policies=policies)
Ken'ichi Ohmichi60a67f72014-05-20 09:19:50 +0900119 group_id = body['id']
120 self.addCleanup(self.client.delete_server_group, group_id)
121
122 hints = {'group': group_id}
David Kranz0fb14292015-02-11 15:55:20 -0500123 server = self.create_test_server(sched_hints=hints,
124 wait_until='ACTIVE')
Ken'ichi Ohmichi60a67f72014-05-20 09:19:50 +0900125
126 # Check a server is in the group
David Kranzae99b9a2015-02-16 13:37:01 -0500127 server_group = self.client.get_server_group(group_id)
Ken'ichi Ohmichi60a67f72014-05-20 09:19:50 +0900128 self.assertIn(server['id'], server_group['members'])
129
Chris Hoge7579c1a2015-02-26 14:12:15 -0800130 @test.idempotent_id('0578d144-ed74-43f8-8e57-ab10dbf9b3c2')
Joseph Lanoux38edc052014-09-18 14:25:46 +0000131 @testtools.skipUnless(CONF.service_available.neutron,
132 'Neutron service must be available.')
133 def test_verify_multiple_nics_order(self):
134 # Verify that the networks order given at the server creation is
135 # preserved within the server.
136 name_net1 = data_utils.rand_name(self.__class__.__name__)
David Kranz34e88122014-12-11 15:24:05 -0500137 net1 = self.network_client.create_network(name=name_net1)
Joseph Lanouxe59f0ff2014-10-17 14:56:56 +0000138 self.addCleanup(self.network_client.delete_network,
139 net1['network']['id'])
140
Joseph Lanoux38edc052014-09-18 14:25:46 +0000141 name_net2 = data_utils.rand_name(self.__class__.__name__)
David Kranz34e88122014-12-11 15:24:05 -0500142 net2 = self.network_client.create_network(name=name_net2)
Joseph Lanouxe59f0ff2014-10-17 14:56:56 +0000143 self.addCleanup(self.network_client.delete_network,
144 net2['network']['id'])
Joseph Lanoux38edc052014-09-18 14:25:46 +0000145
David Kranz34e88122014-12-11 15:24:05 -0500146 subnet1 = self.network_client.create_subnet(
Joseph Lanoux38edc052014-09-18 14:25:46 +0000147 network_id=net1['network']['id'],
148 cidr='19.80.0.0/24',
149 ip_version=4)
Joseph Lanouxe59f0ff2014-10-17 14:56:56 +0000150 self.addCleanup(self.network_client.delete_subnet,
151 subnet1['subnet']['id'])
152
David Kranz34e88122014-12-11 15:24:05 -0500153 subnet2 = self.network_client.create_subnet(
Joseph Lanoux38edc052014-09-18 14:25:46 +0000154 network_id=net2['network']['id'],
155 cidr='19.86.0.0/24',
156 ip_version=4)
Joseph Lanouxe59f0ff2014-10-17 14:56:56 +0000157 self.addCleanup(self.network_client.delete_subnet,
158 subnet2['subnet']['id'])
Joseph Lanoux38edc052014-09-18 14:25:46 +0000159
160 networks = [{'uuid': net1['network']['id']},
161 {'uuid': net2['network']['id']}]
162
David Kranz0fb14292015-02-11 15:55:20 -0500163 server_multi_nics = self.create_test_server(
Joseph Lanoux38edc052014-09-18 14:25:46 +0000164 networks=networks, wait_until='ACTIVE')
165
Joseph Lanouxe59f0ff2014-10-17 14:56:56 +0000166 # Cleanup server; this is needed in the test case because with the LIFO
167 # nature of the cleanups, if we don't delete the server first, the port
168 # will still be part of the subnet and we'll get a 409 from Neutron
169 # when trying to delete the subnet. The tear down in the base class
170 # will try to delete the server and get a 404 but it's ignored so
171 # we're OK.
172 def cleanup_server():
173 self.client.delete_server(server_multi_nics['id'])
174 self.client.wait_for_server_termination(server_multi_nics['id'])
175
176 self.addCleanup(cleanup_server)
177
David Kranzae99b9a2015-02-16 13:37:01 -0500178 addresses = self.client.list_addresses(server_multi_nics['id'])
Joseph Lanoux38edc052014-09-18 14:25:46 +0000179
venkata anilbd2d49a2015-01-16 08:07:15 +0000180 # We can't predict the ip addresses assigned to the server on networks.
181 # Sometimes the assigned addresses are ['19.80.0.2', '19.86.0.2'], at
182 # other times ['19.80.0.3', '19.86.0.3']. So we check if the first
183 # address is in first network, similarly second address is in second
184 # network.
Joseph Lanoux38edc052014-09-18 14:25:46 +0000185 addr = [addresses[name_net1][0]['addr'],
186 addresses[name_net2][0]['addr']]
venkata anilbd2d49a2015-01-16 08:07:15 +0000187 networks = [netaddr.IPNetwork('19.80.0.0/24'),
188 netaddr.IPNetwork('19.86.0.0/24')]
189 for address, network in zip(addr, networks):
190 self.assertIn(address, network)
Joseph Lanoux38edc052014-09-18 14:25:46 +0000191
Dan Smith4307f992012-08-16 09:23:20 -0700192
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800193class ServersWithSpecificFlavorTestJSON(base.BaseV2ComputeAdminTest):
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800194 disk_config = 'AUTO'
195
196 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +0100197 def resource_setup(cls):
Attila Fazekas423834d2014-03-14 17:33:13 +0100198 cls.prepare_instance_network()
Andrea Frittoli50bb80d2014-09-15 12:34:27 +0100199 super(ServersWithSpecificFlavorTestJSON, cls).resource_setup()
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800200 cls.flavor_client = cls.os_adm.flavors_client
Attila Fazekas076f79f2014-03-14 17:43:46 +0100201 cls.client = cls.servers_client
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800202
Chris Hoge7579c1a2015-02-26 14:12:15 -0800203 @test.idempotent_id('b3c7bcfc-bb5b-4e22-b517-c7f686b802ca')
Matt Riedemann6c668202014-03-24 09:17:10 -0700204 @testtools.skipUnless(CONF.compute.run_ssh,
205 'Instance validation tests are disabled.')
Masayuki Igawa209fd502014-02-17 14:46:43 +0900206 @test.attr(type='gate')
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800207 def test_verify_created_server_ephemeral_disk(self):
208 # Verify that the ephemeral disk is created when creating server
209
Attila Fazekas076f79f2014-03-14 17:43:46 +0100210 def create_flavor_with_extra_specs():
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800211 flavor_with_eph_disk_name = data_utils.rand_name('eph_flavor')
212 flavor_with_eph_disk_id = data_utils.rand_int_id(start=1000)
213 ram = 64
214 vcpus = 1
215 disk = 0
216
217 # Create a flavor with extra specs
David Kranz2fa77b22015-02-09 11:39:50 -0500218 flavor = (self.flavor_client.
219 create_flavor(flavor_with_eph_disk_name,
220 ram, vcpus, disk,
221 flavor_with_eph_disk_id,
222 ephemeral=1))
Attila Fazekas076f79f2014-03-14 17:43:46 +0100223 self.addCleanup(flavor_clean_up, flavor['id'])
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800224
225 return flavor['id']
226
Attila Fazekas076f79f2014-03-14 17:43:46 +0100227 def create_flavor_without_extra_specs():
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800228 flavor_no_eph_disk_name = data_utils.rand_name('no_eph_flavor')
229 flavor_no_eph_disk_id = data_utils.rand_int_id(start=1000)
230
231 ram = 64
232 vcpus = 1
233 disk = 0
234
235 # Create a flavor without extra specs
David Kranz2fa77b22015-02-09 11:39:50 -0500236 flavor = (self.flavor_client.
237 create_flavor(flavor_no_eph_disk_name,
238 ram, vcpus, disk,
239 flavor_no_eph_disk_id))
Attila Fazekas076f79f2014-03-14 17:43:46 +0100240 self.addCleanup(flavor_clean_up, flavor['id'])
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800241
242 return flavor['id']
243
Attila Fazekas076f79f2014-03-14 17:43:46 +0100244 def flavor_clean_up(flavor_id):
David Kranz2fa77b22015-02-09 11:39:50 -0500245 self.flavor_client.delete_flavor(flavor_id)
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800246 self.flavor_client.wait_for_resource_deletion(flavor_id)
247
Attila Fazekas076f79f2014-03-14 17:43:46 +0100248 flavor_with_eph_disk_id = create_flavor_with_extra_specs()
249 flavor_no_eph_disk_id = create_flavor_without_extra_specs()
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800250
251 admin_pass = self.image_ssh_password
252
David Kranz0fb14292015-02-11 15:55:20 -0500253 server_no_eph_disk = (self.create_test_server(
254 wait_until='ACTIVE',
255 adminPass=admin_pass,
256 flavor=flavor_no_eph_disk_id))
257 server_with_eph_disk = (self.create_test_server(
258 wait_until='ACTIVE',
259 adminPass=admin_pass,
260 flavor=flavor_with_eph_disk_id))
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800261 # Get partition number of server without extra specs.
David Kranz0fb14292015-02-11 15:55:20 -0500262 server_no_eph_disk = self.client.get_server(
Attila Fazekas076f79f2014-03-14 17:43:46 +0100263 server_no_eph_disk['id'])
Masayuki Igawa209fd502014-02-17 14:46:43 +0900264 linux_client = remote_client.RemoteClient(server_no_eph_disk,
Attila Fazekas076f79f2014-03-14 17:43:46 +0100265 self.ssh_user, admin_pass)
266 partition_num = len(linux_client.get_partitions().split('\n'))
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800267
David Kranz0fb14292015-02-11 15:55:20 -0500268 server_with_eph_disk = self.client.get_server(
Attila Fazekas076f79f2014-03-14 17:43:46 +0100269 server_with_eph_disk['id'])
Masayuki Igawa209fd502014-02-17 14:46:43 +0900270 linux_client = remote_client.RemoteClient(server_with_eph_disk,
Attila Fazekas076f79f2014-03-14 17:43:46 +0100271 self.ssh_user, admin_pass)
272 partition_num_emph = len(linux_client.get_partitions().split('\n'))
273 self.assertEqual(partition_num + 1, partition_num_emph)
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800274
275
Attila Fazekas19044d52013-02-16 07:35:06 +0100276class ServersTestManualDisk(ServersTestJSON):
277 disk_config = 'MANUAL'
278
Daryl Walleck0aea0032012-12-04 00:53:28 -0600279 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +0100280 def resource_setup(cls):
Sean Dague86bd8422013-12-20 09:56:44 -0500281 if not CONF.compute_feature_enabled.disk_config:
Daryl Walleck0aea0032012-12-04 00:53:28 -0600282 msg = "DiskConfig extension not enabled."
ivan-zhu1feeb382013-01-24 10:14:39 +0800283 raise cls.skipException(msg)
Andrea Frittoli50bb80d2014-09-15 12:34:27 +0100284 super(ServersTestManualDisk, cls).resource_setup()