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 | |
| 16 | import testtools |
| 17 | |
| 18 | from tempest import config |
| 19 | from tempest.openstack.common import log |
| 20 | from tempest.scenario import manager |
| 21 | from tempest import test |
| 22 | |
| 23 | CONF = config.CONF |
| 24 | |
| 25 | LOG = log.getLogger(__name__) |
| 26 | |
| 27 | |
| 28 | class 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() |
| 70 | |
| 71 | create_kwargs = { |
| 72 | 'key_name': self.keypair['name'], |
| 73 | 'security_groups': [self.security_group] |
| 74 | } |
| 75 | server = self.create_server(image=CONF.compute.image_ref, |
| 76 | create_kwargs=create_kwargs) |
| 77 | |
| 78 | if CONF.compute.use_floatingip_for_ssh: |
| 79 | _, floating_ip = self.floating_ips_client.create_floating_ip() |
| 80 | self.addCleanup(self.delete_wrapper, |
| 81 | self.floating_ips_client.delete_floating_ip, |
| 82 | floating_ip['id']) |
| 83 | self.floating_ips_client.associate_floating_ip_to_server( |
| 84 | floating_ip['ip'], server['id']) |
| 85 | self._write_timestamp(floating_ip['ip']) |
| 86 | else: |
| 87 | self._write_timestamp(server) |
| 88 | |
| 89 | # Prevent bug #1257594 from coming back |
| 90 | # Unshelve used to boot the instance with the original image, not |
| 91 | # with the instance snapshot |
| 92 | self._shelve_then_unshelve_server(server) |
| 93 | if CONF.compute.use_floatingip_for_ssh: |
| 94 | self._check_timestamp(floating_ip['ip']) |
| 95 | else: |
| 96 | self._check_timestamp(server) |