blob: 8760af65bcbfe0c6ba0fd38a1974afd914a85d64 [file] [log] [blame]
nithya-ganesane6a36c82013-02-15 14:38:27 +00001# 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
zhufl6b7040a2017-01-18 16:38:34 +080016import testtools
17
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000019from tempest.common import waiters
Adam Gandelman2e37b4f2014-06-18 17:34:21 -070020from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080021from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080022from tempest.lib import decorators
nithya-ganesane6a36c82013-02-15 14:38:27 +000023
Adam Gandelman2e37b4f2014-06-18 17:34:21 -070024CONF = config.CONF
25
nithya-ganesane6a36c82013-02-15 14:38:27 +000026
ivan-zhuf2b00502013-10-18 10:06:52 +080027class ServerRescueTestJSON(base.BaseV2ComputeTest):
nithya-ganesane6a36c82013-02-15 14:38:27 +000028
nithya-ganesane6a36c82013-02-15 14:38:27 +000029 @classmethod
Emily Hugenbruche7991d92014-12-12 16:53:36 +000030 def skip_checks(cls):
31 super(ServerRescueTestJSON, cls).skip_checks()
Adam Gandelman2e37b4f2014-06-18 17:34:21 -070032 if not CONF.compute_feature_enabled.rescue:
33 msg = "Server rescue not available."
34 raise cls.skipException(msg)
35
Emily Hugenbruche7991d92014-12-12 16:53:36 +000036 @classmethod
37 def setup_credentials(cls):
Attila Fazekas69095972014-02-06 16:46:18 +010038 cls.set_network_resources(network=True, subnet=True, router=True)
Emily Hugenbruche7991d92014-12-12 16:53:36 +000039 super(ServerRescueTestJSON, cls).setup_credentials()
40
41 @classmethod
42 def resource_setup(cls):
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010043 super(ServerRescueTestJSON, cls).resource_setup()
nithya-ganesane6a36c82013-02-15 14:38:27 +000044
Attila Fazekasf7f34f92013-08-01 17:01:44 +020045 # Floating IP creation
Marc Koderer3b57d802016-03-22 15:23:31 +010046 body = cls.floating_ips_client.create_floating_ip(
47 pool=CONF.network.floating_network_name)['floating_ip']
nithya-ganesane6a36c82013-02-15 14:38:27 +000048 cls.floating_ip_id = str(body['id']).strip()
49 cls.floating_ip = str(body['ip']).strip()
50
Attila Fazekasf7f34f92013-08-01 17:01:44 +020051 # Security group creation
Masayuki Igawa259c1132013-10-31 17:48:44 +090052 cls.sg_name = data_utils.rand_name('sg')
zhufl7e0c9b62017-02-16 11:25:34 +080053 sg_desc = data_utils.rand_name('sg-desc')
Ken'ichi Ohmichi34563cc2015-07-21 00:53:17 +000054 cls.sg = cls.security_groups_client.create_security_group(
zhufl7e0c9b62017-02-16 11:25:34 +080055 name=cls.sg_name, description=sg_desc)['security_group']
nithya-ganesane6a36c82013-02-15 14:38:27 +000056 cls.sg_id = cls.sg['id']
57
Ghanshyam3390d9f2015-12-25 12:48:02 +090058 cls.password = data_utils.rand_password()
nithya-ganesane6a36c82013-02-15 14:38:27 +000059 # Server for positive tests
Ghanshyam3390d9f2015-12-25 12:48:02 +090060 server = cls.create_test_server(adminPass=cls.password,
zhufl3b9e42e2017-02-24 15:59:01 +080061 wait_until='ACTIVE')
nithya-ganesane6a36c82013-02-15 14:38:27 +000062 cls.server_id = server['id']
nithya-ganesane6a36c82013-02-15 14:38:27 +000063
nithya-ganesane6a36c82013-02-15 14:38:27 +000064 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010065 def resource_cleanup(cls):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020066 # Deleting the floating IP which is created in this method
nithya-ganesane6a36c82013-02-15 14:38:27 +000067 cls.floating_ips_client.delete_floating_ip(cls.floating_ip_id)
David Kranz9964b4e2015-02-06 15:45:29 -050068 cls.sg = cls.security_groups_client.delete_security_group(
Sean Dague14c68182013-04-14 15:34:30 -040069 cls.sg_id)
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010070 super(ServerRescueTestJSON, cls).resource_cleanup()
nithya-ganesane6a36c82013-02-15 14:38:27 +000071
Matthew Treinish149142e2013-03-20 16:25:55 -040072 def _unrescue(self, server_id):
David Kranzae99b9a2015-02-16 13:37:01 -050073 self.servers_client.unrescue_server(server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000074 waiters.wait_for_server_status(self.servers_client, server_id,
75 'ACTIVE')
Matthew Treinish149142e2013-03-20 16:25:55 -040076
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080077 @decorators.idempotent_id('fd032140-714c-42e4-a8fd-adcd8df06be6')
nithya-ganesane6a36c82013-02-15 14:38:27 +000078 def test_rescue_unrescue_instance(self):
David Kranzae99b9a2015-02-16 13:37:01 -050079 self.servers_client.rescue_server(
Yuiko Takada7835d502014-01-15 10:15:03 +000080 self.server_id, adminPass=self.password)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000081 waiters.wait_for_server_status(self.servers_client, self.server_id,
82 'RESCUE')
David Kranzae99b9a2015-02-16 13:37:01 -050083 self.servers_client.unrescue_server(self.server_id)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000084 waiters.wait_for_server_status(self.servers_client, self.server_id,
85 'ACTIVE')
nithya-ganesane6a36c82013-02-15 14:38:27 +000086
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080087 @decorators.idempotent_id('4842e0cf-e87d-4d9d-b61f-f4791da3cacc')
zhufl6b7040a2017-01-18 16:38:34 +080088 @testtools.skipUnless(CONF.network.public_network_id,
89 'The public_network_id option must be specified.')
nithya-ganesane6a36c82013-02-15 14:38:27 +000090 def test_rescued_vm_associate_dissociate_floating_ip(self):
91 # Rescue the server
92 self.servers_client.rescue_server(
Yuiko Takada7835d502014-01-15 10:15:03 +000093 self.server_id, adminPass=self.password)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000094 waiters.wait_for_server_status(self.servers_client, self.server_id,
95 'RESCUE')
Joe Gordone4f2b2e2013-04-04 15:54:10 -070096 self.addCleanup(self._unrescue, self.server_id)
nithya-ganesane6a36c82013-02-15 14:38:27 +000097
Attila Fazekasf7f34f92013-08-01 17:01:44 +020098 # Association of floating IP to a rescued vm
nithya-ganesane6a36c82013-02-15 14:38:27 +000099 client = self.floating_ips_client
David Kranze4e3b412015-02-10 10:50:42 -0500100 client.associate_floating_ip_to_server(self.floating_ip,
101 self.server_id)
nithya-ganesane6a36c82013-02-15 14:38:27 +0000102
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200103 # Disassociation of floating IP that was associated in this method
David Kranze4e3b412015-02-10 10:50:42 -0500104 client.disassociate_floating_ip_from_server(self.floating_ip,
105 self.server_id)
nithya-ganesane6a36c82013-02-15 14:38:27 +0000106
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800107 @decorators.idempotent_id('affca41f-7195-492d-8065-e09eee245404')
nithya-ganesane6a36c82013-02-15 14:38:27 +0000108 def test_rescued_vm_add_remove_security_group(self):
Prem Karatfbe87a02013-04-22 21:22:06 +0530109 # Rescue the server
110 self.servers_client.rescue_server(
Yuiko Takada7835d502014-01-15 10:15:03 +0000111 self.server_id, adminPass=self.password)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +0000112 waiters.wait_for_server_status(self.servers_client, self.server_id,
113 'RESCUE')
Attila Fazekas87a409a2014-01-29 15:32:50 +0100114 self.addCleanup(self._unrescue, self.server_id)
Prem Karatfbe87a02013-04-22 21:22:06 +0530115
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200116 # Add Security group
Ken'ichi Ohmichie6349f32015-12-09 06:47:54 +0000117 self.servers_client.add_security_group(self.server_id,
118 name=self.sg_name)
nithya-ganesane6a36c82013-02-15 14:38:27 +0000119
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200120 # Delete Security group
David Kranzae99b9a2015-02-16 13:37:01 -0500121 self.servers_client.remove_security_group(self.server_id,
Ken'ichi Ohmichi36b714c2015-12-09 08:12:47 +0000122 name=self.sg_name)