-
-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use host data for global args (#621)
* Consider host data when collecting global op args. Host data is preferred over the config default, so the order is now: + Operation arguments + Any current deploy arguments + Host data + Config * Add tests for operation arg extraction. * Don't assume `host.data.X` will always return `None`.
- Loading branch information
Showing
4 changed files
with
62 additions
and
4 deletions.
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from unittest import TestCase | ||
|
||
from pyinfra.api import Config, Inventory, State | ||
from pyinfra.api.operation_kwargs import pop_global_op_kwargs | ||
|
||
|
||
class TestOperationKwargs(TestCase): | ||
def test_get_from_config(self): | ||
config = Config(SUDO='config-value') | ||
inventory = Inventory((('somehost',), {})) | ||
|
||
state = State(config=config, inventory=inventory) | ||
|
||
kwargs, keys = pop_global_op_kwargs(state, inventory.get_host('somehost'), {}) | ||
assert kwargs['sudo'] == 'config-value' | ||
|
||
def test_get_from_host(self): | ||
config = Config(SUDO='config-value') | ||
inventory = Inventory(([('somehost', {'sudo': 'host-value'})], {})) | ||
|
||
state = State(config=config, inventory=inventory) | ||
|
||
kwargs, keys = pop_global_op_kwargs(state, inventory.get_host('somehost'), {}) | ||
assert kwargs['sudo'] == 'host-value' | ||
|
||
def test_get_from_state_deploy_kwargs(self): | ||
config = Config(SUDO='config-value') | ||
inventory = Inventory(([('somehost', {'sudo': 'host-value'})], {})) | ||
|
||
state = State(config=config, inventory=inventory) | ||
state.deploy_kwargs = {'sudo': 'deploy-kwarg-value'} | ||
|
||
kwargs, keys = pop_global_op_kwargs(state, inventory.get_host('somehost'), {}) | ||
assert kwargs['sudo'] == 'deploy-kwarg-value' | ||
|
||
def test_get_from_kwargs(self): | ||
config = Config(SUDO='config-value') | ||
inventory = Inventory(([('somehost', {'sudo': 'host-value'})], {})) | ||
|
||
state = State(config=config, inventory=inventory) | ||
state.deploy_kwargs = {'sudo': 'deploy-kwarg-value'} | ||
|
||
kwargs, keys = pop_global_op_kwargs( | ||
state, | ||
inventory.get_host('somehost'), | ||
{'sudo': 'kwarg-value'}, | ||
) | ||
assert kwargs['sudo'] == 'kwarg-value' | ||
assert 'sudo' in keys |