Skip to content

Commit

Permalink
Run dump and outline actions offline (#594)
Browse files Browse the repository at this point in the history
Build does not need access to AWS when run with `dump` or
`outline` options so make it run offline for those actions.
  • Loading branch information
zaro0508 authored and phobologic committed May 12, 2018
1 parent dad8cd8 commit 4c58c0b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
17 changes: 16 additions & 1 deletion stacker/actions/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ def should_submit(stack):
return False


def should_ensure_cfn_bucket(outline, dump):
"""Test whether access to the cloudformation template bucket is required
Args:
outline (bool): The outline action.
dump (bool): The dump action.
Returns:
bool: If access to CF bucket is needed, return True.
"""
return outline is False and dump is False


def _resolve_parameters(parameters, blueprint):
"""Resolves CloudFormation Parameters for a given blueprint.
Expand Down Expand Up @@ -351,7 +365,8 @@ def _generate_plan(self, tail=False):

def pre_run(self, outline=False, dump=False, *args, **kwargs):
"""Any steps that need to be taken prior to running the action."""
self.ensure_cfn_bucket()
if should_ensure_cfn_bucket(outline, dump):
self.ensure_cfn_bucket()
hooks = self.context.config.pre_build
handle_hooks(
"pre_build",
Expand Down
20 changes: 20 additions & 0 deletions stacker/tests/actions/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ def test_should_update(self):
mock_stack.force = t.force
self.assertEqual(build.should_update(mock_stack), t.result)

def test_should_ensure_cfn_bucket(self):
test_scenarios = [
{"outline": False, "dump": False, "result": True},
{"outline": True, "dump": False, "result": False},
{"outline": False, "dump": True, "result": False},
{"outline": True, "dump": True, "result": False},
{"outline": True, "dump": "DUMP", "result": False}
]

for scenario in test_scenarios:
outline = scenario["outline"]
dump = scenario["dump"]
result = scenario["result"]
try:
self.assertEqual(
build.should_ensure_cfn_bucket(outline, dump), result)
except AssertionError as e:
e.args += ("scenario", str(scenario))
raise

def test_should_submit(self):
test_scenario = namedtuple("test_scenario",
["enabled", "result"])
Expand Down

0 comments on commit 4c58c0b

Please sign in to comment.