blob: 8c2cc76ffc73a295aed419a2e9585249996d6860 [file] [log] [blame]
Masayuki Igawaa6de1552013-06-18 17:08:24 +09001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 NEC Corporation
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
Masayuki Igawaa6de1552013-06-18 17:08:24 +090018from tempest.scenario import manager
Matthew Treinish2153ec02013-09-09 20:57:30 +000019from tempest.test import services
Masayuki Igawaa6de1552013-06-18 17:08:24 +090020
21
Masayuki Igawaa6de1552013-06-18 17:08:24 +090022class TestSnapshotPattern(manager.OfficialClientTest):
23 """
24 This test is for snapshotting an instance and booting with it.
25 The following is the scenario outline:
26 * boot a instance and create a timestamp file in it
27 * snapshot the instance
28 * boot a second instance from the snapshot
29 * check the existence of the timestamp file in the second instance
30
31 """
32
Masayuki Igawaa6de1552013-06-18 17:08:24 +090033 def _boot_image(self, image_id):
Ken'ichi Ohmichi61f272b2013-08-15 15:58:53 +090034 create_kwargs = {
35 'key_name': self.keypair.name
36 }
37 return self.create_server(self.compute_client, image=image_id,
38 create_kwargs=create_kwargs)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090039
40 def _add_keypair(self):
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +090041 self.keypair = self.create_keypair()
Masayuki Igawaa6de1552013-06-18 17:08:24 +090042
fujioka yuuichia11994e2013-07-09 11:19:51 +090043 def _ssh_to_server(self, server_or_ip):
Ken'ichi Ohmichib3aa9122013-08-22 23:27:25 +090044 linux_client = self.get_remote_client(server_or_ip)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090045 return linux_client.ssh_client
46
fujioka yuuichia11994e2013-07-09 11:19:51 +090047 def _write_timestamp(self, server_or_ip):
48 ssh_client = self._ssh_to_server(server_or_ip)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090049 ssh_client.exec_command('date > /tmp/timestamp; sync')
50 self.timestamp = ssh_client.exec_command('cat /tmp/timestamp')
51
fujioka yuuichia11994e2013-07-09 11:19:51 +090052 def _check_timestamp(self, server_or_ip):
53 ssh_client = self._ssh_to_server(server_or_ip)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090054 got_timestamp = ssh_client.exec_command('cat /tmp/timestamp')
55 self.assertEqual(self.timestamp, got_timestamp)
56
fujioka yuuichia11994e2013-07-09 11:19:51 +090057 def _create_floating_ip(self):
58 floating_ip = self.compute_client.floating_ips.create()
59 self.addCleanup(floating_ip.delete)
60 return floating_ip
61
62 def _set_floating_ip_to_server(self, server, floating_ip):
63 server.add_floating_ip(floating_ip)
64
Matthew Treinish2153ec02013-09-09 20:57:30 +000065 @services('compute', 'network', 'image')
Masayuki Igawaa6de1552013-06-18 17:08:24 +090066 def test_snapshot_pattern(self):
67 # prepare for booting a instance
68 self._add_keypair()
Ken'ichi Ohmichi3c1f5192013-08-19 19:02:15 +090069 self.create_loginable_secgroup_rule()
Masayuki Igawaa6de1552013-06-18 17:08:24 +090070
71 # boot a instance and create a timestamp file in it
72 server = self._boot_image(self.config.compute.image_ref)
fujioka yuuichia11994e2013-07-09 11:19:51 +090073 if self.config.compute.use_floatingip_for_ssh:
74 fip_for_server = self._create_floating_ip()
75 self._set_floating_ip_to_server(server, fip_for_server)
76 self._write_timestamp(fip_for_server.ip)
77 else:
78 self._write_timestamp(server)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090079
80 # snapshot the instance
Ken'ichi Ohmichia4912232013-08-26 14:03:25 +090081 snapshot_image = self.create_server_snapshot(server=server)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090082
83 # boot a second instance from the snapshot
Ken'ichi Ohmichia4912232013-08-26 14:03:25 +090084 server_from_snapshot = self._boot_image(snapshot_image.id)
Masayuki Igawaa6de1552013-06-18 17:08:24 +090085
86 # check the existence of the timestamp file in the second instance
fujioka yuuichia11994e2013-07-09 11:19:51 +090087 if self.config.compute.use_floatingip_for_ssh:
88 fip_for_snapshot = self._create_floating_ip()
89 self._set_floating_ip_to_server(server_from_snapshot,
90 fip_for_snapshot)
91 self._check_timestamp(fip_for_snapshot.ip)
92 else:
93 self._check_timestamp(server_from_snapshot)