Skip to content

Commit

Permalink
[201911][hostcfgd]:wait updating the feature table till system init i…
Browse files Browse the repository at this point in the history
…s done (#6234)

- Why I did it
The change is done to make sure the system initialization is done before the hostcfgd sets the feature states.

- How I did it
This is port of the PR #6232.
Since the systemctl version in 201911 doesn't support "--wait".
Added a function to check the output of systemctl is-system-running every second, till the command system is done booting up.

For now this change is only applicable to multi asic platforms based on the testing this change will be extended to all platforms in the future PR.

Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
  • Loading branch information
arlakshm authored Dec 18, 2020
1 parent 78c44d1 commit 7f76698
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions files/image_config/hostcfgd/hostcfgd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import ast
import os
import time
import sys
import subprocess
import syslog
Expand Down Expand Up @@ -247,6 +248,20 @@ class HostConfigDaemon:
lpbk_table = self.config_db.get_table('LOOPBACK_INTERFACE')
self.iptables.load(lpbk_table)

def wait_till_system_init_done(self):
systemctl_cmd = "sudo systemctl is-system-running"
while True:
proc = subprocess.Popen(
systemctl_cmd,
shell=True,
stdout=subprocess.PIPE,
)
output = proc.communicate()[0].rstrip('\n')
if output.lower() in ["initializing", "starting"]:
time.sleep(1)
continue

return

def update_feature_state(self, feature_name, state, feature_table):
if state == "always_enabled":
Expand Down Expand Up @@ -383,6 +398,13 @@ class HostConfigDaemon:
self.config_db.subscribe('LOOPBACK_INTERFACE', lambda table, key, data: self.lpbk_handler(key, data))
self.config_db.subscribe('FEATURE', lambda table, key, data: self.feature_state_handler(key, data))

if self.is_multi_npu:
syslog.syslog(syslog.LOG_INFO,
"Waiting for systemctl to finish initialization")
self.wait_till_system_init_done()
syslog.syslog(syslog.LOG_INFO,
"systemctl has finished initialization -- proceeding ...")

# Update all feature states once upon starting
self.update_all_feature_states()

Expand Down

0 comments on commit 7f76698

Please sign in to comment.