blob: 109d36b06dac5146f36b3a5c820c40fe59632c94 [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
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070016import testtools
17
Matthew Treinish6c072292014-01-29 19:15:52 +000018from tempest import config
Nachi Ueno95b41282014-01-15 06:54:21 -080019from tempest.openstack.common import log
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:
32 * boot a instance and create a timestamp file in it
33 * 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
fujioka yuuichia11994e2013-07-09 11:19:51 +090050 def _write_timestamp(self, server_or_ip):
JordanP3fe2dc32014-11-17 13:06:01 +010051 ssh_client = self.get_remote_client(server_or_ip)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090052 ssh_client.exec_command('date > /tmp/timestamp; sync')
53 self.timestamp = ssh_client.exec_command('cat /tmp/timestamp')
54
fujioka yuuichia11994e2013-07-09 11:19:51 +090055 def _check_timestamp(self, server_or_ip):
JordanP3fe2dc32014-11-17 13:06:01 +010056 ssh_client = self.get_remote_client(server_or_ip)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090057 got_timestamp = ssh_client.exec_command('cat /tmp/timestamp')
58 self.assertEqual(self.timestamp, got_timestamp)
59
Chris Hoge7579c1a2015-02-26 14:12:15 -080060 @test.idempotent_id('608e604b-1d63-4a82-8e3e-91bc665c90b4')
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070061 @testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
62 'Snapshotting is not available.')
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090063 @test.services('compute', 'network', 'image')
Masayuki Igawaa6de1552013-06-18 17:08:24 +090064 def test_snapshot_pattern(self):
65 # prepare for booting a instance
66 self._add_keypair()
Yair Fried1fc32a12014-08-04 09:11:30 +030067 self.security_group = self._create_security_group()
Masayuki Igawaa6de1552013-06-18 17:08:24 +090068
69 # boot a instance and create a timestamp file in it
Matthew Treinish6c072292014-01-29 19:15:52 +000070 server = self._boot_image(CONF.compute.image_ref)
71 if CONF.compute.use_floatingip_for_ssh:
Yair Friedae0e73d2014-11-24 11:56:26 +020072 fip_for_server = self.create_floating_ip(server)
nithya-ganesan882595e2014-07-29 18:51:07 +000073 self._write_timestamp(fip_for_server['ip'])
fujioka yuuichia11994e2013-07-09 11:19:51 +090074 else:
75 self._write_timestamp(server)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090076
77 # snapshot the instance
Ken'ichi Ohmichia4912232013-08-26 14:03:25 +090078 snapshot_image = self.create_server_snapshot(server=server)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090079
80 # boot a second instance from the snapshot
nithya-ganesan882595e2014-07-29 18:51:07 +000081 server_from_snapshot = self._boot_image(snapshot_image['id'])
Masayuki Igawaa6de1552013-06-18 17:08:24 +090082
83 # check the existence of the timestamp file in the second instance
Matthew Treinish6c072292014-01-29 19:15:52 +000084 if CONF.compute.use_floatingip_for_ssh:
Yair Friedae0e73d2014-11-24 11:56:26 +020085 fip_for_snapshot = self.create_floating_ip(server_from_snapshot)
nithya-ganesan882595e2014-07-29 18:51:07 +000086 self._check_timestamp(fip_for_snapshot['ip'])
fujioka yuuichia11994e2013-07-09 11:19:51 +090087 else:
88 self._check_timestamp(server_from_snapshot)