blob: f06a0cc63ff546e1d86a7b86f2f32703b5ed98e6 [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
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 +010031@attr(type='smoke')
32class ServersTestJSON(base.BaseComputeTest):
33 _interface = 'json'
Daryl Walleck6b9b2882012-04-08 21:43:39 -050034 run_ssh = tempest.config.TempestConfig().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'
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
Sean Dague7cbc0fe2013-02-26 11:12:31 -050048 cli_resp = cls.create_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'])
76 self.assertEqual(str(self.flavor_ref), self.server['flavor']['id'])
77 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
Daryl Walleck6b9b2882012-04-08 21:43:39 -050095 @attr(type='positive')
ivan-zhu1feeb382013-01-24 10:14:39 +080096 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Daryl Walleck6b9b2882012-04-08 21:43:39 -050097 def test_can_log_into_created_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050098 # Check that the user can authenticate with the generated password
Daryl Walleck6b9b2882012-04-08 21:43:39 -050099 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
100 self.assertTrue(linux_client.can_authenticate())
101
102 @attr(type='positive')
ivan-zhu1feeb382013-01-24 10:14:39 +0800103 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500104 def test_verify_created_server_vcpus(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500105 # Verify that the number of vcpus reported by the instance matches
106 # the amount stated by the flavor
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500107 resp, flavor = self.flavors_client.get_flavor_details(self.flavor_ref)
108 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
109 self.assertEqual(flavor['vcpus'], linux_client.get_number_of_vcpus())
110
111 @attr(type='positive')
ivan-zhu1feeb382013-01-24 10:14:39 +0800112 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500113 def test_host_name_is_same_as_server_name(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500114 # Verify the instance host name is the same as the server name
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500115 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
116 self.assertTrue(linux_client.hostname_equals_servername(self.name))
Dan Smith4307f992012-08-16 09:23:20 -0700117
118
Daryl Walleck0aea0032012-12-04 00:53:28 -0600119@attr(type='positive')
Attila Fazekas19044d52013-02-16 07:35:06 +0100120class ServersTestManualDisk(ServersTestJSON):
121 disk_config = 'MANUAL'
122
Daryl Walleck0aea0032012-12-04 00:53:28 -0600123 @classmethod
124 def setUpClass(cls):
125 if not compute.DISK_CONFIG_ENABLED:
126 msg = "DiskConfig extension not enabled."
ivan-zhu1feeb382013-01-24 10:14:39 +0800127 raise cls.skipException(msg)
Daryl Walleck0aea0032012-12-04 00:53:28 -0600128 super(ServersTestManualDisk, cls).setUpClass()
Daryl Walleck0aea0032012-12-04 00:53:28 -0600129
130
Attila Fazekas19044d52013-02-16 07:35:06 +0100131class ServersTestXML(ServersTestJSON):
132 _interface = 'xml'