From da72c37017784a87bf7876bd5066b3ad44b8d38e Mon Sep 17 00:00:00 2001 From: "Maddie Ford (SHE/HER)" Date: Tue, 8 Nov 2022 15:09:09 -0800 Subject: [PATCH 1/6] Update version to dummy 1.0.0.0' --- azurelinuxagent/common/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurelinuxagent/common/version.py b/azurelinuxagent/common/version.py index ff9c903b93..9a41c2e109 100644 --- a/azurelinuxagent/common/version.py +++ b/azurelinuxagent/common/version.py @@ -209,7 +209,7 @@ def has_logrotate(): # # When doing a release, be sure to use the actual agent version. Current agent version: 2.4.0.0 # -AGENT_VERSION = '9.9.9.9' +AGENT_VERSION = '1.0.0.0' AGENT_LONG_VERSION = "{0}-{1}".format(AGENT_NAME, AGENT_VERSION) AGENT_DESCRIPTION = """ The Azure Linux Agent supports the provisioning and running of Linux From 59dbd2245d6f55e8e4c0eb494bd0d01dcd44a2e3 Mon Sep 17 00:00:00 2001 From: "Maddie Ford (SHE/HER)" Date: Tue, 8 Nov 2022 15:40:54 -0800 Subject: [PATCH 2/6] Revert version change --- azurelinuxagent/common/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurelinuxagent/common/version.py b/azurelinuxagent/common/version.py index 9a41c2e109..ff9c903b93 100644 --- a/azurelinuxagent/common/version.py +++ b/azurelinuxagent/common/version.py @@ -209,7 +209,7 @@ def has_logrotate(): # # When doing a release, be sure to use the actual agent version. Current agent version: 2.4.0.0 # -AGENT_VERSION = '1.0.0.0' +AGENT_VERSION = '9.9.9.9' AGENT_LONG_VERSION = "{0}-{1}".format(AGENT_NAME, AGENT_VERSION) AGENT_DESCRIPTION = """ The Azure Linux Agent supports the provisioning and running of Linux From 162ebbc3f4003442ceabba8063c339951950f992 Mon Sep 17 00:00:00 2001 From: "Maddie Ford (SHE/HER)" Date: Thu, 9 Feb 2023 15:28:32 -0800 Subject: [PATCH 3/6] Update log collector slice unit file without memory limit --- azurelinuxagent/common/cgroupconfigurator.py | 7 +++---- azurelinuxagent/common/logcollector.py | 2 +- tests/common/mock_cgroup_environment.py | 1 + tests/common/test_cgroupconfigurator.py | 21 +++++++++++++++++++ .../azure-walinuxagent-logcollector.slice | 9 ++++++++ 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 tests/data/init/azure-walinuxagent-logcollector.slice diff --git a/azurelinuxagent/common/cgroupconfigurator.py b/azurelinuxagent/common/cgroupconfigurator.py index 840961e7df..5ea2a0dc14 100644 --- a/azurelinuxagent/common/cgroupconfigurator.py +++ b/azurelinuxagent/common/cgroupconfigurator.py @@ -368,10 +368,9 @@ def __setup_azure_slice(): if not os.path.exists(vmextensions_slice): files_to_create.append((vmextensions_slice, _VMEXTENSIONS_SLICE_CONTENTS)) - if not os.path.exists(logcollector_slice): - slice_contents = _LOGCOLLECTOR_SLICE_CONTENTS_FMT.format(cpu_quota=_LOGCOLLECTOR_CPU_QUOTA) - - files_to_create.append((logcollector_slice, slice_contents)) + ## LogCollector slice should be updated to remove MemoryLimit quota from previous GA versions + slice_contents = _LOGCOLLECTOR_SLICE_CONTENTS_FMT.format(cpu_quota=_LOGCOLLECTOR_CPU_QUOTA) + files_to_create.append((logcollector_slice, slice_contents)) if fileutil.findre_in_file(agent_unit_file, r"Slice=") is not None: CGroupConfigurator._Impl.__cleanup_unit_file(agent_drop_in_file_slice) diff --git a/azurelinuxagent/common/logcollector.py b/azurelinuxagent/common/logcollector.py index 393333c962..fe62a7db6a 100644 --- a/azurelinuxagent/common/logcollector.py +++ b/azurelinuxagent/common/logcollector.py @@ -119,7 +119,7 @@ def _set_resource_usage_cgroups(cpu_cgroup_path, memory_cgroup_path): @staticmethod def _initialize_telemetry(): protocol = get_protocol_util().get_protocol(init_goal_state=False) - protocol.client.reset_goal_state(goalstate_properties=GoalStateProperties.RoleConfig | GoalStateProperties.HostingEnv) + protocol.client.reset_goal_state(goal_state_properties=GoalStateProperties.RoleConfig | GoalStateProperties.HostingEnv) # Initialize the common parameters for telemetry events initialize_event_logger_vminfo_common_parameters(protocol) diff --git a/tests/common/mock_cgroup_environment.py b/tests/common/mock_cgroup_environment.py index 10d499077e..e38471060e 100644 --- a/tests/common/mock_cgroup_environment.py +++ b/tests/common/mock_cgroup_environment.py @@ -91,6 +91,7 @@ class UnitFilePaths: walinuxagent = "/lib/systemd/system/walinuxagent.service" + logcollector = "/lib/systemd/system/azure-walinuxagent-logcollector.slice" azure = "/lib/systemd/system/azure.slice" vmextensions = "/lib/systemd/system/azure-vmextensions.slice" extensionslice = "/lib/systemd/system/azure-vmextensions-Microsoft.CPlat.Extension.slice" diff --git a/tests/common/test_cgroupconfigurator.py b/tests/common/test_cgroupconfigurator.py index 60a7cfde1c..63b76105d8 100644 --- a/tests/common/test_cgroupconfigurator.py +++ b/tests/common/test_cgroupconfigurator.py @@ -188,6 +188,27 @@ def test_initialize_should_create_unit_files_when_the_agent_service_file_is_not_ self.assertTrue(os.path.exists(agent_drop_in_file_cpu_accounting), "{0} was not created".format(agent_drop_in_file_cpu_accounting)) self.assertTrue(os.path.exists(agent_drop_in_file_memory_accounting), "{0} was not created".format(agent_drop_in_file_memory_accounting)) + def test_initialize_should_update_logcollector_memorylimit(self): + with self._get_cgroup_configurator(initialize=False) as configurator: + log_collector_unit_file = configurator.mocks.get_mapped_path(UnitFilePaths.logcollector) + original_memory_limit = "MemoryLimit=30M" + + # The mock creates the slice unit file with memory limit + configurator.mocks.add_data_file(os.path.join(data_dir, 'init', "azure-walinuxagent-logcollector.slice"), + UnitFilePaths.logcollector) + self.assertTrue(os.path.exists(log_collector_unit_file), + "{0} was not created".format(log_collector_unit_file)) + self.assertTrue(fileutil.findre_in_file(log_collector_unit_file, original_memory_limit), + "MemoryLimit was not set correctly. Expected: {0}. Got:\n{1}".format( + original_memory_limit, fileutil.read_file(log_collector_unit_file))) + + configurator.initialize() + + # initialize() should update the unit file to remove the memory limit + self.assertFalse(fileutil.findre_in_file(log_collector_unit_file, original_memory_limit), + "Log collector slice unit file was not updated correctly. Expected no memory limit. Got:\n{0}".format( + fileutil.read_file(log_collector_unit_file))) + def test_setup_extension_slice_should_create_unit_files(self): with self._get_cgroup_configurator() as configurator: # get the paths to the mocked files diff --git a/tests/data/init/azure-walinuxagent-logcollector.slice b/tests/data/init/azure-walinuxagent-logcollector.slice new file mode 100644 index 0000000000..63c09d431d --- /dev/null +++ b/tests/data/init/azure-walinuxagent-logcollector.slice @@ -0,0 +1,9 @@ +[Unit] +Description=Slice for Azure VM Agent Periodic Log Collector +DefaultDependencies=no +Before=slices.target +[Slice] +CPUAccounting=yes +CPUQuota=5% +MemoryAccounting=yes +MemoryLimit=30M \ No newline at end of file From c8dda5397222ebaedfd30cdae46f247a80de2f4d Mon Sep 17 00:00:00 2001 From: "Maddie Ford (SHE/HER)" Date: Thu, 9 Feb 2023 15:30:26 -0800 Subject: [PATCH 4/6] Update comment --- azurelinuxagent/common/cgroupconfigurator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurelinuxagent/common/cgroupconfigurator.py b/azurelinuxagent/common/cgroupconfigurator.py index 5ea2a0dc14..849b0f779f 100644 --- a/azurelinuxagent/common/cgroupconfigurator.py +++ b/azurelinuxagent/common/cgroupconfigurator.py @@ -368,7 +368,7 @@ def __setup_azure_slice(): if not os.path.exists(vmextensions_slice): files_to_create.append((vmextensions_slice, _VMEXTENSIONS_SLICE_CONTENTS)) - ## LogCollector slice should be updated to remove MemoryLimit quota from previous GA versions + ## Log collector slice should be updated to remove MemoryLimit quota from previous GA versions slice_contents = _LOGCOLLECTOR_SLICE_CONTENTS_FMT.format(cpu_quota=_LOGCOLLECTOR_CPU_QUOTA) files_to_create.append((logcollector_slice, slice_contents)) From cc879ac0cc4211ca769e6de15d11c3c27c08c62c Mon Sep 17 00:00:00 2001 From: "Maddie Ford (SHE/HER)" Date: Thu, 9 Feb 2023 16:46:54 -0800 Subject: [PATCH 5/6] Update setup errors as exceptions --- tests/common/test_cgroupconfigurator.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/common/test_cgroupconfigurator.py b/tests/common/test_cgroupconfigurator.py index 63b76105d8..d3410cf54a 100644 --- a/tests/common/test_cgroupconfigurator.py +++ b/tests/common/test_cgroupconfigurator.py @@ -196,11 +196,11 @@ def test_initialize_should_update_logcollector_memorylimit(self): # The mock creates the slice unit file with memory limit configurator.mocks.add_data_file(os.path.join(data_dir, 'init', "azure-walinuxagent-logcollector.slice"), UnitFilePaths.logcollector) - self.assertTrue(os.path.exists(log_collector_unit_file), - "{0} was not created".format(log_collector_unit_file)) - self.assertTrue(fileutil.findre_in_file(log_collector_unit_file, original_memory_limit), - "MemoryLimit was not set correctly. Expected: {0}. Got:\n{1}".format( - original_memory_limit, fileutil.read_file(log_collector_unit_file))) + if not os.path.exists(log_collector_unit_file): + raise Exception("{0} should have been created during test setup".format(log_collector_unit_file)) + if not fileutil.findre_in_file(log_collector_unit_file, original_memory_limit): + raise Exception("MemoryLimit was not set correctly. Expected: {0}. Got:\n{1}".format( + original_memory_limit, fileutil.read_file(log_collector_unit_file))) configurator.initialize() From 18f2c24f173e9725e24f3d0577a7b989fe427d53 Mon Sep 17 00:00:00 2001 From: "Maddie Ford (SHE/HER)" Date: Thu, 9 Feb 2023 16:47:47 -0800 Subject: [PATCH 6/6] Update comment for accuracy --- azurelinuxagent/common/cgroupconfigurator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurelinuxagent/common/cgroupconfigurator.py b/azurelinuxagent/common/cgroupconfigurator.py index 849b0f779f..627567b038 100644 --- a/azurelinuxagent/common/cgroupconfigurator.py +++ b/azurelinuxagent/common/cgroupconfigurator.py @@ -368,7 +368,7 @@ def __setup_azure_slice(): if not os.path.exists(vmextensions_slice): files_to_create.append((vmextensions_slice, _VMEXTENSIONS_SLICE_CONTENTS)) - ## Log collector slice should be updated to remove MemoryLimit quota from previous GA versions + # Update log collector slice contents slice_contents = _LOGCOLLECTOR_SLICE_CONTENTS_FMT.format(cpu_quota=_LOGCOLLECTOR_CPU_QUOTA) files_to_create.append((logcollector_slice, slice_contents))