blob: e7a8ec733686aa5ebb4c2c1e892d2aff0dd087ef [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 Walleck1465d612011-11-02 02:22:15 -050018from nose.plugins.attrib import attr
Jay Pipes13b479b2012-06-11 14:52:27 -040019
Daryl Wallecked8bef32011-12-05 23:02:08 -060020from tempest.common.utils.data_utils import rand_name
Dan Smith011164b2012-08-14 09:06:06 -070021from tempest.tests.compute import base
Daryl Walleck1465d612011-11-02 02:22:15 -050022
23
Dan Smith011164b2012-08-14 09:06:06 -070024class ServersTestBase(object):
Daryl Walleck1465d612011-11-02 02:22:15 -050025
Daryl Wallecked97dca2012-07-04 23:25:45 -050026 @attr(type='positive')
Daryl Walleck1465d612011-11-02 02:22:15 -050027 def test_create_server_with_admin_password(self):
28 """
29 If an admin password is provided on server creation, the server's root
30 password should be set to that password.
31 """
32
saradpatele81028a2012-05-02 22:36:06 -070033 try:
David Kranzee3cc8d2012-12-03 09:23:09 -050034 server = None
saradpatele81028a2012-05-02 22:36:06 -070035 name = rand_name('server')
Sean Dague9b669e32012-12-13 18:40:08 -050036 resp, server = self.create_server_with_extras(name, self.image_ref,
37 self.flavor_ref,
38 adminPass='test'
39 'password')
Daryl Walleck1465d612011-11-02 02:22:15 -050040
saradpatele81028a2012-05-02 22:36:06 -070041 #Verify the password is set correctly in the response
42 self.assertEqual('testpassword', server['adminPass'])
Daryl Walleck1465d612011-11-02 02:22:15 -050043
Daryl Walleck1465d612011-11-02 02:22:15 -050044 #Teardown
saradpatele81028a2012-05-02 22:36:06 -070045 finally:
David Kranzee3cc8d2012-12-03 09:23:09 -050046 if server:
47 self.client.delete_server(server['id'])
Daryl Walleck1465d612011-11-02 02:22:15 -050048
Rohit Karajgidc300b22012-05-04 08:11:00 -070049 def test_create_with_existing_server_name(self):
50 """Creating a server with a name that already exists is allowed"""
51
52 try:
David Kranzee3cc8d2012-12-03 09:23:09 -050053 id1 = None
54 id2 = None
Rohit Karajgidc300b22012-05-04 08:11:00 -070055 server_name = rand_name('server')
Sean Dague9b669e32012-12-13 18:40:08 -050056 resp, server = self.create_server_with_extras(server_name,
57 self.image_ref,
58 self.flavor_ref)
Rohit Karajgidc300b22012-05-04 08:11:00 -070059 self.client.wait_for_server_status(server['id'], 'ACTIVE')
60 id1 = server['id']
Sean Dague9b669e32012-12-13 18:40:08 -050061 resp, server = self.create_server_with_extras(server_name,
62 self.image_ref,
63 self.flavor_ref)
Rohit Karajgidc300b22012-05-04 08:11:00 -070064 self.client.wait_for_server_status(server['id'], 'ACTIVE')
65 id2 = server['id']
66 self.assertNotEqual(id1, id2, "Did not create a new server")
67 resp, server = self.client.get_server(id1)
68 name1 = server['name']
69 resp, server = self.client.get_server(id2)
70 name2 = server['name']
71 self.assertEqual(name1, name2)
72 finally:
73 for server_id in (id1, id2):
74 if server_id:
75 self.client.delete_server(server_id)
76
Daryl Wallecked97dca2012-07-04 23:25:45 -050077 @attr(type='positive')
Rohit Karajgidc300b22012-05-04 08:11:00 -070078 def test_create_specify_keypair(self):
79 """Specify a keypair while creating a server"""
80
81 try:
David Kranzee3cc8d2012-12-03 09:23:09 -050082 server = None
Rohit Karajgidc300b22012-05-04 08:11:00 -070083 key_name = rand_name('key')
84 resp, keypair = self.keypairs_client.create_keypair(key_name)
85 resp, body = self.keypairs_client.list_keypairs()
86 server_name = rand_name('server')
Sean Dague9b669e32012-12-13 18:40:08 -050087 resp, server = self.create_server_with_extras(server_name,
88 self.image_ref,
89 self.flavor_ref,
90 key_name=key_name)
Rohit Karajgidc300b22012-05-04 08:11:00 -070091 self.assertEqual('202', resp['status'])
92 self.client.wait_for_server_status(server['id'], 'ACTIVE')
93 resp, server = self.client.get_server(server['id'])
94 self.assertEqual(key_name, server['key_name'])
95 finally:
96 if server:
97 self.client.delete_server(server['id'])
98
Daryl Wallecked97dca2012-07-04 23:25:45 -050099 @attr(type='positive')
Daryl Walleck1465d612011-11-02 02:22:15 -0500100 def test_update_server_name(self):
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600101 """The server name should be changed to the the provided value"""
saradpatele81028a2012-05-02 22:36:06 -0700102 try:
David Kranzee3cc8d2012-12-03 09:23:09 -0500103 server = None
saradpatele81028a2012-05-02 22:36:06 -0700104 name = rand_name('server')
Sean Dague9b669e32012-12-13 18:40:08 -0500105 resp, server = self.create_server_with_extras(name, self.image_ref,
106 self.flavor_ref)
saradpatele81028a2012-05-02 22:36:06 -0700107 self.client.wait_for_server_status(server['id'], 'ACTIVE')
Daryl Walleck1465d612011-11-02 02:22:15 -0500108
saradpatele81028a2012-05-02 22:36:06 -0700109 #Update the server with a new name
110 resp, server = self.client.update_server(server['id'],
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800111 name='newname')
saradpatele81028a2012-05-02 22:36:06 -0700112 self.assertEquals(200, resp.status)
113 self.client.wait_for_server_status(server['id'], 'ACTIVE')
Daryl Walleck1465d612011-11-02 02:22:15 -0500114
saradpatele81028a2012-05-02 22:36:06 -0700115 #Verify the name of the server has changed
116 resp, server = self.client.get_server(server['id'])
117 self.assertEqual('newname', server['name'])
Daryl Walleck1465d612011-11-02 02:22:15 -0500118
119 #Teardown
saradpatele81028a2012-05-02 22:36:06 -0700120 finally:
David Kranzee3cc8d2012-12-03 09:23:09 -0500121 if server:
122 self.client.delete_server(server['id'])
Daryl Walleck1465d612011-11-02 02:22:15 -0500123
Daryl Wallecked97dca2012-07-04 23:25:45 -0500124 @attr(type='positive')
Daryl Walleck1465d612011-11-02 02:22:15 -0500125 def test_update_access_server_address(self):
126 """
127 The server's access addresses should reflect the provided values
128 """
saradpatele81028a2012-05-02 22:36:06 -0700129 try:
David Kranzee3cc8d2012-12-03 09:23:09 -0500130 server = None
saradpatele81028a2012-05-02 22:36:06 -0700131 name = rand_name('server')
Sean Dague9b669e32012-12-13 18:40:08 -0500132 resp, server = self.create_server_with_extras(name, self.image_ref,
133 self.flavor_ref)
saradpatele81028a2012-05-02 22:36:06 -0700134 self.client.wait_for_server_status(server['id'], 'ACTIVE')
Daryl Walleck1465d612011-11-02 02:22:15 -0500135
saradpatele81028a2012-05-02 22:36:06 -0700136 #Update the IPv4 and IPv6 access addresses
137 resp, body = self.client.update_server(server['id'],
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800138 accessIPv4='1.1.1.1',
139 accessIPv6='::babe:2.2.2.2')
saradpatele81028a2012-05-02 22:36:06 -0700140 self.assertEqual(200, resp.status)
141 self.client.wait_for_server_status(server['id'], 'ACTIVE')
Daryl Walleck1465d612011-11-02 02:22:15 -0500142
saradpatele81028a2012-05-02 22:36:06 -0700143 #Verify the access addresses have been updated
144 resp, server = self.client.get_server(server['id'])
145 self.assertEqual('1.1.1.1', server['accessIPv4'])
146 self.assertEqual('::babe:2.2.2.2', server['accessIPv6'])
Daryl Walleck1465d612011-11-02 02:22:15 -0500147
148 #Teardown
saradpatele81028a2012-05-02 22:36:06 -0700149 finally:
David Kranzee3cc8d2012-12-03 09:23:09 -0500150 if server:
151 self.client.delete_server(server['id'])
Rohit Karajgidc300b22012-05-04 08:11:00 -0700152
153 def test_delete_server_while_in_building_state(self):
154 """Delete a server while it's VM state is Building"""
155 name = rand_name('server')
Sean Dague9b669e32012-12-13 18:40:08 -0500156 resp, server = self.create_server_with_extras(name, self.image_ref,
157 self.flavor_ref)
Rohit Karajgidc300b22012-05-04 08:11:00 -0700158 self.client.wait_for_server_status(server['id'], 'BUILD')
159 resp, _ = self.client.delete_server(server['id'])
160 self.assertEqual('204', resp['status'])
Dan Smith011164b2012-08-14 09:06:06 -0700161
162
163class ServersTestJSON(base.BaseComputeTestJSON, ServersTestBase):
164 @classmethod
165 def setUpClass(cls):
166 super(ServersTestJSON, cls).setUpClass()
167 cls.client = cls.servers_client
168
169
170class ServersTestXML(base.BaseComputeTestXML, ServersTestBase):
171 @classmethod
172 def setUpClass(cls):
173 super(ServersTestXML, cls).setUpClass()
174 cls.client = cls.servers_client