blob: b522992a32bfdea77b8c6dde52230e9d21550cef [file] [log] [blame]
Jay Pipes13b479b2012-06-11 14:52:27 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
4# 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
Matthew Treinisha83a16e2012-12-07 13:44:02 -050023
Daryl Walleck6b9b2882012-04-08 21:43:39 -050024from tempest.common.utils.data_utils import rand_name
25from tempest.common.utils.linux.remote_client import RemoteClient
Matthew Treinisha83a16e2012-12-07 13:44:02 -050026import tempest.config
Chris Yeoh9465b0b2013-02-09 22:19:15 +103027from tempest.test import attr
Daryl Walleck0aea0032012-12-04 00:53:28 -060028from tempest.tests import compute
Matthew Treinisha83a16e2012-12-07 13:44:02 -050029from tempest.tests.compute import base
Daryl Walleck6b9b2882012-04-08 21:43:39 -050030
31
Attila Fazekas19044d52013-02-16 07:35:06 +010032@attr(type='smoke')
33class ServersTestJSON(base.BaseComputeTest):
34 _interface = 'json'
Daryl Walleck6b9b2882012-04-08 21:43:39 -050035 run_ssh = tempest.config.TempestConfig().compute.run_ssh
ivan-zhua5141d92013-03-06 23:12:43 +080036 disk_config = 'AUTO'
Daryl Walleck6b9b2882012-04-08 21:43:39 -050037
Attila Fazekas19044d52013-02-16 07:35:06 +010038 @classmethod
Daryl Walleck6b9b2882012-04-08 21:43:39 -050039 def setUpClass(cls):
Attila Fazekas19044d52013-02-16 07:35:06 +010040 super(ServersTestJSON, cls).setUpClass()
Daryl Walleck6b9b2882012-04-08 21:43:39 -050041 cls.meta = {'hello': 'world'}
42 cls.accessIPv4 = '1.1.1.1'
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050043 cls.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2'
Daryl Walleck6b9b2882012-04-08 21:43:39 -050044 cls.name = rand_name('server')
45 file_contents = 'This is a test file.'
Pádraig Bradyc6081cf2013-01-04 17:43:53 +000046 personality = [{'path': '/test.txt',
Daryl Walleck6b9b2882012-04-08 21:43:39 -050047 'contents': base64.b64encode(file_contents)}]
48 cls.client = cls.servers_client
Sean Dague7cbc0fe2013-02-26 11:12:31 -050049 cli_resp = cls.create_server(name=cls.name,
50 meta=cls.meta,
51 accessIPv4=cls.accessIPv4,
52 accessIPv6=cls.accessIPv6,
53 personality=personality,
54 disk_config=cls.disk_config)
Zhongyue Luo79d8d362012-09-25 13:49:27 +080055 cls.resp, cls.server_initial = cli_resp
Daryl Walleck6b9b2882012-04-08 21:43:39 -050056 cls.password = cls.server_initial['adminPass']
57 cls.client.wait_for_server_status(cls.server_initial['id'], 'ACTIVE')
58 resp, cls.server = cls.client.get_server(cls.server_initial['id'])
59
Daryl Walleck6b9b2882012-04-08 21:43:39 -050060 @attr(type='smoke')
61 def test_create_server_response(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050062 # Check that the required fields are returned with values
Daryl Walleck6b9b2882012-04-08 21:43:39 -050063 self.assertEqual(202, self.resp.status)
64 self.assertTrue(self.server_initial['id'] is not None)
65 self.assertTrue(self.server_initial['adminPass'] is not None)
66
67 @attr(type='smoke')
Daryl Wallecked97dca2012-07-04 23:25:45 -050068 def test_verify_server_details(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050069 # Verify the specified server attributes are set correctly
Daryl Walleck6b9b2882012-04-08 21:43:39 -050070 self.assertEqual(self.accessIPv4, self.server['accessIPv4'])
Mauro S. M. Rodrigues54110362013-02-15 13:14:04 -050071 # NOTE(maurosr): See http://tools.ietf.org/html/rfc5952 (section 4)
72 # Here we compare directly with the canonicalized format.
73 self.assertEqual(self.server['accessIPv6'],
74 str(netaddr.IPAddress(self.accessIPv6)))
Daryl Walleck6b9b2882012-04-08 21:43:39 -050075 self.assertEqual(self.name, self.server['name'])
76 self.assertEqual(self.image_ref, self.server['image']['id'])
77 self.assertEqual(str(self.flavor_ref), self.server['flavor']['id'])
78 self.assertEqual(self.meta, self.server['metadata'])
79
Daryl Wallecked97dca2012-07-04 23:25:45 -050080 @attr(type='smoke')
81 def test_list_servers(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050082 # The created server should be in the list of all servers
Daryl Wallecked97dca2012-07-04 23:25:45 -050083 resp, body = self.client.list_servers()
84 servers = body['servers']
85 found = any([i for i in servers if i['id'] == self.server['id']])
86 self.assertTrue(found)
87
88 @attr(type='smoke')
89 def test_list_servers_with_detail(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050090 # The created server should be in the detailed list of all servers
Daryl Wallecked97dca2012-07-04 23:25:45 -050091 resp, body = self.client.list_servers_with_detail()
92 servers = body['servers']
93 found = any([i for i in servers if i['id'] == self.server['id']])
94 self.assertTrue(found)
95
Daryl Walleck6b9b2882012-04-08 21:43:39 -050096 @attr(type='positive')
ivan-zhu1feeb382013-01-24 10:14:39 +080097 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Daryl Walleck6b9b2882012-04-08 21:43:39 -050098 def test_can_log_into_created_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050099 # Check that the user can authenticate with the generated password
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500100 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
101 self.assertTrue(linux_client.can_authenticate())
102
103 @attr(type='positive')
ivan-zhu1feeb382013-01-24 10:14:39 +0800104 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500105 def test_verify_created_server_vcpus(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500106 # Verify that the number of vcpus reported by the instance matches
107 # the amount stated by the flavor
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500108 resp, flavor = self.flavors_client.get_flavor_details(self.flavor_ref)
109 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
110 self.assertEqual(flavor['vcpus'], linux_client.get_number_of_vcpus())
111
112 @attr(type='positive')
ivan-zhu1feeb382013-01-24 10:14:39 +0800113 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500114 def test_host_name_is_same_as_server_name(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500115 # Verify the instance host name is the same as the server name
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500116 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
117 self.assertTrue(linux_client.hostname_equals_servername(self.name))
Dan Smith4307f992012-08-16 09:23:20 -0700118
119
Daryl Walleck0aea0032012-12-04 00:53:28 -0600120@attr(type='positive')
Attila Fazekas19044d52013-02-16 07:35:06 +0100121class ServersTestManualDisk(ServersTestJSON):
122 disk_config = 'MANUAL'
123
Daryl Walleck0aea0032012-12-04 00:53:28 -0600124 @classmethod
125 def setUpClass(cls):
126 if not compute.DISK_CONFIG_ENABLED:
127 msg = "DiskConfig extension not enabled."
ivan-zhu1feeb382013-01-24 10:14:39 +0800128 raise cls.skipException(msg)
Daryl Walleck0aea0032012-12-04 00:53:28 -0600129 super(ServersTestManualDisk, cls).setUpClass()
Daryl Walleck0aea0032012-12-04 00:53:28 -0600130
131
Attila Fazekas19044d52013-02-16 07:35:06 +0100132class ServersTestXML(ServersTestJSON):
133 _interface = 'xml'