Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform output shown in logs as a single string without new lines. #2627

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bkopilov
Copy link
Contributor

Print the terraform output to log.info which print new lines and its clear to read

@openshift-ci openshift-ci bot requested review from avishayt and eliorerz January 30, 2025 11:26
@openshift-ci openshift-ci bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 30, 2025
Copy link

openshift-ci bot commented Jan 30, 2025

Hi @bkopilov. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@bkopilov
Copy link
Contributor Author

@adriengentil . @danmanor

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 30, 2025
Copy link

openshift-ci bot commented Jan 30, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bkopilov, danmanor

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@danmanor
Copy link
Contributor

/ok-to-test

@openshift-ci openshift-ci bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 30, 2025
@@ -74,6 +74,10 @@ def apply(
return_value, output, err = self.tf.apply(
no_color=IsFlagged, refresh=refresh, input=False, skip_plan=True, capture_output=capture_output
)
# print terraform output line by line without \n
if output and type(output) is str:
log.info(output)
Copy link
Contributor

@adriengentil adriengentil Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to store a file somewhere, I fear it can expose credentials publicly in Prow in case of vsphere or nutatix cc @danmanor

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it it really the "terraform" output, or the output log of the resulting of terraform apply?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The terraform outut printed anyway but with \n and shown in single line .
It always in test_infra.log . i just take the same output and print it with a way that translate the \n to new line in output.

it was better to fix it in terraform code ... but ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we fix it? Logs are already hard to read, printing twice the output would be less friendly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The terrfaform package , inside runs the cmd for apply and return the output .

Terraform.apply: (self, dir_or_plan=None, input=False, skip_plan=False, no_color=IsFlagged, **kwargs)                                                                                     │
│ apply                                                                                                                                                                                     │
│ refer to https://terraform.io/docs/commands/apply.html                                                                                                                                    │
│ no-color is flagged by default                                                                                                                                                            │
│ :param no_color: disable color of stdout                                                                                                                                                  │
│ :param input: disable prompt for a missing variable                                                                                                                                       │
│ :param dir_or_plan: folder relative to working folder                                                                                                                                     │
│ :param skip_plan: force apply without plan (default: false)                                                                                                                               │
│ :param kwargs: same as kwags in method 'cmd'                                                                                                                                              │
│ :returns return_code, stdout, stderr   

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The terraform package use subproccess module and run:

p = subprocess.Popen(cmds, stdout=stdout, stderr=stderr,
293 cwd=working_folder, env=environ_vars)
294
295 synchronous = kwargs.pop('synchronous', True)
296 if not synchronous:
297 return p, None, None
298
299 out, err = p.communicate()
300 ret_code = p.returncode
301 log.debug('output: {o}'.format(o=out))
302
303 if ret_code == 0:
304 self.read_state_file()
305 else:
306 log.warn('error: {e}'.format(e=err))
307
308 self.temp_var_files.clean_up()
309 if capture_output is True:
310 out = out.decode('utf-8')
311 err = err.decode('utf-8')
312 else:
313 out = None
314 err = None
315
316 if ret_code != 0 and raise_on_error:
317 raise TerraformCommandError(
318 ret_code, ' '.join(cmds), out=out, err=err)
319
320 return ret_code, out, err

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.debug('output: {o}'.format(o=out))

we can just disable log debug for this package?

@adriengentil
Copy link
Contributor

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 30, 2025
@adriengentil
Copy link
Contributor

adriengentil commented Jan 30, 2025

@bkopilov why do we need to print it on the log output?

we have very few outputs actually:
https://github.com/search?q=language%3AHCL+repo%3Aopenshift%2Fassisted-test-infra+output&type=code

@bkopilov
Copy link
Contributor Author

Not critical .... we can skip it

…lines.

Print the terraform output to log.info which print new lines and its clear to read
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 30, 2025
Copy link

openshift-ci bot commented Jan 30, 2025

New changes are detected. LGTM label has been removed.

Copy link

openshift-ci bot commented Jan 30, 2025

@bkopilov: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants