From 6a3938cbf595ea24d2d2e3802cf78a0519483339 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 26 Apr 2020 11:31:16 +0200 Subject: salt: T2384: migrate config options - delete log_file, log_level and user nodes - rename hash_type to hash - rename mine_interval to interval --- data/templates/salt-minion/minion.tmpl | 4 +-- interface-definitions/salt-minion.xml.in | 9 ++--- src/conf_mode/salt-minion.py | 10 +++--- src/migration-scripts/salt/0-to-1 | 58 ++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 14 deletions(-) create mode 100755 src/migration-scripts/salt/0-to-1 diff --git a/data/templates/salt-minion/minion.tmpl b/data/templates/salt-minion/minion.tmpl index 0b97c0524..9369573a4 100644 --- a/data/templates/salt-minion/minion.tmpl +++ b/data/templates/salt-minion/minion.tmpl @@ -12,7 +12,7 @@ # # Prior to changing this value, the master should be stopped and all Salt # caches should be cleared. -hash_type: {{ hash_type }} +hash_type: {{ hash }} ##### Logging settings ##### ########################################## @@ -54,6 +54,6 @@ id: {{ salt_id }} # The number of minutes between mine updates. -mine_interval: {{ mine_interval }} +mine_interval: {{ interval }} verify_master_pubkey_sign: {{ verify_master_pubkey_sign }} diff --git a/interface-definitions/salt-minion.xml.in b/interface-definitions/salt-minion.xml.in index 1c1dee2fb..d0e8e3e2b 100644 --- a/interface-definitions/salt-minion.xml.in +++ b/interface-definitions/salt-minion.xml.in @@ -8,7 +8,7 @@ 500 - + Hash used when discovering file on master server (default: sha256) @@ -43,12 +43,7 @@ Explicitly declare the id for this minion to use. - - - The user to run the Salt processes. - - - + The number of minutes between mine updates. diff --git a/src/conf_mode/salt-minion.py b/src/conf_mode/salt-minion.py index d3412b7ef..515019014 100755 --- a/src/conf_mode/salt-minion.py +++ b/src/conf_mode/salt-minion.py @@ -30,7 +30,7 @@ config_file = r'/etc/salt/minion' master_keyfile = r'/opt/vyatta/etc/config/salt/pki/minion/master_sign.pub' default_config_data = { - 'hash_type': 'sha256', + 'hash': 'sha256', 'log_level': 'warning', 'master' : 'salt', 'user': 'nobody', @@ -51,8 +51,8 @@ def get_config(): else: conf.set_level(base) - if conf.exists(['hash_type']): - salt['hash_type'] = conf.return_value(['hash_type']) + if conf.exists(['hash']): + salt['hash'] = conf.return_value(['hash']) if conf.exists(['master']): salt['master'] = conf.return_values(['master']) @@ -63,8 +63,8 @@ def get_config(): if conf.exists(['user']): salt['user'] = conf.return_value(['user']) - if conf.exists(['mine_interval']): - salt['mine_interval'] = conf.return_value(['mine_interval']) + if conf.exists(['interval']): + salt['interval'] = conf.return_value(['interval']) if conf.exists(['master-key']): salt['master_key'] = conf.return_value(['master-key']) diff --git a/src/migration-scripts/salt/0-to-1 b/src/migration-scripts/salt/0-to-1 new file mode 100755 index 000000000..79053c056 --- /dev/null +++ b/src/migration-scripts/salt/0-to-1 @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Delete log_file, log_level and user nodes +# rename hash_type to hash +# rename mine_interval to interval + +from sys import argv,exit + +from vyos.configtree import ConfigTree + +if (len(argv) < 1): + print("Must specify file name!") + exit(1) + +file_name = argv[1] + +with open(file_name, 'r') as f: + config_file = f.read() + +config = ConfigTree(config_file) + +base = ['service', 'salt-minion'] +if not config.exists(base): + # Nothing to do + exit(0) +else: + + # delete nodes which are now populated with sane defaults + for node in ['log_file', 'log_level', 'user']: + if config.exists(base + [node]): + config.delete(base + [node]) + + if config.exists(base + ['hash_type']): + config.rename(base + ['hash_type'], 'hash') + + if config.exists(base + ['mine_interval']): + config.rename(base + ['mine_interval'], 'interval') + + try: + with open(file_name, 'w') as f: + f.write(config.to_string()) + except OSError as e: + print("Failed to save the modified config: {}".format(e)) + exit(1) -- cgit v1.2.3