From 667e968568564811a7dc09049f7a1e38cb879e91 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Tue, 5 Sep 2023 13:46:54 -0500 Subject: config-mgmt: T5353: only add log entry if archiving (cherry picked from commit 73e317bee57c03b719019daabd578842d912b761) --- python/vyos/config_mgmt.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'python') diff --git a/python/vyos/config_mgmt.py b/python/vyos/config_mgmt.py index 0fc72e660..996475eb8 100644 --- a/python/vyos/config_mgmt.py +++ b/python/vyos/config_mgmt.py @@ -200,9 +200,9 @@ Proceed ?''' raise ConfigMgmtError(out) entry = self._read_tmp_log_entry() - self._add_log_entry(**entry) if self._archive_active_config(): + self._add_log_entry(**entry) self._update_archive() msg = 'Reboot timer stopped' @@ -334,10 +334,10 @@ Proceed ?''' user = self._get_user() via = 'init' comment = '' - self._add_log_entry(user, via, comment) # add empty init config before boot-config load for revision # and diff consistency if self._archive_active_config(): + self._add_log_entry(user, via, comment) self._update_archive() os.umask(mask) @@ -352,9 +352,8 @@ Proceed ?''' self._new_log_entry(tmp_file=tmp_log_entry) return - self._add_log_entry() - if self._archive_active_config(): + self._add_log_entry() self._update_archive() def commit_archive(self): -- cgit v1.2.3 From c1a078e5e4dd5980715985958b494eca08651893 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Tue, 5 Sep 2023 13:47:10 -0500 Subject: config-mgmt: T5353: correct update check during boot (cherry picked from commit 730e744931e4ccc1f214d3e5bff0e6a2e589fd50) --- python/vyos/config_mgmt.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'python') diff --git a/python/vyos/config_mgmt.py b/python/vyos/config_mgmt.py index 996475eb8..9fad000e8 100644 --- a/python/vyos/config_mgmt.py +++ b/python/vyos/config_mgmt.py @@ -31,6 +31,7 @@ from vyos.configtree import ConfigTree, ConfigTreeError, show_diff from vyos.defaults import directories from vyos.version import get_full_version_data from vyos.utils.io import ask_yes_no +from vyos.utils.boot import boot_configuration_complete from vyos.utils.process import is_systemd_service_active from vyos.utils.process import rc_cmd @@ -474,22 +475,26 @@ Proceed ?''' conf_file.chmod(0o644) def _archive_active_config(self) -> bool: + use_tmp = (boot_configuration_complete() or not + os.path.isfile(archive_config_file)) mask = os.umask(0o113) - ext = os.getpid() - tmp_save = f'/tmp/config.boot.{ext}' - save_config(tmp_save) + if use_tmp: + ext = os.getpid() + cmp_saved = f'/tmp/config.boot.{ext}' + save_config(cmp_saved) + else: + cmp_saved = config_file try: - if cmp(tmp_save, archive_config_file, shallow=False): - # this will be the case on boot, as well as certain - # re-initialiation instances after delete/set - os.unlink(tmp_save) + if cmp(cmp_saved, archive_config_file, shallow=False): + if use_tmp: os.unlink(cmp_saved) + os.umask(mask) return False except FileNotFoundError: pass - rc, out = rc_cmd(f'sudo mv {tmp_save} {archive_config_file}') + rc, out = rc_cmd(f'sudo mv {cmp_saved} {archive_config_file}') os.umask(mask) if rc != 0: -- cgit v1.2.3 From c35a66f327b09686344c63db2da8634b55f18d79 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Tue, 5 Sep 2023 13:57:22 -0500 Subject: config-mgmt: T5353: after updated save-config, one can include init rev The legacy config-mgmt/save-config tools had an abiding bug that would raise an error if comparing/reading the init archive; this is no longer an issue. (cherry picked from commit 52e4b4431ef440f0cffb570ca61c428c78699ee6) --- python/vyos/config_mgmt.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'python') diff --git a/python/vyos/config_mgmt.py b/python/vyos/config_mgmt.py index 9fad000e8..9caf6da2b 100644 --- a/python/vyos/config_mgmt.py +++ b/python/vyos/config_mgmt.py @@ -526,9 +526,8 @@ Proceed ?''' return len(l) def _check_revision_number(self, rev: int) -> bool: - # exclude init revision: maxrev = self._get_number_of_revisions() - if not 0 <= rev < maxrev - 1: + if not 0 <= rev < maxrev: return False return True -- cgit v1.2.3 From d75a7d17a98b30fea1140675849d76dffe5c61f2 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Thu, 7 Sep 2023 13:31:45 -0500 Subject: 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(-) (limited to 'python') diff --git a/python/vyos/config_mgmt.py b/python/vyos/config_mgmt.py index 9caf6da2b..dbf17ade4 100644 --- a/python/vyos/config_mgmt.py +++ b/python/vyos/config_mgmt.py @@ -25,6 +25,7 @@ from datetime import datetime 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 @@ Proceed ?''' 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 @@ Proceed ?''' 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: -- cgit v1.2.3