blob: 6629794d0f6b1bda3d9f7772635f2c5a79ffe0c8 [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
zhufl3cf7aa22018-08-02 10:38:31 +080027class ServerRescueTestBase(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):
zhufl3cf7aa22018-08-02 10:38:31 +080031 super(ServerRescueTestBase, 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)
zhufl3cf7aa22018-08-02 10:38:31 +080039 super(ServerRescueTestBase, cls).setup_credentials()
Emily Hugenbruche7991d92014-12-12 16:53:36 +000040
41 @classmethod
42 def resource_setup(cls):
zhufl3cf7aa22018-08-02 10:38:31 +080043 super(ServerRescueTestBase, cls).resource_setup()
nithya-ganesane6a36c82013-02-15 14:38:27 +000044
zhufl0c042a52017-05-10 16:24:00 +080045 password = data_utils.rand_password()
46 server = cls.create_test_server(adminPass=password,
zhufl3b9e42e2017-02-24 15:59:01 +080047 wait_until='ACTIVE')
zhufl0c042a52017-05-10 16:24:00 +080048 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 Treinish149142e2013-03-20 16:25:55 -040052
zhufl3cf7aa22018-08-02 10:38:31 +080053
54class ServerRescueTestJSON(ServerRescueTestBase):
55
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080056 @decorators.idempotent_id('fd032140-714c-42e4-a8fd-adcd8df06be6')
nithya-ganesane6a36c82013-02-15 14:38:27 +000057 def test_rescue_unrescue_instance(self):
zhufl0c042a52017-05-10 16:24:00 +080058 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 Ohmichi0eb153c2015-07-13 02:18:25 +000063 'RESCUE')
zhufl0c042a52017-05-10 16:24:00 +080064 self.servers_client.unrescue_server(server['id'])
65 waiters.wait_for_server_status(self.servers_client, server['id'],
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000066 'ACTIVE')
nithya-ganesane6a36c82013-02-15 14:38:27 +000067
zhufl3cf7aa22018-08-02 10:38:31 +080068
69class 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 Ohmichi14b0ae12017-01-27 17:18:52 -080077 @decorators.idempotent_id('4842e0cf-e87d-4d9d-b61f-f4791da3cacc')
zhufl6b7040a2017-01-18 16:38:34 +080078 @testtools.skipUnless(CONF.network.public_network_id,
79 'The public_network_id option must be specified.')
Matthew Treinish3312de32017-05-19 12:08:17 -040080 @testtools.skipUnless(CONF.network_feature_enabled.floating_ips,
81 "Floating ips are not available")
nithya-ganesane6a36c82013-02-15 14:38:27 +000082 def test_rescued_vm_associate_dissociate_floating_ip(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020083 # Association of floating IP to a rescued vm
zhufl0c042a52017-05-10 16:24:00 +080084 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-ganesane6a36c82013-02-15 14:38:27 +000091
Attila Fazekasf7f34f92013-08-01 17:01:44 +020092 # Disassociation of floating IP that was associated in this method
zhufl0c042a52017-05-10 16:24:00 +080093 self.floating_ips_client.disassociate_floating_ip_from_server(
94 str(floating_ip_body['ip']).strip(), self.rescued_server_id)
nithya-ganesane6a36c82013-02-15 14:38:27 +000095
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -080096 @decorators.idempotent_id('affca41f-7195-492d-8065-e09eee245404')
nithya-ganesane6a36c82013-02-15 14:38:27 +000097 def test_rescued_vm_add_remove_security_group(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020098 # Add Security group
zhufl0c042a52017-05-10 16:24:00 +080099 sg = self.create_security_group()
100 self.servers_client.add_security_group(self.rescued_server_id,
101 name=sg['name'])
nithya-ganesane6a36c82013-02-15 14:38:27 +0000102
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200103 # Delete Security group
zhufl0c042a52017-05-10 16:24:00 +0800104 self.servers_client.remove_security_group(self.rescued_server_id,
105 name=sg['name'])