summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Topp <andrewt@telekinetica.net>2024-06-19 09:48:45 +1000
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2024-06-21 02:48:25 +0000
commite5bb0529da6cd932878e4f2bde4025bc48a93f23 (patch)
treef0ec7d063d7dea17169cb58a9078ebed9e4857db
parent5d46c64a3041504a81e630790a88738300b232c1 (diff)
downloadvyos-1x-e5bb0529da6cd932878e4f2bde4025bc48a93f23.tar.gz
vyos-1x-e5bb0529da6cd932878e4f2bde4025bc48a93f23.zip
op-mode: T5514: Allow safe reboots to config defaults when config.boot is deleted
* Added flag to vyos.config_mgmt.unsaved_commits() that will tolerate missing config.boot for specific circumstances * Shutdown/reboot uses this flag; config will regenerate from defaults after a reboot (cherry picked from commit 8281383a09f12da20a1c9b4864b38ac3f541b48f)
-rw-r--r--python/vyos/config_mgmt.py4
-rwxr-xr-xsrc/op_mode/powerctrl.py2
2 files changed, 4 insertions, 2 deletions
diff --git a/python/vyos/config_mgmt.py b/python/vyos/config_mgmt.py
index 70b6ea203..d518737ca 100644
--- a/python/vyos/config_mgmt.py
+++ b/python/vyos/config_mgmt.py
@@ -81,9 +81,11 @@ def save_config(target, json_out=None):
if rc != 0:
logger.critical(f'save config failed: {out}')
-def unsaved_commits() -> bool:
+def unsaved_commits(allow_missing_config=False) -> bool:
if get_full_version_data()['boot_via'] == 'livecd':
return False
+ if allow_missing_config and not os.path.exists(config_file):
+ return True
tmp_save = '/tmp/config.running'
save_config(tmp_save)
ret = not cmp(tmp_save, config_file, shallow=False)
diff --git a/src/op_mode/powerctrl.py b/src/op_mode/powerctrl.py
index 6c8f802b5..cb4a175dd 100755
--- a/src/op_mode/powerctrl.py
+++ b/src/op_mode/powerctrl.py
@@ -110,7 +110,7 @@ def check_unsaved_config():
from vyos.config_mgmt import unsaved_commits
from vyos.utils.boot import boot_configuration_success
- if unsaved_commits() and boot_configuration_success():
+ if unsaved_commits(allow_missing_config=True) and boot_configuration_success():
print("Warning: there are unsaved configuration changes!")
print("Run 'save' command if you do not want to lose those changes after reboot/shutdown.")
else: