-
Notifications
You must be signed in to change notification settings - Fork 897
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
Add object retirement_requester #18113
Add object retirement_requester #18113
Conversation
09341ab
to
ae70343
Compare
@miq-bot remove_label wip |
ae70343
to
14cb00b
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.
@miq-bot assign @gmcculloug |
def set_retirement_requester(obj_name, obj_ids, requester) | ||
obj_ids.each do |id| | ||
_log.info("Retirement requester for #{obj_name} #{id} being set to #{requester.userid}") | ||
obj_name.constantize.find(id).update_attributes(:retirement_requester => requester.userid) |
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.
Have you verified that all object types that pass through this mixin logic have a retirement_requester
? They need to be available on Hammer
and Gaprindashvili
branches as well.
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 think that we're at least fine
, haha. May 4th of '17 was the date that this field was available on Services n Vms n OrchStacks and LoadBalancers. Honestly, though, I have no idea why we even have retirement as a thing for load balancers, I don't think that's really a thing. But the column is there!
Anyone? Anyone? I know you all are 👻 s but it's 12 lines of code. |
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 like it - just possibly like a more efficient request to update the objects.
User.current_user = user | ||
expect(ServiceRetireRequest).to receive(:make_request).with(nil, {:src_ids => ['yabadabadoo'], :__request_type__ => "service_retire"}, User.current_user, true) | ||
@service.class.to_s.demodulize.constantize.make_retire_request('yabadabadoo', User.current_user) | ||
expect(ServiceRetireRequest).to receive(:make_request).with(nil, {:src_ids => [service3.id], :__request_type__ => "service_retire"}, user, true) |
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.
ASIDE: (only if this is a quick fix)
these tests are making us not call make_request
. Makes me a little nervous to hide this code.
But I guess this is what the existing code does.
Just curious if it is quick to do this another way.
@@ -26,6 +27,13 @@ def retire(ids, options = {}) | |||
q_options.merge!(:user_id => user.id, :group_id => user.current_group.id, :tenant_id => user.current_tenant.id) if user | |||
MiqQueue.put(q_options) | |||
end | |||
|
|||
def set_retirement_requester(obj_name, obj_ids, requester) | |||
obj_ids.each do |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.
This will be doing an N+1 for looking up object_ids. Not sure how many there will be. Or if some of the ids will be invalid.
obj_name.constatize.where(:id => obj_ids).each do |object|
_log.info("Retirement requester for #{obj_name} #{object.id} being set to #{requester.userid}")
object.update_attributes(:retirement_requester => requester.userid))
end
- Not sure if you need to count the query result and raise a not found error or something
- Also, can't remember the way we typically display
class:id
, but thought it had[]
or something. - an
update_all(:retirement_requester => requester.userid)
would just do it in the database and not fetch any of the results - again, an optimization that may make sense or not.
Or
@@ -96,15 +99,13 @@ | |||
end | |||
|
|||
it "with one src_id" do | |||
User.current_user = user | |||
expect(ServiceRetireRequest).to receive(:make_request).with(nil, {:src_ids => ['yabadabadoo'], :__request_type__ => "service_retire"}, User.current_user, true) | |||
@service.class.to_s.demodulize.constantize.make_retire_request('yabadabadoo', User.current_user) |
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.
thank you so much for removing this 'yabadabadoo'
junk.
I like the Flinstones and all but... yea
end | ||
|
||
it "with many src_ids" do | ||
User.current_user = user | ||
expect(ServiceRetireRequest).to receive(:make_request).with(nil, {:src_ids => [1, 2, 3], :__request_type__ => "service_retire"}, User.current_user, true) |
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.
again - thanks for removing these hardcoded ids - way too fragile
14cb00b
to
94a72f8
Compare
def set_retirement_requester(klass, obj_ids, requester) | ||
existing_objects = klass.where(:id => obj_ids) | ||
existing_objects.update_all(:retirement_requester => requester.userid) | ||
if (obj_ids - existing_objects.pluck(:id)).present? |
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.
Maybe set the variable before the conditional?
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 minor tweaks to avoid downloading all the existing_objects
In this rendition, existing_objects
are just a scope - not downloaded
|
||
def set_retirement_requester(klass, obj_ids, requester) | ||
existing_objects = klass.where(:id => obj_ids) | ||
existing_objects.update_all(:retirement_requester => requester.userid) |
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.
existing_objects.update_all(:retirement_requester => requester.userid) | |
update_count = existing_objects.update_all(:retirement_requester => requester.userid) |
def set_retirement_requester(klass, obj_ids, requester) | ||
existing_objects = klass.where(:id => obj_ids) | ||
existing_objects.update_all(:retirement_requester => requester.userid) | ||
if (obj_ids - existing_objects.pluck(:id)).present? |
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.
if (obj_ids - existing_objects.pluck(:id)).present? | |
if update_count != obj_ids.count |
objects_not_found = (obj_ids - existing_objects.pluck(:id)) | ||
_log.info("Retirement requester for #{obj_name}.pluralize #{objects_not_found} not set because objects not found") | ||
else | ||
_log.info("Retirement requester for #{obj_name}.pluralize #{existing_objects} being set to #{requester.userid}") |
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.
_log.info("Retirement requester for #{obj_name}.pluralize #{existing_objects} being set to #{requester.userid}") | |
_log.info("Retirement requester for #{obj_name}.pluralize #{obj_ids} being set to #{requester.userid}") |
94a72f8
to
2168b96
Compare
Checked commit d-m-u@2168b96 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 app/models/mixins/retirement_mixin.rb
|
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
ASSUMPTION: there is no callback logic triggered by an object being retired.
(If there is callback logic, then we'll need to fallback to existing_objects.each { |o| ... }
)
@simaishi It's g/yes but can't be backported, will be opening another for the gap branch. don't backport me to g, pleasethough h is fine... |
Add object retirement_requester (cherry picked from commit aaf424f) https://bugzilla.redhat.com/show_bug.cgi?id=1638502
Hammer backport details:
|
As per @d-m-u this PR is no longer needed in gaprindashvili branch, removing the label. |
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1638502
We should be setting the retirement_requester on the object, not just on the request.
related PRS:
don't backport me to g, please
but can be backported fine to h