blob: d04cb9a1a6200d3541aa4b99f2d3c11e170c16be [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
Archit Modi2c8e8ae2020-05-21 16:31:41 +000032 * add version metadata to the snapshot image
Masayuki Igawaa6de1552013-06-18 17:08:24 +090033 * boot a second instance from the snapshot
34 * check the existence of the timestamp file in the second instance
Archit Modi2c8e8ae2020-05-21 16:31:41 +000035 * snapshot the instance again
Masayuki Igawaa6de1552013-06-18 17:08:24 +090036
37 """
38
guo yunxian13b456a2016-07-25 11:19:36 +080039 @classmethod
40 def skip_checks(cls):
41 super(TestSnapshotPattern, cls).skip_checks()
42 if not CONF.compute_feature_enabled.snapshot:
43 raise cls.skipException("Snapshotting is not available.")
44
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080045 @decorators.idempotent_id('608e604b-1d63-4a82-8e3e-91bc665c90b4')
Jordan Pittier3b46d272017-04-12 16:17:28 +020046 @decorators.attr(type='slow')
zhufl6b7040a2017-01-18 16:38:34 +080047 @testtools.skipUnless(CONF.network.public_network_id,
48 'The public_network_id option must be specified.')
Andrea Frittolicd368412017-08-14 21:37:56 +010049 @utils.services('compute', 'network', 'image')
Masayuki Igawaa6de1552013-06-18 17:08:24 +090050 def test_snapshot_pattern(self):
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090051 # prepare for booting an instance
Matt Riedemannc5bb7662015-09-30 14:57:22 -070052 keypair = self.create_keypair()
Soniya Vyas582c1702021-02-22 18:26:17 +053053 security_group = self.create_security_group()
Masayuki Igawaa6de1552013-06-18 17:08:24 +090054
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090055 # boot an instance and create a timestamp file in it
lanoux5fc14522015-09-21 08:17:35 +000056 server = self.create_server(
lanoux5fc14522015-09-21 08:17:35 +000057 key_name=keypair['name'],
zhufl13c9c892017-02-10 12:04:07 +080058 security_groups=[{'name': security_group['name']}])
lanoux5fc14522015-09-21 08:17:35 +000059
Sean Dague20e98612016-01-06 14:33:28 -050060 instance_ip = self.get_server_ip(server)
Alexander Gubanovc8829f82015-11-12 10:35:13 +020061 timestamp = self.create_timestamp(instance_ip,
Slawek Kaplonski79d8b0f2018-07-30 22:43:41 +020062 private_key=keypair['private_key'],
63 server=server)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090064
65 # snapshot the instance
Ken'ichi Ohmichia4912232013-08-26 14:03:25 +090066 snapshot_image = self.create_server_snapshot(server=server)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090067
Archit Modi2c8e8ae2020-05-21 16:31:41 +000068 # add version metadata to the snapshot image
69 self.image_client.update_image(
70 snapshot_image['id'], [dict(add='/version',
71 value='8.0')])
72
Masayuki Igawaa6de1552013-06-18 17:08:24 +090073 # boot a second instance from the snapshot
lanoux5fc14522015-09-21 08:17:35 +000074 server_from_snapshot = self.create_server(
75 image_id=snapshot_image['id'],
76 key_name=keypair['name'],
zhufl13c9c892017-02-10 12:04:07 +080077 security_groups=[{'name': security_group['name']}])
Masayuki Igawaa6de1552013-06-18 17:08:24 +090078
79 # check the existence of the timestamp file in the second instance
Sean Dague20e98612016-01-06 14:33:28 -050080 server_from_snapshot_ip = self.get_server_ip(server_from_snapshot)
Alexander Gubanovc8829f82015-11-12 10:35:13 +020081 timestamp2 = self.get_timestamp(server_from_snapshot_ip,
Slawek Kaplonski79d8b0f2018-07-30 22:43:41 +020082 private_key=keypair['private_key'],
83 server=server_from_snapshot)
Alexander Gubanovabd154c2015-09-23 23:24:06 +030084 self.assertEqual(timestamp, timestamp2)
Archit Modi2c8e8ae2020-05-21 16:31:41 +000085
86 # snapshot the instance again
87 self.create_server_snapshot(server=server_from_snapshot)