Skip to content

Commit

Permalink
Remove terraform duplicated logs (#243)
Browse files Browse the repository at this point in the history
Remove from the qesap.py stdout some logs that report messages from
Terraform twice. Issue is present only when run the glue script in
verbose mode.
  • Loading branch information
mpagot authored Jun 17, 2024
1 parent 555b28a commit 37b1c2e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 1 addition & 2 deletions scripts/qesap/lib/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,14 @@ def cmd_terraform(configure_data, base_project, dryrun, workspace='default', des
print(' '.join(command))
else:
ret, out = lib.process_manager.subprocess_run(command)
log.debug('\n> '.join(out))
log.debug("Terraform process return ret:%d", ret)
log_filename = f"terraform.{command[2]}.log.txt"
log.debug("Write %s getcwd:%s", log_filename, os.getcwd())
with open(log_filename, 'w', encoding='utf-8') as log_file:
log_file.write('\n'.join(out))
if ret != 0:
log.error("command:%s returned non zero %d", command, ret)
return Status(f"Error at {command}")
return Status(f"Error rc: {ret} at {command}")
return Status('ok')


Expand Down
10 changes: 7 additions & 3 deletions scripts/qesap/test/e2e/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ set -e
rm "${TEST_PROVIDER}/main.tf"

test_step "[test_3.yaml] Run Terraform"
# correct execution of terraform
# test is checking for 0 exit code
# correct execution of terraform: test is checking for 0 exit code
# and for the generation of the terraform.tfstate
# terraform.tfstate is directly created by the terraform executable
# Test is using an empty main.tf placed in the right provider folder
touch "${TEST_PROVIDER}/main.tf"
qesap.py --verbose -b ${QESAPROOT} -c test_3.yaml terraform || test_die "test_3.yaml fail on terraform"
TEST_TERRAFORM_TFSTATE="${TEST_PROVIDER}/terraform.tfstate"
Expand Down Expand Up @@ -184,6 +184,10 @@ rc=$?; [[ $rc -eq 0 ]] || test_die "rc:$rc in verbose mode there should be some

grep -qE "^INFO" "${THIS_LOG}"
rc=$?; [[ $rc -eq 0 ]] || test_die "rc:$rc in verbose mode there should be some INFO"

# check for duplicated lines
lines=$(grep -c "Apply complete!" "${THIS_LOG}")
[[ $lines -eq 1 ]] || test_die "${THIS_LOG} there's one message in the log repeated $lines times."
set -e
rm "${THIS_LOG}"

Expand Down Expand Up @@ -269,7 +273,7 @@ rc=$?; [[ $rc -eq 0 ]] || test_die "rc:$rc in verbose mode there should be some
grep -qE "^INFO" "${THIS_LOG}"
rc=$?; [[ $rc -eq 0 ]] || test_die "rc:$rc in verbose mode there should be some INFO"

occurrence=$(grep -E "TASK \[Say hello\]" "${THIS_LOG}" | wc -l)
occurrence=$(grep -cE "TASK \[Say hello\]" "${THIS_LOG}")
[[ $occurrence -eq 1 ]] || test_die "Some Ansible stdout lines are repeated ${occurrence} times in place of exactly 1"
set -e
rm "${THIS_LOG}"
Expand Down

0 comments on commit 37b1c2e

Please sign in to comment.