Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions scripts/hostcfgd
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,27 @@ class DeviceMetaCfg(object):
syslog.syslog(syslog.LOG_INFO, 'DeviceMetaCfg: Restart rsyslog after '
'changing timezone')

def rsyslog_config(self, data):
"""
Apply syslog_with_osversion feature flag.
Run the following command in Linux: sudo systemctl restart rsyslog-config
Args:
data: Read table's key's data.
"""
syslog_with_osversion = data.get('syslog_with_osversion')
syslog.syslog(syslog.LOG_DEBUG,
f'DeviceMetaCfg: syslog with os version: {syslog_with_osversion}')

if syslog_with_osversion is None:
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syslog_with_osversion

Should we check the new config with current running config, if only changed, restart service ? #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

syslog.syslog(syslog.LOG_DEBUG,
f'DeviceMetaCfg: syslog with os version feature disabled')
return

run_cmd(['systemctl', 'restart', 'rsyslog-config'], True, False)
syslog.syslog(syslog.LOG_INFO, 'DeviceMetaCfg: Restart rsyslog-config after '
'feature flag change to {}'.format(syslog_with_osversion))


class MgmtIfaceCfg(object):
"""
MgmtIfaceCfg Config Daemon
Expand Down Expand Up @@ -2281,6 +2302,7 @@ class HostConfigDaemon:
syslog.syslog(syslog.LOG_INFO, 'DeviceMeta handler...')
self.devmetacfg.hostname_update(data)
self.devmetacfg.timezone_update(data)
self.devmetacfg.rsyslog_config(data)

def rsyslog_handler(self):
rsyslog_config = self.config_db.get_table(
Expand Down
16 changes: 16 additions & 0 deletions tests/hostcfgd/hostcfgd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def test_devicemeta_event(self):
Test handling DEVICE_METADATA events.
1) Hostname reload
1) Timezone reload
1) syslog_with_osversion flag change
"""
MockConfigDb.set_config_db(HOSTCFG_DAEMON_CFG_DB)
MockConfigDb.event_queue = [(swsscommon.CFG_DEVICE_METADATA_TABLE_NAME,
Expand Down Expand Up @@ -306,6 +307,21 @@ def test_devicemeta_event(self):
]
mocked_syslog.syslog.assert_has_calls(expected)

HOSTCFG_DAEMON_CFG_DB["DEVICE_METADATA"]["localhost"]["syslog_with_osversion"] = 'true'
MockConfigDb.set_config_db(HOSTCFG_DAEMON_CFG_DB)
with mock.patch('hostcfgd.syslog') as mocked_syslog:
with mock.patch('hostcfgd.subprocess') as mocked_subprocess:
mocked_syslog.LOG_INFO = original_syslog.LOG_INFO
try:
daemon.start()
except TimeoutError:
pass

expected = [
call(original_syslog.LOG_INFO, 'DeviceMetaCfg: Restart rsyslog-config after feature flag change to true')
]
mocked_syslog.syslog.assert_has_calls(expected)

def test_mgmtiface_event(self):
"""
Test handling mgmt events.
Expand Down
Loading