blob: 6dedd1d40b9de1e858917140b5abd9b65e612809 [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
Matthew Treinish6c072292014-01-29 19:15:52 +000018from tempest import config
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080019from tempest.lib import decorators
Masayuki Igawaa6de1552013-06-18 17:08:24 +090020from tempest.scenario import manager
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090021from tempest import test
Masayuki Igawaa6de1552013-06-18 17:08:24 +090022
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')
zhufl6b7040a2017-01-18 16:38:34 +080044 @testtools.skipUnless(CONF.network.public_network_id,
45 'The public_network_id option must be specified.')
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090046 @test.services('compute', 'network', 'image')
Masayuki Igawaa6de1552013-06-18 17:08:24 +090047 def test_snapshot_pattern(self):
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090048 # prepare for booting an instance
Matt Riedemannc5bb7662015-09-30 14:57:22 -070049 keypair = self.create_keypair()
50 security_group = self._create_security_group()
Masayuki Igawaa6de1552013-06-18 17:08:24 +090051
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090052 # boot an instance and create a timestamp file in it
lanoux5fc14522015-09-21 08:17:35 +000053 server = self.create_server(
lanoux5fc14522015-09-21 08:17:35 +000054 key_name=keypair['name'],
zhufl13c9c892017-02-10 12:04:07 +080055 security_groups=[{'name': security_group['name']}])
lanoux5fc14522015-09-21 08:17:35 +000056
Sean Dague20e98612016-01-06 14:33:28 -050057 instance_ip = self.get_server_ip(server)
Alexander Gubanovc8829f82015-11-12 10:35:13 +020058 timestamp = self.create_timestamp(instance_ip,
59 private_key=keypair['private_key'])
Masayuki Igawaa6de1552013-06-18 17:08:24 +090060
61 # snapshot the instance
Ken'ichi Ohmichia4912232013-08-26 14:03:25 +090062 snapshot_image = self.create_server_snapshot(server=server)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090063
64 # boot a second instance from the snapshot
lanoux5fc14522015-09-21 08:17:35 +000065 server_from_snapshot = self.create_server(
66 image_id=snapshot_image['id'],
67 key_name=keypair['name'],
zhufl13c9c892017-02-10 12:04:07 +080068 security_groups=[{'name': security_group['name']}])
Masayuki Igawaa6de1552013-06-18 17:08:24 +090069
70 # check the existence of the timestamp file in the second instance
Sean Dague20e98612016-01-06 14:33:28 -050071 server_from_snapshot_ip = self.get_server_ip(server_from_snapshot)
Alexander Gubanovc8829f82015-11-12 10:35:13 +020072 timestamp2 = self.get_timestamp(server_from_snapshot_ip,
73 private_key=keypair['private_key'])
Alexander Gubanovabd154c2015-09-23 23:24:06 +030074 self.assertEqual(timestamp, timestamp2)