Skip to content

Commit 1633661

Browse files
Monitor DNS_OPTIONS for changes (sonic-net#239)
1 parent 9c236d1 commit 1633661

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

scripts/hostcfgd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2230,6 +2230,7 @@ class HostConfigDaemon:
22302230
syslog_cfg = init_data.get(swsscommon.CFG_SYSLOG_CONFIG_TABLE_NAME, {})
22312231
syslog_srv = init_data.get(swsscommon.CFG_SYSLOG_SERVER_TABLE_NAME, {})
22322232
dns = init_data.get('DNS_NAMESERVER', {})
2233+
dns_options = init_data.get('DNS_OPTIONS', {})
22332234
fips_cfg = init_data.get('FIPS', {})
22342235
ntp_global = init_data.get(swsscommon.CFG_NTP_GLOBAL_TABLE_NAME)
22352236
ntp_servers = init_data.get(swsscommon.CFG_NTP_SERVER_TABLE_NAME)
@@ -2246,7 +2247,7 @@ class HostConfigDaemon:
22462247
self.devmetacfg.load(dev_meta)
22472248
self.mgmtifacecfg.load(mgmt_ifc, mgmt_vrf)
22482249
self.rsyslogcfg.load(syslog_cfg, syslog_srv)
2249-
self.dnscfg.load(dns)
2250+
self.dnscfg.load(dns, dns_options)
22502251
self.fipscfg.load(fips_cfg)
22512252
self.ntpcfg.load(ntp_global, ntp_servers, ntp_keys)
22522253
self.serialconscfg.load(serial_console)
@@ -2405,6 +2406,10 @@ class HostConfigDaemon:
24052406
syslog.syslog(syslog.LOG_INFO, 'DNS nameserver handler...')
24062407
self.dnscfg.dns_update(key, data)
24072408

2409+
def dns_options_handler(self, key, op, data):
2410+
syslog.syslog(syslog.LOG_INFO, 'DNS options handler...')
2411+
self.dnscfg.dns_update(key, data)
2412+
24082413
def fips_config_handler(self, key, op, data):
24092414
syslog.syslog(syslog.LOG_INFO, 'FIPS table handler...')
24102415
data = self.config_db.get_table("FIPS")
@@ -2478,6 +2483,7 @@ class HostConfigDaemon:
24782483
make_callback(self.rsyslog_server_handler))
24792484

24802485
self.config_db.subscribe('DNS_NAMESERVER', make_callback(self.dns_nameserver_handler))
2486+
self.config_db.subscribe('DNS_OPTIONS', make_callback(self.dns_options_handler))
24812487

24822488
# Handle FIPS changes
24832489
self.config_db.subscribe('FIPS', make_callback(self.fips_config_handler))

tests/hostcfgd/hostcfgd_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,17 @@ def test_dns_events(self):
429429
pass
430430
mocked_run_cmd.assert_has_calls([call(['systemctl', 'restart', 'resolv-config'], True, False)])
431431

432+
def test_dns_options_events(self):
433+
MockConfigDb.set_config_db(HOSTCFG_DAEMON_CFG_DB)
434+
MockConfigDb.event_queue = [('DNS_OPTIONS', 'ndots')]
435+
daemon = hostcfgd.HostConfigDaemon()
436+
daemon.register_callbacks()
437+
with mock.patch('hostcfgd.run_cmd') as mocked_run_cmd:
438+
try:
439+
daemon.start()
440+
except TimeoutError:
441+
pass
442+
mocked_run_cmd.assert_has_calls([call(['systemctl', 'restart', 'resolv-config'], True, False)])
432443

433444
class TestDnsHandler:
434445

tests/hostcfgd/test_vectors.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"MGMT_VRF_CONFIG": {},
3030
"SYSLOG_CONFIG": {},
3131
"SYSLOG_SERVER": {},
32-
"DNS_NAMESERVER": {}
32+
"DNS_NAMESERVER": {},
33+
"DNS_OPTIONS": {}
3334
}
3435

3536

@@ -98,4 +99,7 @@
9899
"DNS_NAMESERVER": {
99100
"1.1.1.1": {}
100101
},
102+
"DNS_OPTIONS": {
103+
"ndots": "4"
104+
}
101105
}

0 commit comments

Comments
 (0)