-
Notifications
You must be signed in to change notification settings - Fork 993
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 #37395 - New Hosts page perform build actions #10146
Conversation
f5abb42
to
966eebb
Compare
app/controllers/hosts_controller.rb
Outdated
@@ -533,20 +548,39 @@ def submit_multiple_build | |||
message = _('Failed to redeploy %s.') % host | |||
Foreman::Logging.exception(message, error) | |||
success = false | |||
message = _('Failed to reboot %s.') % @host | |||
warning(message) | |||
Foreman::Logging.exception(message, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logging 2 messages for 1 exception feels redundant. Was this intentional?
Trying to re-run redmine issues seems to not be working. |
1f9bea4
to
5cc9598
Compare
manager = BulkHostsManager.new(hosts: @hosts) | ||
missed_hosts = manager.build(reboot: reboot) | ||
if missed_hosts.empty? | ||
process_response(true, { :message => _("Built %{host_count} %{hosts}") % { :host_count => @hosts.count, :hosts => 'host'.pluralize(@hosts.count) }}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks translations because host
or hosts
will not be correctly translated. There are also languages which have a more complex plural system and n_()
is the correct function to use. See https://projects.theforeman.org/projects/foreman/wiki/Translating#Extracting-strings as well:
process_response(true, { :message => _("Built %{host_count} %{hosts}") % { :host_count => @hosts.count, :hosts => 'host'.pluralize(@hosts.count) }}) | |
process_response(true, { :message => n_("Built %s host", "Built %s hosts", @hosts.count) % @hosts.count }) |
I don't know if @hosts.count
will be cached or result in 2 queries, but the previous code already had that too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
if missed_hosts.empty? | ||
process_response(true, { :message => _("Built %{host_count} %{hosts}") % { :host_count => @hosts.count, :hosts => 'host'.pluralize(@hosts.count) }}) | ||
else | ||
process_response(false, { :message => _("The following hosts failed the build operation: %s") % missed_hosts.map(&:name).to_sentence}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does to_sentence
actually work with translations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are not doing to_sentence
anymore
end | ||
|
||
if message.blank? | ||
process_response(true, { :message => _("Rebuilt configuration for %{host_count} %{hosts}") % { :host_count => @hosts.count, :hosts => 'host'.pluralize(@hosts.count) }}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same problem as above, so please use n_()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for re-implementing again @parthaa
I like the BulkHostsManager
approach muuuuuch better than the previous tries! 🚀
A few code comments here; I'll retest once ewoud's and my comments are addressed
...ets/javascripts/react_app/components/HostsIndex/BulkActions/buildHosts/BulkBuildHostModal.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple more minor comments :)
handleSuccess: response => { | ||
if (handleSuccess) handleSuccess(response); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason this won't work?
handleSuccess: response => { | |
if (handleSuccess) handleSuccess(response); | |
}, | |
handleSuccess, |
APIRequest.js already handles it for us if you don't pass handleSuccess
: https://github.com/theforeman/foreman/blob/develop/webpack/assets/javascripts/react_app/redux/API/APIRequest.js#L20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
onClick={setModalOpen} | ||
isDisabled={selectedCount === 0} | ||
> | ||
{__('Build Hosts')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the mockup:
{__('Build Hosts')} | |
{__('Build management')} |
(and don't forget sentence case, not title case)
successToast: () => { | ||
if (params.rebuild_configuration) | ||
return __('Rebuilt the configuration for hosts.'); | ||
return __('Built hosts.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be helpful to have different wording here if you checked reboot?
maybe
Hosts set to build and rebooting.
message = '' | ||
all_fails.each_pair do |key, values| | ||
unless values.empty? | ||
message << ((N_("%{config_type} rebuild failed for host: %{host_names}.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N_()
is for "mark to translate" while n_()
is plural form
message << ((N_("%{config_type} rebuild failed for host: %{host_names}.", | |
message << ((n_("%{config_type} rebuild failed for host: %{host_names}.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evgeni and I were talking about this the other day and looking at https://projects.theforeman.org/projects/foreman/wiki/Translating, and it was unclear which one is correct for "I want to use the percent thingies, but not necessarily pluralize any words." The examples that use %s
all use N_()
.
end | ||
|
||
if message.blank? | ||
process_response(true, { :message => N_("Rebuilt configuration for %{host_count} %{hosts}") % { :host_count => @hosts.count, :hosts => 'host'.pluralize(@hosts.count) }}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also correct the translations here:
process_response(true, { :message => N_("Rebuilt configuration for %{host_count} %{hosts}") % { :host_count => @hosts.count, :hosts => 'host'.pluralize(@hosts.count) }}) | |
process_response(true, { :message => n_("Rebuilt configuration for %s host", "Rebuilt configuration for %s hosts, @hosts.count) % @hosts.count }) |
To fail I changed => bulk_hosts_manager with something like begin
host.built(false) if host.build? && host.token_expired?
host.setBuild
host.power.reset if reboot && host.supports_power_and_running?
raise "Life ...." if host.id.even?
rescue => error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, tested again and works well 👍
APGHA
failed_host_ids = [] | ||
all_fails.each_pair do |key, values| | ||
failed_host_ids.concat(values.map(&:id)) unless values.empty? | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ruby 2.7 introduced flat_map
which can greatly simplify this code:
failed_host_ids = [] | |
all_fails.each_pair do |key, values| | |
failed_host_ids.concat(values.map(&:id)) unless values.empty? | |
end | |
failed_host_ids = all_fails.flat_map { |_key, value| values.map(&:id) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated. @ekohl also let me know if you are ok with the changes. Trying to get this merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a complete review, but I think at least the translation part (that I focused on) is correct now. However, I am concerned about the lack of tests for this.
failed_host_ids.compact! | ||
failed_host_ids.uniq! | ||
|
||
if failed_host_ids.blank? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In normal Ruby blank?
is not defined. Is that a rails extension? I'd still prefer the native empty?
:
if failed_host_ids.blank? | |
if failed_host_ids.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank
is from Rails and seems more useful to me, since it handles more than .empty
. It's used all over Foreman so I think it's fine here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer blank?
over .empty?
to handle nil cases but that being said in this case if failed_host_ids
are nil we have other problems. So going to commit this change
39eaac7
to
29dc337
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a complete review: I focused on the translation part and that now looks correct. I'll leave the JS and other parts to people who know that stuff.
Refs #37395 - Made the hosts controller handle both json and html Refs #37395 - Fails correctly with url Refs #37395 - Moved error notifications to a separate file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per offline discussion: ACK so this can be merged now and it will unblock Samir. Please add test coverage in a followup PR 👍
thanks @parthaa !
Added build actions to work with the new hosts page.
Steps to verify
Build Hosts
from the kebab