Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 1 | # 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 Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 18 | import base64 |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 19 | |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 20 | from nose.plugins.attrib import attr |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 21 | import unittest2 as unittest |
| 22 | |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 23 | import tempest.config |
| 24 | from tempest.common.utils.data_utils import rand_name |
| 25 | from tempest.common.utils.linux.remote_client import RemoteClient |
Dan Smith | 4307f99 | 2012-08-16 09:23:20 -0700 | [diff] [blame] | 26 | from tempest.tests.compute import base |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 27 | |
| 28 | |
Dan Smith | 4307f99 | 2012-08-16 09:23:20 -0700 | [diff] [blame] | 29 | class ServersTest(object): |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 30 | |
| 31 | run_ssh = tempest.config.TempestConfig().compute.run_ssh |
| 32 | |
Dan Smith | 4307f99 | 2012-08-16 09:23:20 -0700 | [diff] [blame] | 33 | @staticmethod |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 34 | 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 Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame^] | 43 | 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 Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 51 | 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 Smith | 4307f99 | 2012-08-16 09:23:20 -0700 | [diff] [blame] | 55 | @staticmethod |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 56 | def tearDownClass(cls): |
| 57 | cls.client.delete_server(cls.server_initial['id']) |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 58 | |
| 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 Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 67 | def test_verify_server_details(self): |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 68 | """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 Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 77 | @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 Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 93 | @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 Smith | 4307f99 | 2012-08-16 09:23:20 -0700 | [diff] [blame] | 117 | |
| 118 | |
| 119 | class 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 | |
| 132 | class 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() |