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 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 18 | from tempest import config |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 19 | from tempest.lib import decorators |
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 | |
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') |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame^] | 44 | @testtools.skipUnless(CONF.network.public_network_id, |
| 45 | 'The public_network_id option must be specified.') |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 46 | @test.services('compute', 'network', 'image') |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 47 | def test_snapshot_pattern(self): |
Takashi NATSUME | 6d5a2b4 | 2015-09-08 11:27:49 +0900 | [diff] [blame] | 48 | # prepare for booting an instance |
Matt Riedemann | c5bb766 | 2015-09-30 14:57:22 -0700 | [diff] [blame] | 49 | keypair = self.create_keypair() |
| 50 | security_group = self._create_security_group() |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 51 | |
Takashi NATSUME | 6d5a2b4 | 2015-09-08 11:27:49 +0900 | [diff] [blame] | 52 | # boot an instance and create a timestamp file in it |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 53 | server = self.create_server( |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 54 | key_name=keypair['name'], |
zhufl | 13c9c89 | 2017-02-10 12:04:07 +0800 | [diff] [blame] | 55 | security_groups=[{'name': security_group['name']}]) |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 56 | |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 57 | instance_ip = self.get_server_ip(server) |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 58 | timestamp = self.create_timestamp(instance_ip, |
| 59 | private_key=keypair['private_key']) |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 60 | |
| 61 | # snapshot the instance |
Ken'ichi Ohmichi | a491223 | 2013-08-26 14:03:25 +0900 | [diff] [blame] | 62 | snapshot_image = self.create_server_snapshot(server=server) |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 63 | |
| 64 | # boot a second instance from the snapshot |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 65 | server_from_snapshot = self.create_server( |
| 66 | image_id=snapshot_image['id'], |
| 67 | key_name=keypair['name'], |
zhufl | 13c9c89 | 2017-02-10 12:04:07 +0800 | [diff] [blame] | 68 | security_groups=[{'name': security_group['name']}]) |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 69 | |
| 70 | # check the existence of the timestamp file in the second instance |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 71 | server_from_snapshot_ip = self.get_server_ip(server_from_snapshot) |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 72 | timestamp2 = self.get_timestamp(server_from_snapshot_ip, |
| 73 | private_key=keypair['private_key']) |
Alexander Gubanov | abd154c | 2015-09-23 23:24:06 +0300 | [diff] [blame] | 74 | self.assertEqual(timestamp, timestamp2) |