blob: 5d6c2ba7985654677cda879fd9650fd1769a30d7 [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
Jay Pipes13b479b2012-06-11 14:52:27 -040021import unittest2 as unittest
22
Daryl Walleck6b9b2882012-04-08 21:43:39 -050023import tempest.config
24from tempest.common.utils.data_utils import rand_name
25from tempest.common.utils.linux.remote_client import RemoteClient
Dan Smith4307f992012-08-16 09:23:20 -070026from tempest.tests.compute import base
Daryl Walleck6b9b2882012-04-08 21:43:39 -050027
28
Dan Smith4307f992012-08-16 09:23:20 -070029class ServersTest(object):
Daryl Walleck6b9b2882012-04-08 21:43:39 -050030
31 run_ssh = tempest.config.TempestConfig().compute.run_ssh
32
Dan Smith4307f992012-08-16 09:23:20 -070033 @staticmethod
Daryl Walleck6b9b2882012-04-08 21:43:39 -050034 def setUpClass(cls):
35 cls.meta = {'hello': 'world'}
36 cls.accessIPv4 = '1.1.1.1'
37 cls.accessIPv6 = '::babe:220.12.22.2'
38 cls.name = rand_name('server')
39 file_contents = 'This is a test file.'
40 personality = [{'path': '/etc/test.txt',
41 'contents': base64.b64encode(file_contents)}]
42 cls.client = cls.servers_client
Zhongyue Luo79d8d362012-09-25 13:49:27 +080043 cli_resp = cls.client.create_server(cls.name,
44 cls.image_ref,
45 cls.flavor_ref,
46 meta=cls.meta,
47 accessIPv4=cls.accessIPv4,
48 accessIPv6=cls.accessIPv6,
49 personality=personality)
50 cls.resp, cls.server_initial = cli_resp
Daryl Walleck6b9b2882012-04-08 21:43:39 -050051 cls.password = cls.server_initial['adminPass']
52 cls.client.wait_for_server_status(cls.server_initial['id'], 'ACTIVE')
53 resp, cls.server = cls.client.get_server(cls.server_initial['id'])
54
Dan Smith4307f992012-08-16 09:23:20 -070055 @staticmethod
Daryl Walleck6b9b2882012-04-08 21:43:39 -050056 def tearDownClass(cls):
57 cls.client.delete_server(cls.server_initial['id'])
Daryl Walleck6b9b2882012-04-08 21:43:39 -050058
59 @attr(type='smoke')
60 def test_create_server_response(self):
61 """Check that the required fields are returned with values"""
62 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):
Daryl Walleck6b9b2882012-04-08 21:43:39 -050068 """Verify the specified server attributes are set correctly"""
69
70 self.assertEqual(self.accessIPv4, self.server['accessIPv4'])
71 self.assertEqual(self.accessIPv6, self.server['accessIPv6'])
72 self.assertEqual(self.name, self.server['name'])
73 self.assertEqual(self.image_ref, self.server['image']['id'])
74 self.assertEqual(str(self.flavor_ref), self.server['flavor']['id'])
75 self.assertEqual(self.meta, self.server['metadata'])
76
Daryl Wallecked97dca2012-07-04 23:25:45 -050077 @attr(type='smoke')
78 def test_list_servers(self):
79 """The created server should be in the list of all servers"""
80 resp, body = self.client.list_servers()
81 servers = body['servers']
82 found = any([i for i in servers if i['id'] == self.server['id']])
83 self.assertTrue(found)
84
85 @attr(type='smoke')
86 def test_list_servers_with_detail(self):
87 """The created server should be in the detailed list of all servers"""
88 resp, body = self.client.list_servers_with_detail()
89 servers = body['servers']
90 found = any([i for i in servers if i['id'] == self.server['id']])
91 self.assertTrue(found)
92
Daryl Walleck6b9b2882012-04-08 21:43:39 -050093 @attr(type='positive')
94 @unittest.skipIf(not run_ssh, 'Instance validation tests are disabled.')
95 def test_can_log_into_created_server(self):
96 """Check that the user can authenticate with the generated password"""
97 linux_client = RemoteClient(self.server, self.ssh_user, self.password)
98 self.assertTrue(linux_client.can_authenticate())
99
100 @attr(type='positive')
101 @unittest.skipIf(not run_ssh, 'Instance validation tests are disabled.')
102 def test_verify_created_server_vcpus(self):
103 """
104 Verify that the number of vcpus reported by the instance matches
105 the amount stated by the flavor
106 """
107 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')
112 @unittest.skipIf(not run_ssh, 'Instance validation tests are disabled.')
113 def test_host_name_is_same_as_server_name(self):
114 """Verify the instance host name is the same as the server name"""
115 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
119class ServersTestJSON(base.BaseComputeTestJSON,
120 ServersTest):
121 @classmethod
122 def setUpClass(cls):
123 super(ServersTestJSON, cls).setUpClass()
124 ServersTest.setUpClass(cls)
125
126 @classmethod
127 def tearDownClass(cls):
128 ServersTest.tearDownClass(cls)
129 super(ServersTestJSON, cls).tearDownClass()
130
131
132class ServersTestXML(base.BaseComputeTestXML,
133 ServersTest):
134 @classmethod
135 def setUpClass(cls):
136 super(ServersTestXML, cls).setUpClass()
137 ServersTest.setUpClass(cls)
138
139 @classmethod
140 def tearDownClass(cls):
141 ServersTest.tearDownClass(cls)
142 super(ServersTestXML, cls).tearDownClass()