From ec56f31f66f61bfe4d85e630d4cdf127abc86056 Mon Sep 17 00:00:00 2001 From: Nageswara Nandigam Date: Tue, 7 Mar 2023 16:48:22 -0800 Subject: [PATCH 1/2] remove version suffix from extension slice --- azurelinuxagent/common/cgroupapi.py | 6 +++++- azurelinuxagent/common/cgroupconfigurator.py | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/azurelinuxagent/common/cgroupapi.py b/azurelinuxagent/common/cgroupapi.py index 66e893ef6b..98f7dffca6 100644 --- a/azurelinuxagent/common/cgroupapi.py +++ b/azurelinuxagent/common/cgroupapi.py @@ -253,7 +253,11 @@ def _is_systemd_failure(scope_name, stderr): return unit_not_found in stderr or scope_name not in stderr @staticmethod - def get_extension_slice_name(extension_name): + def get_extension_slice_name(extension_name, old_slice=False): + # old slice includes .- + # new slice without version . + if not old_slice: + extension_name = extension_name.rsplit("-", 1)[0] # Since '-' is used as a separator in systemd unit names, we replace it with '_' to prevent side-effects. return EXTENSION_SLICE_PREFIX + "-" + extension_name.replace('-', '_') + ".slice" diff --git a/azurelinuxagent/common/cgroupconfigurator.py b/azurelinuxagent/common/cgroupconfigurator.py index 627567b038..ec0f8434e6 100644 --- a/azurelinuxagent/common/cgroupconfigurator.py +++ b/azurelinuxagent/common/cgroupconfigurator.py @@ -455,6 +455,11 @@ def __create_all_files(files_to_create): def is_extension_resource_limits_setup_completed(self, extension_name, cpu_quota=None): unit_file_install_path = systemd.get_unit_file_install_path() + old_extension_slice_path = os.path.join(unit_file_install_path, SystemdCgroupsApi.get_extension_slice_name(extension_name, old_slice=True)) + # clean up the old slice from the desk + if os.path.exists(old_extension_slice_path): + CGroupConfigurator._Impl.__cleanup_unit_file(old_extension_slice_path) + extension_slice_path = os.path.join(unit_file_install_path, SystemdCgroupsApi.get_extension_slice_name(extension_name)) cpu_quota = str( @@ -921,7 +926,10 @@ def setup_extension_slice(self, extension_name, cpu_quota): SystemdCgroupsApi.get_extension_slice_name(extension_name)) try: cpu_quota = str(cpu_quota) + "%" if cpu_quota is not None else "" # setting an empty value resets to the default (infinity) - _log_cgroup_info("Ensuring the {0}'s CPUQuota is {1}", extension_name, cpu_quota) + if cpu_quota == "": + _log_cgroup_info("CPUQuota not set for {0}", extension_name) + else: + _log_cgroup_info("Ensuring the {0}'s CPUQuota is {1}", extension_name, cpu_quota) slice_contents = _EXTENSION_SLICE_CONTENTS.format(extension_name=extension_name, cpu_quota=cpu_quota) CGroupConfigurator._Impl.__create_unit_file(extension_slice_path, slice_contents) From 1a733113cfaf84df31f1c9312e2210cc663c12a9 Mon Sep 17 00:00:00 2001 From: Nageswara Nandigam Date: Thu, 9 Mar 2023 13:02:23 -0800 Subject: [PATCH 2/2] address comments --- azurelinuxagent/common/cgroupapi.py | 1 + azurelinuxagent/common/cgroupconfigurator.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/azurelinuxagent/common/cgroupapi.py b/azurelinuxagent/common/cgroupapi.py index 98f7dffca6..ca0ef3bb5b 100644 --- a/azurelinuxagent/common/cgroupapi.py +++ b/azurelinuxagent/common/cgroupapi.py @@ -254,6 +254,7 @@ def _is_systemd_failure(scope_name, stderr): @staticmethod def get_extension_slice_name(extension_name, old_slice=False): + # The old slice makes it difficult for user to override the limits because they need to place drop-in files on every upgrade if extension slice is different for each version. # old slice includes .- # new slice without version . if not old_slice: diff --git a/azurelinuxagent/common/cgroupconfigurator.py b/azurelinuxagent/common/cgroupconfigurator.py index ec0f8434e6..767786f014 100644 --- a/azurelinuxagent/common/cgroupconfigurator.py +++ b/azurelinuxagent/common/cgroupconfigurator.py @@ -456,7 +456,7 @@ def __create_all_files(files_to_create): def is_extension_resource_limits_setup_completed(self, extension_name, cpu_quota=None): unit_file_install_path = systemd.get_unit_file_install_path() old_extension_slice_path = os.path.join(unit_file_install_path, SystemdCgroupsApi.get_extension_slice_name(extension_name, old_slice=True)) - # clean up the old slice from the desk + # clean up the old slice from the disk if os.path.exists(old_extension_slice_path): CGroupConfigurator._Impl.__cleanup_unit_file(old_extension_slice_path)