blob: 5ac3a7e6d94193a1e31655e92b78f62c4d3caea2 [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):
Masayuki Igawaa6de1552013-06-18 17:08:24 +090029 """
30 This test is for snapshotting an instance and booting with it.
31 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
Matt Riedemannc5bb7662015-09-30 14:57:22 -070039 def _boot_image(self, image_id, keypair, security_group):
40 security_groups = [{'name': security_group['name']}]
Ken'ichi Ohmichi61f272b2013-08-15 15:58:53 +090041 create_kwargs = {
Matt Riedemannc5bb7662015-09-30 14:57:22 -070042 'key_name': keypair['name'],
Grishkin0f1e11c2014-05-04 20:44:52 +040043 'security_groups': security_groups
Ken'ichi Ohmichi61f272b2013-08-15 15:58:53 +090044 }
Giulio Fidente61cadca2013-09-24 18:33:37 +020045 return self.create_server(image=image_id, create_kwargs=create_kwargs)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090046
Chris Hoge7579c1a2015-02-26 14:12:15 -080047 @test.idempotent_id('608e604b-1d63-4a82-8e3e-91bc665c90b4')
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070048 @testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
49 'Snapshotting is not available.')
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090050 @test.services('compute', 'network', 'image')
Masayuki Igawaa6de1552013-06-18 17:08:24 +090051 def test_snapshot_pattern(self):
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090052 # prepare for booting an instance
Matt Riedemannc5bb7662015-09-30 14:57:22 -070053 keypair = self.create_keypair()
54 security_group = self._create_security_group()
Masayuki Igawaa6de1552013-06-18 17:08:24 +090055
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090056 # boot an instance and create a timestamp file in it
Matt Riedemannc5bb7662015-09-30 14:57:22 -070057 server = self._boot_image(CONF.compute.image_ref, keypair,
58 security_group)
Matthew Treinish6c072292014-01-29 19:15:52 +000059 if CONF.compute.use_floatingip_for_ssh:
Yair Friedae0e73d2014-11-24 11:56:26 +020060 fip_for_server = self.create_floating_ip(server)
Matt Riedemannc5bb7662015-09-30 14:57:22 -070061 timestamp = self.create_timestamp(
62 fip_for_server['ip'], private_key=keypair['private_key'])
fujioka yuuichia11994e2013-07-09 11:19:51 +090063 else:
Matt Riedemannc5bb7662015-09-30 14:57:22 -070064 timestamp = self.create_timestamp(
65 server, private_key=keypair['private_key'])
Masayuki Igawaa6de1552013-06-18 17:08:24 +090066
67 # snapshot the instance
Ken'ichi Ohmichia4912232013-08-26 14:03:25 +090068 snapshot_image = self.create_server_snapshot(server=server)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090069
70 # boot a second instance from the snapshot
Matt Riedemannc5bb7662015-09-30 14:57:22 -070071 server_from_snapshot = self._boot_image(snapshot_image['id'],
72 keypair, security_group)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090073
74 # check the existence of the timestamp file in the second instance
Matthew Treinish6c072292014-01-29 19:15:52 +000075 if CONF.compute.use_floatingip_for_ssh:
Yair Friedae0e73d2014-11-24 11:56:26 +020076 fip_for_snapshot = self.create_floating_ip(server_from_snapshot)
Matt Riedemannc5bb7662015-09-30 14:57:22 -070077 timestamp2 = self.get_timestamp(fip_for_snapshot['ip'],
78 private_key=keypair['private_key'])
fujioka yuuichia11994e2013-07-09 11:19:51 +090079 else:
Matt Riedemannc5bb7662015-09-30 14:57:22 -070080 timestamp2 = self.get_timestamp(server_from_snapshot,
81 private_key=keypair['private_key'])
Alexander Gubanovabd154c2015-09-23 23:24:06 +030082 self.assertEqual(timestamp, timestamp2)