-
Notifications
You must be signed in to change notification settings - Fork 32
Resource limits now also from services key; Added tests #1173
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/data/usage_scenarios/resource_limits_disalign_cpu.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
name: Test Stress | ||
author: Dan Mateas | ||
description: test | ||
|
||
services: | ||
|
||
test-container-memory-int: | ||
type: container | ||
image: alpine | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: 2 | ||
cpus: 3 | ||
|
||
flow: | ||
- name: Stress | ||
container: test-container | ||
commands: | ||
- type: console | ||
command: stress-ng -c 1 -t 1 -q | ||
note: Starting Stress |
23 changes: 23 additions & 0 deletions
23
tests/data/usage_scenarios/resource_limits_disalign_memory.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
name: Test Stress | ||
author: Dan Mateas | ||
description: test | ||
|
||
services: | ||
|
||
test-container-memory-int: | ||
type: container | ||
image: alpine | ||
deploy: | ||
resources: | ||
limits: | ||
memory: "10M" | ||
mem_limit: "100M" | ||
|
||
flow: | ||
- name: Stress | ||
container: test-container | ||
ArneTR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
commands: | ||
- type: console | ||
command: stress-ng -c 1 -t 1 -q | ||
note: Starting Stress |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
name: Test Stress | ||
author: Dan Mateas | ||
description: test | ||
|
||
services: | ||
test-container-only-cpu: | ||
type: container | ||
image: alpine | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "1.2" | ||
|
||
test-container-only-memory: | ||
type: container | ||
image: alpine | ||
deploy: | ||
resources: | ||
limits: | ||
memory: "100MB" | ||
|
||
test-container-both: | ||
type: container | ||
image: alpine | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "1.2" | ||
memory: "10M" | ||
|
||
test-container-cpu-float: | ||
type: container | ||
image: alpine | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: 1.2 | ||
memory: "10M" | ||
|
||
test-container-cpu-int: | ||
type: container | ||
image: alpine | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: 1 | ||
memory: "10M" | ||
|
||
test-container-limits-partial: | ||
type: container | ||
image: alpine | ||
deploy: # allowed to be None | ||
|
||
test-container-cpu-and-memory-in-both: | ||
type: container | ||
image: alpine | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: 1 | ||
memory: "10M" | ||
cpus: 1 | ||
mem_limit: "10M" | ||
|
||
test-container-limit-only-service-level: | ||
type: container | ||
image: alpine | ||
cpus: 1 | ||
mem_limit: "10M" | ||
|
||
|
||
flow: | ||
- name: Stress | ||
container: test-container | ||
ArneTR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
commands: | ||
- type: console | ||
command: stress-ng -c 1 -t 1 -q | ||
note: Starting Stress |
22 changes: 22 additions & 0 deletions
22
tests/data/usage_scenarios/resource_limits_memory_float.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
name: Test Stress | ||
author: Dan Mateas | ||
description: test | ||
|
||
services: | ||
|
||
test-container-memory-int: | ||
type: container | ||
image: alpine | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 1.2 | ||
ArneTR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
flow: | ||
- name: Stress | ||
container: test-container | ||
ArneTR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
commands: | ||
- type: console | ||
command: stress-ng -c 1 -t 1 -q | ||
note: Starting Stress |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
name: Test Stress | ||
author: Dan Mateas | ||
description: test | ||
|
||
services: | ||
|
||
test-container-memory-int: | ||
type: container | ||
image: alpine | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 1 | ||
ArneTR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
flow: | ||
- name: Stress | ||
container: test-container | ||
ArneTR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
commands: | ||
- type: console | ||
command: stress-ng -c 1 -t 1 -q | ||
note: Starting Stress |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# https://docs.docker.com/engine/reference/commandline/port/ | ||
# List port mappings or a specific mapping for the container | ||
# docker port CONTAINER [PRIVATE_PORT[/PROTO]] | ||
|
||
import io | ||
import os | ||
import subprocess | ||
|
||
GMT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../') | ||
|
||
from contextlib import redirect_stdout, redirect_stderr | ||
import pytest | ||
|
||
from tests import test_functions as Tests | ||
from lib.scenario_runner import ScenarioRunner | ||
from lib.schema_checker import SchemaError | ||
|
||
## Note: | ||
# Always do asserts after try:finally: blocks | ||
# otherwise failing Tests will not run the runner.cleanup() properly | ||
|
||
|
||
# This function runs the runner up to and *including* the specified step | ||
#pylint: disable=redefined-argument-from-local | ||
### The Tests for usage_scenario configurations | ||
|
||
# environment: [object] (optional) | ||
# Key-Value pairs for ENV variables inside the container | ||
|
||
def get_env_vars(): | ||
ps = subprocess.run( | ||
['docker', 'exec', 'test-container', '/bin/sh', | ||
'-c', 'env'], | ||
check=True, | ||
stderr=subprocess.PIPE, | ||
stdout=subprocess.PIPE, | ||
encoding='UTF-8' | ||
) | ||
env_var_output = ps.stdout | ||
return env_var_output | ||
|
||
def test_resource_limits_good(): | ||
|
||
runner = ScenarioRunner(uri=GMT_DIR, uri_type='folder', filename='tests/data/usage_scenarios/resource_limits_good.yml', skip_unsafe=False, skip_system_checks=True, dev_cache_build=True, dev_no_sleeps=True, dev_no_metrics=True, dev_no_phase_stats=True) | ||
|
||
out = io.StringIO() | ||
err = io.StringIO() | ||
|
||
with redirect_stdout(out), redirect_stderr(err): | ||
with Tests.RunUntilManager(runner) as context: | ||
context.run_until('setup_services') | ||
|
||
assert err.getvalue() == '' | ||
assert 'Applying CPU Limit from deploy' in out.getvalue() | ||
assert 'Applying CPU Limit from services' in out.getvalue() | ||
assert 'Applying Memory Limit from deploy' in out.getvalue() | ||
assert 'Applying Memory Limit from services' in out.getvalue() | ||
|
||
def test_resource_limits_memory_int(): | ||
runner = ScenarioRunner(uri=GMT_DIR, uri_type='folder', filename='tests/data/usage_scenarios/resource_limits_memory_int.yml', skip_system_checks=True, dev_no_metrics=True, dev_no_phase_stats=True, dev_no_sleeps=True, dev_cache_build=True) | ||
with pytest.raises(SchemaError) as e: | ||
with Tests.RunUntilManager(runner) as context: | ||
context.run_until('setup_services') | ||
|
||
assert "Or({Optional('resources'): {Optional('limits'): {Optional('cpus'): Or(<class 'str'>, <class 'float'>, <class 'int'>), Optional('memory'): <class 'str'>}}}, None) did not validate {'resources': {'limits': {'memory': 1}}}" in str(e.value) | ||
assert "1 should be instance of 'str'" in str(e.value) | ||
|
||
def test_resource_limits_memory_float(): | ||
runner = ScenarioRunner(uri=GMT_DIR, uri_type='folder', filename='tests/data/usage_scenarios/resource_limits_memory_float.yml', skip_system_checks=True, dev_no_metrics=True, dev_no_phase_stats=True, dev_no_sleeps=True, dev_cache_build=True) | ||
with pytest.raises(SchemaError) as e: | ||
with Tests.RunUntilManager(runner) as context: | ||
context.run_until('setup_services') | ||
|
||
assert "1.2 should be instance of 'str'" in str(e.value) | ||
|
||
|
||
def test_resource_limits_disalign_cpu(): | ||
runner = ScenarioRunner(uri=GMT_DIR, uri_type='folder', filename='tests/data/usage_scenarios/resource_limits_disalign_cpu.yml', skip_system_checks=True, dev_no_metrics=True, dev_no_phase_stats=True, dev_no_sleeps=True, dev_cache_build=True) | ||
with pytest.raises(SchemaError) as e: | ||
with Tests.RunUntilManager(runner) as context: | ||
context.run_until('setup_services') | ||
|
||
assert "cpus service top level key and deploy.resources.limits.cpus must be identical" in str(e.value) | ||
|
||
def test_resource_limits_disalign_memory(): | ||
runner = ScenarioRunner(uri=GMT_DIR, uri_type='folder', filename='tests/data/usage_scenarios/resource_limits_disalign_memory.yml', skip_system_checks=True, dev_no_metrics=True, dev_no_phase_stats=True, dev_no_sleeps=True, dev_cache_build=True) | ||
with pytest.raises(SchemaError) as e: | ||
with Tests.RunUntilManager(runner) as context: | ||
context.run_until('setup_services') | ||
|
||
assert "mem_limit service top level key and deploy.resources.limits.memory must be identical" in str(e.value) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.