From dd3b7384dbc113aa8ab0775c254f131d832b44dd Mon Sep 17 00:00:00 2001 From: troyready Date: Fri, 3 Aug 2018 15:17:34 -0700 Subject: [PATCH 1/5] allow configs without stacks This relaxes the current stack validation, replacing it instead with action warning messages. With this, configurations can be created with only hooks. --- stacker/actions/build.py | 2 ++ stacker/actions/destroy.py | 2 ++ stacker/actions/diff.py | 5 ++++- stacker/actions/info.py | 2 ++ stacker/config/__init__.py | 2 +- stacker/tests/test_config.py | 10 ---------- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/stacker/actions/build.py b/stacker/actions/build.py index fa6a31ef4..ed10d6cb6 100644 --- a/stacker/actions/build.py +++ b/stacker/actions/build.py @@ -413,6 +413,8 @@ def run(self, concurrency=0, outline=False, """ plan = self._generate_plan(tail=tail) + if not plan.keys(): + logger.warn('WARNING: No stacks detected (error in config?)') if not outline and not dump: plan.outline(logging.DEBUG) logger.debug("Launching stacks: %s", ", ".join(plan.keys())) diff --git a/stacker/actions/destroy.py b/stacker/actions/destroy.py index 3c70776a4..6ef39e68d 100644 --- a/stacker/actions/destroy.py +++ b/stacker/actions/destroy.py @@ -90,6 +90,8 @@ def pre_run(self, outline=False, *args, **kwargs): def run(self, force, concurrency=0, tail=False, *args, **kwargs): plan = self._generate_plan(tail=tail) + if not plan.keys(): + logger.warn('WARNING: No stacks detected (error in config?)') if force: # need to generate a new plan to log since the outline sets the # steps to COMPLETE in order to log them diff --git a/stacker/actions/diff.py b/stacker/actions/diff.py index 3db8cd05f..7b13a6d04 100644 --- a/stacker/actions/diff.py +++ b/stacker/actions/diff.py @@ -278,7 +278,10 @@ def _generate_plan(self): def run(self, concurrency=0, *args, **kwargs): plan = self._generate_plan() plan.outline(logging.DEBUG) - logger.info("Diffing stacks: %s", ", ".join(plan.keys())) + if plan.keys(): + logger.info("Diffing stacks: %s", ", ".join(plan.keys())) + else: + logger.warn('WARNING: No stacks detected (error in config?)') walker = build_walker(concurrency) plan.execute(walker) diff --git a/stacker/actions/info.py b/stacker/actions/info.py index 25aa27472..1508de2f0 100644 --- a/stacker/actions/info.py +++ b/stacker/actions/info.py @@ -18,6 +18,8 @@ class Action(BaseAction): def run(self, *args, **kwargs): logger.info('Outputs for stacks: %s', self.context.get_fqn()) + if not self.context.get_stacks(): + logger.warn('WARNING: No stacks detected (error in config?)') for stack in self.context.get_stacks(): provider = self.build_provider(stack) diff --git a/stacker/config/__init__.py b/stacker/config/__init__.py index d1d10124d..9580e106d 100644 --- a/stacker/config/__init__.py +++ b/stacker/config/__init__.py @@ -402,7 +402,7 @@ class Config(Model): lookups = DictType(StringType, serialize_when_none=False) stacks = ListType( - ModelType(Stack), default=[], validators=[not_empty_list]) + ModelType(Stack), default=[]) def _remove_excess_keys(self, data): excess_keys = set(data.keys()) diff --git a/stacker/tests/test_config.py b/stacker/tests/test_config.py index f1e7b25dd..d42582746 100644 --- a/stacker/tests/test_config.py +++ b/stacker/tests/test_config.py @@ -94,16 +94,6 @@ def test_config_validate_stack_class_and_template_paths(self): stack_errors['class_path'][0].__str__(), "template_path cannot be present when class_path is provided.") - def test_config_validate_no_stacks(self): - config = Config({"namespace": "prod"}) - with self.assertRaises(exceptions.InvalidConfig) as ex: - config.validate() - - error = ex.exception.errors['stacks'].errors[0] - self.assertEquals( - error.__str__(), - "Should have more than one element.") - def test_config_validate_missing_name(self): config = Config({ "namespace": "prod", From c8d559c19740e2f39dee7ebe59d5ab2aef28c9a6 Mon Sep 17 00:00:00 2001 From: troyready Date: Fri, 3 Aug 2018 17:50:49 -0700 Subject: [PATCH 2/5] update functional test --- tests/test_suite/03_stacker_build-config_with_no_stacks.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_suite/03_stacker_build-config_with_no_stacks.bats b/tests/test_suite/03_stacker_build-config_with_no_stacks.bats index cb538e1a9..4231db42e 100644 --- a/tests/test_suite/03_stacker_build-config_with_no_stacks.bats +++ b/tests/test_suite/03_stacker_build-config_with_no_stacks.bats @@ -7,5 +7,5 @@ load ../test_helper namespace: ${STACKER_NAMESPACE} EOF assert ! "$status" -eq 0 - assert_has_line 'Should have more than one element' + assert_has_line 'WARNING: No stacks detected' } From db75ecec2c2eab075964fb5150d44990bef9561f Mon Sep 17 00:00:00 2001 From: Michael Barrett Date: Sun, 5 Aug 2018 13:13:29 -0700 Subject: [PATCH 3/5] Fix tests --- tests/test_suite/02_stacker_build_empty_config.bats | 2 +- tests/test_suite/03_stacker_build-config_with_no_stacks.bats | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_suite/02_stacker_build_empty_config.bats b/tests/test_suite/02_stacker_build_empty_config.bats index 589672312..7dadb202b 100644 --- a/tests/test_suite/02_stacker_build_empty_config.bats +++ b/tests/test_suite/02_stacker_build_empty_config.bats @@ -5,5 +5,5 @@ load ../test_helper @test "stacker build - empty config" { stacker build <(echo "") assert ! "$status" -eq 0 - assert_has_line 'Should have more than one element' + assert_has_line 'stacker.exceptions.InvalidConfig:' } diff --git a/tests/test_suite/03_stacker_build-config_with_no_stacks.bats b/tests/test_suite/03_stacker_build-config_with_no_stacks.bats index 4231db42e..6b6bd0ac8 100644 --- a/tests/test_suite/03_stacker_build-config_with_no_stacks.bats +++ b/tests/test_suite/03_stacker_build-config_with_no_stacks.bats @@ -3,9 +3,11 @@ load ../test_helper @test "stacker build - config with no stacks" { + needs_aws + stacker build - < Date: Sun, 5 Aug 2018 13:25:12 -0700 Subject: [PATCH 4/5] Fix output for warning when no stacks detected --- tests/test_suite/03_stacker_build-config_with_no_stacks.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_suite/03_stacker_build-config_with_no_stacks.bats b/tests/test_suite/03_stacker_build-config_with_no_stacks.bats index 6b6bd0ac8..53dfbcabb 100644 --- a/tests/test_suite/03_stacker_build-config_with_no_stacks.bats +++ b/tests/test_suite/03_stacker_build-config_with_no_stacks.bats @@ -9,5 +9,5 @@ load ../test_helper namespace: ${STACKER_NAMESPACE} EOF assert ! "$status" -eq 0 - assert_has_line 'Should have more than one element' + assert_has_line 'WARNING: No stacks detected (error in config?)' } From 24eab2257e2d23f3f4c0a40e207c8c48744b0067 Mon Sep 17 00:00:00 2001 From: Michael Barrett Date: Sun, 5 Aug 2018 13:31:58 -0700 Subject: [PATCH 5/5] No longer throw error when configs missing stacks --- tests/test_suite/03_stacker_build-config_with_no_stacks.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_suite/03_stacker_build-config_with_no_stacks.bats b/tests/test_suite/03_stacker_build-config_with_no_stacks.bats index 53dfbcabb..320f5bb4c 100644 --- a/tests/test_suite/03_stacker_build-config_with_no_stacks.bats +++ b/tests/test_suite/03_stacker_build-config_with_no_stacks.bats @@ -8,6 +8,6 @@ load ../test_helper stacker build - <