Skip to content

Commit

Permalink
Update hostcfgd with review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrallen committed Mar 16, 2022
1 parent 18a294d commit 3b5e76d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
35 changes: 12 additions & 23 deletions src/sonic-host-services/scripts/hostcfgd
Original file line number Diff line number Diff line change
Expand Up @@ -1014,32 +1014,24 @@ class HostConfigDaemon:
self.hostname_cache=""
self.aaacfg = AaaCfg()

# Initialize cache
self.cache = {}


def load(self):
features = self.config_db.get_table('FEATURE')
aaa = self.config_db.get_table('AAA')
tacacs_global = self.config_db.get_table('TACPLUS')
tacacs_server = self.config_db.get_table('TACPLUS_SERVER')
radius_global = self.config_db.get_table('RADIUS')
radius_server = self.config_db.get_table('RADIUS_SERVER')
lpbk_table = self.config_db.get_table('LOOPBACK_INTERFACE')
ntp_server = self.config_db.get_table('NTP_SERVER')
ntp_global = self.config_db.get_table('NTP')

self.cache = {'FEATURES': features, 'AAA': aaa, 'TACPLUS': tacacs_global, 'TACPLUS_SERVER': tacacs_server,
'RADIUS': radius_global, 'RADIUS_SERVER': radius_server, 'LOOPBACK_INTERFACE': lpbk_table, 'NTP_SERVER': ntp_server,
'NTP': ntp_global}
def load(self, init_data):
features = init_data['FEATURE']
aaa = init_data['AAA']
tacacs_global = init_data['TACPLUS']
tacacs_server = init_data['TACPLUS_SERVER']
radius_global = init_data['RADIUS']
radius_server = init_data['RADIUS_SERVER']
lpbk_table = init_data['LOOPBACK_INTERFACE']
ntp_server = init_data['NTP_SERVER']
ntp_global = init_data['NTP']

self.feature_handler.update_all_features_config(features)
self.aaacfg.load(aaa, tacacs_global, tacacs_server, radius_global, radius_server)
self.iptables.load(lpbk_table)
self.ntpcfg.load(ntp_global, ntp_server)

try:
dev_meta = self.config_db.get_table('DEVICE_METADATA')
dev_meta = init_data['DEVICE_METADATA']
if 'localhost' in dev_meta:
if 'hostname' in dev_meta['localhost']:
self.hostname_cache = dev_meta['localhost']['hostname']
Expand Down Expand Up @@ -1176,10 +1168,8 @@ class HostConfigDaemon:
syslog.syslog(syslog.LOG_INFO,
"systemctl has finished initialization -- proceeding ...")

self.config_db.listen(start=False)

def start(self):
self.config_db.process(cache=self.cache)
self.config_db.listen(init=self.load)


def main():
Expand All @@ -1188,7 +1178,6 @@ def main():
signal.signal(signal.SIGHUP, signal_handler)
daemon = HostConfigDaemon()
daemon.register_callbacks()
daemon.load()
daemon.start()

if __name__ == "__main__":
Expand Down
5 changes: 1 addition & 4 deletions src/sonic-host-services/tests/common/mock_configdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ def get_table(self, table_name):
def subscribe(self, table_name, callback):
self.handlers[table_name] = callback

def listen(self, start):
pass

def process(self, cache):
def listen(self, init=None):
for e in MockConfigDb.event_queue:
self.handlers[e[0]](e[0], e[1], self.get_entry(e[0], e[1]))

0 comments on commit 3b5e76d

Please sign in to comment.