blob: 2782119d8c10e1fa9d651ceac6cc3256a4830f2f [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016from oslo_log import log as logging
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070017import testtools
Sean Daguefe8a6092013-07-27 08:15:55 -040018
Andrea Frittolicd368412017-08-14 21:37:56 +010019from tempest.common import utils
Matthew Treinish6c072292014-01-29 19:15:52 +000020from tempest import config
Jordan Pittier35a63752016-08-30 13:09:12 +020021from tempest.lib.common.utils import test_utils
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050022from tempest.lib import decorators
23from tempest.lib import exceptions as lib_exc
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000024from tempest.scenario import manager
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000025
Matthew Treinish6c072292014-01-29 19:15:52 +000026CONF = config.CONF
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000027LOG = logging.getLogger(__name__)
28
29
Andrea Frittolic0651b22014-09-17 16:34:01 +010030class TestStampPattern(manager.ScenarioTest):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000031 """The test suite for both snapshoting and attaching of volume
32
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000033 This test is for snapshotting an instance/volume and attaching the volume
34 created from snapshot to the instance booted from snapshot.
35 The following is the scenario outline:
36 1. Boot an instance "instance1"
37 2. Create a volume "volume1"
38 3. Attach volume1 to instance1
39 4. Create a filesystem on volume1
40 5. Mount volume1
41 6. Create a file which timestamp is written in volume1
42 7. Unmount volume1
43 8. Detach volume1 from instance1
44 9. Get a snapshot "snapshot_from_volume" of volume1
45 10. Get a snapshot "snapshot_from_instance" of instance1
46 11. Boot an instance "instance2" from snapshot_from_instance
47 12. Create a volume "volume2" from snapshot_from_volume
48 13. Attach volume2 to instance2
49 14. Check the existence of a file which created at 6. in volume2
50 """
51
JordanPbce55532014-03-19 12:10:32 +010052 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000053 def skip_checks(cls):
54 super(TestStampPattern, cls).skip_checks()
JordanPbce55532014-03-19 12:10:32 +010055 if not CONF.volume_feature_enabled.snapshot:
56 raise cls.skipException("Cinder volume snapshots are disabled")
57
Sean Dague20e98612016-01-06 14:33:28 -050058 def _wait_for_volume_available_on_the_system(self, ip_address,
Matt Riedemannfd5657d2015-09-30 14:47:07 -070059 private_key):
Sean Dague20e98612016-01-06 14:33:28 -050060 ssh = self.get_remote_client(ip_address, private_key=private_key)
Attila Fazekas70431ba2013-07-26 18:47:37 +020061
62 def _func():
Evgeny Antyshev4894a912016-11-21 12:17:18 +000063 disks = ssh.get_disks()
Jordan Pittier525ec712016-12-07 17:51:26 +010064 LOG.debug("Disks: %s", disks)
Evgeny Antyshev4894a912016-11-21 12:17:18 +000065 return CONF.compute.volume_device_name in disks
Attila Fazekas70431ba2013-07-26 18:47:37 +020066
Jordan Pittier35a63752016-08-30 13:09:12 +020067 if not test_utils.call_until_true(_func,
68 CONF.compute.build_timeout,
69 CONF.compute.build_interval):
guo yunxianebb15f22016-11-01 21:03:35 +080070 raise lib_exc.TimeoutException
Attila Fazekas70431ba2013-07-26 18:47:37 +020071
Jordan Pittier3b46d272017-04-12 16:17:28 +020072 @decorators.attr(type='slow')
zhufl758b7672017-02-23 10:37:50 +080073 @decorators.skip_because(bug="1664793")
Ken'ichi Ohmichic85a9512017-01-27 18:34:24 -080074 @decorators.idempotent_id('10fd234a-515c-41e5-b092-8323060598c5')
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070075 @testtools.skipUnless(CONF.compute_feature_enabled.snapshot,
76 'Snapshotting is not available.')
zhufl6b7040a2017-01-18 16:38:34 +080077 @testtools.skipUnless(CONF.network.public_network_id,
78 'The public_network_id option must be specified.')
Andrea Frittolicd368412017-08-14 21:37:56 +010079 @utils.services('compute', 'network', 'volume', 'image')
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000080 def test_stamp_pattern(self):
Takashi NATSUME6d5a2b42015-09-08 11:27:49 +090081 # prepare for booting an instance
Matt Riedemannfd5657d2015-09-30 14:47:07 -070082 keypair = self.create_keypair()
83 security_group = self._create_security_group()
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000084
85 # boot an instance and create a timestamp file in it
Jordan Pittierbbb17122016-01-26 17:10:55 +010086 volume = self.create_volume()
lanoux5fc14522015-09-21 08:17:35 +000087 server = self.create_server(
lanoux5fc14522015-09-21 08:17:35 +000088 key_name=keypair['name'],
zhufl96c36cf2017-02-10 09:51:57 +080089 security_groups=[{'name': security_group['name']}])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000090
91 # create and add floating IP to server1
Sean Dague20e98612016-01-06 14:33:28 -050092 ip_for_server = self.get_server_ip(server)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +000093
Jordan Pittierbbb17122016-01-26 17:10:55 +010094 self.nova_volume_attach(server, volume)
Matt Riedemannfd5657d2015-09-30 14:47:07 -070095 self._wait_for_volume_available_on_the_system(ip_for_server,
96 keypair['private_key'])
Alexander Gubanovabd154c2015-09-23 23:24:06 +030097 timestamp = self.create_timestamp(ip_for_server,
Matt Riedemannfd5657d2015-09-30 14:47:07 -070098 CONF.compute.volume_device_name,
Slawek Kaplonski79d8b0f2018-07-30 22:43:41 +020099 private_key=keypair['private_key'],
100 server=server)
Jordan Pittierbbb17122016-01-26 17:10:55 +0100101 self.nova_volume_detach(server, volume)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000102
103 # snapshot the volume
lkuchlan73ed1f32017-07-06 16:22:12 +0300104 volume_snapshot = self.create_volume_snapshot(volume['id'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000105
106 # snapshot the instance
Ken'ichi Ohmichia4912232013-08-26 14:03:25 +0900107 snapshot_image = self.create_server_snapshot(server=server)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000108
109 # create second volume from the snapshot(volume2)
Jordan Pittierbbb17122016-01-26 17:10:55 +0100110 volume_from_snapshot = self.create_volume(
Andrea Frittolic0651b22014-09-17 16:34:01 +0100111 snapshot_id=volume_snapshot['id'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000112
113 # boot second instance from the snapshot(instance2)
lanoux5fc14522015-09-21 08:17:35 +0000114 server_from_snapshot = self.create_server(
115 image_id=snapshot_image['id'],
116 key_name=keypair['name'],
zhufl96c36cf2017-02-10 09:51:57 +0800117 security_groups=[{'name': security_group['name']}])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000118
119 # create and add floating IP to server_from_snapshot
Sean Dague20e98612016-01-06 14:33:28 -0500120 ip_for_snapshot = self.get_server_ip(server_from_snapshot)
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000121
122 # attach volume2 to instance2
Jordan Pittierbbb17122016-01-26 17:10:55 +0100123 self.nova_volume_attach(server_from_snapshot, volume_from_snapshot)
Matt Riedemannfd5657d2015-09-30 14:47:07 -0700124 self._wait_for_volume_available_on_the_system(ip_for_snapshot,
125 keypair['private_key'])
Yuiko Takadaebcf6af2013-07-09 05:10:55 +0000126
127 # check the existence of the timestamp file in the volume2
Alexander Gubanovabd154c2015-09-23 23:24:06 +0300128 timestamp2 = self.get_timestamp(ip_for_snapshot,
Matt Riedemannfd5657d2015-09-30 14:47:07 -0700129 CONF.compute.volume_device_name,
Slawek Kaplonski79d8b0f2018-07-30 22:43:41 +0200130 private_key=keypair['private_key'],
131 server=server_from_snapshot)
Alexander Gubanovabd154c2015-09-23 23:24:06 +0300132 self.assertEqual(timestamp, timestamp2)