Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 1 | # Copyright 2013 NEC Corporation |
| 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 |
Adam Gandelman | fbc95ac | 2014-06-19 17:33:43 -0700 | [diff] [blame] | 17 | import testtools |
| 18 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 19 | from tempest import config |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 20 | from tempest.scenario import manager |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 21 | from tempest import test |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 22 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 23 | CONF = config.CONF |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 24 | |
Nachi Ueno | 95b4128 | 2014-01-15 06:54:21 -0800 | [diff] [blame] | 25 | LOG = log.getLogger(__name__) |
| 26 | |
| 27 | |
nithya-ganesan | 882595e | 2014-07-29 18:51:07 +0000 | [diff] [blame] | 28 | class TestSnapshotPattern(manager.ScenarioTest): |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 29 | """ |
| 30 | This test is for snapshotting an instance and booting with it. |
| 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 |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 33 | * snapshot the instance |
| 34 | * boot a second instance from the snapshot |
| 35 | * check the existence of the timestamp file in the second instance |
| 36 | |
| 37 | """ |
| 38 | |
Matt Riedemann | c5bb766 | 2015-09-30 14:57:22 -0700 | [diff] [blame] | 39 | def _boot_image(self, image_id, keypair, security_group): |
| 40 | security_groups = [{'name': security_group['name']}] |
Ken'ichi Ohmichi | 61f272b | 2013-08-15 15:58:53 +0900 | [diff] [blame] | 41 | create_kwargs = { |
Matt Riedemann | c5bb766 | 2015-09-30 14:57:22 -0700 | [diff] [blame] | 42 | 'key_name': keypair['name'], |
Grishkin | 0f1e11c | 2014-05-04 20:44:52 +0400 | [diff] [blame] | 43 | 'security_groups': security_groups |
Ken'ichi Ohmichi | 61f272b | 2013-08-15 15:58:53 +0900 | [diff] [blame] | 44 | } |
Giulio Fidente | 61cadca | 2013-09-24 18:33:37 +0200 | [diff] [blame] | 45 | return self.create_server(image=image_id, create_kwargs=create_kwargs) |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 46 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 47 | @test.idempotent_id('608e604b-1d63-4a82-8e3e-91bc665c90b4') |
Adam Gandelman | fbc95ac | 2014-06-19 17:33:43 -0700 | [diff] [blame] | 48 | @testtools.skipUnless(CONF.compute_feature_enabled.snapshot, |
| 49 | 'Snapshotting is not available.') |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 50 | @test.services('compute', 'network', 'image') |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 51 | def test_snapshot_pattern(self): |
Takashi NATSUME | 6d5a2b4 | 2015-09-08 11:27:49 +0900 | [diff] [blame] | 52 | # prepare for booting an instance |
Matt Riedemann | c5bb766 | 2015-09-30 14:57:22 -0700 | [diff] [blame] | 53 | keypair = self.create_keypair() |
| 54 | security_group = self._create_security_group() |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 55 | |
Takashi NATSUME | 6d5a2b4 | 2015-09-08 11:27:49 +0900 | [diff] [blame] | 56 | # boot an instance and create a timestamp file in it |
Matt Riedemann | c5bb766 | 2015-09-30 14:57:22 -0700 | [diff] [blame] | 57 | server = self._boot_image(CONF.compute.image_ref, keypair, |
| 58 | security_group) |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 59 | if CONF.compute.use_floatingip_for_ssh: |
Yair Fried | ae0e73d | 2014-11-24 11:56:26 +0200 | [diff] [blame] | 60 | fip_for_server = self.create_floating_ip(server) |
Matt Riedemann | c5bb766 | 2015-09-30 14:57:22 -0700 | [diff] [blame] | 61 | timestamp = self.create_timestamp( |
| 62 | fip_for_server['ip'], private_key=keypair['private_key']) |
fujioka yuuichi | a11994e | 2013-07-09 11:19:51 +0900 | [diff] [blame] | 63 | else: |
Matt Riedemann | c5bb766 | 2015-09-30 14:57:22 -0700 | [diff] [blame] | 64 | timestamp = self.create_timestamp( |
| 65 | server, private_key=keypair['private_key']) |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 66 | |
| 67 | # snapshot the instance |
Ken'ichi Ohmichi | a491223 | 2013-08-26 14:03:25 +0900 | [diff] [blame] | 68 | snapshot_image = self.create_server_snapshot(server=server) |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 69 | |
| 70 | # boot a second instance from the snapshot |
Matt Riedemann | c5bb766 | 2015-09-30 14:57:22 -0700 | [diff] [blame] | 71 | server_from_snapshot = self._boot_image(snapshot_image['id'], |
| 72 | keypair, security_group) |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 73 | |
| 74 | # check the existence of the timestamp file in the second instance |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 75 | if CONF.compute.use_floatingip_for_ssh: |
Yair Fried | ae0e73d | 2014-11-24 11:56:26 +0200 | [diff] [blame] | 76 | fip_for_snapshot = self.create_floating_ip(server_from_snapshot) |
Matt Riedemann | c5bb766 | 2015-09-30 14:57:22 -0700 | [diff] [blame] | 77 | timestamp2 = self.get_timestamp(fip_for_snapshot['ip'], |
| 78 | private_key=keypair['private_key']) |
fujioka yuuichi | a11994e | 2013-07-09 11:19:51 +0900 | [diff] [blame] | 79 | else: |
Matt Riedemann | c5bb766 | 2015-09-30 14:57:22 -0700 | [diff] [blame] | 80 | timestamp2 = self.get_timestamp(server_from_snapshot, |
| 81 | private_key=keypair['private_key']) |
Alexander Gubanov | abd154c | 2015-09-23 23:24:06 +0300 | [diff] [blame] | 82 | self.assertEqual(timestamp, timestamp2) |