Fix backup/restore file name for ephemeral heat

We seem to be using different name when restoring.

Change-Id: I2638192fb8e4aeb8b22f054bd65690261fc4ccfa
This commit is contained in:
ramishra 2021-05-31 14:16:05 +05:30
parent 7adcd64952
commit 899f86285f
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 return True
def tar_file(self, file_path, cleanup=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 = tarfile.open(tf_name, 'w:bz2')
tf.add(file_path, os.path.basename(file_path)) tf.add(file_path, os.path.basename(file_path))
tf.close() tf.close()
@ -530,18 +531,18 @@ class HeatPodLauncher(HeatContainerLauncher):
def do_restore_db(self, db_dump_path=None): def do_restore_db(self, db_dump_path=None):
if not db_dump_path: if not db_dump_path:
db_dump_path = self.db_dump_path
# Find the latest dump from self.heat_dir # Find the latest dump from self.heat_dir
db_dumps = glob.glob( db_dumps = glob.glob(
'{}/heat-db-dump*{}'.format '{}-*{}'.format
(self.heat_dir, (db_dump_path,
self.zipped_db_suffix)) self.zipped_db_suffix))
if not db_dumps: if not db_dumps:
raise Exception('No db backups found to restore in %s' % raise Exception('No db backups found to restore in %s' %
self.heat_dir) self.heat_dir)
db_dump_path = max(db_dumps, key=os.path.getmtime) db_dump = max(db_dumps, key=os.path.getmtime)
self.untar_file(db_dump_path, self.heat_dir) self.untar_file(db_dump, self.heat_dir)
db_dump_path = db_dump_path.rstrip(self.zipped_db_suffix) log.info("Restoring db from {}".format(db_dump))
log.info("Restoring db from {}".format(db_dump_path))
try: try:
with open(db_dump_path) as f: with open(db_dump_path) as f:
subprocess.run([ subprocess.run([

View File

@ -188,9 +188,9 @@ class TestHeatPodLauncher(base.TestCase):
launcher.do_restore_db() launcher.do_restore_db()
self.assertEqual(mock.call(str(three), launcher.heat_dir), self.assertEqual(mock.call(str(three), launcher.heat_dir),
mock_untar.call_args) 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_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)) self.assertTrue(self.check_call('mysql heat', self.run))
mock_unlink.reset_mock() mock_unlink.reset_mock()
@ -202,9 +202,9 @@ class TestHeatPodLauncher(base.TestCase):
launcher.do_restore_db() launcher.do_restore_db()
self.assertEqual(mock.call(str(two), launcher.heat_dir), self.assertEqual(mock.call(str(two), launcher.heat_dir),
mock_untar.call_args) 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_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)) self.assertTrue(self.check_call('mysql heat', self.run))
@mock.patch('tripleoclient.heat_launcher.HeatPodLauncher.tar_file') @mock.patch('tripleoclient.heat_launcher.HeatPodLauncher.tar_file')