blob: 778294e4014af9d57d534a8df87bca4854b30015 [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):
Sean Dague86bd8422013-12-20 09:56:44 -050031 run_ssh = CONF.compute.run_ssh
ivan-zhua5141d92013-03-06 23:12:43 +080032 disk_config = 'AUTO'
Daryl Walleck6b9b2882012-04-08 21:43:39 -050033
Attila Fazekas19044d52013-02-16 07:35:06 +010034 @classmethod
Daryl Walleck6b9b2882012-04-08 21:43:39 -050035 def setUpClass(cls):
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 Walleck6b9b2882012-04-08 21:43:39 -050057 def test_create_server_response(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050058 # Check that the required fields are returned with values
Daryl Walleck6b9b2882012-04-08 21:43:39 -050059 self.assertEqual(202, self.resp.status)
60 self.assertTrue(self.server_initial['id'] is not None)
61 self.assertTrue(self.server_initial['adminPass'] is not None)
62
Masayuki Igawa209fd502014-02-17 14:46:43 +090063 @test.attr(type='smoke')
Daryl Wallecked97dca2012-07-04 23:25:45 -050064 def test_verify_server_details(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050065 # Verify the specified server attributes are set correctly
Daryl Walleck6b9b2882012-04-08 21:43:39 -050066 self.assertEqual(self.accessIPv4, self.server['accessIPv4'])
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050067 # NOTE(maurosr): See http://tools.ietf.org/html/rfc5952 (section 4)
68 # Here we compare directly with the canonicalized format.
69 self.assertEqual(self.server['accessIPv6'],
70 str(netaddr.IPAddress(self.accessIPv6)))
Daryl Walleck6b9b2882012-04-08 21:43:39 -050071 self.assertEqual(self.name, self.server['name'])
72 self.assertEqual(self.image_ref, self.server['image']['id'])
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +090073 self.assertEqual(self.flavor_ref, self.server['flavor']['id'])
Daryl Walleck6b9b2882012-04-08 21:43:39 -050074 self.assertEqual(self.meta, self.server['metadata'])
75
Masayuki Igawa209fd502014-02-17 14:46:43 +090076 @test.attr(type='smoke')
Daryl Wallecked97dca2012-07-04 23:25:45 -050077 def test_list_servers(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050078 # The created server should be in the list of all servers
Daryl Wallecked97dca2012-07-04 23:25:45 -050079 resp, body = self.client.list_servers()
80 servers = body['servers']
81 found = any([i for i in servers if i['id'] == self.server['id']])
82 self.assertTrue(found)
83
Masayuki Igawa209fd502014-02-17 14:46:43 +090084 @test.attr(type='smoke')
Daryl Wallecked97dca2012-07-04 23:25:45 -050085 def test_list_servers_with_detail(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050086 # The created server should be in the detailed list of all servers
Daryl Wallecked97dca2012-07-04 23:25:45 -050087 resp, body = self.client.list_servers_with_detail()
88 servers = body['servers']
89 found = any([i for i in servers if i['id'] == self.server['id']])
90 self.assertTrue(found)
91
ivan-zhu1feeb382013-01-24 10:14:39 +080092 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Masayuki Igawa209fd502014-02-17 14:46:43 +090093 @test.attr(type='gate')
Daryl Walleck6b9b2882012-04-08 21:43:39 -050094 def test_verify_created_server_vcpus(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050095 # Verify that the number of vcpus reported by the instance matches
96 # the amount stated by the flavor
Daryl Walleck6b9b2882012-04-08 21:43:39 -050097 resp, flavor = self.flavors_client.get_flavor_details(self.flavor_ref)
Masayuki Igawa209fd502014-02-17 14:46:43 +090098 linux_client = remote_client.RemoteClient(self.server, self.ssh_user,
99 self.password)
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500100 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.')
Masayuki Igawa209fd502014-02-17 14:46:43 +0900103 @test.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
Masayuki Igawa209fd502014-02-17 14:46:43 +0900106 linux_client = remote_client.RemoteClient(self.server, self.ssh_user,
107 self.password)
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500108 self.assertTrue(linux_client.hostname_equals_servername(self.name))
Dan Smith4307f992012-08-16 09:23:20 -0700109
110
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800111class ServersWithSpecificFlavorTestJSON(base.BaseV2ComputeAdminTest):
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800112 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.')
Masayuki Igawa209fd502014-02-17 14:46:43 +0900139 @test.attr(type='gate')
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800140 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
Zhi Kun Liu228e73d2014-03-10 15:06:10 +0800189 resp, server_no_eph_disk = (self.create_test_server(
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800190 wait_until='ACTIVE',
191 adminPass=admin_pass,
192 flavor=flavor_no_eph_disk_id))
193 resp, server_with_eph_disk = (self.create_test_server(
194 wait_until='ACTIVE',
195 adminPass=admin_pass,
196 flavor=flavor_with_eph_disk_id))
197 # Get partition number of server without extra specs.
Masayuki Igawa209fd502014-02-17 14:46:43 +0900198 linux_client = remote_client.RemoteClient(server_no_eph_disk,
199 self.ssh_user, self.password)
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800200 partition_num = len(linux_client.get_partitions())
201
Masayuki Igawa209fd502014-02-17 14:46:43 +0900202 linux_client = remote_client.RemoteClient(server_with_eph_disk,
203 self.ssh_user, self.password)
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800204 self.assertEqual(partition_num + 1, linux_client.get_partitions())
205
206
Attila Fazekas19044d52013-02-16 07:35:06 +0100207class ServersTestManualDisk(ServersTestJSON):
208 disk_config = 'MANUAL'
209
Daryl Walleck0aea0032012-12-04 00:53:28 -0600210 @classmethod
211 def setUpClass(cls):
Sean Dague86bd8422013-12-20 09:56:44 -0500212 if not CONF.compute_feature_enabled.disk_config:
Daryl Walleck0aea0032012-12-04 00:53:28 -0600213 msg = "DiskConfig extension not enabled."
ivan-zhu1feeb382013-01-24 10:14:39 +0800214 raise cls.skipException(msg)
Daryl Walleck0aea0032012-12-04 00:53:28 -0600215 super(ServersTestManualDisk, cls).setUpClass()
Daryl Walleck0aea0032012-12-04 00:53:28 -0600216
217
Attila Fazekas19044d52013-02-16 07:35:06 +0100218class ServersTestXML(ServersTestJSON):
219 _interface = 'xml'
Chang Bo Guoedd6ec02013-12-12 23:53:09 -0800220
221
222class ServersWithSpecificFlavorTestXML(ServersWithSpecificFlavorTestJSON):
223 _interface = 'xml'