ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Mauro S. M. Rodrigues | 5411036 | 2013-02-15 13:14:04 -0500 | [diff] [blame] | 16 | import netaddr |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 17 | import testtools |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 18 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 19 | from tempest.api.compute import base |
Masayuki Igawa | 209fd50 | 2014-02-17 14:46:43 +0900 | [diff] [blame] | 20 | from tempest.common.utils.linux import remote_client |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 21 | from tempest import config |
Ken'ichi Ohmichi | 757833a | 2017-03-10 10:30:30 -0800 | [diff] [blame] | 22 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 23 | from tempest.lib import decorators |
Masayuki Igawa | 209fd50 | 2014-02-17 14:46:43 +0900 | [diff] [blame] | 24 | from tempest import test |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 25 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 26 | CONF = config.CONF |
| 27 | |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 28 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 29 | class ServersTestJSON(base.BaseV2ComputeTest): |
ivan-zhu | a5141d9 | 2013-03-06 23:12:43 +0800 | [diff] [blame] | 30 | disk_config = 'AUTO' |
Andrea Frittoli | 9958b17 | 2017-07-13 11:24:59 +0100 | [diff] [blame] | 31 | volume_backed = False |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 32 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 33 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 34 | def setup_credentials(cls): |
Attila Fazekas | 423834d | 2014-03-14 17:33:13 +0100 | [diff] [blame] | 35 | cls.prepare_instance_network() |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 36 | super(ServersTestJSON, cls).setup_credentials() |
| 37 | |
| 38 | @classmethod |
| 39 | def setup_clients(cls): |
| 40 | super(ServersTestJSON, cls).setup_clients() |
| 41 | cls.client = cls.servers_client |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 42 | |
| 43 | @classmethod |
| 44 | def resource_setup(cls): |
nithya-ganesan | 222efd7 | 2015-01-22 12:20:27 +0000 | [diff] [blame] | 45 | cls.set_validation_resources() |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 46 | super(ServersTestJSON, cls).resource_setup() |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 47 | cls.meta = {'hello': 'world'} |
| 48 | cls.accessIPv4 = '1.1.1.1' |
Mauro S. M. Rodrigues | 5411036 | 2013-02-15 13:14:04 -0500 | [diff] [blame] | 49 | cls.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2' |
zhufl | c6ce539 | 2016-08-17 14:34:37 +0800 | [diff] [blame] | 50 | cls.name = data_utils.rand_name(cls.__name__ + '-server') |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 51 | cls.password = data_utils.rand_password() |
David Kranz | 0fb1429 | 2015-02-11 15:55:20 -0500 | [diff] [blame] | 52 | disk_config = cls.disk_config |
zhufl | 7e0c9b6 | 2017-02-16 11:25:34 +0800 | [diff] [blame] | 53 | server_initial = cls.create_test_server( |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 54 | validatable=True, |
| 55 | wait_until='ACTIVE', |
| 56 | name=cls.name, |
Ken'ichi Ohmichi | f2d436e | 2015-09-03 01:13:16 +0000 | [diff] [blame] | 57 | metadata=cls.meta, |
Joseph Lanoux | b3e1f87 | 2015-01-30 11:13:07 +0000 | [diff] [blame] | 58 | accessIPv4=cls.accessIPv4, |
| 59 | accessIPv6=cls.accessIPv6, |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 60 | disk_config=disk_config, |
Andrea Frittoli | 9958b17 | 2017-07-13 11:24:59 +0100 | [diff] [blame] | 61 | adminPass=cls.password, |
| 62 | volume_backed=cls.volume_backed) |
zhufl | 7e0c9b6 | 2017-02-16 11:25:34 +0800 | [diff] [blame] | 63 | cls.server = (cls.client.show_server(server_initial['id']) |
ghanshyam | 0f82525 | 2015-08-25 16:02:50 +0900 | [diff] [blame] | 64 | ['server']) |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 65 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 66 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 67 | @decorators.idempotent_id('5de47127-9977-400a-936f-abcfbec1218f') |
Daryl Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 68 | def test_verify_server_details(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 69 | # Verify the specified server attributes are set correctly |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 70 | self.assertEqual(self.accessIPv4, self.server['accessIPv4']) |
Mauro S. M. Rodrigues | 5411036 | 2013-02-15 13:14:04 -0500 | [diff] [blame] | 71 | # NOTE(maurosr): See http://tools.ietf.org/html/rfc5952 (section 4) |
| 72 | # Here we compare directly with the canonicalized format. |
| 73 | self.assertEqual(self.server['accessIPv6'], |
| 74 | str(netaddr.IPAddress(self.accessIPv6))) |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 75 | self.assertEqual(self.name, self.server['name']) |
Andrea Frittoli | 9958b17 | 2017-07-13 11:24:59 +0100 | [diff] [blame] | 76 | if self.volume_backed: |
| 77 | # Image is an empty string as per documentation |
| 78 | self.assertEqual("", self.server['image']) |
| 79 | else: |
| 80 | self.assertEqual(self.image_ref, self.server['image']['id']) |
Ken'ichi Ohmichi | 3577260 | 2013-11-14 15:03:27 +0900 | [diff] [blame] | 81 | self.assertEqual(self.flavor_ref, self.server['flavor']['id']) |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 82 | self.assertEqual(self.meta, self.server['metadata']) |
| 83 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 84 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 85 | @decorators.idempotent_id('9a438d88-10c6-4bcd-8b5b-5b6e25e1346f') |
Daryl Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 86 | def test_list_servers(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 87 | # The created server should be in the list of all servers |
David Kranz | ae99b9a | 2015-02-16 13:37:01 -0500 | [diff] [blame] | 88 | body = self.client.list_servers() |
Daryl Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 89 | servers = body['servers'] |
zhufl | 63f059e | 2017-06-12 13:56:18 +0800 | [diff] [blame] | 90 | found = [i for i in servers if i['id'] == self.server['id']] |
| 91 | self.assertNotEmpty(found) |
Daryl Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 92 | |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 93 | @decorators.idempotent_id('585e934c-448e-43c4-acbf-d06a9b899997') |
Daryl Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 94 | def test_list_servers_with_detail(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 95 | # The created server should be in the detailed list of all servers |
Ken'ichi Ohmichi | cbc26a8 | 2015-07-03 08:18:04 +0000 | [diff] [blame] | 96 | body = self.client.list_servers(detail=True) |
Daryl Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 97 | servers = body['servers'] |
zhufl | 63f059e | 2017-06-12 13:56:18 +0800 | [diff] [blame] | 98 | found = [i for i in servers if i['id'] == self.server['id']] |
| 99 | self.assertNotEmpty(found) |
Daryl Walleck | ed97dca | 2012-07-04 23:25:45 -0500 | [diff] [blame] | 100 | |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 101 | @decorators.idempotent_id('cbc0f52f-05aa-492b-bdc1-84b575ca294b') |
Matthew Treinish | e5cca00 | 2015-05-11 15:36:50 -0400 | [diff] [blame] | 102 | @testtools.skipUnless(CONF.validation.run_validation, |
Matt Riedemann | 6c66820 | 2014-03-24 09:17:10 -0700 | [diff] [blame] | 103 | 'Instance validation tests are disabled.') |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 104 | def test_verify_created_server_vcpus(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 105 | # Verify that the number of vcpus reported by the instance matches |
| 106 | # the amount stated by the flavor |
ghanshyam | 19973be | 2015-08-18 15:46:42 +0900 | [diff] [blame] | 107 | flavor = self.flavors_client.show_flavor(self.flavor_ref)['flavor'] |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 108 | linux_client = remote_client.RemoteClient( |
| 109 | self.get_server_ip(self.server), |
| 110 | self.ssh_user, |
| 111 | self.password, |
Andrea Frittoli (andreaf) | 2a70a61 | 2016-04-29 16:09:13 -0500 | [diff] [blame] | 112 | self.validation_resources['keypair']['private_key'], |
| 113 | server=self.server, |
| 114 | servers_client=self.client) |
Ken'ichi Ohmichi | 326a6b3 | 2017-03-01 14:35:30 -0800 | [diff] [blame] | 115 | output = linux_client.exec_command('grep -c ^processor /proc/cpuinfo') |
| 116 | self.assertEqual(flavor['vcpus'], int(output)) |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 117 | |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 118 | @decorators.idempotent_id('ac1ad47f-984b-4441-9274-c9079b7a0666') |
Matthew Treinish | e5cca00 | 2015-05-11 15:36:50 -0400 | [diff] [blame] | 119 | @testtools.skipUnless(CONF.validation.run_validation, |
Matt Riedemann | 6c66820 | 2014-03-24 09:17:10 -0700 | [diff] [blame] | 120 | 'Instance validation tests are disabled.') |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 121 | def test_host_name_is_same_as_server_name(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 122 | # Verify the instance host name is the same as the server name |
Joseph Lanoux | ffe09dd | 2015-03-18 16:45:33 +0000 | [diff] [blame] | 123 | linux_client = remote_client.RemoteClient( |
| 124 | self.get_server_ip(self.server), |
| 125 | self.ssh_user, |
| 126 | self.password, |
Andrea Frittoli (andreaf) | 2a70a61 | 2016-04-29 16:09:13 -0500 | [diff] [blame] | 127 | self.validation_resources['keypair']['private_key'], |
| 128 | server=self.server, |
| 129 | servers_client=self.client) |
Ken'ichi Ohmichi | 326a6b3 | 2017-03-01 14:35:30 -0800 | [diff] [blame] | 130 | hostname = linux_client.exec_command("hostname").rstrip() |
imran malik | cdf2038 | 2016-06-16 00:43:57 -0700 | [diff] [blame] | 131 | msg = ('Failed while verifying servername equals hostname. Expected ' |
| 132 | 'hostname "%s" but got "%s".' % (self.name, hostname)) |
obutenko | 149feaf | 2016-08-31 16:14:45 +0300 | [diff] [blame] | 133 | self.assertEqual(self.name.lower(), hostname, msg) |
Dan Smith | 4307f99 | 2012-08-16 09:23:20 -0700 | [diff] [blame] | 134 | |
| 135 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 136 | class ServersTestManualDisk(ServersTestJSON): |
| 137 | disk_config = 'MANUAL' |
| 138 | |
Daryl Walleck | 0aea003 | 2012-12-04 00:53:28 -0600 | [diff] [blame] | 139 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 140 | def skip_checks(cls): |
| 141 | super(ServersTestManualDisk, cls).skip_checks() |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 142 | if not CONF.compute_feature_enabled.disk_config: |
Daryl Walleck | 0aea003 | 2012-12-04 00:53:28 -0600 | [diff] [blame] | 143 | msg = "DiskConfig extension not enabled." |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 144 | raise cls.skipException(msg) |
Andrea Frittoli | 9958b17 | 2017-07-13 11:24:59 +0100 | [diff] [blame] | 145 | |
| 146 | |
| 147 | class ServersTestBootFromVolume(ServersTestJSON): |
| 148 | """Run the `ServersTestJSON` tests with a volume backed VM""" |
| 149 | volume_backed = True |
| 150 | |
| 151 | @classmethod |
| 152 | def skip_checks(cls): |
| 153 | super(ServersTestBootFromVolume, cls).skip_checks() |
| 154 | if not test.get_service_list()['volume']: |
| 155 | msg = "Volume service not enabled." |
| 156 | raise cls.skipException(msg) |