From e7c7fa9be113af553e43a04cc1f372f6346e16b6 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Thu, 7 Sep 2023 13:31:45 -0500 Subject: [PATCH] config-mgmt: T5556: fix bug in revision to archive update (cherry picked from commit fd5517b38191f5bb5897912ef62f5a8d1156b7b3) --- python/vyos/config_mgmt.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/python/vyos/config_mgmt.py b/python/vyos/config_mgmt.py index 9caf6da2b93..dbf17ade425 100644 --- a/python/vyos/config_mgmt.py +++ b/python/vyos/config_mgmt.py @@ -25,6 +25,7 @@ from textwrap import dedent from pathlib import Path from tabulate import tabulate +from shutil import copy from vyos.config import Config from vyos.configtree import ConfigTree, ConfigTreeError, show_diff @@ -224,8 +225,6 @@ def revert(self) -> Tuple[str,int]: def rollback(self, rev: int, no_prompt: bool=False) -> Tuple[str,int]: """Reboot to config revision 'rev'. """ - from shutil import copy - msg = '' if not self._check_revision_number(rev): @@ -475,20 +474,20 @@ def _add_logrotate_conf(self): conf_file.chmod(0o644) def _archive_active_config(self) -> bool: - use_tmp = (boot_configuration_complete() or not - os.path.isfile(archive_config_file)) + save_to_tmp = (boot_configuration_complete() or not + os.path.isfile(archive_config_file)) mask = os.umask(0o113) - if use_tmp: - ext = os.getpid() - cmp_saved = f'/tmp/config.boot.{ext}' + ext = os.getpid() + cmp_saved = f'/tmp/config.boot.{ext}' + if save_to_tmp: save_config(cmp_saved) else: - cmp_saved = config_file + copy(config_file, cmp_saved) try: if cmp(cmp_saved, archive_config_file, shallow=False): - if use_tmp: os.unlink(cmp_saved) + os.unlink(cmp_saved) os.umask(mask) return False except FileNotFoundError: