-
Notifications
You must be signed in to change notification settings - Fork 377
cgroup: change conversion from CPU shares to weight #1767
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -291,23 +291,26 @@ def test_resources_cpu_weight_systemd(): | |
| sys.stderr.write("# found wrong CPUWeight for the systemd scope\n") | ||
| return 1 | ||
|
|
||
| run_crun_command(['update', '--cpu-share', '4321', cid]) | ||
| # this is the expected cpu weight after the conversion from the CPUShares | ||
| expected_weight = "165" | ||
| for values in [(2, 1), (3, 2), (1024, 100), (260000, 9929), (262144, 10000)]: | ||
| cpu_shares = values[0] | ||
| # this is the expected cpu weight after the conversion from the CPUShares | ||
| expected_weight = str(values[1]) | ||
|
|
||
| out = run_crun_command(["exec", cid, "/init", "cat", "/sys/fs/cgroup/cpu.weight"]) | ||
| if expected_weight not in out: | ||
| sys.stderr.write("# found wrong CPUWeight %s for the container cgroup\n" % out) | ||
| return -1 | ||
| run_crun_command(['update', '--cpu-share', str(cpu_shares), cid]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Test uses substring matching for weight validation, which may lead to false positives.
|
||
|
|
||
| out = subprocess.check_output(['systemctl', 'show','-PCPUWeight', scope ], close_fds=False).decode().strip() | ||
| # as above | ||
| if out != expected_weight: | ||
| out = subprocess.check_output(['systemctl', '--user', 'show','-PCPUWeight', scope ], close_fds=False).decode().strip() | ||
| out = run_crun_command(["exec", cid, "/init", "cat", "/sys/fs/cgroup/cpu.weight"]) | ||
| if expected_weight not in out: | ||
| sys.stderr.write("found wrong CPUWeight %s instead of %s for the container cgroup\n" % (out, expected_weight)) | ||
| return -1 | ||
|
Comment on lines
+302
to
+304
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (code-quality): Avoid conditionals in tests. ( ExplanationAvoid complex code, like conditionals, in test functions.Google's software engineering guidelines says:
Some ways to fix this:
Software Engineering at Google / Don't Put Logic in Tests |
||
|
|
||
| if out != expected_weight: | ||
| sys.stderr.write("# found wrong CPUWeight for the systemd scope\n") | ||
| return 1 | ||
| out = subprocess.check_output(['systemctl', 'show','-PCPUWeight', scope ], close_fds=False).decode().strip() | ||
| # as above | ||
| if out != expected_weight: | ||
| out = subprocess.check_output(['systemctl', '--user', 'show','-PCPUWeight', scope ], close_fds=False).decode().strip() | ||
|
Comment on lines
+308
to
+309
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (code-quality): Avoid conditionals in tests. ( ExplanationAvoid complex code, like conditionals, in test functions.Google's software engineering guidelines says:
Some ways to fix this:
Software Engineering at Google / Don't Put Logic in Tests |
||
|
|
||
| if out != expected_weight: | ||
| sys.stderr.write("found wrong CPUWeight for the systemd scope\n") | ||
| return 1 | ||
|
Comment on lines
+311
to
+313
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (code-quality): Avoid conditionals in tests. ( ExplanationAvoid complex code, like conditionals, in test functions.Google's software engineering guidelines says:
Some ways to fix this:
Software Engineering at Google / Don't Put Logic in Tests |
||
| finally: | ||
| if cid is not None: | ||
| run_crun_command(["delete", "-f", cid]) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Variable naming could be more descriptive for clarity.
Consider renaming 'l' to 'log_shares' and 'exponent' to 'weight_exponent' for better readability and maintainability.
Suggested implementation: