Merge "Fix backup/restore file name for ephemeral heat"

This commit is contained in:
Zuul 2021-06-06 21:07:41 +00:00 committed by Gerrit Code Review
commit 5f2c2cac4b
2 changed files with 12 additions and 11 deletions

View File

@ -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([

View File

@ -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')