blob: 279dc51229914cd791f24314e0ceeade5f51c252 [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
Daryl Walleck6b9b2882012-04-08 21:43:39 -050034 def setUpClass(cls):
Attila Fazekas423834d2014-03-14 17:33:13 +010035 cls.prepare_instance_network()
Attila Fazekas19044d52013-02-16 07:35:06 +010036 super(ServersTestJSON, cls).setUpClass()
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
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090045 cli_resp = cls.create_test_server(name=cls.name,
46 meta=cls.meta,
47 accessIPv4=cls.accessIPv4,
48 accessIPv6=cls.accessIPv6,
49 personality=personality,
50 disk_config=cls.disk_config)
Zhongyue Luo79d8d362012-09-25 13:49:27 +080051 cls.resp, cls.server_initial = cli_resp
Daryl Walleck6b9b2882012-04-08 21:43:39 -050052 cls.password = cls.server_initial['adminPass']
53 cls.client.wait_for_server_status(cls.server_initial['id'], 'ACTIVE')
54 resp, cls.server = cls.client.get_server(cls.server_initial['id'])
55
Masayuki Igawa209fd502014-02-17 14:46:43 +090056 @test.attr(type='smoke')
Daryl Wallecked97dca2012-07-04 23:25:45 -050057 def test_verify_server_details(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050058 # Verify the specified server attributes are set correctly
Daryl Walleck6b9b2882012-04-08 21:43:39 -050059 self.assertEqual(self.accessIPv4, self.server['accessIPv4'])
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050060 # NOTE(maurosr): See http://tools.ietf.org/html/rfc5952 (section 4)
61 # Here we compare directly with the canonicalized format.
62 self.assertEqual(self.server['accessIPv6'],
63 str(netaddr.IPAddress(self.accessIPv6)))
Daryl Walleck6b9b2882012-04-08 21:43:39 -050064 self.assertEqual(self.name, self.server['name'])
65 self.assertEqual(self.image_ref, self.server['image']['id'])
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +090066 self.assertEqual(self.flavor_ref, self.server['flavor']['id'])
Daryl Walleck6b9b2882012-04-08 21:43:39 -050067 self.assertEqual(self.meta, self.server['metadata'])
68
Masayuki Igawa209fd502014-02-17 14:46:43 +090069 @test.attr(type='smoke')
Daryl Wallecked97dca2012-07-04 23:25:45 -050070 def test_list_servers(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050071 # The created server should be in the list of all servers
Daryl Wallecked97dca2012-07-04 23:25:45 -050072 resp, body = self.client.list_servers()
73 servers = body['servers']
74 found = any([i for i in servers if i['id'] == self.server['id']])
75 self.assertTrue(found)
76
Masayuki Igawa209fd502014-02-17 14:46:43 +090077 @test.attr(type='smoke')
Daryl Wallecked97dca2012-07-04 23:25:45 -050078 def test_list_servers_with_detail(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050079 # The created server should be in the detailed list of all servers
Daryl Wallecked97dca2012-07-04 23:25:45 -050080 resp, body = self.client.list_servers_with_detail()
81 servers = body['servers']
82 found = any([i for i in servers if i['id'] == self.server['id']])
83 self.assertTrue(found)
84
Matt Riedemann6c668202014-03-24 09:17:10 -070085 @testtools.skipUnless(CONF.compute.run_ssh,
86 'Instance validation tests are disabled.')
Masayuki Igawa209fd502014-02-17 14:46:43 +090087 @test.attr(type='gate')
Daryl Walleck6b9b2882012-04-08 21:43:39 -050088 def test_verify_created_server_vcpus(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050089 # Verify that the number of vcpus reported by the instance matches
90 # the amount stated by the flavor
Daryl Walleck6b9b2882012-04-08 21:43:39 -050091 resp, flavor = self.flavors_client.get_flavor_details(self.flavor_ref)
Masayuki Igawa209fd502014-02-17 14:46:43 +090092 linux_client = remote_client.RemoteClient(self.server, self.ssh_user,
93 self.password)
Daryl Walleck6b9b2882012-04-08 21:43:39 -050094 self.assertEqual(flavor['vcpus'], linux_client.get_number_of_vcpus())
95
Matt Riedemann6c668202014-03-24 09:17:10 -070096 @testtools.skipUnless(CONF.compute.run_ssh,
97 'Instance validation tests are disabled.')
Masayuki Igawa209fd502014-02-17 14:46:43 +090098 @test.attr(type='gate')
Daryl Walleck6b9b2882012-04-08 21:43:39 -050099 def test_host_name_is_same_as_server_name(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500100 # Verify the instance host name is the same as the server name
Masayuki Igawa209fd502014-02-17 14:46:43 +0900101 linux_client = remote_client.RemoteClient(self.server, self.ssh_user,
102 self.password)
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500103 self.assertTrue(linux_client.hostname_equals_servername(self.name))
Dan Smith4307f992012-08-16 09:23:20 -0700104
Ken'ichi Ohmichi60a67f72014-05-20 09:19:50 +0900105 @test.skip_because(bug="1306367", interface="xml")
106 @test.attr(type='gate')
107 def test_create_server_with_scheduler_hint_group(self):
108 # Create a server with the scheduler hint "group".
109 name = data_utils.rand_name('server_group')
110 policies = ['affinity']
111 resp, body = self.client.create_server_group(name=name,
112 policies=policies)
113 self.assertEqual(200, resp.status)
114 group_id = body['id']
115 self.addCleanup(self.client.delete_server_group, group_id)
116
117 hints = {'group': group_id}
118 resp, server = self.create_test_server(sched_hints=hints,
119 wait_until='ACTIVE')
120 self.assertEqual(202, resp.status)
121
122 # Check a server is in the group
123 resp, server_group = self.client.get_server_group(group_id)
124 self.assertEqual(200, resp.status)
125 self.assertIn(server['id'], server_group['members'])
126
Dan Smith4307f992012-08-16 09:23:20 -0700127
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800128class ServersWithSpecificFlavorTestJSON(base.BaseV2ComputeAdminTest):
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800129 disk_config = 'AUTO'
130
131 @classmethod
132 def setUpClass(cls):
Attila Fazekas423834d2014-03-14 17:33:13 +0100133 cls.prepare_instance_network()
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800134 super(ServersWithSpecificFlavorTestJSON, cls).setUpClass()
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800135 cls.flavor_client = cls.os_adm.flavors_client
Attila Fazekas076f79f2014-03-14 17:43:46 +0100136 cls.client = cls.servers_client
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800137
Matt Riedemann6c668202014-03-24 09:17:10 -0700138 @testtools.skipUnless(CONF.compute.run_ssh,
139 'Instance validation tests are disabled.')
Masayuki Igawa209fd502014-02-17 14:46:43 +0900140 @test.attr(type='gate')
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800141 def test_verify_created_server_ephemeral_disk(self):
142 # Verify that the ephemeral disk is created when creating server
143
Attila Fazekas076f79f2014-03-14 17:43:46 +0100144 def create_flavor_with_extra_specs():
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800145 flavor_with_eph_disk_name = data_utils.rand_name('eph_flavor')
146 flavor_with_eph_disk_id = data_utils.rand_int_id(start=1000)
147 ram = 64
148 vcpus = 1
149 disk = 0
150
151 # Create a flavor with extra specs
152 resp, flavor = (self.flavor_client.
153 create_flavor(flavor_with_eph_disk_name,
154 ram, vcpus, disk,
155 flavor_with_eph_disk_id,
156 ephemeral=1))
Attila Fazekas076f79f2014-03-14 17:43:46 +0100157 self.addCleanup(flavor_clean_up, flavor['id'])
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800158 self.assertEqual(200, resp.status)
159
160 return flavor['id']
161
Attila Fazekas076f79f2014-03-14 17:43:46 +0100162 def create_flavor_without_extra_specs():
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800163 flavor_no_eph_disk_name = data_utils.rand_name('no_eph_flavor')
164 flavor_no_eph_disk_id = data_utils.rand_int_id(start=1000)
165
166 ram = 64
167 vcpus = 1
168 disk = 0
169
170 # Create a flavor without extra specs
171 resp, flavor = (self.flavor_client.
172 create_flavor(flavor_no_eph_disk_name,
173 ram, vcpus, disk,
174 flavor_no_eph_disk_id))
Attila Fazekas076f79f2014-03-14 17:43:46 +0100175 self.addCleanup(flavor_clean_up, flavor['id'])
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800176 self.assertEqual(200, resp.status)
177
178 return flavor['id']
179
Attila Fazekas076f79f2014-03-14 17:43:46 +0100180 def flavor_clean_up(flavor_id):
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800181 resp, body = self.flavor_client.delete_flavor(flavor_id)
182 self.assertEqual(resp.status, 202)
183 self.flavor_client.wait_for_resource_deletion(flavor_id)
184
Attila Fazekas076f79f2014-03-14 17:43:46 +0100185 flavor_with_eph_disk_id = create_flavor_with_extra_specs()
186 flavor_no_eph_disk_id = create_flavor_without_extra_specs()
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800187
188 admin_pass = self.image_ssh_password
189
Zhi Kun Liu228e73d2014-03-10 15:06:10 +0800190 resp, server_no_eph_disk = (self.create_test_server(
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800191 wait_until='ACTIVE',
192 adminPass=admin_pass,
193 flavor=flavor_no_eph_disk_id))
194 resp, server_with_eph_disk = (self.create_test_server(
195 wait_until='ACTIVE',
196 adminPass=admin_pass,
197 flavor=flavor_with_eph_disk_id))
198 # Get partition number of server without extra specs.
Attila Fazekas076f79f2014-03-14 17:43:46 +0100199 _, server_no_eph_disk = self.client.get_server(
200 server_no_eph_disk['id'])
Masayuki Igawa209fd502014-02-17 14:46:43 +0900201 linux_client = remote_client.RemoteClient(server_no_eph_disk,
Attila Fazekas076f79f2014-03-14 17:43:46 +0100202 self.ssh_user, admin_pass)
203 partition_num = len(linux_client.get_partitions().split('\n'))
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800204
Attila Fazekas076f79f2014-03-14 17:43:46 +0100205 _, server_with_eph_disk = self.client.get_server(
206 server_with_eph_disk['id'])
Masayuki Igawa209fd502014-02-17 14:46:43 +0900207 linux_client = remote_client.RemoteClient(server_with_eph_disk,
Attila Fazekas076f79f2014-03-14 17:43:46 +0100208 self.ssh_user, admin_pass)
209 partition_num_emph = len(linux_client.get_partitions().split('\n'))
210 self.assertEqual(partition_num + 1, partition_num_emph)
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800211
212
Attila Fazekas19044d52013-02-16 07:35:06 +0100213class ServersTestManualDisk(ServersTestJSON):
214 disk_config = 'MANUAL'
215
Daryl Walleck0aea0032012-12-04 00:53:28 -0600216 @classmethod
217 def setUpClass(cls):
Sean Dague86bd8422013-12-20 09:56:44 -0500218 if not CONF.compute_feature_enabled.disk_config:
Daryl Walleck0aea0032012-12-04 00:53:28 -0600219 msg = "DiskConfig extension not enabled."
ivan-zhu1feeb382013-01-24 10:14:39 +0800220 raise cls.skipException(msg)
Daryl Walleck0aea0032012-12-04 00:53:28 -0600221 super(ServersTestManualDisk, cls).setUpClass()
Daryl Walleck0aea0032012-12-04 00:53:28 -0600222
223
Attila Fazekas19044d52013-02-16 07:35:06 +0100224class ServersTestXML(ServersTestJSON):
225 _interface = 'xml'
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800226
227
228class ServersWithSpecificFlavorTestXML(ServersWithSpecificFlavorTestJSON):
229 _interface = 'xml'