blob: 5ba650d5ae7942af8c7dcce872d3f2ad4005652b [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
16import testtools
17
18from tempest import config
19from tempest.openstack.common import log
20from tempest.scenario import manager
21from tempest import test
22
23CONF = config.CONF
24
25LOG = log.getLogger(__name__)
26
27
28class TestShelveInstance(manager.ScenarioTest):
29 """
30 This test shelves then unshelves a Nova instance
31 The following is the scenario outline:
32 * boot a instance and create a timestamp file in it
33 * shelve the instance
34 * unshelve the instance
35 * check the existence of the timestamp file in the unshelved instance
36
37 """
38
39 def _write_timestamp(self, server_or_ip):
40 ssh_client = self.get_remote_client(server_or_ip)
41 ssh_client.exec_command('date > /tmp/timestamp; sync')
42 self.timestamp = ssh_client.exec_command('cat /tmp/timestamp')
43
44 def _check_timestamp(self, server_or_ip):
45 ssh_client = self.get_remote_client(server_or_ip)
46 got_timestamp = ssh_client.exec_command('cat /tmp/timestamp')
47 self.assertEqual(self.timestamp, got_timestamp)
48
49 def _shelve_then_unshelve_server(self, server):
50 self.servers_client.shelve_server(server['id'])
51 offload_time = CONF.compute.shelved_offload_time
52 if offload_time >= 0:
53 self.servers_client.wait_for_server_status(
54 server['id'], 'SHELVED_OFFLOADED', extra_timeout=offload_time)
55 else:
56 self.servers_client.wait_for_server_status(server['id'], 'SHELVED')
57 self.servers_client.shelve_offload_server(server['id'])
58 self.servers_client.wait_for_server_status(server['id'],
59 'SHELVED_OFFLOADED')
60 self.servers_client.unshelve_server(server['id'])
61 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
62
63 @testtools.skipUnless(CONF.compute_feature_enabled.shelve,
64 'Shelve is not available.')
65 @test.services('compute', 'network', 'image')
66 def test_shelve_instance(self):
67 self.keypair = self.create_keypair()
68
69 self.security_group = self._create_security_group()
Ken'ichi Ohmichi1b3461e2014-12-02 03:41:07 +000070 security_groups = [{'name': self.security_group['name']}]
JordanPc240f7b2014-11-14 19:16:01 +010071
72 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 }
76 server = self.create_server(image=CONF.compute.image_ref,
77 create_kwargs=create_kwargs)
78
79 if CONF.compute.use_floatingip_for_ssh:
David Kranze4e3b412015-02-10 10:50:42 -050080 floating_ip = self.floating_ips_client.create_floating_ip()
JordanPc240f7b2014-11-14 19:16:01 +010081 self.addCleanup(self.delete_wrapper,
82 self.floating_ips_client.delete_floating_ip,
83 floating_ip['id'])
84 self.floating_ips_client.associate_floating_ip_to_server(
85 floating_ip['ip'], server['id'])
86 self._write_timestamp(floating_ip['ip'])
87 else:
88 self._write_timestamp(server)
89
90 # Prevent bug #1257594 from coming back
91 # Unshelve used to boot the instance with the original image, not
92 # with the instance snapshot
93 self._shelve_then_unshelve_server(server)
94 if CONF.compute.use_floatingip_for_ssh:
95 self._check_timestamp(floating_ip['ip'])
96 else:
97 self._check_timestamp(server)