blob: 0dcc79f5afa324880be15be2b836d75c0ecf0900 [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
Daryl Walleck6b9b2882012-04-08 21:43:39 -050020from nose.plugins.attrib import attr
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
Daryl Walleck0aea0032012-12-04 00:53:28 -060027from tempest.tests import compute
Matthew Treinisha83a16e2012-12-07 13:44:02 -050028from tempest.tests.compute import base
Daryl Walleck6b9b2882012-04-08 21:43:39 -050029
30
James E. Blaire6d8ee12013-01-18 21:33:45 +000031class ServersTest(object):
Daryl Walleck6b9b2882012-04-08 21:43:39 -050032
33 run_ssh = tempest.config.TempestConfig().compute.run_ssh
34
Dan Smith4307f992012-08-16 09:23:20 -070035 @staticmethod
Daryl Walleck6b9b2882012-04-08 21:43:39 -050036 def setUpClass(cls):
37 cls.meta = {'hello': 'world'}
38 cls.accessIPv4 = '1.1.1.1'
39 cls.accessIPv6 = '::babe:220.12.22.2'
Joshua Harlow48001f12012-12-04 12:54:23 -080040 # See: http://tools.ietf.org/html/rfc5952 (section 4)
41 # This is the canonicalized form of the above.
42 cls.accessIPv6canon = '::babe:dc0c:1602'
Daryl Walleck6b9b2882012-04-08 21:43:39 -050043 cls.name = rand_name('server')
44 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
Zhongyue Luo79d8d362012-09-25 13:49:27 +080048 cli_resp = cls.client.create_server(cls.name,
49 cls.image_ref,
50 cls.flavor_ref,
51 meta=cls.meta,
52 accessIPv4=cls.accessIPv4,
53 accessIPv6=cls.accessIPv6,
Daryl Walleck0aea0032012-12-04 00:53:28 -060054 personality=personality,
55 disk_config=cls.disk_config)
Zhongyue Luo79d8d362012-09-25 13:49:27 +080056 cls.resp, cls.server_initial = cli_resp
Daryl Walleck6b9b2882012-04-08 21:43:39 -050057 cls.password = cls.server_initial['adminPass']
58 cls.client.wait_for_server_status(cls.server_initial['id'], 'ACTIVE')
59 resp, cls.server = cls.client.get_server(cls.server_initial['id'])
60
Dan Smith4307f992012-08-16 09:23:20 -070061 @staticmethod
Daryl Walleck6b9b2882012-04-08 21:43:39 -050062 def tearDownClass(cls):
63 cls.client.delete_server(cls.server_initial['id'])
Daryl Walleck6b9b2882012-04-08 21:43:39 -050064
65 @attr(type='smoke')
66 def test_create_server_response(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050067 # Check that the required fields are returned with values
Daryl Walleck6b9b2882012-04-08 21:43:39 -050068 self.assertEqual(202, self.resp.status)
69 self.assertTrue(self.server_initial['id'] is not None)
70 self.assertTrue(self.server_initial['adminPass'] is not None)
71
72 @attr(type='smoke')
Daryl Wallecked97dca2012-07-04 23:25:45 -050073 def test_verify_server_details(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050074 # Verify the specified server attributes are set correctly
Daryl Walleck6b9b2882012-04-08 21:43:39 -050075 self.assertEqual(self.accessIPv4, self.server['accessIPv4'])
Joshua Harlow48001f12012-12-04 12:54:23 -080076 self.assertIn(self.server['accessIPv6'],
77 [self.accessIPv6, self.accessIPv6canon])
Daryl Walleck6b9b2882012-04-08 21:43:39 -050078 self.assertEqual(self.name, self.server['name'])
79 self.assertEqual(self.image_ref, self.server['image']['id'])
80 self.assertEqual(str(self.flavor_ref), self.server['flavor']['id'])
81 self.assertEqual(self.meta, self.server['metadata'])
82
Daryl Wallecked97dca2012-07-04 23:25:45 -050083 @attr(type='smoke')
84 def test_list_servers(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050085 # The created server should be in the list of all servers
Daryl Wallecked97dca2012-07-04 23:25:45 -050086 resp, body = self.client.list_servers()
87 servers = body['servers']
88 found = any([i for i in servers if i['id'] == self.server['id']])
89 self.assertTrue(found)
90
91 @attr(type='smoke')
92 def test_list_servers_with_detail(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050093 # The created server should be in the detailed list of all servers
Daryl Wallecked97dca2012-07-04 23:25:45 -050094 resp, body = self.client.list_servers_with_detail()
95 servers = body['servers']
96 found = any([i for i in servers if i['id'] == self.server['id']])
97 self.assertTrue(found)
98
Daryl Walleck6b9b2882012-04-08 21:43:39 -050099 @attr(type='positive')
ivan-zhu1feeb382013-01-24 10:14:39 +0800100 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500101 def test_can_log_into_created_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500102 # Check that the user can authenticate with the generated password
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500103 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
104 self.assertTrue(linux_client.can_authenticate())
105
106 @attr(type='positive')
ivan-zhu1feeb382013-01-24 10:14:39 +0800107 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500108 def test_verify_created_server_vcpus(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500109 # Verify that the number of vcpus reported by the instance matches
110 # the amount stated by the flavor
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500111 resp, flavor = self.flavors_client.get_flavor_details(self.flavor_ref)
112 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
113 self.assertEqual(flavor['vcpus'], linux_client.get_number_of_vcpus())
114
115 @attr(type='positive')
ivan-zhu1feeb382013-01-24 10:14:39 +0800116 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500117 def test_host_name_is_same_as_server_name(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500118 # Verify the instance host name is the same as the server name
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500119 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
120 self.assertTrue(linux_client.hostname_equals_servername(self.name))
Dan Smith4307f992012-08-16 09:23:20 -0700121
122
Daryl Walleck0aea0032012-12-04 00:53:28 -0600123@attr(type='positive')
James E. Blaire6d8ee12013-01-18 21:33:45 +0000124class ServersTestAutoDisk(base.BaseComputeTestJSON,
125 ServersTest):
Daryl Walleck0aea0032012-12-04 00:53:28 -0600126 @classmethod
127 def setUpClass(cls):
128 if not compute.DISK_CONFIG_ENABLED:
129 msg = "DiskConfig extension not enabled."
ivan-zhu1feeb382013-01-24 10:14:39 +0800130 raise cls.skipException(msg)
Daryl Walleck0aea0032012-12-04 00:53:28 -0600131 super(ServersTestAutoDisk, cls).setUpClass()
132 cls.disk_config = 'AUTO'
James E. Blaire6d8ee12013-01-18 21:33:45 +0000133 ServersTest.setUpClass(cls)
Daryl Walleck0aea0032012-12-04 00:53:28 -0600134
135 @classmethod
136 def tearDownClass(cls):
James E. Blaire6d8ee12013-01-18 21:33:45 +0000137 ServersTest.tearDownClass(cls)
Daryl Walleck0aea0032012-12-04 00:53:28 -0600138 super(ServersTestAutoDisk, cls).tearDownClass()
139
140
141@attr(type='positive')
James E. Blaire6d8ee12013-01-18 21:33:45 +0000142class ServersTestManualDisk(base.BaseComputeTestJSON,
143 ServersTest):
Daryl Walleck0aea0032012-12-04 00:53:28 -0600144 @classmethod
145 def setUpClass(cls):
146 if not compute.DISK_CONFIG_ENABLED:
147 msg = "DiskConfig extension not enabled."
ivan-zhu1feeb382013-01-24 10:14:39 +0800148 raise cls.skipException(msg)
Daryl Walleck0aea0032012-12-04 00:53:28 -0600149 super(ServersTestManualDisk, cls).setUpClass()
150 cls.disk_config = 'MANUAL'
James E. Blaire6d8ee12013-01-18 21:33:45 +0000151 ServersTest.setUpClass(cls)
Daryl Walleck0aea0032012-12-04 00:53:28 -0600152
153 @classmethod
154 def tearDownClass(cls):
James E. Blaire6d8ee12013-01-18 21:33:45 +0000155 ServersTest.tearDownClass(cls)
Daryl Walleck0aea0032012-12-04 00:53:28 -0600156 super(ServersTestManualDisk, cls).tearDownClass()
157
158
159@attr(type='smoke')
James E. Blaire6d8ee12013-01-18 21:33:45 +0000160class ServersTestJSON(base.BaseComputeTestJSON,
161 ServersTest):
Dan Smith4307f992012-08-16 09:23:20 -0700162 @classmethod
163 def setUpClass(cls):
James E. Blaire6d8ee12013-01-18 21:33:45 +0000164 super(ServersTestJSON, cls).setUpClass()
Daryl Walleck0aea0032012-12-04 00:53:28 -0600165 cls.disk_config = None
James E. Blaire6d8ee12013-01-18 21:33:45 +0000166 ServersTest.setUpClass(cls)
Dan Smith4307f992012-08-16 09:23:20 -0700167
168 @classmethod
169 def tearDownClass(cls):
James E. Blaire6d8ee12013-01-18 21:33:45 +0000170 ServersTest.tearDownClass(cls)
171 super(ServersTestJSON, cls).tearDownClass()
172
173
174@attr(type='smoke')
175class ServersTestXML(base.BaseComputeTestXML,
176 ServersTest):
177 @classmethod
178 def setUpClass(cls):
179 super(ServersTestXML, cls).setUpClass()
180 cls.disk_config = None
181 ServersTest.setUpClass(cls)
182
183 @classmethod
184 def tearDownClass(cls):
185 ServersTest.tearDownClass(cls)
186 super(ServersTestXML, cls).tearDownClass()