Browse Source

Merge "Fix backup/restore file name for ephemeral heat" into stable/wallaby

changes/31/795431/1
Zuul 4 months ago
committed by Gerrit Code Review
parent
commit
48e5e285e8
  1. 15
      tripleoclient/heat_launcher.py
  2. 8
      tripleoclient/tests/test_heat_launcher.py

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

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

Loading…
Cancel
Save