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

Fixes #26355 - background template rendering #414

Merged
merged 4 commits into from
Apr 15, 2019

Conversation

ezr-ondrej
Copy link
Member

I have added scheduling, so you can schedule report and download it once it is ready through second command.

The schedule command has --wait option, which will wait for the result actively.

Copy link
Member

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

Thanks, @ezr-ondrej! I know it's WIP, but I'd rather review it ASAP, so you have something to begin with :)

See inline comments, otherwise everything looks fine. Also, there is need to upgrade our apidoc data (test/data/1.21.1 or 1.22) for newer version of Foreman so your tests can pass (I've tried it locally and they seemed to be passing).

lib/hammer_cli_foreman/report_template.rb Outdated Show resolved Hide resolved
lib/hammer_cli_foreman/report_template.rb Outdated Show resolved Hide resolved
lib/hammer_cli_foreman/report_template.rb Outdated Show resolved Hide resolved
lib/hammer_cli_foreman/report_template.rb Outdated Show resolved Hide resolved
test/functional/report_template_test.rb Outdated Show resolved Hide resolved
@ezr-ondrej ezr-ondrej changed the title [WIP] Fixes #26355 - background template rendering Fixes #26355 - background template rendering Mar 30, 2019
@ezr-ondrej ezr-ondrej force-pushed the report_templates_background branch from c1036e1 to 8c525ed Compare March 30, 2019 14:18
test/test_helper.rb Outdated Show resolved Hide resolved
@ezr-ondrej
Copy link
Member Author

Thanks for the pushes in right direction @ofedoren I believe it is ready, as of foreman PR were merged.
Just do not know what to do with the data, because the API is going to get to foreman 1.22, but it is not done, so I should not put the data now, right?

@mbacovsky
Copy link
Member

@ezr-ondrej I think you can do 1.22 from current foreman develop. If there is anything else that will slip in last minute in 1.22 and it is needed for testing in hammer we can always update.

Copy link
Member

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

I agree with @mbacovsky and I'm sure you know how to do it, but if not here's readme: https://github.com/theforeman/hammer-cli-foreman/tree/master/test/data (if I'm not mistaken we generate data without Katello plugin, but pure Foreman).

Also, see the last notes inline :)

if option_wait?
poll_for_report(data)
else
puts data['job_id']
Copy link
Member

Choose a reason for hiding this comment

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

Printing job id only is not very user-friendly approach to tell user what's happening now, isn't it? I mean, what do you think about doing something like print_message(_('The report has been scheduled. Job ID: %{job_id}') % { job_id: data['job_id'] })?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, sounds much more useful 👍 thanks.

response = send_request
if response.code == 204
print_message(_('The report is not ready yet.'))
return HammerCLI::EX_OK
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: you can lower this statement to the end of the method and remove return.

Copy link
Member Author

Choose a reason for hiding this comment

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

🎯 👍

else
puts response.body
end
return HammerCLI::EX_OK
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: redundant return.

def handle_success(response)
if option_path
filepath = store_response(response)
print_message(_('The response has been saved to %{path}s.'), {:path => filepath})
Copy link
Member

Choose a reason for hiding this comment

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

Redundant s at the end of the sentence.

Copy link
Member Author

Choose a reason for hiding this comment

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

🎯 👍

@ezr-ondrej
Copy link
Member Author

Blocked by #418 or at least just #409 as without it, tests won't be green on new data.

@ezr-ondrej ezr-ondrej force-pushed the report_templates_background branch from adb6039 to 7dd5547 Compare April 9, 2019 13:48
@ezr-ondrej
Copy link
Member Author

Rebased on top of #409 so is no longer blocked, #418 is not blocking this.

@ezr-ondrej ezr-ondrej force-pushed the report_templates_background branch from 7dd5547 to 746b08d Compare April 11, 2019 21:52
def execute
response = send_request
if response.code == 204
print_message(_('The report is not ready yet.'))
Copy link
Member Author

@ezr-ondrej ezr-ondrej Apr 12, 2019

Choose a reason for hiding this comment

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

Is there some Exit code to suggest that?

Copy link
Member

Choose a reason for hiding this comment

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

Well, I could suggest HammerCLI::EX_RETRY but I'm sure it will flood the terminal with that message in some cases, which is not quite good. HammerCLI::EX_OK is good enough for it. If you meant something else, ping me on irc (ofedoren) so we can merge it today.

Copy link
Member

Choose a reason for hiding this comment

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

EX_RETRY will lead in re-executing the command again which in the end will make hammer loop here till the report is delivered. If this is not what we want I'd suggest to look at https://github.com/theforeman/hammer-cli/blob/master/lib/hammer_cli/exit_codes.rb
EX_TEMPFAIL may be a good candidate. From certain perspective (expected result, no error) the EX_OK is fine too if no better option is found.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I have rolled out with EX_TEMPFAIL 👍 Thank you both for advises!

Copy link
Member

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

For me it's ready to merge if you're ready :)

@ezr-ondrej
Copy link
Member Author

@ofedoren I believe it is ready :)

@ares
Copy link
Member

ares commented Apr 15, 2019

I'm also ready :-) could this be merged please @ofedoren :-)

@ofedoren
Copy link
Member

@ares. sure :)

@ezr-ondrej. merging then, thanks! :)

@ofedoren ofedoren merged commit d36721b into theforeman:master Apr 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants