blob: 8e332ed2d999b6d968640f8b575fa0ea8e493378 [file] [log] [blame]
Daryl Wallecked8bef32011-12-05 23:02:08 -06001from tempest.common import ssh
Daryl Walleck1465d612011-11-02 02:22:15 -05002from nose.plugins.attrib import attr
Daryl Wallecked8bef32011-12-05 23:02:08 -06003from tempest import openstack
4from tempest.common.utils.data_utils import rand_name
Daryl Walleck1465d612011-11-02 02:22:15 -05005import base64
Daryl Wallecked8bef32011-12-05 23:02:08 -06006import tempest.config
Daryl Walleck1465d612011-11-02 02:22:15 -05007import unittest2 as unittest
8
9
10class ServersTest(unittest.TestCase):
11
12 @classmethod
13 def setUpClass(cls):
14 cls.os = openstack.Manager()
15 cls.client = cls.os.servers_client
Jay Pipes7f757632011-12-02 15:53:32 -050016 cls.config = cls.os.config
Daryl Walleck1465d612011-11-02 02:22:15 -050017 cls.image_ref = cls.config.env.image_ref
18 cls.flavor_ref = cls.config.env.flavor_ref
Daryl Walleck1465d612011-11-02 02:22:15 -050019
20 @attr(type='smoke')
21 def test_create_delete_server(self):
22 meta = {'hello': 'world'}
23 accessIPv4 = '1.1.1.1'
24 accessIPv6 = '::babe:220.12.22.2'
25 name = rand_name('server')
26 file_contents = 'This is a test file.'
27 personality = [{'path': '/etc/test.txt',
28 'contents': base64.b64encode(file_contents)}]
29 resp, server = self.client.create_server(name,
30 self.image_ref,
31 self.flavor_ref,
32 meta=meta,
33 accessIPv4=accessIPv4,
34 accessIPv6=accessIPv6,
35 personality=personality)
Daryl Wallecked8bef32011-12-05 23:02:08 -060036 #Check the initial response
37 self.assertEqual(202, resp.status)
38 self.assertTrue(server['id'] is not None)
39 self.assertTrue(server['adminPass'] is not None)
Daryl Walleck1465d612011-11-02 02:22:15 -050040
41 #Wait for the server to become active
42 self.client.wait_for_server_status(server['id'], 'ACTIVE')
43
44 #Verify the specified attributes are set correctly
45 resp, server = self.client.get_server(server['id'])
46 self.assertEqual('1.1.1.1', server['accessIPv4'])
47 self.assertEqual('::babe:220.12.22.2', server['accessIPv6'])
48 self.assertEqual(name, server['name'])
49 self.assertEqual(self.image_ref, server['image']['id'])
50 self.assertEqual(str(self.flavor_ref), server['flavor']['id'])
51
Daryl Wallecked8bef32011-12-05 23:02:08 -060052 #Delete the server
53 resp, body = self.client.delete_server(server['id'])
54 self.assertEqual(204, resp.status)
Daryl Walleck1465d612011-11-02 02:22:15 -050055
56 @attr(type='smoke')
57 def test_create_server_with_admin_password(self):
58 """
59 If an admin password is provided on server creation, the server's root
60 password should be set to that password.
61 """
62
63 name = rand_name('server')
64 resp, server = self.client.create_server(name, self.image_ref,
65 self.flavor_ref,
66 adminPass='testpassword')
67
68 #Verify the password is set correctly in the response
69 self.assertEqual('testpassword', server['adminPass'])
70
Daryl Walleck1465d612011-11-02 02:22:15 -050071 #Teardown
72 self.client.delete_server(server['id'])
73
74 @attr(type='smoke')
75 def test_update_server_name(self):
Daryl Wallecke5b83d42011-11-10 14:39:02 -060076 """The server name should be changed to the the provided value"""
Daryl Walleck1465d612011-11-02 02:22:15 -050077 name = rand_name('server')
78 resp, server = self.client.create_server(name, self.image_ref,
79 self.flavor_ref)
80 self.client.wait_for_server_status(server['id'], 'ACTIVE')
81
82 #Update the server with a new name
Daryl Wallecked8bef32011-12-05 23:02:08 -060083 resp, server = self.client.update_server(server['id'], name='newname')
84 self.assertEquals(200, resp.status)
Daryl Walleck1465d612011-11-02 02:22:15 -050085 self.client.wait_for_server_status(server['id'], 'ACTIVE')
86
87 #Verify the name of the server has changed
88 resp, server = self.client.get_server(server['id'])
89 self.assertEqual('newname', server['name'])
90
91 #Teardown
92 self.client.delete_server(server['id'])
93
94 @attr(type='smoke')
95 def test_update_access_server_address(self):
96 """
97 The server's access addresses should reflect the provided values
98 """
99 name = rand_name('server')
100 resp, server = self.client.create_server(name, self.image_ref,
101 self.flavor_ref)
102 self.client.wait_for_server_status(server['id'], 'ACTIVE')
103
104 #Update the IPv4 and IPv6 access addresses
Daryl Wallecked8bef32011-12-05 23:02:08 -0600105 resp, body = self.client.update_server(server['id'],
106 accessIPv4='1.1.1.1',
107 accessIPv6='::babe:2.2.2.2')
108 self.assertEqual(200, resp.status)
Daryl Walleck1465d612011-11-02 02:22:15 -0500109 self.client.wait_for_server_status(server['id'], 'ACTIVE')
110
111 #Verify the access addresses have been updated
112 resp, server = self.client.get_server(server['id'])
113 self.assertEqual('1.1.1.1', server['accessIPv4'])
114 self.assertEqual('::babe:2.2.2.2', server['accessIPv6'])
115
116 #Teardown
117 self.client.delete_server(server['id'])