Skip to content

Commit

Permalink
Fix bug in get_dhcp_pid/CoreOS (#2784)
Browse files Browse the repository at this point in the history
Co-authored-by: narrieta <narrieta>
  • Loading branch information
narrieta committed Mar 10, 2023
1 parent b49b11a commit 355dd09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 4 additions & 2 deletions azurelinuxagent/common/osutil/coreos.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#

import os
import azurelinuxagent.common.utils.shellutil as shellutil
from azurelinuxagent.common.utils import shellutil
from azurelinuxagent.common.osutil.default import DefaultOSUtil


Expand Down Expand Up @@ -78,7 +78,9 @@ def stop_agent_service(self):
return shellutil.run("systemctl stop {0}".format(self.service_name), chk_err=False)

def get_dhcp_pid(self):
return self._get_dhcp_pid(["systemctl", "show", "-p", "MainPID", "systemd-networkd"])
return self._get_dhcp_pid(
["systemctl", "show", "-p", "MainPID", "systemd-networkd"],
transform_command_output=lambda o: o.replace("MainPID=", ""))

def conf_sshd(self, disable_password):
# In CoreOS, /etc/sshd_config is mount readonly. Skip the setting.
Expand Down
17 changes: 10 additions & 7 deletions azurelinuxagent/common/osutil/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@

import array

import azurelinuxagent.common.conf as conf
import azurelinuxagent.common.logger as logger
import azurelinuxagent.common.utils.fileutil as fileutil
import azurelinuxagent.common.utils.shellutil as shellutil
import azurelinuxagent.common.utils.textutil as textutil
from azurelinuxagent.common import conf
from azurelinuxagent.common import logger
from azurelinuxagent.common.utils import fileutil
from azurelinuxagent.common.utils import shellutil
from azurelinuxagent.common.utils import textutil

from azurelinuxagent.common.exception import OSUtilError
from azurelinuxagent.common.future import ustr, array_to_bytes
Expand Down Expand Up @@ -1137,9 +1137,12 @@ def _text_to_pid_list(text):
return [int(n) for n in text.split()]

@staticmethod
def _get_dhcp_pid(command):
def _get_dhcp_pid(command, transform_command_output=None):
try:
return DefaultOSUtil._text_to_pid_list(shellutil.run_command(command))
output = shellutil.run_command(command)
if transform_command_output is not None:
output = transform_command_output(output)
return DefaultOSUtil._text_to_pid_list(output)
except CommandError as exception: # pylint: disable=W0612
return []

Expand Down

0 comments on commit 355dd09

Please sign in to comment.