From 7203db78c280f702221f2d062c910126c9aa0f47 Mon Sep 17 00:00:00 2001 From: "narrieta@microsoft" Date: Fri, 3 Jan 2025 16:21:04 -0800 Subject: [PATCH] . --- azurelinuxagent/ga/cgroupconfigurator.py | 2 +- tests/data/ext/sample_ext-1.3.0/python.sh | 2 +- tests/ga/test_cgroupapi.py | 6 +++--- tests/ga/test_cgroupconfigurator.py | 20 ++++++++++---------- tests/python_eol/Dockerfile | 5 +++-- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/azurelinuxagent/ga/cgroupconfigurator.py b/azurelinuxagent/ga/cgroupconfigurator.py index 5b6a8b368..eb9d90ac4 100644 --- a/azurelinuxagent/ga/cgroupconfigurator.py +++ b/azurelinuxagent/ga/cgroupconfigurator.py @@ -437,7 +437,7 @@ def _get_current_cpu_quota(unit_name): # Calculate CPU percentage cpu_percentage = (cpu_quota_us / 1000000) * 100 - return "{:g}%".format(cpu_percentage) # :g Removes trailing zeros after decimal point + return "{0:g}%".format(cpu_percentage) # :g Removes trailing zeros after decimal point except Exception as e: log_cgroup_warning("Error parsing current CPUQuotaPerSecUSec: {0}".format(ustr(e))) return "unknown" diff --git a/tests/data/ext/sample_ext-1.3.0/python.sh b/tests/data/ext/sample_ext-1.3.0/python.sh index dfa6afcd6..53adc0bb6 100755 --- a/tests/data/ext/sample_ext-1.3.0/python.sh +++ b/tests/data/ext/sample_ext-1.3.0/python.sh @@ -4,7 +4,7 @@ # python=$(command -v python 2> /dev/null) -if [ -z "$PYTHON" ]; then +if [ -z "$python" ]; then python=$(command -v python3) fi diff --git a/tests/ga/test_cgroupapi.py b/tests/ga/test_cgroupapi.py index 3e43d83bf..61ec6a43b 100644 --- a/tests/ga/test_cgroupapi.py +++ b/tests/ga/test_cgroupapi.py @@ -301,7 +301,7 @@ def mock_popen(command, *args, **kwargs): shell=True, timeout=300, cwd=self.tmp_dir, - env={}, + env={}.update(os.environ), stdout=output_file, stderr=output_file) @@ -317,7 +317,7 @@ def test_start_extension_cgroups_v1_command_should_execute_the_command_in_a_cgro shell=False, timeout=300, cwd=self.tmp_dir, - env={}, + env={}.update(os.environ), stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -344,7 +344,7 @@ def test_start_extension_cgroups_v1_command_should_use_systemd_to_execute_the_co timeout=300, shell=True, cwd=self.tmp_dir, - env={}, + env={}.update(os.environ), stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/tests/ga/test_cgroupconfigurator.py b/tests/ga/test_cgroupconfigurator.py index 646ed2006..0805d52e5 100644 --- a/tests/ga/test_cgroupconfigurator.py +++ b/tests/ga/test_cgroupconfigurator.py @@ -354,7 +354,7 @@ def test_start_extension_command_should_not_use_systemd_when_cgroups_are_not_ena timeout=300, shell=False, cwd=self.tmp_dir, - env={}, + env={}.update(os.environ), stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -374,7 +374,7 @@ def test_start_extension_command_should_use_systemd_run_when_cgroups_v1_are_enab timeout=300, shell=False, cwd=self.tmp_dir, - env={}, + env={}.update(os.environ), stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -395,7 +395,7 @@ def test_start_extension_command_should_start_tracking_the_extension_cgroups(sel timeout=300, shell=False, cwd=self.tmp_dir, - env={}, + env={}.update(os.environ), stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -426,7 +426,7 @@ def mock_popen(command_arg, *args, **kwargs): timeout=300, shell=False, cwd=self.tmp_dir, - env={}, + env={}.update(os.environ), stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -446,7 +446,7 @@ def test_start_extension_command_should_not_use_systemd_when_cgroup_v2_enabled(s timeout=300, shell=False, cwd=self.tmp_dir, - env={}, + env={}.update(os.environ), stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -480,7 +480,7 @@ def test_start_extension_command_should_disable_cgroups_and_invoke_the_command_d timeout=300, shell=True, cwd=self.tmp_dir, - env={}, + env={}.update(os.environ), stdout=output_file, stderr=output_file) @@ -526,7 +526,7 @@ def test_start_extension_command_should_disable_cgroups_and_invoke_the_command_d timeout=300, shell=True, cwd=self.tmp_dir, - env={}, + env={}.update(os.environ), stdout=stdout, stderr=stderr) @@ -571,7 +571,7 @@ def mock_popen(command, *args, **kwargs): timeout=300, shell=True, cwd=self.tmp_dir, - env={}, + env={}.update(os.environ), stdout=stdout, stderr=stderr) @@ -856,7 +856,7 @@ def mock_popen(command, *args, **kwargs): # For the agent's processes, we use the current process and its parent (in the actual agent these would be the daemon and the extension # handler), and the commands started by the agent. # - # For other processes, we use process 1, a process that already completed, and an extension. Note that extensions are started using + # For other processes, we use a process that already completed, and an extension process. Note that extensions are started using # systemd-run and the process for that commands belongs to the agent's cgroup but the processes for the extension should be in a # different cgroup # @@ -868,7 +868,7 @@ def get_completed_process(): return completed agent_processes = [os.getppid(), os.getpid()] + agent_command_processes + [start_extension.systemd_run_pid] - other_processes = [1, get_completed_process()] + extension_processes + other_processes = [get_completed_process()] + extension_processes with patch("azurelinuxagent.ga.cgroupapi.CgroupV1.get_processes", return_value=agent_processes + other_processes): with self.assertRaises(CGroupsException) as context_manager: diff --git a/tests/python_eol/Dockerfile b/tests/python_eol/Dockerfile index 52b32a20c..79adf8ab8 100644 --- a/tests/python_eol/Dockerfile +++ b/tests/python_eol/Dockerfile @@ -46,10 +46,11 @@ RUN \ sed -i 's/mesg n || true/tty -s \&\& mesg n/' ~/.profile && \ : -# TODO: Some unit tests have a dependency on Python 3; this needs to be fixed, but installing Python 3 is a workaround for now. +# +# TODO: Some unit tests create helper scripts that use 'python3' as shebang; we should probably port them to Bash, but installing Python 3 as a workaround for now. +# RUN \ if [[ "${PYTHON_VERSION}" == "2.6" ]]; then \ - apt-get update && \ apt-get -y install python3; \ fi