-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a class that can execute templated commands
A new class was added that takes IPAContainer instance, list of command templates and mapping with the expanded values, substitutes the commands using the mappings and runs them succesively on the specifed container. This is the basis for configurable command steps. https://github.com/martbab/ipa-docker-test-runner/issues/4
- Loading branch information
Martin Babinsky
committed
Nov 16, 2016
1 parent
b5512c5
commit a1f5207
Showing
3 changed files
with
115 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Author: Martin Babinsky <martbab@gmail.com> | ||
# See LICENSE file for license | ||
|
||
""" | ||
Tests for command execution logic | ||
""" | ||
|
||
import pytest | ||
|
||
from ipadocker import cli, command, config, constants | ||
|
||
|
||
@pytest.fixture | ||
def ipaconfig(): | ||
""" | ||
flattened default IPA config | ||
""" | ||
return config.IPADockerConfig() | ||
|
||
|
||
@pytest.fixture() | ||
def flattened_config(request, ipaconfig): | ||
return ipaconfig.flatten() | ||
|
||
|
||
DEFAULT_BUILDS_SUBSTITUTED = { | ||
'build': ['make {c.DEFAULT_MAKE_TARGET}'.format(c=cli)], | ||
'install_server': [ | ||
('ipa-server-install -U --domain ipa.test ' | ||
'--realm IPA.TEST -p Secret123 -a Secret123 ' | ||
'--setup-dns --auto-forwarders'), | ||
'ipa-kra-install -p Secret123' | ||
], | ||
} | ||
|
||
|
||
@pytest.fixture( | ||
params=[(k, v) for k, v in DEFAULT_BUILDS_SUBSTITUTED.items()]) | ||
def substituted_commands(request): | ||
return request.param | ||
|
||
|
||
@pytest.fixture | ||
def default_namespace(request, substituted_commands): | ||
parser = cli.make_parser() | ||
subcommand_name = substituted_commands[0].replace('_', '-') | ||
args = parser.parse_args([subcommand_name]) | ||
return vars(args) | ||
|
||
|
||
def test_execution_step_instantiation(ipaconfig, flattened_config, | ||
substituted_commands, default_namespace): | ||
step_name, commands = substituted_commands | ||
command_templates = ipaconfig['steps'][step_name] | ||
|
||
step = command.ExecutionStep(command_templates, flattened_config, | ||
**default_namespace) | ||
|
||
assert step.commands == commands | ||
|
||
|
||
def test_invalid_template_string(flattened_config): | ||
with pytest.raises(KeyError): | ||
command.ExecutionStep(['make ${invalid_var}'], flattened_config) |