Skip to content

Commit 86783e8

Browse files
pehalasoyacz
authored andcommitted
improvement(sct): Do not require AWS for doc commands
Currently, both conf-docs and update-conf-docs require AWS due to instantiation of SCTConfiguration class. Make required methods class methods to prevent unnecessary validation.
1 parent 93fc13b commit 86783e8

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

sct.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def getTestCaseNames(self, testCaseClass):
194194
def cli(ctx):
195195
disable_loggers_during_startup()
196196
# Ugly way of filtering the few command that do not require OKTA verification
197-
if ctx.invoked_subcommand not in ("update-conf-docs", "nemesis-list", "create-nemesis-pipelines"):
197+
if ctx.invoked_subcommand not in ("update-conf-docs", "conf-docs", "nemesis-list", "create-nemesis-pipelines"):
198198
try_auth_with_okta()
199199

200200
key_store = KeyStore()
@@ -925,28 +925,16 @@ def conf(config_file, backend):
925925
@cli.command('conf-docs', help="Show all available configuration in yaml/markdown format")
926926
@click.option('-o', '--output-format', type=click.Choice(["yaml", "markdown"]), default="yaml", help="type of the output")
927927
def conf_docs(output_format):
928-
add_file_logger()
929-
930-
os.environ['SCT_CLUSTER_BACKEND'] = "aws" # just to pass SCTConfiguration() verification.
931-
932-
config_logger = logging.getLogger('sdcm.sct_config')
933-
config_logger.setLevel(logging.ERROR)
934928
if output_format == 'markdown':
935-
click.secho(SCTConfiguration().dump_help_config_markdown())
929+
click.secho(SCTConfiguration.dump_help_config_markdown())
936930
elif output_format == 'yaml':
937-
click.secho(SCTConfiguration().dump_help_config_yaml())
931+
click.secho(SCTConfiguration.dump_help_config_yaml())
938932

939933

940934
@cli.command('update-conf-docs', help="Update the docs configuration markdown")
941935
def update_conf_docs():
942-
add_file_logger()
943-
944-
os.environ['SCT_CLUSTER_BACKEND'] = "aws" # just to pass SCTConfiguration() verification.
945-
946-
config_logger = logging.getLogger('sdcm.sct_config')
947-
config_logger.setLevel(logging.ERROR)
948936
markdown_file = Path(__name__).parent / 'docs' / 'configuration_options.md'
949-
markdown_file.write_text(SCTConfiguration().dump_help_config_markdown())
937+
markdown_file.write_text(SCTConfiguration.dump_help_config_markdown())
950938
click.secho(f"docs written into {markdown_file}")
951939

952940

sdcm/sct_config.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,7 +2817,8 @@ def dump_config(self):
28172817
"""
28182818
return anyconfig.dumps(self.dict(), ac_parser="yaml")
28192819

2820-
def dump_help_config_markdown(self):
2820+
@classmethod
2821+
def dump_help_config_markdown(cls):
28212822
"""
28222823
Dump all configuration options with their defaults and help to string in markdown format
28232824
@@ -2832,6 +2833,7 @@ def dump_help_config_markdown(self):
28322833
* **list:** can be appended by adding `++` as the first item of the list
28332834
`export SCT_SCYLLA_D_OVERRIDES_FILES='["++", "extra_file/scylla.d/io.conf"]'`
28342835
"""
2836+
defaults = anyconfig.load(sct_abs_path('defaults/test_default.yaml'))
28352837

28362838
def strip_help_text(text):
28372839
"""
@@ -2842,32 +2844,34 @@ def strip_help_text(text):
28422844

28432845
ret = strip_help_text(header)
28442846

2845-
for opt in self.config_options:
2847+
for opt in cls.config_options:
28462848
ret += '\n\n'
28472849
if opt['help']:
28482850
help_text = '<br>'.join(strip_help_text(opt['help']).splitlines())
28492851
else:
28502852
help_text = ''
28512853
appendable = ' (appendable)' if is_config_option_appendable(opt.get('name')) else ''
2852-
default = self.get_default_value(opt['name'])
2854+
default = defaults.get(opt['name'], None)
28532855
default_text = default if default else 'N/A'
28542856
ret += f"""## **{opt['name']}** / {opt['env']}\n\n{help_text}\n\n**default:** {default_text}\n\n**type:** {opt.get('type').__name__}{appendable}\n"""
28552857

28562858
return ret
28572859

2858-
def dump_help_config_yaml(self):
2860+
@classmethod
2861+
def dump_help_config_yaml(cls):
28592862
"""
28602863
Dump all configuration options with their defaults and help to string in yaml format
28612864
28622865
:return: str
28632866
"""
2867+
defaults = anyconfig.load(sct_abs_path('defaults/test_default.yaml'))
28642868
ret = ""
2865-
for opt in self.config_options:
2869+
for opt in cls.config_options:
28662870
if opt['help']:
2867-
help_text = '\n'.join(["# {}".format(l.strip()) for l in opt['help'].splitlines() if l.strip()]) + '\n'
2871+
help_text = '\n'.join("# {}".format(l.strip()) for l in opt['help'].splitlines() if l.strip()) + '\n'
28682872
else:
28692873
help_text = ''
2870-
default = self.get_default_value(opt['name'])
2874+
default = defaults.get(opt['name'], None)
28712875
default = default if default else 'N/A'
28722876
ret += "{help_text}{name}: {default}\n\n".format(help_text=help_text, default=default, **opt)
28732877

0 commit comments

Comments
 (0)