blob: 0f2c78c974a15d748df14f6630fe7a26795fc0f7 [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
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070019import testtools
Sean Daguefe8a6092013-07-27 08:15:55 -040020
Fei Long Wangd39431f2015-05-14 11:30:48 +120021from tempest.common.utils import data_utils
Yaroslav Lobankoved3a35b2016-03-24 22:41:30 -050022from tempest.common import waiters
Matthew Treinish6c072292014-01-29 19:15:52 +000023from tempest import config
Jordan Pittier35a63752016-08-30 13:09:12 +020024from tempest.lib.common.utils import test_utils
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050025from tempest.lib import decorators
26from tempest.lib import exceptions as lib_exc
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000027from tempest.scenario import manager
Chris Hoge7579c1a2015-02-26 14:12:15 -080028from tempest import test
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000029
Matthew Treinish6c072292014-01-29 19:15:52 +000030CONF = config.CONF
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000031LOG = logging.getLogger(__name__)
32
33
Andrea Frittolic0651b22014-09-17 16:34:01 +010034class TestStampPattern(manager.ScenarioTest):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000035 """The test suite for both snapshoting and attaching of volume
36
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000037 This test is for snapshotting an instance/volume and attaching the volume
38 created from snapshot to the instance booted from snapshot.
39 The following is the scenario outline:
40 1. Boot an instance "instance1"
41 2. Create a volume "volume1"
42 3. Attach volume1 to instance1
43 4. Create a filesystem on volume1
44 5. Mount volume1
45 6. Create a file which timestamp is written in volume1
46 7. Unmount volume1
47 8. Detach volume1 from instance1
48 9. Get a snapshot "snapshot_from_volume" of volume1
49 10. Get a snapshot "snapshot_from_instance" of instance1
50 11. Boot an instance "instance2" from snapshot_from_instance
51 12. Create a volume "volume2" from snapshot_from_volume
52 13. Attach volume2 to instance2
53 14. Check the existence of a file which created at 6. in volume2
54 """
55
JordanPbce55532014-03-19 12:10:32 +010056 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000057 def skip_checks(cls):
58 super(TestStampPattern, cls).skip_checks()
JordanPbce55532014-03-19 12:10:32 +010059 if not CONF.volume_feature_enabled.snapshot:
60 raise cls.skipException("Cinder volume snapshots are disabled")
61
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000062 def _create_volume_snapshot(self, volume):
Ken'ichi Ohmichi6ded8df2015-03-23 02:00:19 +000063 snapshot_name = data_utils.rand_name('scenario-snapshot')
Matt Riedemannfd5657d2015-09-30 14:47:07 -070064 snapshot = self.snapshots_client.create_snapshot(
Ghanshyam0b75b632015-12-11 15:08:28 +090065 volume_id=volume['id'], display_name=snapshot_name)['snapshot']
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000066
67 def cleaner():
Andrea Frittolic0651b22014-09-17 16:34:01 +010068 self.snapshots_client.delete_snapshot(snapshot['id'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000069 try:
John Warrenff7faf62015-08-17 16:59:06 +000070 while self.snapshots_client.show_snapshot(
Yaroslav Lobankov667aaa22016-03-24 23:13:28 -050071 snapshot['id'])['snapshot']:
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000072 time.sleep(1)
Masayuki Igawabfa07602015-01-20 18:47:17 +090073 except lib_exc.NotFound:
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000074 pass
75 self.addCleanup(cleaner)
Yaroslav Lobankoved3a35b2016-03-24 22:41:30 -050076 waiters.wait_for_volume_status(self.volumes_client,
77 volume['id'], 'available')
Yaroslav Lobankov667aaa22016-03-24 23:13:28 -050078 waiters.wait_for_snapshot_status(self.snapshots_client,
79 snapshot['id'], 'available')
Andrea Frittolic0651b22014-09-17 16:34:01 +010080 self.assertEqual(snapshot_name, snapshot['display_name'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000081 return snapshot
82
Sean Dague20e98612016-01-06 14:33:28 -050083 def _wait_for_volume_available_on_the_system(self, ip_address,
Matt Riedemannfd5657d2015-09-30 14:47:07 -070084 private_key):
Sean Dague20e98612016-01-06 14:33:28 -050085 ssh = self.get_remote_client(ip_address, private_key=private_key)
Attila Fazekas70431ba2013-07-26 18:47:37 +020086
87 def _func():
88 part = ssh.get_partitions()
89 LOG.debug("Partitions:%s" % part)
Alexander Gubanove0634ab2015-05-25 10:28:25 +030090 return CONF.compute.volume_device_name in part
Attila Fazekas70431ba2013-07-26 18:47:37 +020091
Jordan Pittier35a63752016-08-30 13:09:12 +020092 if not test_utils.call_until_true(_func,
93 CONF.compute.build_timeout,
94 CONF.compute.build_interval):
guo yunxianebb15f22016-11-01 21:03:35 +080095 raise lib_exc.TimeoutException
Attila Fazekas70431ba2013-07-26 18:47:37 +020096
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050097 @decorators.skip_because(bug="1205344")
Chris Hoge7579c1a2015-02-26 14:12:15 -080098 @test.idempotent_id('10fd234a-515c-41e5-b092-8323060598c5')
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070099 @testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
100 'Snapshotting is not available.')
Alexander Gubanovea75ca92016-01-26 13:43:13 +0200101 @test.services('compute', 'network', 'volume', 'image')
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000102 def test_stamp_pattern(self):
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +0900103 # prepare for booting an instance
Matt Riedemannfd5657d2015-09-30 14:47:07 -0700104 keypair = self.create_keypair()
105 security_group = self._create_security_group()
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000106
107 # boot an instance and create a timestamp file in it
Jordan Pittierbbb17122016-01-26 17:10:55 +0100108 volume = self.create_volume()
lanoux5fc14522015-09-21 08:17:35 +0000109 server = self.create_server(
110 image_id=CONF.compute.image_ref,
111 key_name=keypair['name'],
112 security_groups=security_group,
113 wait_until='ACTIVE')
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000114
115 # create and add floating IP to server1
Sean Dague20e98612016-01-06 14:33:28 -0500116 ip_for_server = self.get_server_ip(server)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000117
Jordan Pittierbbb17122016-01-26 17:10:55 +0100118 self.nova_volume_attach(server, volume)
Matt Riedemannfd5657d2015-09-30 14:47:07 -0700119 self._wait_for_volume_available_on_the_system(ip_for_server,
120 keypair['private_key'])
Alexander Gubanovabd154c2015-09-23 23:24:06 +0300121 timestamp = self.create_timestamp(ip_for_server,
Matt Riedemannfd5657d2015-09-30 14:47:07 -0700122 CONF.compute.volume_device_name,
123 private_key=keypair['private_key'])
Jordan Pittierbbb17122016-01-26 17:10:55 +0100124 self.nova_volume_detach(server, volume)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000125
126 # snapshot the volume
127 volume_snapshot = self._create_volume_snapshot(volume)
128
129 # snapshot the instance
Ken'ichi Ohmichia4912232013-08-26 14:03:25 +0900130 snapshot_image = self.create_server_snapshot(server=server)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000131
132 # create second volume from the snapshot(volume2)
Jordan Pittierbbb17122016-01-26 17:10:55 +0100133 volume_from_snapshot = self.create_volume(
Andrea Frittolic0651b22014-09-17 16:34:01 +0100134 snapshot_id=volume_snapshot['id'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000135
136 # boot second instance from the snapshot(instance2)
lanoux5fc14522015-09-21 08:17:35 +0000137 server_from_snapshot = self.create_server(
138 image_id=snapshot_image['id'],
139 key_name=keypair['name'],
140 security_groups=security_group)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000141
142 # create and add floating IP to server_from_snapshot
Sean Dague20e98612016-01-06 14:33:28 -0500143 ip_for_snapshot = self.get_server_ip(server_from_snapshot)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000144
145 # attach volume2 to instance2
Jordan Pittierbbb17122016-01-26 17:10:55 +0100146 self.nova_volume_attach(server_from_snapshot, volume_from_snapshot)
Matt Riedemannfd5657d2015-09-30 14:47:07 -0700147 self._wait_for_volume_available_on_the_system(ip_for_snapshot,
148 keypair['private_key'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000149
150 # check the existence of the timestamp file in the volume2
Alexander Gubanovabd154c2015-09-23 23:24:06 +0300151 timestamp2 = self.get_timestamp(ip_for_snapshot,
Matt Riedemannfd5657d2015-09-30 14:47:07 -0700152 CONF.compute.volume_device_name,
153 private_key=keypair['private_key'])
Alexander Gubanovabd154c2015-09-23 23:24:06 +0300154 self.assertEqual(timestamp, timestamp2)