Skip to content

Commit

Permalink
new comment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nagworld9 committed Dec 17, 2024
1 parent 274def2 commit 39ec1ea
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
9 changes: 8 additions & 1 deletion azurelinuxagent/common/osutil/systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#
import os
import re
from logging import exception

from azurelinuxagent.common.osutil import get_osutil
from azurelinuxagent.common.utils import shellutil
Expand All @@ -43,7 +44,13 @@ def get_version():
# systemd 245 (245.4-4ubuntu3)
# +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP etc
#
return shellutil.run_command(['systemctl', '--version'])
# return fist line systemd 245 (245.4-4ubuntu3)
try:
output = shellutil.run_command(['systemctl', '--version'])
version = output.split('\n')[0]
return version
except:
return "unknown"


def get_unit_file_install_path():
Expand Down
8 changes: 4 additions & 4 deletions azurelinuxagent/ga/cgroupconfigurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def _set_cpu_quota(unit_name, quota):
over this setting.
"""
quota_percentage = "{0}%".format(quota)
log_cgroup_info("Setting {0}'s CPUQuota is {1}".format(unit_name, quota_percentage))
log_cgroup_info("Setting {0}'s CPUQuota to {1}".format(unit_name, quota_percentage))
CGroupConfigurator._Impl._try_set_cpu_quota(unit_name, quota_percentage)

@staticmethod
Expand Down Expand Up @@ -629,7 +629,7 @@ def _check_processes_in_agent_cgroup(self, report_immediately):
if current == 0 and not (self._is_process_descendant_of_the_agent(process) or self._is_zombie_process(process)):
current_unexpected[process] = self._format_process(process)
if report_immediately:
report = [current_unexpected[process] for process in current_unexpected]
report = current_unexpected.values()
else:
for process in current_unexpected:
if process in self._unexpected_processes:
Expand Down Expand Up @@ -904,7 +904,7 @@ def setup_extension_slice(self, extension_name, cpu_quota):
if cpu_quota == "infinity":
log_cgroup_info("CPUQuota not set for {0}".format(extension_name))
else:
log_cgroup_info("Setting {0}'s CPUQuota is {1}".format(extension_name, cpu_quota))
log_cgroup_info("Setting {0}'s CPUQuota to {1}".format(extension_name, cpu_quota))

log_cgroup_info("Setting up the resource properties: {0} for {1}".format(properties_to_update, extension_slice))
systemd.set_unit_run_time_properties(extension_slice, properties_to_update, properties_values)
Expand Down Expand Up @@ -955,7 +955,7 @@ def set_extension_services_cpu_memory_quota(self, services_list):
# If systemd is unaware of extension services and not loaded in the system yet, we get error while setting quotas. Hence, added unit loaded check.
if systemd.is_unit_loaded(service_name) and len(properties_to_update) > 0:
if cpu_quota != "infinity":
log_cgroup_info("Setting {0}'s CPUQuota is {1}".format(service_name, cpu_quota))
log_cgroup_info("Setting {0}'s CPUQuota to {1}".format(service_name, cpu_quota))
else:
log_cgroup_info("CPUQuota not set for {0}".format(service_name))
log_cgroup_info("Setting up resource properties: {0} for {1}" .format(properties_to_update, service_name))
Expand Down
2 changes: 2 additions & 0 deletions azurelinuxagent/ga/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,15 @@ def run(self, debug=False):
u"Python: {py_major}.{py_minor}.{py_micro}; "\
u"Arch: {vm_arch}; "\
u"systemd: {systemd}; "\
u"systemd_version: {systemd_version}; "\
u"LISDrivers: {lis_ver}; "\
u"logrotate: {has_logrotate};".format(
dist_name=DISTRO_NAME, dist_ver=DISTRO_VERSION,
util_name=type(self.osutil).__name__,
service_name=self.osutil.service_name,
py_major=PY_VERSION_MAJOR, py_minor=PY_VERSION_MINOR,
py_micro=PY_VERSION_MICRO, vm_arch=vm_arch, systemd=systemd.is_systemd(),
systemd_version=systemd.get_version(),
lis_ver=get_lis_version(), has_logrotate=has_logrotate()
)
logger.info(os_info_msg)
Expand Down
9 changes: 0 additions & 9 deletions tests/ga/test_cgroupapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,6 @@ def test_create_cgroup_api_raises_exception_when_cgroup_mode_cannot_be_determine
create_cgroup_api()
self.assertTrue("/sys/fs/cgroup has an unexpected file type: {0}".format(unknown_cgroup_type) in str(context.exception))

def test_get_systemd_version_should_return_a_version_number(self):
# We expect same behavior for v1 and v2
mock_envs = [mock_cgroup_v1_environment(self.tmp_dir), mock_cgroup_v2_environment(self.tmp_dir)]
for env in mock_envs:
with env:
version_info = systemd.get_version()
found = re.search(r"systemd \d+", version_info) is not None
self.assertTrue(found, "Could not determine the systemd version: {0}".format(version_info))

def test_get_unit_property_should_return_the_value_of_the_given_property(self):
# We expect same behavior for v1 and v2
mock_envs = [mock_cgroup_v1_environment(self.tmp_dir), mock_cgroup_v2_environment(self.tmp_dir)]
Expand Down
3 changes: 1 addition & 2 deletions tests_e2e/tests/lib/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ def run_command(command: Any, shell=False) -> str:
"""
process = Popen(command, stdout=PIPE, stderr=PIPE, shell=shell, text=True)
timer = threading.Timer(15 * 60, process.kill) # Kill process after timeout

timer.start()
try:
timer.start()
stdout, stderr = process.communicate()
finally:
timer.cancel()
Expand Down

0 comments on commit 39ec1ea

Please sign in to comment.