JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 1 | # 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 Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 16 | from oslo_log import log |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 17 | import testtools |
| 18 | |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 19 | from tempest.common import waiters |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 20 | from tempest import config |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 21 | from tempest.scenario import manager |
| 22 | from tempest import test |
| 23 | |
| 24 | CONF = config.CONF |
| 25 | |
| 26 | LOG = log.getLogger(__name__) |
| 27 | |
| 28 | |
| 29 | class TestShelveInstance(manager.ScenarioTest): |
| 30 | """ |
| 31 | This test shelves then unshelves a Nova instance |
| 32 | The following is the scenario outline: |
Takashi NATSUME | 6d5a2b4 | 2015-09-08 11:27:49 +0900 | [diff] [blame^] | 33 | * boot an instance and create a timestamp file in it |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 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 Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 54 | waiters.wait_for_server_status(self.servers_client, server['id'], |
| 55 | 'SHELVED_OFFLOADED', |
| 56 | extra_timeout=offload_time) |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 57 | else: |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 58 | waiters.wait_for_server_status(self.servers_client, |
| 59 | server['id'], 'SHELVED') |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 60 | self.servers_client.shelve_offload_server(server['id']) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 61 | waiters.wait_for_server_status(self.servers_client, server['id'], |
| 62 | 'SHELVED_OFFLOADED') |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 63 | self.servers_client.unshelve_server(server['id']) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 64 | waiters.wait_for_server_status(self.servers_client, server['id'], |
| 65 | 'ACTIVE') |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 66 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 67 | @test.idempotent_id('1164e700-0af0-4a4c-8792-35909a88743c') |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 68 | @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 Ohmichi | 1b3461e | 2014-12-02 03:41:07 +0000 | [diff] [blame] | 75 | security_groups = [{'name': self.security_group['name']}] |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 76 | |
| 77 | create_kwargs = { |
| 78 | 'key_name': self.keypair['name'], |
Ken'ichi Ohmichi | 1b3461e | 2014-12-02 03:41:07 +0000 | [diff] [blame] | 79 | 'security_groups': security_groups |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 80 | } |
| 81 | server = self.create_server(image=CONF.compute.image_ref, |
| 82 | create_kwargs=create_kwargs) |
| 83 | |
| 84 | if CONF.compute.use_floatingip_for_ssh: |
ghanshyam | 9a3a9a2 | 2015-08-18 17:03:55 +0900 | [diff] [blame] | 85 | floating_ip = (self.floating_ips_client.create_floating_ip() |
| 86 | ['floating_ip']) |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 87 | 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) |