Merge "debian: auto-upgrade stx.conf on pod restart"

This commit is contained in:
Zuul 2022-04-26 21:15:31 +00:00 committed by Gerrit Code Review
commit eb148e3f35
3 changed files with 25 additions and 1 deletions

View File

@ -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"

View File

@ -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())

View File

@ -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',