blob: 31ca3874504ecdfed5b11f4a9395c51631eb4dff [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 import compute
24from tempest.api.compute import base
Daryl Walleck6b9b2882012-04-08 21:43:39 -050025from tempest.common.utils.data_utils import rand_name
26from tempest.common.utils.linux.remote_client import RemoteClient
Matthew Treinisha83a16e2012-12-07 13:44:02 -050027import tempest.config
Chris Yeoh9465b0b2013-02-09 22:19:15 +103028from tempest.test import attr
Daryl Walleck6b9b2882012-04-08 21:43:39 -050029
30
Attila Fazekas19044d52013-02-16 07:35:06 +010031class ServersTestJSON(base.BaseComputeTest):
32 _interface = 'json'
Daryl Walleck6b9b2882012-04-08 21:43:39 -050033 run_ssh = tempest.config.TempestConfig().compute.run_ssh
ivan-zhua5141d92013-03-06 23:12:43 +080034 disk_config = 'AUTO'
Daryl Walleck6b9b2882012-04-08 21:43:39 -050035
Attila Fazekas19044d52013-02-16 07:35:06 +010036 @classmethod
Daryl Walleck6b9b2882012-04-08 21:43:39 -050037 def setUpClass(cls):
Attila Fazekas19044d52013-02-16 07:35:06 +010038 super(ServersTestJSON, cls).setUpClass()
Daryl Walleck6b9b2882012-04-08 21:43:39 -050039 cls.meta = {'hello': 'world'}
40 cls.accessIPv4 = '1.1.1.1'
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050041 cls.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2'
Daryl Walleck6b9b2882012-04-08 21:43:39 -050042 cls.name = rand_name('server')
43 file_contents = 'This is a test file.'
Pádraig Bradyc6081cf2013-01-04 17:43:53 +000044 personality = [{'path': '/test.txt',
Daryl Walleck6b9b2882012-04-08 21:43:39 -050045 'contents': base64.b64encode(file_contents)}]
46 cls.client = cls.servers_client
Sean Dague7cbc0fe2013-02-26 11:12:31 -050047 cli_resp = cls.create_server(name=cls.name,
48 meta=cls.meta,
49 accessIPv4=cls.accessIPv4,
50 accessIPv6=cls.accessIPv6,
51 personality=personality,
52 disk_config=cls.disk_config)
Zhongyue Luo79d8d362012-09-25 13:49:27 +080053 cls.resp, cls.server_initial = cli_resp
Daryl Walleck6b9b2882012-04-08 21:43:39 -050054 cls.password = cls.server_initial['adminPass']
55 cls.client.wait_for_server_status(cls.server_initial['id'], 'ACTIVE')
56 resp, cls.server = cls.client.get_server(cls.server_initial['id'])
57
Daryl Walleck6b9b2882012-04-08 21:43:39 -050058 @attr(type='smoke')
59 def test_create_server_response(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050060 # Check that the required fields are returned with values
Daryl Walleck6b9b2882012-04-08 21:43:39 -050061 self.assertEqual(202, self.resp.status)
62 self.assertTrue(self.server_initial['id'] is not None)
63 self.assertTrue(self.server_initial['adminPass'] is not None)
64
65 @attr(type='smoke')
Daryl Wallecked97dca2012-07-04 23:25:45 -050066 def test_verify_server_details(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050067 # Verify the specified server attributes are set correctly
Daryl Walleck6b9b2882012-04-08 21:43:39 -050068 self.assertEqual(self.accessIPv4, self.server['accessIPv4'])
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050069 # NOTE(maurosr): See http://tools.ietf.org/html/rfc5952 (section 4)
70 # Here we compare directly with the canonicalized format.
71 self.assertEqual(self.server['accessIPv6'],
72 str(netaddr.IPAddress(self.accessIPv6)))
Daryl Walleck6b9b2882012-04-08 21:43:39 -050073 self.assertEqual(self.name, self.server['name'])
74 self.assertEqual(self.image_ref, self.server['image']['id'])
75 self.assertEqual(str(self.flavor_ref), self.server['flavor']['id'])
76 self.assertEqual(self.meta, self.server['metadata'])
77
Daryl Wallecked97dca2012-07-04 23:25:45 -050078 @attr(type='smoke')
79 def test_list_servers(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050080 # The created server should be in the list of all servers
Daryl Wallecked97dca2012-07-04 23:25:45 -050081 resp, body = self.client.list_servers()
82 servers = body['servers']
83 found = any([i for i in servers if i['id'] == self.server['id']])
84 self.assertTrue(found)
85
86 @attr(type='smoke')
87 def test_list_servers_with_detail(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050088 # The created server should be in the detailed list of all servers
Daryl Wallecked97dca2012-07-04 23:25:45 -050089 resp, body = self.client.list_servers_with_detail()
90 servers = body['servers']
91 found = any([i for i in servers if i['id'] == self.server['id']])
92 self.assertTrue(found)
93
ivan-zhu1feeb382013-01-24 10:14:39 +080094 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Giulio Fidenteba3985a2013-05-29 01:46:36 +020095 @attr(type='gate')
Daryl Walleck6b9b2882012-04-08 21:43:39 -050096 def test_can_log_into_created_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050097 # Check that the user can authenticate with the generated password
Daryl Walleck6b9b2882012-04-08 21:43:39 -050098 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
99 self.assertTrue(linux_client.can_authenticate())
100
ivan-zhu1feeb382013-01-24 10:14:39 +0800101 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Giulio Fidenteba3985a2013-05-29 01:46:36 +0200102 @attr(type='gate')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500103 def test_verify_created_server_vcpus(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500104 # Verify that the number of vcpus reported by the instance matches
105 # the amount stated by the flavor
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500106 resp, flavor = self.flavors_client.get_flavor_details(self.flavor_ref)
107 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
108 self.assertEqual(flavor['vcpus'], linux_client.get_number_of_vcpus())
109
ivan-zhu1feeb382013-01-24 10:14:39 +0800110 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Giulio Fidenteba3985a2013-05-29 01:46:36 +0200111 @attr(type='gate')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500112 def test_host_name_is_same_as_server_name(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500113 # Verify the instance host name is the same as the server name
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500114 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
115 self.assertTrue(linux_client.hostname_equals_servername(self.name))
Dan Smith4307f992012-08-16 09:23:20 -0700116
117
Attila Fazekas19044d52013-02-16 07:35:06 +0100118class ServersTestManualDisk(ServersTestJSON):
119 disk_config = 'MANUAL'
120
Daryl Walleck0aea0032012-12-04 00:53:28 -0600121 @classmethod
122 def setUpClass(cls):
123 if not compute.DISK_CONFIG_ENABLED:
124 msg = "DiskConfig extension not enabled."
ivan-zhu1feeb382013-01-24 10:14:39 +0800125 raise cls.skipException(msg)
Daryl Walleck0aea0032012-12-04 00:53:28 -0600126 super(ServersTestManualDisk, cls).setUpClass()
Daryl Walleck0aea0032012-12-04 00:53:28 -0600127
128
Attila Fazekas19044d52013-02-16 07:35:06 +0100129class ServersTestXML(ServersTestJSON):
130 _interface = 'xml'