blob: cbd0eb1357b199c81c66bb76579687ccace00f93 [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
Masayuki Igawa259c1132013-10-31 17:48:44 +090025from tempest.common.utils import data_utils
Daryl Walleck6b9b2882012-04-08 21:43:39 -050026from 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
ivan-zhuf2b00502013-10-18 10:06:52 +080031class ServersTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010032 _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'
Masayuki Igawa259c1132013-10-31 17:48:44 +090042 cls.name = data_utils.rand_name('server')
Daryl Walleck6b9b2882012-04-08 21:43:39 -050043 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
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090047 cli_resp = cls.create_test_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'])
Ken'ichi Ohmichi35772602013-11-14 15:03:27 +090075 self.assertEqual(self.flavor_ref, self.server['flavor']['id'])
Daryl Walleck6b9b2882012-04-08 21:43:39 -050076 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_verify_created_server_vcpus(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050097 # Verify that the number of vcpus reported by the instance matches
98 # the amount stated by the flavor
Daryl Walleck6b9b2882012-04-08 21:43:39 -050099 resp, flavor = self.flavors_client.get_flavor_details(self.flavor_ref)
100 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
101 self.assertEqual(flavor['vcpus'], linux_client.get_number_of_vcpus())
102
ivan-zhu1feeb382013-01-24 10:14:39 +0800103 @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
Giulio Fidenteba3985a2013-05-29 01:46:36 +0200104 @attr(type='gate')
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500105 def test_host_name_is_same_as_server_name(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500106 # Verify the instance host name is the same as the server name
Daryl Walleck6b9b2882012-04-08 21:43:39 -0500107 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
108 self.assertTrue(linux_client.hostname_equals_servername(self.name))
Dan Smith4307f992012-08-16 09:23:20 -0700109
110
Attila Fazekas19044d52013-02-16 07:35:06 +0100111class ServersTestManualDisk(ServersTestJSON):
112 disk_config = 'MANUAL'
113
Daryl Walleck0aea0032012-12-04 00:53:28 -0600114 @classmethod
115 def setUpClass(cls):
116 if not compute.DISK_CONFIG_ENABLED:
117 msg = "DiskConfig extension not enabled."
ivan-zhu1feeb382013-01-24 10:14:39 +0800118 raise cls.skipException(msg)
Daryl Walleck0aea0032012-12-04 00:53:28 -0600119 super(ServersTestManualDisk, cls).setUpClass()
Daryl Walleck0aea0032012-12-04 00:53:28 -0600120
121
Attila Fazekas19044d52013-02-16 07:35:06 +0100122class ServersTestXML(ServersTestJSON):
123 _interface = 'xml'