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

Remove cgroup files during deprovisioning #2790

Merged
merged 17 commits into from
Mar 24, 2023
Merged
Changes from all 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
23 changes: 22 additions & 1 deletion azurelinuxagent/pa/deprovision/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import azurelinuxagent.common.conf as conf
import azurelinuxagent.common.utils.fileutil as fileutil
from azurelinuxagent.common import version
from azurelinuxagent.common.cgroupconfigurator import _AGENT_DROP_IN_FILE_SLICE, _DROP_IN_FILE_CPU_ACCOUNTING, \
_DROP_IN_FILE_CPU_QUOTA, _DROP_IN_FILE_MEMORY_ACCOUNTING, LOGCOLLECTOR_SLICE
from azurelinuxagent.common.exception import ProtocolError
from azurelinuxagent.common.osutil import get_osutil
from azurelinuxagent.common.osutil import get_osutil, systemd
from azurelinuxagent.common.persist_firewall_rules import PersistFirewallRulesHandler
from azurelinuxagent.common.protocol.util import get_protocol_util
from azurelinuxagent.ga.exthandlers import HANDLER_COMPLETE_NAME_PATTERN
Expand Down Expand Up @@ -199,6 +201,7 @@ def setup(self, deluser):
self.del_user(warnings, actions)

self.del_persist_firewall_rules(actions)
self.remove_agent_cgroup_config(actions)

return warnings, actions

Expand All @@ -210,6 +213,7 @@ def setup_changed_unique_id(self):
self.del_lib_dir_files(warnings, actions)
self.del_ext_handler_files(warnings, actions)
self.del_persist_firewall_rules(actions)
self.remove_agent_cgroup_config(actions)

return warnings, actions

Expand Down Expand Up @@ -266,3 +270,20 @@ def del_persist_firewall_rules(actions):
actions.append(DeprovisionAction(fileutil.rm_files,
[agent_network_service_path, os.path.join(conf.get_lib_dir(),
PersistFirewallRulesHandler.BINARY_FILE_NAME)]))

@staticmethod
def remove_agent_cgroup_config(actions):
# Get all service drop in file paths
agent_drop_in_path = systemd.get_agent_drop_in_path()
slice_path = os.path.join(agent_drop_in_path, _AGENT_DROP_IN_FILE_SLICE)
cpu_accounting_path = os.path.join(agent_drop_in_path, _DROP_IN_FILE_CPU_ACCOUNTING)
cpu_quota_path = os.path.join(agent_drop_in_path, _DROP_IN_FILE_CPU_QUOTA)
mem_accounting_path = os.path.join(agent_drop_in_path, _DROP_IN_FILE_MEMORY_ACCOUNTING)

# Get log collector slice
unit_file_install_path = systemd.get_unit_file_install_path()
log_collector_slice_path = os.path.join(unit_file_install_path, LOGCOLLECTOR_SLICE)

actions.append(DeprovisionAction(fileutil.rm_files,
[slice_path, cpu_accounting_path, cpu_quota_path, mem_accounting_path,
log_collector_slice_path]))