blob: faae800ec1a0cfd1e7e1b6dee92b40756bdf3971 [file] [log] [blame]
Yuiko Takadaebcf6af2013-07-09 05:10:55 +00001# 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
Sean Daguefe8a6092013-07-27 08:15:55 -040016import time
17
Doug Hellmann583ce2c2015-03-11 14:55:46 +000018from oslo_log import log as logging
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050019from tempest_lib import decorators
Masayuki Igawabfa07602015-01-20 18:47:17 +090020from tempest_lib import exceptions as lib_exc
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070021import testtools
Sean Daguefe8a6092013-07-27 08:15:55 -040022
Fei Long Wangd39431f2015-05-14 11:30:48 +120023from tempest.common.utils import data_utils
Matthew Treinish6c072292014-01-29 19:15:52 +000024from tempest import config
Attila Fazekas70431ba2013-07-26 18:47:37 +020025from tempest import exceptions
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000026from tempest.scenario import manager
Chris Hoge7579c1a2015-02-26 14:12:15 -080027from tempest import test
Attila Fazekas70431ba2013-07-26 18:47:37 +020028import tempest.test
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000029
Matthew Treinish6c072292014-01-29 19:15:52 +000030CONF = config.CONF
31
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000032LOG = logging.getLogger(__name__)
33
34
Andrea Frittolic0651b22014-09-17 16:34:01 +010035class TestStampPattern(manager.ScenarioTest):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000036 """The test suite for both snapshoting and attaching of volume
37
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000038 This test is for snapshotting an instance/volume and attaching the volume
39 created from snapshot to the instance booted from snapshot.
40 The following is the scenario outline:
41 1. Boot an instance "instance1"
42 2. Create a volume "volume1"
43 3. Attach volume1 to instance1
44 4. Create a filesystem on volume1
45 5. Mount volume1
46 6. Create a file which timestamp is written in volume1
47 7. Unmount volume1
48 8. Detach volume1 from instance1
49 9. Get a snapshot "snapshot_from_volume" of volume1
50 10. Get a snapshot "snapshot_from_instance" of instance1
51 11. Boot an instance "instance2" from snapshot_from_instance
52 12. Create a volume "volume2" from snapshot_from_volume
53 13. Attach volume2 to instance2
54 14. Check the existence of a file which created at 6. in volume2
55 """
56
JordanPbce55532014-03-19 12:10:32 +010057 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000058 def skip_checks(cls):
59 super(TestStampPattern, cls).skip_checks()
JordanPbce55532014-03-19 12:10:32 +010060 if not CONF.volume_feature_enabled.snapshot:
61 raise cls.skipException("Cinder volume snapshots are disabled")
62
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000063 def _wait_for_volume_snapshot_status(self, volume_snapshot, status):
Andrea Frittolic0651b22014-09-17 16:34:01 +010064 self.snapshots_client.wait_for_snapshot_status(volume_snapshot['id'],
65 status)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000066
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000067 def _create_volume_snapshot(self, volume):
Ken'ichi Ohmichi6ded8df2015-03-23 02:00:19 +000068 snapshot_name = data_utils.rand_name('scenario-snapshot')
Matt Riedemannfd5657d2015-09-30 14:47:07 -070069 snapshot = self.snapshots_client.create_snapshot(
John Warrenff7faf62015-08-17 16:59:06 +000070 volume['id'], display_name=snapshot_name)['snapshot']
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000071
72 def cleaner():
Andrea Frittolic0651b22014-09-17 16:34:01 +010073 self.snapshots_client.delete_snapshot(snapshot['id'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000074 try:
John Warrenff7faf62015-08-17 16:59:06 +000075 while self.snapshots_client.show_snapshot(
76 snapshot['id'])['snapshot']:
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000077 time.sleep(1)
Masayuki Igawabfa07602015-01-20 18:47:17 +090078 except lib_exc.NotFound:
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000079 pass
80 self.addCleanup(cleaner)
81 self._wait_for_volume_status(volume, 'available')
Andrea Frittolic0651b22014-09-17 16:34:01 +010082 self.snapshots_client.wait_for_snapshot_status(snapshot['id'],
83 'available')
84 self.assertEqual(snapshot_name, snapshot['display_name'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000085 return snapshot
86
87 def _wait_for_volume_status(self, volume, status):
Andrea Frittolic0651b22014-09-17 16:34:01 +010088 self.volumes_client.wait_for_volume_status(volume['id'], status)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000089
90 def _create_volume(self, snapshot_id=None):
Ken'ichi Ohmichi70672df2013-08-19 18:35:19 +090091 return self.create_volume(snapshot_id=snapshot_id)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000092
93 def _attach_volume(self, server, volume):
David Kranz3ebc7212015-02-10 12:19:19 -050094 attached_volume = self.servers_client.attach_volume(
Ken'ichi Ohmichidfc88de2015-08-13 05:12:20 +000095 server['id'], volumeId=volume['id'], device='/dev/%s'
ghanshyam0f825252015-08-25 16:02:50 +090096 % CONF.compute.volume_device_name)['volumeAttachment']
Andrea Frittolic0651b22014-09-17 16:34:01 +010097 self.assertEqual(volume['id'], attached_volume['id'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000098 self._wait_for_volume_status(attached_volume, 'in-use')
99
100 def _detach_volume(self, server, volume):
Andrea Frittolic0651b22014-09-17 16:34:01 +0100101 self.servers_client.detach_volume(server['id'], volume['id'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000102 self._wait_for_volume_status(volume, 'available')
103
Matt Riedemannfd5657d2015-09-30 14:47:07 -0700104 def _wait_for_volume_available_on_the_system(self, server_or_ip,
105 private_key):
106 ssh = self.get_remote_client(server_or_ip, private_key=private_key)
Attila Fazekas70431ba2013-07-26 18:47:37 +0200107
108 def _func():
109 part = ssh.get_partitions()
110 LOG.debug("Partitions:%s" % part)
Alexander Gubanove0634ab2015-05-25 10:28:25 +0300111 return CONF.compute.volume_device_name in part
Attila Fazekas70431ba2013-07-26 18:47:37 +0200112
113 if not tempest.test.call_until_true(_func,
Matthew Treinish6c072292014-01-29 19:15:52 +0000114 CONF.compute.build_timeout,
115 CONF.compute.build_interval):
Attila Fazekas70431ba2013-07-26 18:47:37 +0200116 raise exceptions.TimeoutException
117
Matthew Treinishc49fcbe2015-02-05 23:37:34 -0500118 @decorators.skip_because(bug="1205344")
Chris Hoge7579c1a2015-02-26 14:12:15 -0800119 @test.idempotent_id('10fd234a-515c-41e5-b092-8323060598c5')
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -0700120 @testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
121 'Snapshotting is not available.')
Matthew Treinish2153ec02013-09-09 20:57:30 +0000122 @tempest.test.services('compute', 'network', 'volume', 'image')
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000123 def test_stamp_pattern(self):
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +0900124 # prepare for booting an instance
Matt Riedemannfd5657d2015-09-30 14:47:07 -0700125 keypair = self.create_keypair()
126 security_group = self._create_security_group()
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000127
128 # boot an instance and create a timestamp file in it
129 volume = self._create_volume()
lanoux5fc14522015-09-21 08:17:35 +0000130 server = self.create_server(
131 image_id=CONF.compute.image_ref,
132 key_name=keypair['name'],
133 security_groups=security_group,
134 wait_until='ACTIVE')
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000135
136 # create and add floating IP to server1
Alexander Gubanovc8829f82015-11-12 10:35:13 +0200137 ip_for_server = self.get_server_or_ip(server)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000138
139 self._attach_volume(server, volume)
Matt Riedemannfd5657d2015-09-30 14:47:07 -0700140 self._wait_for_volume_available_on_the_system(ip_for_server,
141 keypair['private_key'])
Alexander Gubanovabd154c2015-09-23 23:24:06 +0300142 timestamp = self.create_timestamp(ip_for_server,
Matt Riedemannfd5657d2015-09-30 14:47:07 -0700143 CONF.compute.volume_device_name,
144 private_key=keypair['private_key'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000145 self._detach_volume(server, volume)
146
147 # snapshot the volume
148 volume_snapshot = self._create_volume_snapshot(volume)
149
150 # snapshot the instance
Ken'ichi Ohmichia4912232013-08-26 14:03:25 +0900151 snapshot_image = self.create_server_snapshot(server=server)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000152
153 # create second volume from the snapshot(volume2)
154 volume_from_snapshot = self._create_volume(
Andrea Frittolic0651b22014-09-17 16:34:01 +0100155 snapshot_id=volume_snapshot['id'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000156
157 # boot second instance from the snapshot(instance2)
lanoux5fc14522015-09-21 08:17:35 +0000158 server_from_snapshot = self.create_server(
159 image_id=snapshot_image['id'],
160 key_name=keypair['name'],
161 security_groups=security_group)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000162
163 # create and add floating IP to server_from_snapshot
Alexander Gubanovc8829f82015-11-12 10:35:13 +0200164 ip_for_snapshot = self.get_server_or_ip(server_from_snapshot)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000165
166 # attach volume2 to instance2
167 self._attach_volume(server_from_snapshot, volume_from_snapshot)
Matt Riedemannfd5657d2015-09-30 14:47:07 -0700168 self._wait_for_volume_available_on_the_system(ip_for_snapshot,
169 keypair['private_key'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000170
171 # check the existence of the timestamp file in the volume2
Alexander Gubanovabd154c2015-09-23 23:24:06 +0300172 timestamp2 = self.get_timestamp(ip_for_snapshot,
Matt Riedemannfd5657d2015-09-30 14:47:07 -0700173 CONF.compute.volume_device_name,
174 private_key=keypair['private_key'])
Alexander Gubanovabd154c2015-09-23 23:24:06 +0300175 self.assertEqual(timestamp, timestamp2)