blob: 5cc05092799b34d0f6695c2a5d8359076138cebd [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016from oslo_log import log
JordanPc240f7b2014-11-14 19:16:01 +010017import testtools
18
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000019from tempest.common import waiters
JordanPc240f7b2014-11-14 19:16:01 +010020from tempest import config
JordanPc240f7b2014-11-14 19:16:01 +010021from tempest.scenario import manager
22from tempest import test
23
24CONF = config.CONF
25
26LOG = log.getLogger(__name__)
27
28
29class TestShelveInstance(manager.ScenarioTest):
30 """
31 This test shelves then unshelves a Nova instance
32 The following is the scenario outline:
33 * boot a instance and create a timestamp file in it
34 * shelve the instance
35 * unshelve the instance
36 * check the existence of the timestamp file in the unshelved instance
37
38 """
39
40 def _write_timestamp(self, server_or_ip):
41 ssh_client = self.get_remote_client(server_or_ip)
42 ssh_client.exec_command('date > /tmp/timestamp; sync')
43 self.timestamp = ssh_client.exec_command('cat /tmp/timestamp')
44
45 def _check_timestamp(self, server_or_ip):
46 ssh_client = self.get_remote_client(server_or_ip)
47 got_timestamp = ssh_client.exec_command('cat /tmp/timestamp')
48 self.assertEqual(self.timestamp, got_timestamp)
49
50 def _shelve_then_unshelve_server(self, server):
51 self.servers_client.shelve_server(server['id'])
52 offload_time = CONF.compute.shelved_offload_time
53 if offload_time >= 0:
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000054 waiters.wait_for_server_status(self.servers_client, server['id'],
55 'SHELVED_OFFLOADED',
56 extra_timeout=offload_time)
JordanPc240f7b2014-11-14 19:16:01 +010057 else:
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000058 waiters.wait_for_server_status(self.servers_client,
59 server['id'], 'SHELVED')
JordanPc240f7b2014-11-14 19:16:01 +010060 self.servers_client.shelve_offload_server(server['id'])
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000061 waiters.wait_for_server_status(self.servers_client, server['id'],
62 'SHELVED_OFFLOADED')
JordanPc240f7b2014-11-14 19:16:01 +010063 self.servers_client.unshelve_server(server['id'])
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000064 waiters.wait_for_server_status(self.servers_client, server['id'],
65 'ACTIVE')
JordanPc240f7b2014-11-14 19:16:01 +010066
PranaliDeore9fe5eb32015-07-22 05:28:00 -070067 def _create_server_then_shelve_and_unshelve(self, boot_from_volume=False):
JordanPc240f7b2014-11-14 19:16:01 +010068 self.keypair = self.create_keypair()
69
70 self.security_group = self._create_security_group()
Ken'ichi Ohmichi1b3461e2014-12-02 03:41:07 +000071 security_groups = [{'name': self.security_group['name']}]
JordanPc240f7b2014-11-14 19:16:01 +010072 create_kwargs = {
73 'key_name': self.keypair['name'],
Ken'ichi Ohmichi1b3461e2014-12-02 03:41:07 +000074 'security_groups': security_groups
JordanPc240f7b2014-11-14 19:16:01 +010075 }
PranaliDeore9fe5eb32015-07-22 05:28:00 -070076
77 if boot_from_volume:
78 volume = self.create_volume(size=CONF.volume.volume_size,
79 imageRef=CONF.compute.image_ref)
80 bd_map = [{
81 'device_name': 'vda',
82 'volume_id': volume['id'],
83 'delete_on_termination': '0'}]
84
85 create_kwargs['block_device_mapping'] = bd_map
86 server = self.create_server(create_kwargs=create_kwargs)
87 else:
88 server = self.create_server(image=CONF.compute.image_ref,
89 create_kwargs=create_kwargs)
JordanPc240f7b2014-11-14 19:16:01 +010090
91 if CONF.compute.use_floatingip_for_ssh:
ghanshyam9a3a9a22015-08-18 17:03:55 +090092 floating_ip = (self.floating_ips_client.create_floating_ip()
93 ['floating_ip'])
JordanPc240f7b2014-11-14 19:16:01 +010094 self.addCleanup(self.delete_wrapper,
95 self.floating_ips_client.delete_floating_ip,
96 floating_ip['id'])
97 self.floating_ips_client.associate_floating_ip_to_server(
98 floating_ip['ip'], server['id'])
99 self._write_timestamp(floating_ip['ip'])
100 else:
101 self._write_timestamp(server)
102
103 # Prevent bug #1257594 from coming back
104 # Unshelve used to boot the instance with the original image, not
105 # with the instance snapshot
106 self._shelve_then_unshelve_server(server)
107 if CONF.compute.use_floatingip_for_ssh:
108 self._check_timestamp(floating_ip['ip'])
109 else:
110 self._check_timestamp(server)
PranaliDeore9fe5eb32015-07-22 05:28:00 -0700111
112 @test.idempotent_id('1164e700-0af0-4a4c-8792-35909a88743c')
113 @testtools.skipUnless(CONF.compute_feature_enabled.shelve,
114 'Shelve is not available.')
115 @test.services('compute', 'network', 'image')
116 def test_shelve_instance(self):
117 self._create_server_then_shelve_and_unshelve()
118
119 @test.idempotent_id('c1b6318c-b9da-490b-9c67-9339b627271f')
120 @testtools.skipUnless(CONF.compute_feature_enabled.shelve,
121 'Shelve is not available.')
122 @test.services('compute', 'volume', 'network', 'image')
123 def test_shelve_volume_backed_instance(self):
124 self._create_server_then_shelve_and_unshelve(boot_from_volume=True)