From 137520ea2d95215823bc535d3b2bcdf96125c515 Mon Sep 17 00:00:00 2001 From: yangyapeng Date: Fri, 13 May 2016 07:10:46 +0000 Subject: [PATCH] Restore cindernative-vol-id by increment Because backup cinder by cinder_backup, volume.create_at is format of datetime,but from_date_time is timestamp. When restore cindernative-vol-id, it it restore the oldest backup, but incremental backup, always. Add when restore_from_date is greater than the newest backup, it shoud restore cinder by newest incremental backup. Closes-Bug: #1581330 Change-Id: Id4fd9888a6282861e15dd868c3fee1f11d5fdc73 --- freezer/openstack/restore.py | 12 ++++++++---- freezer/tests/commons.py | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/freezer/openstack/restore.py b/freezer/openstack/restore.py index e6763e14..fc04018b 100644 --- a/freezer/openstack/restore.py +++ b/freezer/openstack/restore.py @@ -83,11 +83,15 @@ class RestoreOs: 'status': 'available', } backups = cinder.backups.list(search_opts=search_opts) - backups = [x for x in backups if x.created_at >= restore_from_timestamp] - if not backups: - logging.error("no available backups for cinder volume") + backups_filter = [x for x in backups if (utils.date_to_timestamp(x.created_at.split('.')[0]) + >= restore_from_timestamp)] + if not backups_filter: + logging.warning("no available backups for cinder volume," + "restore newest backup") + backup = max(backups, key=lambda x: x.created_at) + cinder.restores.restore(backup_id=backup.id) else: - backup = min(backups, key=lambda x: x.created_at) + backup = min(backups_filter, key=lambda x: x.created_at) cinder.restores.restore(backup_id=backup.id) def restore_cinder_by_glance(self, volume_id, restore_from_timestamp): diff --git a/freezer/tests/commons.py b/freezer/tests/commons.py index 9a68c016..253d6c99 100644 --- a/freezer/tests/commons.py +++ b/freezer/tests/commons.py @@ -113,7 +113,7 @@ class FakeIdObject: self.status = "available" self.size = 10 self.min_disk = 10 - self.created_at = 1234 + self.created_at = '2016-05-12T02:00:22.000000' class FakeCinderClient: