blob: 8197d52a40e8fd802b8d0e99ad00bf3a8569e8c7 [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
Matthew Treinish6c072292014-01-29 19:15:52 +000016from tempest import config
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080017from tempest.lib import decorators
Masayuki Igawaa6de1552013-06-18 17:08:24 +090018from tempest.scenario import manager
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090019from tempest import test
Masayuki Igawaa6de1552013-06-18 17:08:24 +090020
Matthew Treinish6c072292014-01-29 19:15:52 +000021CONF = config.CONF
Masayuki Igawaa6de1552013-06-18 17:08:24 +090022
Nachi Ueno95b41282014-01-15 06:54:21 -080023
nithya-ganesan882595e2014-07-29 18:51:07 +000024class TestSnapshotPattern(manager.ScenarioTest):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000025 """This test is for snapshotting an instance and booting with it.
26
Masayuki Igawaa6de1552013-06-18 17:08:24 +090027 The following is the scenario outline:
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090028 * boot an instance and create a timestamp file in it
Masayuki Igawaa6de1552013-06-18 17:08:24 +090029 * snapshot the instance
30 * boot a second instance from the snapshot
31 * check the existence of the timestamp file in the second instance
32
33 """
34
guo yunxian13b456a2016-07-25 11:19:36 +080035 @classmethod
36 def skip_checks(cls):
37 super(TestSnapshotPattern, cls).skip_checks()
38 if not CONF.compute_feature_enabled.snapshot:
39 raise cls.skipException("Snapshotting is not available.")
40
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080041 @decorators.idempotent_id('608e604b-1d63-4a82-8e3e-91bc665c90b4')
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090042 @test.services('compute', 'network', 'image')
Masayuki Igawaa6de1552013-06-18 17:08:24 +090043 def test_snapshot_pattern(self):
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090044 # prepare for booting an instance
Matt Riedemannc5bb7662015-09-30 14:57:22 -070045 keypair = self.create_keypair()
46 security_group = self._create_security_group()
Masayuki Igawaa6de1552013-06-18 17:08:24 +090047
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090048 # boot an instance and create a timestamp file in it
lanoux5fc14522015-09-21 08:17:35 +000049 server = self.create_server(
50 image_id=CONF.compute.image_ref,
51 key_name=keypair['name'],
zhufl13c9c892017-02-10 12:04:07 +080052 security_groups=[{'name': security_group['name']}])
lanoux5fc14522015-09-21 08:17:35 +000053
Sean Dague20e98612016-01-06 14:33:28 -050054 instance_ip = self.get_server_ip(server)
Alexander Gubanovc8829f82015-11-12 10:35:13 +020055 timestamp = self.create_timestamp(instance_ip,
56 private_key=keypair['private_key'])
Masayuki Igawaa6de1552013-06-18 17:08:24 +090057
58 # snapshot the instance
Ken'ichi Ohmichia4912232013-08-26 14:03:25 +090059 snapshot_image = self.create_server_snapshot(server=server)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090060
61 # boot a second instance from the snapshot
lanoux5fc14522015-09-21 08:17:35 +000062 server_from_snapshot = self.create_server(
63 image_id=snapshot_image['id'],
64 key_name=keypair['name'],
zhufl13c9c892017-02-10 12:04:07 +080065 security_groups=[{'name': security_group['name']}])
Masayuki Igawaa6de1552013-06-18 17:08:24 +090066
67 # check the existence of the timestamp file in the second instance
Sean Dague20e98612016-01-06 14:33:28 -050068 server_from_snapshot_ip = self.get_server_ip(server_from_snapshot)
Alexander Gubanovc8829f82015-11-12 10:35:13 +020069 timestamp2 = self.get_timestamp(server_from_snapshot_ip,
70 private_key=keypair['private_key'])
Alexander Gubanovabd154c2015-09-23 23:24:06 +030071 self.assertEqual(timestamp, timestamp2)