Skip to content

Commit

Permalink
Multi ASIC support
Browse files Browse the repository at this point in the history
  • Loading branch information
Junchao-Mellanox committed Aug 6, 2024
1 parent cb72134 commit 02c77e4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
21 changes: 13 additions & 8 deletions config/syslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,27 +658,32 @@ def disable_rate_limit_feature(db, service_name, namespace):
help="Program name to which the SIGHUP is sent (provided with --service)")
@click.option("--pid",
help="Process ID to which the SIGHUP is sent (provided with --service if PID is from container)")
@click.option('--namespace', '-n', 'namespace', default=None,
type=click.Choice(multi_asic_util.multi_asic_ns_choices()),
show_default=True, help='Namespace name')
@clicommon.pass_db
def level(db, component, level, service, program, pid):
def level(db, component, level, service, program, pid, namespace):
""" Configure log level """
if program and not service:
raise click.UsageError('--program must be specified with --service')

if service and not program and not pid:
raise click.UsageError('--service must be specified with --pid or --program')

if component and level:
output, ret = clicommon.run_command(['swssloglevel', '-c', component, '-l', level], return_cmd=True)
if ret != 0:
raise click.ClickException(f'Failed: {output}')

if not namespace:
cfg_db = db.cfgdb
else:
asic_id = multi_asic.get_asic_id_from_name(namespace)
service = f'{service}{asic_id}'
cfg_db = db.cfgdb_clients[namespace]

cfg_db.mod_entry('LOGGER', component, {'LOGLEVEL': level})
if not service and not program and not pid:
return

log_config = db.cfgdb.get_entry('LOGGER', component)
log_config = cfg_db.get_entry('LOGGER', component)
require_manual_refresh = log_config.get('require_manual_refresh')
if not require_manual_refresh:
click.echo(f'Log {component} does not need manual refresh')
return

if service:
Expand Down
16 changes: 16 additions & 0 deletions tests/syslog_multi_asic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,19 @@ def test_disable_syslog_rate_limit_feature(self, setup_cmd_module):
['database', '-n', 'asic0']
)
assert result.exit_code == 0

@mock.patch('config.syslog.clicommon.run_command')
def test_config_log_level(self, mock_run, setup_cmd_module):
_, config = setup_cmd_module
db = Db()
runner = CliRunner()

mock_run.return_value = ('something', 0)
result = runner.invoke(
config.config.commands["syslog"].commands["level"],
['-c', 'component', '-l', 'DEBUG', '-n', 'asic0'], obj=db
)
assert result.exit_code == 0
cfg_db = db.cfgdb_clients['asic0']
data = cfg_db.get_entry('LOGGER', 'component')
assert data.get('LOGLEVEL') == 'DEBUG'
12 changes: 3 additions & 9 deletions tests/syslog_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ def test_config_log_level(self, mock_run):
['-c', 'component', '-l', 'DEBUG'], obj=db
)
assert result.exit_code == SUCCESS
data = db.cfgdb.get_entry('LOGGER', 'component')
assert data.get('LOGLEVEL') == 'DEBUG'

result = runner.invoke(
config.config.commands["syslog"].commands["level"],
Expand Down Expand Up @@ -543,17 +545,9 @@ def test_config_log_level_negative(self, mock_run):
)
assert result.exit_code == SUCCESS
# Verify it does not send signal to orchagent if require_manual_refresh is not true
assert mock_run.call_count == 1
assert mock_run.call_count == 0

mock_run.return_value = ('something', -1)
result = runner.invoke(
config.config.commands["syslog"].commands["level"],
['-c', 'log1', '-l', 'DEBUG'], obj=db
)

assert result.exit_code != SUCCESS

mock_run.side_effect = [('something', 0), ('something', -1)]
db.cfgdb.set_entry('LOGGER', 'log1', {'require_manual_refresh': 'true'})
result = runner.invoke(
config.config.commands["syslog"].commands["level"],
Expand Down

0 comments on commit 02c77e4

Please sign in to comment.