blob: 5d62e1bc0a17ffb50c1391893269145a17b366cd [file] [log] [blame]
Jay Pipes13b479b2012-06-11 14:52:27 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04004# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
Daryl Walleck6b9b2882012-04-08 21:43:39 -050018import base64
Jay Pipes13b479b2012-06-11 14:52:27 -040019
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050020import netaddr
ivan-zhu1feeb382013-01-24 10:14:39 +080021import testtools
Jay Pipes13b479b2012-06-11 14:52:27 -040022
Sean Dague1937d092013-05-17 16:36:38 -040023from tempest.api.compute import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090024from tempest.common.utils import data_utils
Daryl Walleck6b9b2882012-04-08 21:43:39 -050025from tempest.common.utils.linux.remote_client import RemoteClient
Sean Dague86bd8422013-12-20 09:56:44 -050026from tempest import config
Chris Yeoh9465b0b2013-02-09 22:19:15 +103027from tempest.test import attr
Daryl Walleck6b9b2882012-04-08 21:43:39 -050028
Sean Dague86bd8422013-12-20 09:56:44 -050029CONF = config.CONF
30
Daryl Walleck6b9b2882012-04-08 21:43:39 -050031
ivan-zhuf2b00502013-10-18 10:06:52 +080032class ServersTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010033 _interface = 'json'
Sean Dague86bd8422013-12-20 09:56:44 -050034 run_ssh = CONF.compute.run_ssh
ivan-zhua5141d92013-03-06 23:12:43 +080035 disk_config = 'AUTO'
Daryl Walleck6b9b2882012-04-08 21:43:39 -050036
Attila Fazekas19044d52013-02-16 07:35:06 +010037 @classmethod
Daryl Walleck6b9b2882012-04-08 21:43:39 -050038 def setUpClass(cls):
Attila Fazekas19044d52013-02-16 07:35:06 +010039 super(ServersTestJSON, cls).setUpClass()
Daryl Walleck6b9b2882012-04-08 21:43:39 -050040 cls.meta = {'hello': 'world'}
41 cls.accessIPv4 = '1.1.1.1'
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050042 cls.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2'
Masayuki Igawa259c1132013-10-31 17:48:44 +090043 cls.name = data_utils.rand_name('server')
Daryl Walleck6b9b2882012-04-08 21:43:39 -050044 file_contents = 'This is a test file.'
Pádraig Bradyc6081cf2013-01-04 17:43:53 +000045 personality = [{'path': '/test.txt',
Daryl Walleck6b9b2882012-04-08 21:43:39 -050046 'contents': base64.b64encode(file_contents)}]
47 cls.client = cls.servers_client
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090048 cli_resp = cls.create_test_server(name=cls.name,
49 meta=cls.meta,
50 accessIPv4=cls.accessIPv4,
51 accessIPv6=cls.accessIPv6,
52 personality=personality,
53 disk_config=cls.disk_config)
Zhongyue Luo79d8d362012-09-25 13:49:27 +080054 cls.resp, cls.server_initial = cli_resp
Daryl Walleck6b9b2882012-04-08 21:43:39 -050055 cls.password = cls.server_initial['adminPass']
56 cls.client.wait_for_server_status(cls.server_initial['id'], 'ACTIVE')
57 resp, cls.server = cls.client.get_server(cls.server_initial['id'])
58
Daryl Walleck6b9b2882012-04-08 21:43:39 -050059 @attr(type='smoke')
60 def test_create_server_response(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050061 # Check that the required fields are returned with values
Daryl Walleck6b9b2882012-04-08 21:43:39 -050062 self.assertEqual(202, self.resp.status)
63 self.assertTrue(self.server_initial['id'] is not None)
64 self.assertTrue(self.server_initial['adminPass'] is not None)
65
66 @attr(type='smoke')
Daryl Wallecked97dca2012-07-04 23:25:45 -050067 def test_verify_server_details(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050068 # Verify the specified server attributes are set correctly
Daryl Walleck6b9b2882012-04-08 21:43:39 -050069 self.assertEqual(self.accessIPv4, self.server['accessIPv4'])
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050070 # NOTE(maurosr): See http://tools.ietf.org/html/rfc5952 (section 4)
71 # Here we compare directly with the canonicalized format.
72 self.assertEqual(self.server['accessIPv6'],
73 str(netaddr.IPAddress(self.accessIPv6)))
Daryl Walleck6b9b2882012-04-08 21:43:39 -050074 self.assertEqual(self.name, self.server['name'])
75 self.assertEqual(self.image_ref, self.server['image']['id'])
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +090076 self.assertEqual(self.flavor_ref, self.server['flavor']['id'])
Daryl Walleck6b9b2882012-04-08 21:43:39 -050077 self.assertEqual(self.meta, self.server['metadata'])
78
Daryl Wallecked97dca2012-07-04 23:25:45 -050079 @attr(type='smoke')
80 def test_list_servers(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050081 # The created server should be in the list of all servers
Daryl Wallecked97dca2012-07-04 23:25:45 -050082 resp, body = self.client.list_servers()
83 servers = body['servers']
84 found = any([i for i in servers if i['id'] == self.server['id']])
85 self.assertTrue(found)
86
87 @attr(type='smoke')
88 def test_list_servers_with_detail(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050089 # The created server should be in the detailed list of all servers
Daryl Wallecked97dca2012-07-04 23:25:45 -050090 resp, body = self.client.list_servers_with_detail()
91 servers = body['servers']
92 found = any([i for i in servers if i['id'] == self.server['id']])
93 self.assertTrue(found)
94
ivan-zhu1feeb382013-01-24 10:14:39 +080095 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Giulio Fidenteba3985a2013-05-29 01:46:36 +020096 @attr(type='gate')
Daryl Walleck6b9b2882012-04-08 21:43:39 -050097 def test_verify_created_server_vcpus(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050098 # Verify that the number of vcpus reported by the instance matches
99 # the amount stated by the flavor
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500100 resp, flavor = self.flavors_client.get_flavor_details(self.flavor_ref)
101 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
102 self.assertEqual(flavor['vcpus'], linux_client.get_number_of_vcpus())
103
ivan-zhu1feeb382013-01-24 10:14:39 +0800104 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Giulio Fidenteba3985a2013-05-29 01:46:36 +0200105 @attr(type='gate')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500106 def test_host_name_is_same_as_server_name(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500107 # Verify the instance host name is the same as the server name
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500108 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
109 self.assertTrue(linux_client.hostname_equals_servername(self.name))
Dan Smith4307f992012-08-16 09:23:20 -0700110
111
Attila Fazekas19044d52013-02-16 07:35:06 +0100112class ServersTestManualDisk(ServersTestJSON):
113 disk_config = 'MANUAL'
114
Daryl Walleck0aea0032012-12-04 00:53:28 -0600115 @classmethod
116 def setUpClass(cls):
Sean Dague86bd8422013-12-20 09:56:44 -0500117 if not CONF.compute_feature_enabled.disk_config:
Daryl Walleck0aea0032012-12-04 00:53:28 -0600118 msg = "DiskConfig extension not enabled."
ivan-zhu1feeb382013-01-24 10:14:39 +0800119 raise cls.skipException(msg)
Daryl Walleck0aea0032012-12-04 00:53:28 -0600120 super(ServersTestManualDisk, cls).setUpClass()
Daryl Walleck0aea0032012-12-04 00:53:28 -0600121
122
Attila Fazekas19044d52013-02-16 07:35:06 +0100123class ServersTestXML(ServersTestJSON):
124 _interface = 'xml'