blob: 4b9c61cff3b9a66868a7708acd1bb100eef840a1 [file] [log] [blame]
JordanPc240f7b2014-11-14 19:16:01 +01001# Copyright 2014 Scality
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
ghanshyam017b5fe2016-04-15 18:49:26 +090016from tempest.common import compute
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000017from tempest.common import waiters
JordanPc240f7b2014-11-14 19:16:01 +010018from tempest import config
JordanPc240f7b2014-11-14 19:16:01 +010019from tempest.scenario import manager
20from tempest import test
21
22CONF = config.CONF
23
JordanPc240f7b2014-11-14 19:16:01 +010024
25class TestShelveInstance(manager.ScenarioTest):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000026 """This test shelves then unshelves a Nova instance
27
JordanPc240f7b2014-11-14 19:16:01 +010028 The following is the scenario outline:
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090029 * boot an instance and create a timestamp file in it
JordanPc240f7b2014-11-14 19:16:01 +010030 * shelve the instance
31 * unshelve the instance
32 * check the existence of the timestamp file in the unshelved instance
33
34 """
35
zhufl8ed23d22016-07-13 11:00:05 +080036 @classmethod
37 def skip_checks(cls):
38 super(TestShelveInstance, cls).skip_checks()
39 if not CONF.compute_feature_enabled.shelve:
40 raise cls.skipException("Shelve is not available.")
41
JordanPc240f7b2014-11-14 19:16:01 +010042 def _shelve_then_unshelve_server(self, server):
ghanshyam017b5fe2016-04-15 18:49:26 +090043 compute.shelve_server(self.servers_client, server['id'],
44 force_shelve_offload=True)
45
JordanPc240f7b2014-11-14 19:16:01 +010046 self.servers_client.unshelve_server(server['id'])
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000047 waiters.wait_for_server_status(self.servers_client, server['id'],
48 'ACTIVE')
JordanPc240f7b2014-11-14 19:16:01 +010049
PranaliDeore9fe5eb32015-07-22 05:28:00 -070050 def _create_server_then_shelve_and_unshelve(self, boot_from_volume=False):
Matt Riedemann73764bf2015-09-30 14:53:25 -070051 keypair = self.create_keypair()
JordanPc240f7b2014-11-14 19:16:01 +010052
Matt Riedemann73764bf2015-09-30 14:53:25 -070053 security_group = self._create_security_group()
54 security_groups = [{'name': security_group['name']}]
PranaliDeore9fe5eb32015-07-22 05:28:00 -070055
56 if boot_from_volume:
57 volume = self.create_volume(size=CONF.volume.volume_size,
58 imageRef=CONF.compute.image_ref)
59 bd_map = [{
60 'device_name': 'vda',
61 'volume_id': volume['id'],
62 'delete_on_termination': '0'}]
63
lanoux5fc14522015-09-21 08:17:35 +000064 server = self.create_server(
65 key_name=keypair['name'],
66 security_groups=security_groups,
67 block_device_mapping=bd_map,
68 wait_until='ACTIVE')
PranaliDeore9fe5eb32015-07-22 05:28:00 -070069 else:
lanoux5fc14522015-09-21 08:17:35 +000070 server = self.create_server(
71 image_id=CONF.compute.image_ref,
72 key_name=keypair['name'],
73 security_groups=security_groups,
74 wait_until='ACTIVE')
JordanPc240f7b2014-11-14 19:16:01 +010075
Sean Dague20e98612016-01-06 14:33:28 -050076 instance_ip = self.get_server_ip(server)
Alexander Gubanovc8829f82015-11-12 10:35:13 +020077 timestamp = self.create_timestamp(instance_ip,
78 private_key=keypair['private_key'])
JordanPc240f7b2014-11-14 19:16:01 +010079
80 # Prevent bug #1257594 from coming back
81 # Unshelve used to boot the instance with the original image, not
82 # with the instance snapshot
83 self._shelve_then_unshelve_server(server)
Alexander Gubanovc8829f82015-11-12 10:35:13 +020084
85 timestamp2 = self.get_timestamp(instance_ip,
86 private_key=keypair['private_key'])
Alexander Gubanovabd154c2015-09-23 23:24:06 +030087 self.assertEqual(timestamp, timestamp2)
PranaliDeore9fe5eb32015-07-22 05:28:00 -070088
89 @test.idempotent_id('1164e700-0af0-4a4c-8792-35909a88743c')
PranaliDeore9fe5eb32015-07-22 05:28:00 -070090 @test.services('compute', 'network', 'image')
91 def test_shelve_instance(self):
92 self._create_server_then_shelve_and_unshelve()
93
94 @test.idempotent_id('c1b6318c-b9da-490b-9c67-9339b627271f')
PranaliDeore9fe5eb32015-07-22 05:28:00 -070095 @test.services('compute', 'volume', 'network', 'image')
96 def test_shelve_volume_backed_instance(self):
97 self._create_server_then_shelve_and_unshelve(boot_from_volume=True)