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 | |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 16 | import testtools |
| 17 | |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 18 | from tempest.common import utils |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 19 | from tempest import config |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 20 | from tempest.lib import decorators |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 21 | from tempest.scenario import manager |
| 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 | |
nithya-ganesan | 882595e | 2014-07-29 18:51:07 +0000 | [diff] [blame] | 26 | class TestSnapshotPattern(manager.ScenarioTest): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 27 | """This test is for snapshotting an instance and booting with it. |
| 28 | |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 29 | The following is the scenario outline: |
Takashi NATSUME | 6d5a2b4 | 2015-09-08 11:27:49 +0900 | [diff] [blame] | 30 | * boot an instance and create a timestamp file in it |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 31 | * snapshot the instance |
| 32 | * boot a second instance from the snapshot |
| 33 | * check the existence of the timestamp file in the second instance |
| 34 | |
| 35 | """ |
| 36 | |
guo yunxian | 13b456a | 2016-07-25 11:19:36 +0800 | [diff] [blame] | 37 | @classmethod |
| 38 | def skip_checks(cls): |
| 39 | super(TestSnapshotPattern, cls).skip_checks() |
| 40 | if not CONF.compute_feature_enabled.snapshot: |
| 41 | raise cls.skipException("Snapshotting is not available.") |
| 42 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 43 | @decorators.idempotent_id('608e604b-1d63-4a82-8e3e-91bc665c90b4') |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 44 | @decorators.attr(type='slow') |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 45 | @testtools.skipUnless(CONF.network.public_network_id, |
| 46 | 'The public_network_id option must be specified.') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 47 | @utils.services('compute', 'network', 'image') |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 48 | def test_snapshot_pattern(self): |
Takashi NATSUME | 6d5a2b4 | 2015-09-08 11:27:49 +0900 | [diff] [blame] | 49 | # prepare for booting an instance |
Matt Riedemann | c5bb766 | 2015-09-30 14:57:22 -0700 | [diff] [blame] | 50 | keypair = self.create_keypair() |
| 51 | security_group = self._create_security_group() |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 52 | |
Takashi NATSUME | 6d5a2b4 | 2015-09-08 11:27:49 +0900 | [diff] [blame] | 53 | # boot an instance and create a timestamp file in it |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 54 | server = self.create_server( |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 55 | key_name=keypair['name'], |
zhufl | 13c9c89 | 2017-02-10 12:04:07 +0800 | [diff] [blame] | 56 | security_groups=[{'name': security_group['name']}]) |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 57 | |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 58 | instance_ip = self.get_server_ip(server) |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 59 | timestamp = self.create_timestamp(instance_ip, |
| 60 | private_key=keypair['private_key']) |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 61 | |
| 62 | # snapshot the instance |
Ken'ichi Ohmichi | a491223 | 2013-08-26 14:03:25 +0900 | [diff] [blame] | 63 | snapshot_image = self.create_server_snapshot(server=server) |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 64 | |
| 65 | # boot a second instance from the snapshot |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 66 | server_from_snapshot = self.create_server( |
| 67 | image_id=snapshot_image['id'], |
| 68 | key_name=keypair['name'], |
zhufl | 13c9c89 | 2017-02-10 12:04:07 +0800 | [diff] [blame] | 69 | security_groups=[{'name': security_group['name']}]) |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 70 | |
| 71 | # check the existence of the timestamp file in the second instance |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 72 | server_from_snapshot_ip = self.get_server_ip(server_from_snapshot) |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 73 | timestamp2 = self.get_timestamp(server_from_snapshot_ip, |
| 74 | private_key=keypair['private_key']) |
Alexander Gubanov | abd154c | 2015-09-23 23:24:06 +0300 | [diff] [blame] | 75 | self.assertEqual(timestamp, timestamp2) |