-
Notifications
You must be signed in to change notification settings - Fork 290
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
[FLOC-4530] Pass the swappiness configuration value to the Docker API #2946
Open
wallrj
wants to merge
7
commits into
master
Choose a base branch
from
release-maintenance/flocker-1.15.0/swappiness-for-real-FLOC-4530
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+106
−10
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
220e602
Test that swappiness is used by StartApplication
wallrj 004c9b2
Set the swappiness attribute of applications during discovery
wallrj 986e490
A failing test demonstrating a bug in the current swappiness setting …
wallrj 4415015
remove the broken code
wallrj 588c576
Discover the swappiness value and set it on the Application....also r…
wallrj c758b1f
Since Docker API 1.19 the mem_limit is configured through HostConfig
wallrj 7d389c8
Add a test that swappiness changes trigger an application restart
wallrj 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 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 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 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 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 |
---|---|---|
|
@@ -460,6 +460,34 @@ def test_command_line(self): | |
pvector(command_line), | ||
) | ||
|
||
def test_swappiness(self): | ||
""" | ||
``StartApplication.run()`` passes ``swappiness`` to | ||
``DockerClient.add`` which is used when creating a Unit. | ||
""" | ||
expected_swappiness = 99 | ||
fake_docker = FakeDockerClient() | ||
deployer = ApplicationNodeDeployer(u'example.com', fake_docker) | ||
|
||
application_name = u'site-example.com' | ||
application = Application( | ||
name=application_name, | ||
image=DockerImage(repository=u'clusterhq/postgresql', | ||
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. Why dont we use a smaller image here? Any reason we are using postgresql just to test the swappiness? Could mean longer pulls for new test nodes. |
||
tag=u'9.3.5'), | ||
swappiness=expected_swappiness, | ||
) | ||
|
||
StartApplication( | ||
application=application, | ||
node_state=EMPTY_NODESTATE, | ||
).run(deployer, state_persister=InMemoryStatePersister()) | ||
|
||
[unit] = self.successResultOf(fake_docker.list()) | ||
self.assertEqual( | ||
expected_swappiness, | ||
unit.swappiness, | ||
) | ||
|
||
|
||
class LinkEnviromentTests(TestCase): | ||
""" | ||
|
@@ -677,6 +705,17 @@ def test_discover_application_with_memory_limit(self): | |
applications = [APP.set("memory_limit", memory_limit)] | ||
self._verify_discover_state_applications(units, applications) | ||
|
||
def test_discover_application_with_swappiness(self): | ||
""" | ||
An ``Application`` with a swappiness value is discovered from a | ||
``Unit`` with a swappiness value. | ||
""" | ||
swappiness = 99 | ||
unit1 = UNIT_FOR_APP.set("swappiness", swappiness) | ||
units = {unit1.name: unit1} | ||
applications = [APP.set("swappiness", swappiness)] | ||
self._verify_discover_state_applications(units, applications) | ||
|
||
def test_discover_application_with_environment(self): | ||
""" | ||
An ``Application`` with ``Environment`` objects is discovered from a | ||
|
@@ -1481,6 +1520,49 @@ def test_app_with_changed_links_restarted(self): | |
|
||
self.assertEqual(expected, result) | ||
|
||
def test_app_with_changed_swappiness_restarted(self): | ||
""" | ||
An ``Application`` running on a given node that has different | ||
swappiness specified in the desired state to the swappiness specified | ||
by the application's current state is added to the list of applications | ||
to restart. | ||
""" | ||
api = ApplicationNodeDeployer( | ||
u'node1.example.com', | ||
docker_client=FakeDockerClient(), | ||
) | ||
old_wordpress_app = Application( | ||
name=u'wordpress-example', | ||
image=DockerImage.from_string(u'clusterhq/wordpress:latest'), | ||
volume=None, | ||
swappiness=97, | ||
) | ||
postgres_app = Application( | ||
name=u'postgres-example', | ||
image=DockerImage.from_string(u'clusterhq/postgres:latest') | ||
) | ||
new_wordpress_app = old_wordpress_app.set("swappiness", 98) | ||
|
||
desired = Deployment(nodes=frozenset({ | ||
Node(hostname=u'node1.example.com', | ||
applications=frozenset({new_wordpress_app, postgres_app})), | ||
})) | ||
node_state = NodeState(hostname=api.hostname, | ||
applications={postgres_app, old_wordpress_app}) | ||
result = api.calculate_changes( | ||
desired_configuration=desired, | ||
current_cluster_state=DeploymentState(nodes={node_state}), | ||
local_state=NodeLocalState(node_state=node_state), | ||
) | ||
expected = sequentially(changes=[in_parallel(changes=[ | ||
sequentially(changes=[ | ||
StopApplication(application=old_wordpress_app), | ||
StartApplication(application=new_wordpress_app, | ||
node_state=node_state) | ||
]), | ||
])]) | ||
self.assertEqual(expected, result) | ||
|
||
def test_stopped_app_with_change_restarted(self): | ||
""" | ||
An ``Application`` that is stopped, and then reconfigured such that it | ||
|
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.
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.
Do we need to do a similar thing for swappiness here?