Skip to content

Commit

Permalink
new test
Browse files Browse the repository at this point in the history
  • Loading branch information
nagworld9 committed Dec 3, 2024
1 parent 2f8fbc7 commit b863a09
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion azurelinuxagent/ga/cgroupconfigurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def _calculate_current_cpu_quota(cpu_quota_per_sec_usec):

# Calculate CPU percentage
cpu_percentage = (cpu_quota_us / 1000000) * 100
return "{0}%".format(cpu_percentage)
return "{: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"
Expand Down
24 changes: 24 additions & 0 deletions tests/ga/test_cgroupconfigurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,30 @@ def test_it_should_set_extension_services_cpu_memory_quota(self):
cmd = 'systemctl set-property extension.service {0} {1} {2} --runtime'.format(expected_cpu_accounting, expected_memory_accounting, expected_cpu_quota_percentage)
self.assertIn(cmd, configurator.mocks.commands_call_list, "The command to set the CPU quota was not called")

def test_it_should_not_update_quota_when_quota_is_not_changed(self):
command_mocks = [MockCommand(r"^systemctl show extension\.service --property CPUQuotaPerSecUSec",
'''CPUQuotaPerSecUSec=50ms
'''),
MockCommand(r"^systemctl show extension\.service --property CPUAccounting",
'''CPUAccounting=yes
'''),
MockCommand(r"^systemctl show extension\.service --property MemoryAccounting",
'''MemoryAccounting=yes
''')]
service_list = [
{
"name": "extension.service",
"cpuQuotaPercentage": 5
}
]

with self._get_cgroup_configurator(mock_commands=command_mocks) as configurator:
configurator.set_extension_services_cpu_memory_quota(service_list)
cmd = 'systemctl set-property extension.service'
commands_list = configurator.mocks.commands_call_list
for command in commands_list:
self.assertNotIn(cmd, command, "The command to set CPU quota was called")

def test_it_should_set_extension_services_when_quotas_not_defined(self):
service_list = [
{
Expand Down

0 comments on commit b863a09

Please sign in to comment.