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 | |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 16 | import testtools |
| 17 | |
ghanshyam | 017b5fe | 2016-04-15 18:49:26 +0900 | [diff] [blame] | 18 | from tempest.common import compute |
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 |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 21 | from tempest.lib import decorators |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 22 | from tempest.scenario import manager |
| 23 | from tempest import test |
| 24 | |
| 25 | CONF = config.CONF |
| 26 | |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 27 | |
| 28 | class TestShelveInstance(manager.ScenarioTest): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 29 | """This test shelves then unshelves a Nova instance |
| 30 | |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 31 | The following is the scenario outline: |
Takashi NATSUME | 6d5a2b4 | 2015-09-08 11:27:49 +0900 | [diff] [blame] | 32 | * boot an instance and create a timestamp file in it |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 33 | * shelve the instance |
| 34 | * unshelve the instance |
| 35 | * check the existence of the timestamp file in the unshelved instance |
| 36 | |
| 37 | """ |
| 38 | |
zhufl | 8ed23d2 | 2016-07-13 11:00:05 +0800 | [diff] [blame] | 39 | @classmethod |
| 40 | def skip_checks(cls): |
| 41 | super(TestShelveInstance, cls).skip_checks() |
| 42 | if not CONF.compute_feature_enabled.shelve: |
| 43 | raise cls.skipException("Shelve is not available.") |
| 44 | |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 45 | def _shelve_then_unshelve_server(self, server): |
ghanshyam | 017b5fe | 2016-04-15 18:49:26 +0900 | [diff] [blame] | 46 | compute.shelve_server(self.servers_client, server['id'], |
| 47 | force_shelve_offload=True) |
| 48 | |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 49 | self.servers_client.unshelve_server(server['id']) |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 50 | waiters.wait_for_server_status(self.servers_client, server['id'], |
| 51 | 'ACTIVE') |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 52 | |
PranaliDeore | 9fe5eb3 | 2015-07-22 05:28:00 -0700 | [diff] [blame] | 53 | def _create_server_then_shelve_and_unshelve(self, boot_from_volume=False): |
Matt Riedemann | 73764bf | 2015-09-30 14:53:25 -0700 | [diff] [blame] | 54 | keypair = self.create_keypair() |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 55 | |
Matt Riedemann | 73764bf | 2015-09-30 14:53:25 -0700 | [diff] [blame] | 56 | security_group = self._create_security_group() |
| 57 | security_groups = [{'name': security_group['name']}] |
PranaliDeore | 9fe5eb3 | 2015-07-22 05:28:00 -0700 | [diff] [blame] | 58 | |
Xiangfei Zhu | 0b5dca0 | 2016-08-16 21:16:25 -0700 | [diff] [blame] | 59 | server = self.create_server( |
Xiangfei Zhu | 0b5dca0 | 2016-08-16 21:16:25 -0700 | [diff] [blame] | 60 | key_name=keypair['name'], |
| 61 | security_groups=security_groups, |
Xiangfei Zhu | 0b5dca0 | 2016-08-16 21:16:25 -0700 | [diff] [blame] | 62 | volume_backed=boot_from_volume) |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 63 | |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 64 | instance_ip = self.get_server_ip(server) |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 65 | timestamp = self.create_timestamp(instance_ip, |
| 66 | private_key=keypair['private_key']) |
JordanP | c240f7b | 2014-11-14 19:16:01 +0100 | [diff] [blame] | 67 | |
| 68 | # Prevent bug #1257594 from coming back |
| 69 | # Unshelve used to boot the instance with the original image, not |
| 70 | # with the instance snapshot |
| 71 | self._shelve_then_unshelve_server(server) |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 72 | |
| 73 | timestamp2 = self.get_timestamp(instance_ip, |
| 74 | private_key=keypair['private_key']) |
Alexander Gubanov | abd154c | 2015-09-23 23:24:06 +0300 | [diff] [blame] | 75 | self.assertEqual(timestamp, timestamp2) |
PranaliDeore | 9fe5eb3 | 2015-07-22 05:28:00 -0700 | [diff] [blame] | 76 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 77 | @decorators.idempotent_id('1164e700-0af0-4a4c-8792-35909a88743c') |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 78 | @testtools.skipUnless(CONF.network.public_network_id, |
| 79 | 'The public_network_id option must be specified.') |
PranaliDeore | 9fe5eb3 | 2015-07-22 05:28:00 -0700 | [diff] [blame] | 80 | @test.services('compute', 'network', 'image') |
| 81 | def test_shelve_instance(self): |
| 82 | self._create_server_then_shelve_and_unshelve() |
| 83 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 84 | @decorators.idempotent_id('c1b6318c-b9da-490b-9c67-9339b627271f') |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 85 | @testtools.skipUnless(CONF.network.public_network_id, |
| 86 | 'The public_network_id option must be specified.') |
PranaliDeore | 9fe5eb3 | 2015-07-22 05:28:00 -0700 | [diff] [blame] | 87 | @test.services('compute', 'volume', 'network', 'image') |
| 88 | def test_shelve_volume_backed_instance(self): |
| 89 | self._create_server_then_shelve_and_unshelve(boot_from_volume=True) |