Fixes #38456 - Hosts bulk action: Disassociate hosts - #10560
Conversation
ekohl
left a comment
There was a problem hiding this comment.
I like the bulk action, but I have questions about the preview. What if the user selects all entries, also those on other pages. Will it render potentially 100s or 1000s of hosts?
There was a problem hiding this comment.
This is the message from mock page.
How about change it to server?
There was a problem hiding this comment.
If you change it to Foreman, the branding plugin will take care of changing it to Satellite downstream.
There was a problem hiding this comment.
We also support VMs that aren't associated so I don't think you should explicitly mention physical.
Also, the title needs to be translatable.
There was a problem hiding this comment.
Physical hosts is what is used in the existing old page and in the mock page.
Any suggestion if we do need to change it?
There was a problem hiding this comment.
Why a magic 7 here?
| apiUrl: `${HOSTS_API_PATH}?per_page=7`, | |
| apiUrl: HOSTS_API_PATH, |
Or did you intend per_page=all to avoid pagination? If so, I think that should be passed via defaultParams and not as part of the URL.
There was a problem hiding this comment.
I'll take responsibility for this, as I assume it was copied and pasted from one of the wizards on the same page. A per_page = 7 was the starting page size that looks the best with these modals. It doesn't make sense to start with the default per_page of 20 in this case, because they don't all fit on the screen. However, the per_page may not be relevant here, if there's no table involved.
There was a problem hiding this comment.
It may be. On the non-react all host page you can also select all items. Also, the user may have changed the page size on the overview to be more than the default. So I'd suggest per_page=all to avoid pagination.
There was a problem hiding this comment.
Does it make sense to also list the name of the compute resource and possibly the type of the compute resource? If so, a table view already makes more sense.
There was a problem hiding this comment.
I added information about compute resource when it's available.
There was a problem hiding this comment.
Removed host details. Only host count would be displayed.
There was a problem hiding this comment.
This doesn't work with translations. Please use n_() to translate with respecting plurals. See https://projects.theforeman.org/projects/foreman/wiki/Translating#Extracting-strings for more information.
You asked many questions that I have kept asking myself when working on this. |
c077386 to
e0979c4
Compare
TreeView would display a scrollbar if the list is long. |
4e68cae to
9fcaad6
Compare
|
Could we have a review here? |
On the Packages wizards (and also Errata I think) we only show the badge count for hosts, and don't let you expand the tree or see the individual hosts at all. If we do that here, it'd be consistent so I'd be fine with that. |
9fcaad6 to
991e777
Compare
|
Updated. |
ekohl
left a comment
There was a problem hiding this comment.
Naming wise I think we should avoid physical vs virtual. We have many people who have virtual machines but don't use compute resources.
It would be really good if we had some automated tests for this. Could you have a look at creating those so we build up a regression test suite?
There was a problem hiding this comment.
I think this text could be improved on what it actually does. The "To avoid deleting" part is really confusing because we already have a setting destroy_vm_on_host_delete that already prevents deletion of the VM on deletion from Foreman.
I'm not sure what a good text actually is though. Perhaps ask our writers for input?
There was a problem hiding this comment.
Repeating my suggestion from offline discussion:
This will disassociate the host in Foreman from its compute resource.
After disassociating, a host can be deleted from Foreman without affecting its virtual machine.
Hosts without a compute resource will be excluded.
There was a problem hiding this comment.
Thinking more: is this a good moment to consider the naming? I know it was already there, but perhaps this is clearer what it actually does:
| api :PUT, "/hosts/bulk/disassociate", N_("Disassociate hosts") | |
| api :PUT, "/hosts/bulk/disassociate", N_("Disassociate compute resources") |
My reasoning is that the hosts part doesn't add anything because we're already on the hosts overview. The new subject makes it clear what will happen.
There was a problem hiding this comment.
Does this change apply only here? Or all places where Disassociate hosts is displayed?
There was a problem hiding this comment.
Looks like there is only one place now:
I lean to not updating the old texts because I'm not sure where else that's referred to.
There was a problem hiding this comment.
Thanks for looking into this @ekohl 👍
I think this task really means disassociate hosts from their compute resources.
If that is correct, then disassociate hosts makes more sense than disassociate compute resources.
There was a problem hiding this comment.
I lean to not updating the old texts because I'm not sure where else that's referred to.
I mean Disassociate hosts in the action menu and the modal.
But Disassociate hosts seems right to me at this moment.
There was a problem hiding this comment.
My point is that you're on the hosts page, so that bit should be implicit. But disassociate from what? Disassociate from compute resources is the answer. I left out the word from for brevity.
Perhaps Maria can weigh in on the UX aspect of it. Or @jeremylenz cpuld be a tie breaker
There was a problem hiding this comment.
api :PUT, "/hosts/bulk/disassociate" implies that hosts are already involved, so IMO "Disassociate compute resources" is sufficient. It could be short for any number of things ('disassociate compute resources from their hosts?' 'disassociate [hosts] from compute resources?') but we don't need all of those words.
991e777 to
096fd52
Compare
There was a problem hiding this comment.
Should we keep this consistent with the action description?
| process_response(true, { :message => n_("Updated %{count} host: Disassociated from VM", | |
| "Updated %{count} hosts: Disassociated from VM", | |
| process_response(true, { :message => n_("Updated %{count} host: Disassociated from compute resource", | |
| "Updated %{count} hosts: Disassociated from compute resource", |
There was a problem hiding this comment.
Perhaps also avoid virtual vs physical in variable naming?
| const virtualHosts = selectedResults?.filter( | |
| const hostsWithComputeResource = selectedResults?.filter( |
There was a problem hiding this comment.
I think Applicable could be confusing. Perhaps write out what it actually is?
| name: __('Applicable hosts'), | |
| name: __('Hosts associated to compute resources'), |
There was a problem hiding this comment.
Can we keep these sorted alphabetically?
I also wonder why it doesn't use the easier way. https://guides.rubyonrails.org/routing.html#http-verb-constraints says match is only useful if you want to match multiple methods:
In general, you should use the get, post, put, patch, and delete methods to constrain a route to a particular verb. There is a match method that you could use with the :via option to match multiple verbs at once:
So you could simplify this to:
| match 'hosts/bulk/disassociate', :to => 'hosts_bulk_actions#disassociate', :via => [:put] | |
| put 'hosts/bulk/disassociate', :to => 'hosts_bulk_actions#disassociate' |
096fd52 to
07834c2
Compare
There was a problem hiding this comment.
I'd be tempted to BulkHostsManager.new(hosts: @hosts).disassociate return the count and then use:
| BulkHostsManager.new(hosts: @hosts).disassociate | |
| process_response(true, { :message => n_("Updated %{count} host: Disassociated from compute resource", | |
| "Updated %{count} hosts: Disassociated from compute resource", | |
| @hosts.count) % {count: @hosts.count}}) | |
| count = BulkHostsManager.new(hosts: @hosts).disassociate | |
| process_response(true, { :message => n_("Updated %{count} host: Disassociated from compute resource", | |
| "Updated %{count} hosts: Disassociated from compute resource", | |
| count) % {count: count}}) |
Mostly because it's neatly separating the concern.
There was a problem hiding this comment.
I'm going to note this down for my own sanity, because I've been looking at it multiple times.
The method disassociate! is defined here:
foreman/app/models/host/managed.rb
Lines 589 to 593 in f4246cd
Now the comment says it doesn't trigger callbacks, but not what https://api.rubyonrails.org/v8.0.2/classes/ActiveRecord/Persistence.html#method-i-save-21 states it does run callbacks. Callbacks triggers audits and hooks, possibly more. That means you can't replace it with update_all since that uses direct SQL to update them all in bulk.
If we already accept that we need to save each individual object then there's still the question of counting the affected rows.
save!() will always return true or raise an exception so there's no way of knowing if it actually modified any records. That means you need to count.
Last note: that I found while looking this up: there is MyClass.in_batches.each_record to avoid instantiating all objects. For large collections of records this can save with memory consumption. That's probably something more for a general BulkHostsManager optimization.
Short summary is that for now this is probably the best we can do.
There was a problem hiding this comment.
In my previous message it was implied to also move away from the "physical" naming, just like with virtual.
07834c2 to
05cceb6
Compare
|
I have tested the basic functionality of this PR here SatelliteQE/robottelo#18859, it passes the test. |
3486310 to
579dd14
Compare
|
Could we have another review? |
|
Note: also tested with the newest commit, and it still works :) |
|
Failed test seems not related. |
|
Any update? |
ekohl
left a comment
There was a problem hiding this comment.
Untested, but API wise and translation wise I think this is correct.
|
Could we have some care here? Thanks! |
jeremylenz
left a comment
There was a problem hiding this comment.
One small comment, just to be consistent with @chris1984 's #10589
Other than that, ACK after tests are green. Perhaps a rebase will help.
There was a problem hiding this comment.
| {__('Confirm')} | |
| {__('Disassociate')} |
72de859 to
9926688
Compare
9926688 to
09b6a9a
Compare
|
Updated. Waiting... |


Add
Disassociate hostsfor new hosts page.To test
Select hosts - Disassociate hosts from Kebab menu.