blob: 887608ff8809ae667494c99b8e9c9ed2a76c4d14 [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
Daryl Walleck6b9b2882012-04-08 21:43:39 -050023from tempest.common.utils.linux.remote_client import RemoteClient
Sean Dague86bd8422013-12-20 09:56:44 -050024from tempest import config
Chris Yeoh9465b0b2013-02-09 22:19:15 +103025from tempest.test import attr
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):
Attila Fazekas19044d52013-02-16 07:35:06 +010031 _interface = 'json'
Sean Dague86bd8422013-12-20 09:56:44 -050032 run_ssh = CONF.compute.run_ssh
ivan-zhua5141d92013-03-06 23:12:43 +080033 disk_config = 'AUTO'
Daryl Walleck6b9b2882012-04-08 21:43:39 -050034
Attila Fazekas19044d52013-02-16 07:35:06 +010035 @classmethod
Daryl Walleck6b9b2882012-04-08 21:43:39 -050036 def setUpClass(cls):
Attila Fazekas19044d52013-02-16 07:35:06 +010037 super(ServersTestJSON, cls).setUpClass()
Daryl Walleck6b9b2882012-04-08 21:43:39 -050038 cls.meta = {'hello': 'world'}
39 cls.accessIPv4 = '1.1.1.1'
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050040 cls.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2'
Masayuki Igawa259c1132013-10-31 17:48:44 +090041 cls.name = data_utils.rand_name('server')
Daryl Walleck6b9b2882012-04-08 21:43:39 -050042 file_contents = 'This is a test file.'
Pádraig Bradyc6081cf2013-01-04 17:43:53 +000043 personality = [{'path': '/test.txt',
Daryl Walleck6b9b2882012-04-08 21:43:39 -050044 'contents': base64.b64encode(file_contents)}]
45 cls.client = cls.servers_client
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090046 cli_resp = cls.create_test_server(name=cls.name,
47 meta=cls.meta,
48 accessIPv4=cls.accessIPv4,
49 accessIPv6=cls.accessIPv6,
50 personality=personality,
51 disk_config=cls.disk_config)
Zhongyue Luo79d8d362012-09-25 13:49:27 +080052 cls.resp, cls.server_initial = cli_resp
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')
55 resp, cls.server = cls.client.get_server(cls.server_initial['id'])
56
Daryl Walleck6b9b2882012-04-08 21:43:39 -050057 @attr(type='smoke')
58 def test_create_server_response(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050059 # Check that the required fields are returned with values
Daryl Walleck6b9b2882012-04-08 21:43:39 -050060 self.assertEqual(202, self.resp.status)
61 self.assertTrue(self.server_initial['id'] is not None)
62 self.assertTrue(self.server_initial['adminPass'] is not None)
63
64 @attr(type='smoke')
Daryl Wallecked97dca2012-07-04 23:25:45 -050065 def test_verify_server_details(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050066 # Verify the specified server attributes are set correctly
Daryl Walleck6b9b2882012-04-08 21:43:39 -050067 self.assertEqual(self.accessIPv4, self.server['accessIPv4'])
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050068 # NOTE(maurosr): See http://tools.ietf.org/html/rfc5952 (section 4)
69 # Here we compare directly with the canonicalized format.
70 self.assertEqual(self.server['accessIPv6'],
71 str(netaddr.IPAddress(self.accessIPv6)))
Daryl Walleck6b9b2882012-04-08 21:43:39 -050072 self.assertEqual(self.name, self.server['name'])
73 self.assertEqual(self.image_ref, self.server['image']['id'])
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +090074 self.assertEqual(self.flavor_ref, self.server['flavor']['id'])
Daryl Walleck6b9b2882012-04-08 21:43:39 -050075 self.assertEqual(self.meta, self.server['metadata'])
76
Daryl Wallecked97dca2012-07-04 23:25:45 -050077 @attr(type='smoke')
78 def test_list_servers(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050079 # The created server should be in the list of all servers
Daryl Wallecked97dca2012-07-04 23:25:45 -050080 resp, body = self.client.list_servers()
81 servers = body['servers']
82 found = any([i for i in servers if i['id'] == self.server['id']])
83 self.assertTrue(found)
84
85 @attr(type='smoke')
86 def test_list_servers_with_detail(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050087 # The created server should be in the detailed list of all servers
Daryl Wallecked97dca2012-07-04 23:25:45 -050088 resp, body = self.client.list_servers_with_detail()
89 servers = body['servers']
90 found = any([i for i in servers if i['id'] == self.server['id']])
91 self.assertTrue(found)
92
ivan-zhu1feeb382013-01-24 10:14:39 +080093 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Giulio Fidenteba3985a2013-05-29 01:46:36 +020094 @attr(type='gate')
Daryl Walleck6b9b2882012-04-08 21:43:39 -050095 def test_verify_created_server_vcpus(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050096 # Verify that the number of vcpus reported by the instance matches
97 # the amount stated by the flavor
Daryl Walleck6b9b2882012-04-08 21:43:39 -050098 resp, flavor = self.flavors_client.get_flavor_details(self.flavor_ref)
99 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
100 self.assertEqual(flavor['vcpus'], linux_client.get_number_of_vcpus())
101
ivan-zhu1feeb382013-01-24 10:14:39 +0800102 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Giulio Fidenteba3985a2013-05-29 01:46:36 +0200103 @attr(type='gate')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500104 def test_host_name_is_same_as_server_name(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500105 # Verify the instance host name is the same as the server name
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500106 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
107 self.assertTrue(linux_client.hostname_equals_servername(self.name))
Dan Smith4307f992012-08-16 09:23:20 -0700108
109
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800110class ServersWithSpecificFlavorTestJSON(base.BaseV2ComputeAdminTest):
111 _interface = 'json'
112 run_ssh = CONF.compute.run_ssh
113 disk_config = 'AUTO'
114
115 @classmethod
116 def setUpClass(cls):
117 super(ServersWithSpecificFlavorTestJSON, cls).setUpClass()
118 cls.meta = {'hello': 'world'}
119 cls.accessIPv4 = '1.1.1.1'
120 cls.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2'
121 cls.name = data_utils.rand_name('server')
122 file_contents = 'This is a test file.'
123 personality = [{'path': '/test.txt',
124 'contents': base64.b64encode(file_contents)}]
125 cls.client = cls.servers_client
126 cls.flavor_client = cls.os_adm.flavors_client
127 cli_resp = cls.create_test_server(name=cls.name,
128 meta=cls.meta,
129 accessIPv4=cls.accessIPv4,
130 accessIPv6=cls.accessIPv6,
131 personality=personality,
132 disk_config=cls.disk_config)
133 cls.resp, cls.server_initial = cli_resp
134 cls.password = cls.server_initial['adminPass']
135 cls.client.wait_for_server_status(cls.server_initial['id'], 'ACTIVE')
136 resp, cls.server = cls.client.get_server(cls.server_initial['id'])
137
138 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
139 @attr(type='gate')
140 def test_verify_created_server_ephemeral_disk(self):
141 # Verify that the ephemeral disk is created when creating server
142
143 def create_flavor_with_extra_specs(self):
144 flavor_with_eph_disk_name = data_utils.rand_name('eph_flavor')
145 flavor_with_eph_disk_id = data_utils.rand_int_id(start=1000)
146 ram = 64
147 vcpus = 1
148 disk = 0
149
150 # Create a flavor with extra specs
151 resp, flavor = (self.flavor_client.
152 create_flavor(flavor_with_eph_disk_name,
153 ram, vcpus, disk,
154 flavor_with_eph_disk_id,
155 ephemeral=1))
156 self.addCleanup(self.flavor_clean_up, flavor['id'])
157 self.assertEqual(200, resp.status)
158
159 return flavor['id']
160
161 def create_flavor_without_extra_specs(self):
162 flavor_no_eph_disk_name = data_utils.rand_name('no_eph_flavor')
163 flavor_no_eph_disk_id = data_utils.rand_int_id(start=1000)
164
165 ram = 64
166 vcpus = 1
167 disk = 0
168
169 # Create a flavor without extra specs
170 resp, flavor = (self.flavor_client.
171 create_flavor(flavor_no_eph_disk_name,
172 ram, vcpus, disk,
173 flavor_no_eph_disk_id))
174 self.addCleanup(self.flavor_clean_up, flavor['id'])
175 self.assertEqual(200, resp.status)
176
177 return flavor['id']
178
179 def flavor_clean_up(self, flavor_id):
180 resp, body = self.flavor_client.delete_flavor(flavor_id)
181 self.assertEqual(resp.status, 202)
182 self.flavor_client.wait_for_resource_deletion(flavor_id)
183
184 flavor_with_eph_disk_id = self.create_flavor_with_extra_specs()
185 flavor_no_eph_disk_id = self.create_flavor_without_extra_specs()
186
187 admin_pass = self.image_ssh_password
188
189 resp, server_no_eph_disk = (self.
190 create_test_server(
191 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.
199 linux_client = RemoteClient(server_no_eph_disk,
200 self.ssh_user, self.password)
201 partition_num = len(linux_client.get_partitions())
202
203 linux_client = RemoteClient(server_with_eph_disk,
204 self.ssh_user, self.password)
205 self.assertEqual(partition_num + 1, linux_client.get_partitions())
206
207
Attila Fazekas19044d52013-02-16 07:35:06 +0100208class ServersTestManualDisk(ServersTestJSON):
209 disk_config = 'MANUAL'
210
Daryl Walleck0aea0032012-12-04 00:53:28 -0600211 @classmethod
212 def setUpClass(cls):
Sean Dague86bd8422013-12-20 09:56:44 -0500213 if not CONF.compute_feature_enabled.disk_config:
Daryl Walleck0aea0032012-12-04 00:53:28 -0600214 msg = "DiskConfig extension not enabled."
ivan-zhu1feeb382013-01-24 10:14:39 +0800215 raise cls.skipException(msg)
Daryl Walleck0aea0032012-12-04 00:53:28 -0600216 super(ServersTestManualDisk, cls).setUpClass()
Daryl Walleck0aea0032012-12-04 00:53:28 -0600217
218
Attila Fazekas19044d52013-02-16 07:35:06 +0100219class ServersTestXML(ServersTestJSON):
220 _interface = 'xml'
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800221
222
223class ServersWithSpecificFlavorTestXML(ServersWithSpecificFlavorTestJSON):
224 _interface = 'xml'