blob: 79b809f8e9f7c0c2acb24288012d58990d4fc2a3 [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
Masayuki Igawaa6de1552013-06-18 17:08:24 +090039 def _boot_image(self, image_id):
Ken'ichi Ohmichi1b3461e2014-12-02 03:41:07 +000040 security_groups = [{'name': self.security_group['name']}]
Ken'ichi Ohmichi61f272b2013-08-15 15:58:53 +090041 create_kwargs = {
nithya-ganesan882595e2014-07-29 18:51:07 +000042 'key_name': self.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
47 def _add_keypair(self):
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +090048 self.keypair = self.create_keypair()
Masayuki Igawaa6de1552013-06-18 17:08:24 +090049
Chris Hoge7579c1a2015-02-26 14:12:15 -080050 @test.idempotent_id('608e604b-1d63-4a82-8e3e-91bc665c90b4')
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070051 @testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
52 'Snapshotting is not available.')
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090053 @test.services('compute', 'network', 'image')
Masayuki Igawaa6de1552013-06-18 17:08:24 +090054 def test_snapshot_pattern(self):
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090055 # prepare for booting an instance
Masayuki Igawaa6de1552013-06-18 17:08:24 +090056 self._add_keypair()
Yair Fried1fc32a12014-08-04 09:11:30 +030057 self.security_group = self._create_security_group()
Masayuki Igawaa6de1552013-06-18 17:08:24 +090058
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090059 # boot an instance and create a timestamp file in it
Matthew Treinish6c072292014-01-29 19:15:52 +000060 server = self._boot_image(CONF.compute.image_ref)
61 if CONF.compute.use_floatingip_for_ssh:
Yair Friedae0e73d2014-11-24 11:56:26 +020062 fip_for_server = self.create_floating_ip(server)
Alexander Gubanovabd154c2015-09-23 23:24:06 +030063 timestamp = self.create_timestamp(fip_for_server['ip'])
fujioka yuuichia11994e2013-07-09 11:19:51 +090064 else:
Alexander Gubanovabd154c2015-09-23 23:24:06 +030065 timestamp = self.create_timestamp(server)
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
nithya-ganesan882595e2014-07-29 18:51:07 +000071 server_from_snapshot = self._boot_image(snapshot_image['id'])
Masayuki Igawaa6de1552013-06-18 17:08:24 +090072
73 # check the existence of the timestamp file in the second instance
Matthew Treinish6c072292014-01-29 19:15:52 +000074 if CONF.compute.use_floatingip_for_ssh:
Yair Friedae0e73d2014-11-24 11:56:26 +020075 fip_for_snapshot = self.create_floating_ip(server_from_snapshot)
Alexander Gubanovabd154c2015-09-23 23:24:06 +030076 timestamp2 = self.get_timestamp(fip_for_snapshot['ip'])
fujioka yuuichia11994e2013-07-09 11:19:51 +090077 else:
Alexander Gubanovabd154c2015-09-23 23:24:06 +030078 timestamp2 = self.get_timestamp(server_from_snapshot)
79 self.assertEqual(timestamp, timestamp2)