nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 1 | # Copyright 2013 Hewlett-Packard Development Company, L.P. |
| 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 | |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 16 | import testtools |
| 17 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 18 | from tempest.api.compute import base |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 19 | from tempest.common import waiters |
Adam Gandelman | 2e37b4f | 2014-06-18 17:34:21 -0700 | [diff] [blame] | 20 | from tempest import config |
Ken'ichi Ohmichi | 757833a | 2017-03-10 10:30:30 -0800 | [diff] [blame] | 21 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 22 | from tempest.lib import decorators |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 23 | |
Adam Gandelman | 2e37b4f | 2014-06-18 17:34:21 -0700 | [diff] [blame] | 24 | CONF = config.CONF |
| 25 | |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 26 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 27 | class ServerRescueTestJSON(base.BaseV2ComputeTest): |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 28 | |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 29 | @classmethod |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 30 | def skip_checks(cls): |
| 31 | super(ServerRescueTestJSON, cls).skip_checks() |
Adam Gandelman | 2e37b4f | 2014-06-18 17:34:21 -0700 | [diff] [blame] | 32 | if not CONF.compute_feature_enabled.rescue: |
| 33 | msg = "Server rescue not available." |
| 34 | raise cls.skipException(msg) |
| 35 | |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 36 | @classmethod |
| 37 | def setup_credentials(cls): |
Attila Fazekas | 6909597 | 2014-02-06 16:46:18 +0100 | [diff] [blame] | 38 | cls.set_network_resources(network=True, subnet=True, router=True) |
Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 39 | super(ServerRescueTestJSON, cls).setup_credentials() |
| 40 | |
| 41 | @classmethod |
| 42 | def resource_setup(cls): |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 43 | super(ServerRescueTestJSON, cls).resource_setup() |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 44 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 45 | # Floating IP creation |
Marc Koderer | 3b57d80 | 2016-03-22 15:23:31 +0100 | [diff] [blame] | 46 | body = cls.floating_ips_client.create_floating_ip( |
| 47 | pool=CONF.network.floating_network_name)['floating_ip'] |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 48 | cls.floating_ip_id = str(body['id']).strip() |
| 49 | cls.floating_ip = str(body['ip']).strip() |
| 50 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 51 | # Security group creation |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 52 | cls.sg_name = data_utils.rand_name('sg') |
zhufl | 7e0c9b6 | 2017-02-16 11:25:34 +0800 | [diff] [blame] | 53 | sg_desc = data_utils.rand_name('sg-desc') |
Ken'ichi Ohmichi | 34563cc | 2015-07-21 00:53:17 +0000 | [diff] [blame] | 54 | cls.sg = cls.security_groups_client.create_security_group( |
zhufl | 7e0c9b6 | 2017-02-16 11:25:34 +0800 | [diff] [blame] | 55 | name=cls.sg_name, description=sg_desc)['security_group'] |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 56 | cls.sg_id = cls.sg['id'] |
| 57 | |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 58 | cls.password = data_utils.rand_password() |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 59 | # Server for positive tests |
Ghanshyam | 3390d9f | 2015-12-25 12:48:02 +0900 | [diff] [blame] | 60 | server = cls.create_test_server(adminPass=cls.password, |
zhufl | 3b9e42e | 2017-02-24 15:59:01 +0800 | [diff] [blame] | 61 | wait_until='ACTIVE') |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 62 | cls.server_id = server['id'] |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 63 | |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 64 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 65 | def resource_cleanup(cls): |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 66 | # Deleting the floating IP which is created in this method |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 67 | cls.floating_ips_client.delete_floating_ip(cls.floating_ip_id) |
David Kranz | 9964b4e | 2015-02-06 15:45:29 -0500 | [diff] [blame] | 68 | cls.sg = cls.security_groups_client.delete_security_group( |
Sean Dague | 14c6818 | 2013-04-14 15:34:30 -0400 | [diff] [blame] | 69 | cls.sg_id) |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 70 | super(ServerRescueTestJSON, cls).resource_cleanup() |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 71 | |
Matthew Treinish | 149142e | 2013-03-20 16:25:55 -0400 | [diff] [blame] | 72 | def _unrescue(self, server_id): |
David Kranz | ae99b9a | 2015-02-16 13:37:01 -0500 | [diff] [blame] | 73 | self.servers_client.unrescue_server(server_id) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 74 | waiters.wait_for_server_status(self.servers_client, server_id, |
| 75 | 'ACTIVE') |
Matthew Treinish | 149142e | 2013-03-20 16:25:55 -0400 | [diff] [blame] | 76 | |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 77 | @decorators.idempotent_id('fd032140-714c-42e4-a8fd-adcd8df06be6') |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 78 | def test_rescue_unrescue_instance(self): |
David Kranz | ae99b9a | 2015-02-16 13:37:01 -0500 | [diff] [blame] | 79 | self.servers_client.rescue_server( |
Yuiko Takada | 7835d50 | 2014-01-15 10:15:03 +0000 | [diff] [blame] | 80 | self.server_id, adminPass=self.password) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 81 | waiters.wait_for_server_status(self.servers_client, self.server_id, |
| 82 | 'RESCUE') |
David Kranz | ae99b9a | 2015-02-16 13:37:01 -0500 | [diff] [blame] | 83 | self.servers_client.unrescue_server(self.server_id) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 84 | waiters.wait_for_server_status(self.servers_client, self.server_id, |
| 85 | 'ACTIVE') |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 86 | |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 87 | @decorators.idempotent_id('4842e0cf-e87d-4d9d-b61f-f4791da3cacc') |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 88 | @testtools.skipUnless(CONF.network.public_network_id, |
| 89 | 'The public_network_id option must be specified.') |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 90 | def test_rescued_vm_associate_dissociate_floating_ip(self): |
| 91 | # Rescue the server |
| 92 | self.servers_client.rescue_server( |
Yuiko Takada | 7835d50 | 2014-01-15 10:15:03 +0000 | [diff] [blame] | 93 | self.server_id, adminPass=self.password) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 94 | waiters.wait_for_server_status(self.servers_client, self.server_id, |
| 95 | 'RESCUE') |
Joe Gordon | e4f2b2e | 2013-04-04 15:54:10 -0700 | [diff] [blame] | 96 | self.addCleanup(self._unrescue, self.server_id) |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 97 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 98 | # Association of floating IP to a rescued vm |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 99 | client = self.floating_ips_client |
David Kranz | e4e3b41 | 2015-02-10 10:50:42 -0500 | [diff] [blame] | 100 | client.associate_floating_ip_to_server(self.floating_ip, |
| 101 | self.server_id) |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 102 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 103 | # Disassociation of floating IP that was associated in this method |
David Kranz | e4e3b41 | 2015-02-10 10:50:42 -0500 | [diff] [blame] | 104 | client.disassociate_floating_ip_from_server(self.floating_ip, |
| 105 | self.server_id) |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 106 | |
Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 107 | @decorators.idempotent_id('affca41f-7195-492d-8065-e09eee245404') |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 108 | def test_rescued_vm_add_remove_security_group(self): |
Prem Karat | fbe87a0 | 2013-04-22 21:22:06 +0530 | [diff] [blame] | 109 | # Rescue the server |
| 110 | self.servers_client.rescue_server( |
Yuiko Takada | 7835d50 | 2014-01-15 10:15:03 +0000 | [diff] [blame] | 111 | self.server_id, adminPass=self.password) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 112 | waiters.wait_for_server_status(self.servers_client, self.server_id, |
| 113 | 'RESCUE') |
Attila Fazekas | 87a409a | 2014-01-29 15:32:50 +0100 | [diff] [blame] | 114 | self.addCleanup(self._unrescue, self.server_id) |
Prem Karat | fbe87a0 | 2013-04-22 21:22:06 +0530 | [diff] [blame] | 115 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 116 | # Add Security group |
Ken'ichi Ohmichi | e6349f3 | 2015-12-09 06:47:54 +0000 | [diff] [blame] | 117 | self.servers_client.add_security_group(self.server_id, |
| 118 | name=self.sg_name) |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 119 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 120 | # Delete Security group |
David Kranz | ae99b9a | 2015-02-16 13:37:01 -0500 | [diff] [blame] | 121 | self.servers_client.remove_security_group(self.server_id, |
Ken'ichi Ohmichi | 36b714c | 2015-12-09 08:12:47 +0000 | [diff] [blame] | 122 | name=self.sg_name) |