From 899f86285f58da280a226f653fe74f7bb1c3f76f Mon Sep 17 00:00:00 2001 From: ramishra Date: Mon, 31 May 2021 14:16:05 +0530 Subject: [PATCH] Fix backup/restore file name for ephemeral heat We seem to be using different name when restoring. Change-Id: I2638192fb8e4aeb8b22f054bd65690261fc4ccfa --- tripleoclient/heat_launcher.py | 15 ++++++++------- tripleoclient/tests/test_heat_launcher.py | 8 ++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tripleoclient/heat_launcher.py b/tripleoclient/heat_launcher.py index a15cfcec2..c3006ab7c 100644 --- a/tripleoclient/heat_launcher.py +++ b/tripleoclient/heat_launcher.py @@ -313,7 +313,8 @@ heat.filter_factory = heat.api.openstack:faultwrap_filter return True def tar_file(self, file_path, cleanup=True): - tf_name = '{}-{}.tar.bzip2'.format(file_path, self.timestamp) + tf_name = '{}-{}{}'.format(file_path, self.timestamp, + self.zipped_db_suffix) tf = tarfile.open(tf_name, 'w:bz2') tf.add(file_path, os.path.basename(file_path)) tf.close() @@ -530,18 +531,18 @@ class HeatPodLauncher(HeatContainerLauncher): def do_restore_db(self, db_dump_path=None): if not db_dump_path: + db_dump_path = self.db_dump_path # Find the latest dump from self.heat_dir db_dumps = glob.glob( - '{}/heat-db-dump*{}'.format - (self.heat_dir, + '{}-*{}'.format + (db_dump_path, self.zipped_db_suffix)) if not db_dumps: raise Exception('No db backups found to restore in %s' % self.heat_dir) - db_dump_path = max(db_dumps, key=os.path.getmtime) - self.untar_file(db_dump_path, self.heat_dir) - db_dump_path = db_dump_path.rstrip(self.zipped_db_suffix) - log.info("Restoring db from {}".format(db_dump_path)) + db_dump = max(db_dumps, key=os.path.getmtime) + self.untar_file(db_dump, self.heat_dir) + log.info("Restoring db from {}".format(db_dump)) try: with open(db_dump_path) as f: subprocess.run([ diff --git a/tripleoclient/tests/test_heat_launcher.py b/tripleoclient/tests/test_heat_launcher.py index 19b7addfc..144d3a00f 100644 --- a/tripleoclient/tests/test_heat_launcher.py +++ b/tripleoclient/tests/test_heat_launcher.py @@ -188,9 +188,9 @@ class TestHeatPodLauncher(base.TestCase): launcher.do_restore_db() self.assertEqual(mock.call(str(three), launcher.heat_dir), mock_untar.call_args) - self.assertEqual(mock.call(str(three).rstrip('.tar.bz2')), + self.assertEqual(mock.call(launcher.heat_dir + '/heat-db.sql'), mock_unlink.call_args) - mock_open.assert_called_with(str(three).rstrip('.tar.bz2')) # noqa + mock_open.assert_called_with(launcher.heat_dir + '/heat-db.sql') # noqa self.assertTrue(self.check_call('mysql heat', self.run)) mock_unlink.reset_mock() @@ -202,9 +202,9 @@ class TestHeatPodLauncher(base.TestCase): launcher.do_restore_db() self.assertEqual(mock.call(str(two), launcher.heat_dir), mock_untar.call_args) - self.assertEqual(mock.call(str(two).rstrip('.tar.bz2')), # noqa + self.assertEqual(mock.call(launcher.heat_dir + '/heat-db.sql'), mock_unlink.call_args) - mock_open.assert_called_with(str(two).rstrip('.tar.bz2')) # noqa + mock_open.assert_called_with(launcher.heat_dir + '/heat-db.sql') # noqa self.assertTrue(self.check_call('mysql heat', self.run)) @mock.patch('tripleoclient.heat_launcher.HeatPodLauncher.tar_file')