Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in get_dhcp_pid (CoreOS) #2784

Merged
merged 3 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
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