debian: auto-upgrade stx.conf on pod restart
This patch adds any missing keys to stx.conf while restarting pods via stx-init-env. This should minimize disruption to developers when new keys are added to the reference file, stx.conf.sample. TESTS ======================== - Remove some required keys from stx.conf, then run stx-init-env and make sure they get re-added Story: 2009897 Task: 45179 Signed-off-by: Davlet Panech <davlet.panech@windriver.com> Change-Id: Ifbed10e01dc2e5653b827274a556f6dad166f1d8
This commit is contained in:
parent
4a906920df
commit
0ed3e55da6
@ -271,6 +271,7 @@ fi
|
||||
# Restart pods
|
||||
notice "Restarting pods"
|
||||
stx control stop || exit 1
|
||||
stx config --upgrade || exit 1
|
||||
stx control start || exit 1
|
||||
|
||||
notice "Run 'stx control status' to check the pod startup status"
|
||||
|
@ -124,6 +124,23 @@ class STXConfigParser:
|
||||
def syncConfigFile(self):
|
||||
self.cf.write(open(self.configpath, "w"))
|
||||
|
||||
def upgradeConfigFile(self):
|
||||
ref_config_path = os.path.join(os.environ['PRJDIR'], "stx.conf.sample")
|
||||
ref_config = configparser.ConfigParser()
|
||||
ref_config.read(ref_config_path, encoding="utf-8")
|
||||
for section_name, data in ref_config.items():
|
||||
if section_name == 'DEFAULT':
|
||||
ref_options = ref_config.defaults()
|
||||
else:
|
||||
ref_options = ref_config.options(section_name)
|
||||
if not self.cf.has_section(section_name):
|
||||
self.cf.add_section(section_name)
|
||||
for key in ref_options:
|
||||
value = ref_config.get(section_name, key, raw=True)
|
||||
if not self.cf.has_option(section_name, key):
|
||||
self.cf.set(section_name, key, value)
|
||||
self.syncConfigFile()
|
||||
|
||||
|
||||
class HandleConfigTask:
|
||||
'''Handle the task for the config sub-command'''
|
||||
@ -188,5 +205,8 @@ class HandleConfigTask:
|
||||
elif args.show is True:
|
||||
self.handleShow()
|
||||
|
||||
elif args.upgrade:
|
||||
self.stxconfig.upgradeConfigFile()
|
||||
|
||||
else:
|
||||
print(helper.help_config())
|
||||
|
@ -69,7 +69,7 @@ task.\t\teg: [start|enter|stop|status|upgrade]')
|
||||
|
||||
config_subparser = subparsers.add_parser('config',
|
||||
help='Change stx config \
|
||||
settings.\t\teg: [ --show|--get|--add|--unset|--remove-section ]')
|
||||
settings.\t\teg: [ --show|--get|--add|--unset|--remove-section|--upgrade ]')
|
||||
config_subparser.add_argument('--show',
|
||||
help='Show all the content of the config\
|
||||
file\n\n', action='store_true')
|
||||
@ -89,6 +89,9 @@ settings.\t\teg: [ --show|--get|--add|--unset|--remove-section ]')
|
||||
help='Remove the section from the \
|
||||
config file.\n\n', nargs=1,
|
||||
required=False)
|
||||
config_subparser.add_argument('--upgrade',
|
||||
help='Upgrade stx.conf',
|
||||
action='store_true')
|
||||
config_subparser.set_defaults(handle=self.handleconfig.handleConfig)
|
||||
|
||||
build_subparser = subparsers.add_parser('build',
|
||||
|
Loading…
x
Reference in New Issue
Block a user