blob: b51a7814bf4ad0f0dd3b49f8fd49318292d67978 [file] [log] [blame]
Masayuki Igawaa6de1552013-06-18 17:08:24 +09001# 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
zhufl6b7040a2017-01-18 16:38:34 +080016import testtools
17
Andrea Frittolicd368412017-08-14 21:37:56 +010018from tempest.common import utils
Matthew Treinish6c072292014-01-29 19:15:52 +000019from tempest import config
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080020from tempest.lib import decorators
Masayuki Igawaa6de1552013-06-18 17:08:24 +090021from tempest.scenario import manager
22
Matthew Treinish6c072292014-01-29 19:15:52 +000023CONF = config.CONF
Masayuki Igawaa6de1552013-06-18 17:08:24 +090024
Nachi Ueno95b41282014-01-15 06:54:21 -080025
nithya-ganesan882595e2014-07-29 18:51:07 +000026class TestSnapshotPattern(manager.ScenarioTest):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000027 """This test is for snapshotting an instance and booting with it.
28
Masayuki Igawaa6de1552013-06-18 17:08:24 +090029 The following is the scenario outline:
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090030 * boot an instance and create a timestamp file in it
Masayuki Igawaa6de1552013-06-18 17:08:24 +090031 * 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 yunxian13b456a2016-07-25 11:19:36 +080037 @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 Ohmichic85a9512017-01-27 18:34:24 -080043 @decorators.idempotent_id('608e604b-1d63-4a82-8e3e-91bc665c90b4')
Jordan Pittier3b46d272017-04-12 16:17:28 +020044 @decorators.attr(type='slow')
zhufl6b7040a2017-01-18 16:38:34 +080045 @testtools.skipUnless(CONF.network.public_network_id,
46 'The public_network_id option must be specified.')
Andrea Frittolicd368412017-08-14 21:37:56 +010047 @utils.services('compute', 'network', 'image')
Masayuki Igawaa6de1552013-06-18 17:08:24 +090048 def test_snapshot_pattern(self):
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090049 # prepare for booting an instance
Matt Riedemannc5bb7662015-09-30 14:57:22 -070050 keypair = self.create_keypair()
51 security_group = self._create_security_group()
Masayuki Igawaa6de1552013-06-18 17:08:24 +090052
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090053 # boot an instance and create a timestamp file in it
lanoux5fc14522015-09-21 08:17:35 +000054 server = self.create_server(
lanoux5fc14522015-09-21 08:17:35 +000055 key_name=keypair['name'],
zhufl13c9c892017-02-10 12:04:07 +080056 security_groups=[{'name': security_group['name']}])
lanoux5fc14522015-09-21 08:17:35 +000057
Sean Dague20e98612016-01-06 14:33:28 -050058 instance_ip = self.get_server_ip(server)
Alexander Gubanovc8829f82015-11-12 10:35:13 +020059 timestamp = self.create_timestamp(instance_ip,
60 private_key=keypair['private_key'])
Masayuki Igawaa6de1552013-06-18 17:08:24 +090061
62 # snapshot the instance
Ken'ichi Ohmichia4912232013-08-26 14:03:25 +090063 snapshot_image = self.create_server_snapshot(server=server)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090064
65 # boot a second instance from the snapshot
lanoux5fc14522015-09-21 08:17:35 +000066 server_from_snapshot = self.create_server(
67 image_id=snapshot_image['id'],
68 key_name=keypair['name'],
zhufl13c9c892017-02-10 12:04:07 +080069 security_groups=[{'name': security_group['name']}])
Masayuki Igawaa6de1552013-06-18 17:08:24 +090070
71 # check the existence of the timestamp file in the second instance
Sean Dague20e98612016-01-06 14:33:28 -050072 server_from_snapshot_ip = self.get_server_ip(server_from_snapshot)
Alexander Gubanovc8829f82015-11-12 10:35:13 +020073 timestamp2 = self.get_timestamp(server_from_snapshot_ip,
74 private_key=keypair['private_key'])
Alexander Gubanovabd154c2015-09-23 23:24:06 +030075 self.assertEqual(timestamp, timestamp2)