blob: 4896447c56ad8f09d7c3ca3471bfe754607a58c9 [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:
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090033 * boot an instance and create a timestamp file in it
JordanPc240f7b2014-11-14 19:16:01 +010034 * 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
Chris Hoge7579c1a2015-02-26 14:12:15 -080067 @test.idempotent_id('1164e700-0af0-4a4c-8792-35909a88743c')
JordanPc240f7b2014-11-14 19:16:01 +010068 @testtools.skipUnless(CONF.compute_feature_enabled.shelve,
69 'Shelve is not available.')
70 @test.services('compute', 'network', 'image')
71 def test_shelve_instance(self):
72 self.keypair = self.create_keypair()
73
74 self.security_group = self._create_security_group()
Ken'ichi Ohmichi1b3461e2014-12-02 03:41:07 +000075 security_groups = [{'name': self.security_group['name']}]
JordanPc240f7b2014-11-14 19:16:01 +010076
77 create_kwargs = {
78 'key_name': self.keypair['name'],
Ken'ichi Ohmichi1b3461e2014-12-02 03:41:07 +000079 'security_groups': security_groups
JordanPc240f7b2014-11-14 19:16:01 +010080 }
81 server = self.create_server(image=CONF.compute.image_ref,
82 create_kwargs=create_kwargs)
83
84 if CONF.compute.use_floatingip_for_ssh:
ghanshyam9a3a9a22015-08-18 17:03:55 +090085 floating_ip = (self.floating_ips_client.create_floating_ip()
86 ['floating_ip'])
JordanPc240f7b2014-11-14 19:16:01 +010087 self.addCleanup(self.delete_wrapper,
88 self.floating_ips_client.delete_floating_ip,
89 floating_ip['id'])
90 self.floating_ips_client.associate_floating_ip_to_server(
91 floating_ip['ip'], server['id'])
92 self._write_timestamp(floating_ip['ip'])
93 else:
94 self._write_timestamp(server)
95
96 # Prevent bug #1257594 from coming back
97 # Unshelve used to boot the instance with the original image, not
98 # with the instance snapshot
99 self._shelve_then_unshelve_server(server)
100 if CONF.compute.use_floatingip_for_ssh:
101 self._check_timestamp(floating_ip['ip'])
102 else:
103 self._check_timestamp(server)