From 73e317bee57c03b719019daabd578842d912b761 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 --- 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 730e744931e4ccc1f214d3e5bff0e6a2e589fd50 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 --- 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 52e4b4431ef440f0cffb570ca61c428c78699ee6 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. --- 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