blob: f3b65589a0415e54edee0385fde8525035a67785 [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016from oslo_log import log
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070017import testtools
18
Matthew Treinish6c072292014-01-29 19:15:52 +000019from tempest import config
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 -080025LOG = log.getLogger(__name__)
26
27
nithya-ganesan882595e2014-07-29 18:51:07 +000028class TestSnapshotPattern(manager.ScenarioTest):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000029 """This test is for snapshotting an instance and booting with it.
30
Masayuki Igawaa6de1552013-06-18 17:08:24 +090031 The following is the scenario outline:
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090032 * boot an instance and create a timestamp file in it
Masayuki Igawaa6de1552013-06-18 17:08:24 +090033 * snapshot the instance
34 * boot a second instance from the snapshot
35 * check the existence of the timestamp file in the second instance
36
37 """
38
Chris Hoge7579c1a2015-02-26 14:12:15 -080039 @test.idempotent_id('608e604b-1d63-4a82-8e3e-91bc665c90b4')
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070040 @testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
41 'Snapshotting is not available.')
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'],
52 security_groups=[{'name': security_group['name']}],
53 wait_until='ACTIVE')
54
Alexander Gubanovc8829f82015-11-12 10:35:13 +020055 instance_ip = self.get_server_or_ip(server)
56 timestamp = self.create_timestamp(instance_ip,
57 private_key=keypair['private_key'])
Masayuki Igawaa6de1552013-06-18 17:08:24 +090058
59 # snapshot the instance
Ken'ichi Ohmichia4912232013-08-26 14:03:25 +090060 snapshot_image = self.create_server_snapshot(server=server)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090061
62 # boot a second instance from the snapshot
lanoux5fc14522015-09-21 08:17:35 +000063 server_from_snapshot = self.create_server(
64 image_id=snapshot_image['id'],
65 key_name=keypair['name'],
66 security_groups=[{'name': security_group['name']}],
67 wait_until='ACTIVE')
Masayuki Igawaa6de1552013-06-18 17:08:24 +090068
69 # check the existence of the timestamp file in the second instance
Alexander Gubanovc8829f82015-11-12 10:35:13 +020070 server_from_snapshot_ip = self.get_server_or_ip(server_from_snapshot)
71 timestamp2 = self.get_timestamp(server_from_snapshot_ip,
72 private_key=keypair['private_key'])
Alexander Gubanovabd154c2015-09-23 23:24:06 +030073 self.assertEqual(timestamp, timestamp2)