Skip to content

Commit

Permalink
Add an ability to return to default config
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Fastiuk <yfastiuk@nvidia.com>
  • Loading branch information
fastiuk committed May 21, 2024
1 parent b101a64 commit fb95e49
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
40 changes: 23 additions & 17 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7753,20 +7753,27 @@ def notice(db, category_list, max_events, namespace):
#
# 'logrotate' group ('config logrotate ...')
#
@config.group()
def logrotate():
@config.group(invoke_without_command=True)
@click.pass_context
@click.argument('file', required=True, type=click.Choice(['syslog', 'debug']))
def logrotate(ctx, file):
"""Configuring logrotate"""
pass
# If invoking subcomand, no need to do anything
if ctx.invoked_subcommand is not None:
return

config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry(swsscommon.CFG_LOGGING_TABLE_NAME, file, None)


@logrotate.command()
@click.argument('file', metavar='<syslog|debug>', required=True,
type=click.Choice(['syslog', 'debug']))
@click.pass_context
@click.argument('disk_percentage', metavar='<disk-percentage>',
required=True, type=float)
def disk_percentage(file, disk_percentage):
def disk_percentage(ctx, disk_percentage):
"""Configuring logrotate disk-precentage file <syslog|debug> <disk_percentage>"""

file = ctx.parent.params.get('file')
if 0 > disk_percentage > 100:
click.echo(f'Disk percentage {disk_percentage} is not in range [0 - 100]')
pass
Expand All @@ -7778,39 +7785,38 @@ def disk_percentage(file, disk_percentage):


@logrotate.command()
@click.argument('file', metavar='<syslog|debug>', required=True,
type=click.Choice(['syslog', 'debug']))
@click.pass_context
@click.argument('frequency', metavar='<daily|weekly|monthly|yearly>',
required=True,
type=click.Choice(['daily', 'weekly', 'monthly', 'yearly']))
def frequency(file, frequency):
def frequency(ctx, frequency):
"""Configuring logrotate frequency file <syslog|debug> <frequency>"""
file = ctx.parent.params.get('file')
config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry(swsscommon.CFG_LOGGING_TABLE_NAME, file,
{'frequency': frequency})


@logrotate.command()
@click.argument('file', metavar='<syslog|debug>', required=True,
type=click.Choice(['syslog', 'debug']))
@click.pass_context
@click.argument('max_number', metavar='<max-number>',
type=click.IntRange(0, 999999), required=True)
def max_number(file, max_number):
def max_number(ctx, max_number):
"""Configuring logrotate max-number file <syslog|debug> <max_number>"""
file = ctx.parent.params.get('file')
config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry(swsscommon.CFG_LOGGING_TABLE_NAME, file,
{'max_number': max_number})


@logrotate.command()
@click.argument('file', metavar='<syslog|debug>', required=True,
type=click.Choice(['syslog', 'debug']))
@click.pass_context
@click.argument('size', metavar='<size>', type=float, required=True)
def size(file, size):
def size(ctx, size):
"""Configuring logrotate size file <syslog|debug> <size>"""

file = ctx.parent.params.get('file')
if 0.001 > size > 3500.0:
click.echo(f'Size {disk_percentage} is not in range [0.001 - 3500.0]')
pass
Expand Down
16 changes: 8 additions & 8 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3109,8 +3109,8 @@ def test_logrotate_disk_percentage(self):
obj = {'db': Db().cfgdb}

result = runner.invoke(
config.config.commands['logrotate'].commands['disk-percentage'],
['debug', '24.25'], obj=obj)
config.config.commands['logrotate'].commands['debug'],
['disk-percentage', '24.25'], obj=obj)

assert result.exit_code == 0

Expand All @@ -3121,8 +3121,8 @@ def test_logrotate_frequency(self):
obj = {'db': Db().cfgdb}

result = runner.invoke(
config.config.commands['logrotate'].commands['frequency'],
['debug', 'daily'], obj=obj)
config.config.commands['logrotate'].commands['debug'],
['frequency', 'daily'], obj=obj)

assert result.exit_code == 0

Expand All @@ -3133,8 +3133,8 @@ def test_logrotate_max_number(self):
obj = {'db': Db().cfgdb}

result = runner.invoke(
config.config.commands['logrotate'].commands['max-number'],
['debug', '2024'], obj=obj)
config.config.commands['logrotate'].commands['syslog'],
['max-number', '2024'], obj=obj)

assert result.exit_code == 0

Expand All @@ -3145,8 +3145,8 @@ def test_logrotate_size(self):
obj = {'db': Db().cfgdb}

result = runner.invoke(
config.config.commands['logrotate'].commands['size'],
['debug', '30.0'], obj=obj)
config.config.commands['logrotate'].commands['syslog'],
['size', '30.0'], obj=obj)

assert result.exit_code == 0

Expand Down

0 comments on commit fb95e49

Please sign in to comment.