| 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 |  | 
| zhufl | 3cf7aa2 | 2018-08-02 10:38:31 +0800 | [diff] [blame] | 27 | class ServerRescueTestBase(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): | 
| zhufl | 3cf7aa2 | 2018-08-02 10:38:31 +0800 | [diff] [blame] | 31 | super(ServerRescueTestBase, 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) | 
| zhufl | 3cf7aa2 | 2018-08-02 10:38:31 +0800 | [diff] [blame] | 39 | super(ServerRescueTestBase, cls).setup_credentials() | 
| Emily Hugenbruch | e7991d9 | 2014-12-12 16:53:36 +0000 | [diff] [blame] | 40 |  | 
|  | 41 | @classmethod | 
|  | 42 | def resource_setup(cls): | 
| zhufl | 3cf7aa2 | 2018-08-02 10:38:31 +0800 | [diff] [blame] | 43 | super(ServerRescueTestBase, cls).resource_setup() | 
| nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 44 |  | 
| zhufl | 0c042a5 | 2017-05-10 16:24:00 +0800 | [diff] [blame] | 45 | password = data_utils.rand_password() | 
|  | 46 | server = cls.create_test_server(adminPass=password, | 
| zhufl | 3b9e42e | 2017-02-24 15:59:01 +0800 | [diff] [blame] | 47 | wait_until='ACTIVE') | 
| zhufl | 0c042a5 | 2017-05-10 16:24:00 +0800 | [diff] [blame] | 48 | cls.servers_client.rescue_server(server['id'], adminPass=password) | 
|  | 49 | waiters.wait_for_server_status(cls.servers_client, server['id'], | 
|  | 50 | 'RESCUE') | 
|  | 51 | cls.rescued_server_id = server['id'] | 
| Matthew Treinish | 149142e | 2013-03-20 16:25:55 -0400 | [diff] [blame] | 52 |  | 
| zhufl | 3cf7aa2 | 2018-08-02 10:38:31 +0800 | [diff] [blame] | 53 |  | 
|  | 54 | class ServerRescueTestJSON(ServerRescueTestBase): | 
|  | 55 |  | 
| Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 56 | @decorators.idempotent_id('fd032140-714c-42e4-a8fd-adcd8df06be6') | 
| nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 57 | def test_rescue_unrescue_instance(self): | 
| zhufl | 0c042a5 | 2017-05-10 16:24:00 +0800 | [diff] [blame] | 58 | password = data_utils.rand_password() | 
|  | 59 | server = self.create_test_server(adminPass=password, | 
|  | 60 | wait_until='ACTIVE') | 
|  | 61 | self.servers_client.rescue_server(server['id'], adminPass=password) | 
|  | 62 | waiters.wait_for_server_status(self.servers_client, server['id'], | 
| Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 63 | 'RESCUE') | 
| zhufl | 0c042a5 | 2017-05-10 16:24:00 +0800 | [diff] [blame] | 64 | self.servers_client.unrescue_server(server['id']) | 
|  | 65 | waiters.wait_for_server_status(self.servers_client, server['id'], | 
| Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 66 | 'ACTIVE') | 
| nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 67 |  | 
| zhufl | 3cf7aa2 | 2018-08-02 10:38:31 +0800 | [diff] [blame] | 68 |  | 
|  | 69 | class ServerRescueTestJSONUnderV235(ServerRescueTestBase): | 
|  | 70 |  | 
|  | 71 | max_microversion = '2.35' | 
|  | 72 |  | 
|  | 73 | # TODO(zhufl): After 2.35 we should switch to neutron client to create | 
|  | 74 | # floating ip, but that will need admin credential, so the testcases will | 
|  | 75 | # have to be added in somewhere in admin directory. | 
|  | 76 |  | 
| Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 77 | @decorators.idempotent_id('4842e0cf-e87d-4d9d-b61f-f4791da3cacc') | 
| zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 78 | @testtools.skipUnless(CONF.network.public_network_id, | 
|  | 79 | 'The public_network_id option must be specified.') | 
| Matthew Treinish | 3312de3 | 2017-05-19 12:08:17 -0400 | [diff] [blame] | 80 | @testtools.skipUnless(CONF.network_feature_enabled.floating_ips, | 
|  | 81 | "Floating ips are not available") | 
| nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 82 | def test_rescued_vm_associate_dissociate_floating_ip(self): | 
| Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 83 | # Association of floating IP to a rescued vm | 
| zhufl | 0c042a5 | 2017-05-10 16:24:00 +0800 | [diff] [blame] | 84 | floating_ip_body = self.floating_ips_client.create_floating_ip( | 
|  | 85 | pool=CONF.network.floating_network_name)['floating_ip'] | 
|  | 86 | self.addCleanup(self.floating_ips_client.delete_floating_ip, | 
|  | 87 | floating_ip_body['id']) | 
|  | 88 |  | 
|  | 89 | self.floating_ips_client.associate_floating_ip_to_server( | 
|  | 90 | str(floating_ip_body['ip']).strip(), self.rescued_server_id) | 
| nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 91 |  | 
| Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 92 | # Disassociation of floating IP that was associated in this method | 
| zhufl | 0c042a5 | 2017-05-10 16:24:00 +0800 | [diff] [blame] | 93 | self.floating_ips_client.disassociate_floating_ip_from_server( | 
|  | 94 | str(floating_ip_body['ip']).strip(), self.rescued_server_id) | 
| nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 95 |  | 
| Ken'ichi Ohmichi | 14b0ae1 | 2017-01-27 17:18:52 -0800 | [diff] [blame] | 96 | @decorators.idempotent_id('affca41f-7195-492d-8065-e09eee245404') | 
| nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 97 | def test_rescued_vm_add_remove_security_group(self): | 
| Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 98 | # Add Security group | 
| zhufl | 0c042a5 | 2017-05-10 16:24:00 +0800 | [diff] [blame] | 99 | sg = self.create_security_group() | 
|  | 100 | self.servers_client.add_security_group(self.rescued_server_id, | 
|  | 101 | name=sg['name']) | 
| 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 | # Delete Security group | 
| zhufl | 0c042a5 | 2017-05-10 16:24:00 +0800 | [diff] [blame] | 104 | self.servers_client.remove_security_group(self.rescued_server_id, | 
|  | 105 | name=sg['name']) |