Skip to content

Commit

Permalink
[Resolve #1517] Updated the Cloudformation Hook logging message
Browse files Browse the repository at this point in the history
The Cloudformation hook logging message was bit confusing as it stated the hookmode at the end of the hook log.

The log is shown as below for the successful hook execution:

07:17:25  [2024-09-17 01:47:24] - sbox-01/sbucket Bucket AWS::S3::Bucket CREATE_IN_PROGRESS  sample::Generic::Megahookblock HOOK_COMPLETE_SUCCEEDED Hook succeeded with message: Hook Successfully completed **FAIL**
Even though the hook completed successfully, it mode mentioned at the end of the message is misleading to the end user looking into the logs.

As the failure/warn is mentioned in the hook message after the execution, removing the HOOKMODE from this log message.

Log when Hook Fails in the FAIL mode

07:17:33  [2024-09-17 01:47:33] - sbox-01/sbucket Bucket AWS::S3::Bucket CREATE_IN_PROGRESS  sample::Generic::Megahook HOOK_COMPLETE_FAILED Hook failed with message: Rule [
07:17:33          [CT.S3.PR.1]: Require an Amazon S3 bucket to have block public access settings configured
07:17:33          [FIX]: The parameters 'BlockPublicAcls', 'BlockPublicPolicy', 'IgnorePublicAcls', 'RestrictPublicBuckets' must be set to "true" under the bucket-level 'PublicAccessBlockConfiguration'.
07:17:33          ] failed. FAIL
07:17:33  [2024-09-17 01:47:33] - sbox-01/sbucket Bucket AWS::S3::Bucket CREATE_FAILED The following hook(s) failed: [sample::Generic::Megahook]
Log when Hook Fails in the WARN mode

13:14:32  [2024-09-12 07:44:32] - sbox-01/sbucket Bucket AWS::S3::Bucket CREATE_IN_PROGRESS  sample::Generic::Megahook HOOK_COMPLETE_FAILED Hook failed with message: Rule [
13:14:32          [CT.S3.PR.1]: Require an Amazon S3 bucket to have block public access settings configured
13:14:32          [FIX]: The parameters 'BlockPublicAcls', 'BlockPublicPolicy', 'IgnorePublicAcls', 'RestrictPublicBuckets' must be set to "true" under the bucket-level 'PublicAccessBlockConfiguration'.
13:14:32          ] failed.. Failure was ignored under WARN mode. WARN
13:14:32  [2024-09-12 07:44:32] - sbox-01/sbucket Bucket AWS::S3::Bucket CREATE_IN_PROGRESS Hook invocations complete.  Resource creation initiated
Hence removing the HOOKMODE at the end of the hook logging. Have not updated any logic.
  • Loading branch information
sujit-kulkarni authored Sep 24, 2024
1 parent 1ba2b87 commit 12eb4d6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 5 deletions.
1 change: 0 additions & 1 deletion sceptre/plan/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,6 @@ def _log_new_events(self, after_datetime: datetime) -> datetime:
event["HookType"],
event["HookStatus"],
event.get("HookStatusReason", ""),
event["HookFailureMode"],
]
)
self.logger.info(" ".join(stack_event_status))
Expand Down
4 changes: 0 additions & 4 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,6 @@ def test_log_new_events_with_hook_status_prints_correct_event(
"ResourceStatus": "resource-with-cf-hook",
"HookType": "type-3",
"HookStatus": "HOOK_COMPLETE_SUCCEEDED",
"HookFailureMode": "WARN",
},
{
"Timestamp": datetime.datetime(
Expand All @@ -1138,7 +1137,6 @@ def test_log_new_events_with_hook_status_prints_correct_event(
"HookType": "type-4",
"HookStatus": "HOOK_IN_PROGRESS",
"HookStatusReason": "Good hook",
"HookFailureMode": "WARN",
},
]
}
Expand All @@ -1153,7 +1151,6 @@ def test_log_new_events_with_hook_status_prints_correct_event(
self.actions.describe_events()["StackEvents"][1]["ResourceStatus"],
self.actions.describe_events()["StackEvents"][1]["HookType"],
self.actions.describe_events()["StackEvents"][1]["HookStatus"],
self.actions.describe_events()["StackEvents"][1]["HookFailureMode"],
].sort() == caplog.messages[0].split().sort()
assert [
self.actions.stack.name,
Expand All @@ -1166,7 +1163,6 @@ def test_log_new_events_with_hook_status_prints_correct_event(
self.actions.describe_events()["StackEvents"][0]["HookType"],
self.actions.describe_events()["StackEvents"][0]["HookStatus"],
self.actions.describe_events()["StackEvents"][0]["HookStatusReason"],
self.actions.describe_events()["StackEvents"][0]["HookFailureMode"],
].sort() == caplog.messages[1].split().sort()

@patch("sceptre.plan.actions.StackActions._get_cs_status")
Expand Down

0 comments on commit 12eb4d6

Please sign in to comment.