Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 1 | # 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 | |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 16 | import testtools |
| 17 | |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 18 | from tempest.common import utils |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 19 | from tempest import config |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 20 | from tempest.lib import decorators |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 21 | from tempest.scenario import manager |
| 22 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 23 | CONF = config.CONF |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 24 | |
Nachi Ueno | 95b4128 | 2014-01-15 06:54:21 -0800 | [diff] [blame] | 25 | |
nithya-ganesan | 882595e | 2014-07-29 18:51:07 +0000 | [diff] [blame] | 26 | class TestSnapshotPattern(manager.ScenarioTest): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 27 | """This test is for snapshotting an instance and booting with it. |
| 28 | |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 29 | The following is the scenario outline: |
Takashi NATSUME | 6d5a2b4 | 2015-09-08 11:27:49 +0900 | [diff] [blame] | 30 | * boot an instance and create a timestamp file in it |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 31 | * snapshot the instance |
Archit Modi | 2c8e8ae | 2020-05-21 16:31:41 +0000 | [diff] [blame] | 32 | * add version metadata to the snapshot image |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 33 | * boot a second instance from the snapshot |
| 34 | * check the existence of the timestamp file in the second instance |
Archit Modi | 2c8e8ae | 2020-05-21 16:31:41 +0000 | [diff] [blame] | 35 | * snapshot the instance again |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 36 | |
| 37 | """ |
| 38 | |
guo yunxian | 13b456a | 2016-07-25 11:19:36 +0800 | [diff] [blame] | 39 | @classmethod |
| 40 | def skip_checks(cls): |
| 41 | super(TestSnapshotPattern, cls).skip_checks() |
| 42 | if not CONF.compute_feature_enabled.snapshot: |
| 43 | raise cls.skipException("Snapshotting is not available.") |
| 44 | |
Ken'ichi Ohmichi | c85a951 | 2017-01-27 18:34:24 -0800 | [diff] [blame] | 45 | @decorators.idempotent_id('608e604b-1d63-4a82-8e3e-91bc665c90b4') |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 46 | @decorators.attr(type='slow') |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 47 | @testtools.skipUnless(CONF.network.public_network_id, |
| 48 | 'The public_network_id option must be specified.') |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 49 | @utils.services('compute', 'network', 'image') |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 50 | def test_snapshot_pattern(self): |
Takashi NATSUME | 6d5a2b4 | 2015-09-08 11:27:49 +0900 | [diff] [blame] | 51 | # prepare for booting an instance |
Matt Riedemann | c5bb766 | 2015-09-30 14:57:22 -0700 | [diff] [blame] | 52 | keypair = self.create_keypair() |
Soniya Vyas | 582c170 | 2021-02-22 18:26:17 +0530 | [diff] [blame] | 53 | security_group = self.create_security_group() |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 54 | |
Takashi NATSUME | 6d5a2b4 | 2015-09-08 11:27:49 +0900 | [diff] [blame] | 55 | # boot an instance and create a timestamp file in it |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 56 | server = self.create_server( |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 57 | key_name=keypair['name'], |
zhufl | 13c9c89 | 2017-02-10 12:04:07 +0800 | [diff] [blame] | 58 | security_groups=[{'name': security_group['name']}]) |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 59 | |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 60 | instance_ip = self.get_server_ip(server) |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 61 | timestamp = self.create_timestamp(instance_ip, |
Slawek Kaplonski | 79d8b0f | 2018-07-30 22:43:41 +0200 | [diff] [blame] | 62 | private_key=keypair['private_key'], |
| 63 | server=server) |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 64 | |
| 65 | # snapshot the instance |
Ken'ichi Ohmichi | a491223 | 2013-08-26 14:03:25 +0900 | [diff] [blame] | 66 | snapshot_image = self.create_server_snapshot(server=server) |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 67 | |
Archit Modi | 2c8e8ae | 2020-05-21 16:31:41 +0000 | [diff] [blame] | 68 | # add version metadata to the snapshot image |
| 69 | self.image_client.update_image( |
| 70 | snapshot_image['id'], [dict(add='/version', |
| 71 | value='8.0')]) |
| 72 | |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 73 | # boot a second instance from the snapshot |
lanoux | 5fc1452 | 2015-09-21 08:17:35 +0000 | [diff] [blame] | 74 | server_from_snapshot = self.create_server( |
| 75 | image_id=snapshot_image['id'], |
| 76 | key_name=keypair['name'], |
zhufl | 13c9c89 | 2017-02-10 12:04:07 +0800 | [diff] [blame] | 77 | security_groups=[{'name': security_group['name']}]) |
Masayuki Igawa | a6de155 | 2013-06-18 17:08:24 +0900 | [diff] [blame] | 78 | |
| 79 | # check the existence of the timestamp file in the second instance |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 80 | server_from_snapshot_ip = self.get_server_ip(server_from_snapshot) |
Alexander Gubanov | c8829f8 | 2015-11-12 10:35:13 +0200 | [diff] [blame] | 81 | timestamp2 = self.get_timestamp(server_from_snapshot_ip, |
Slawek Kaplonski | 79d8b0f | 2018-07-30 22:43:41 +0200 | [diff] [blame] | 82 | private_key=keypair['private_key'], |
| 83 | server=server_from_snapshot) |
Alexander Gubanov | abd154c | 2015-09-23 23:24:06 +0300 | [diff] [blame] | 84 | self.assertEqual(timestamp, timestamp2) |
Archit Modi | 2c8e8ae | 2020-05-21 16:31:41 +0000 | [diff] [blame] | 85 | |
| 86 | # snapshot the instance again |
| 87 | self.create_server_snapshot(server=server_from_snapshot) |