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

Add object retirement_requester #18113

Merged
merged 1 commit into from
Oct 22, 2018

Conversation

d-m-u
Copy link
Contributor

@d-m-u d-m-u commented Oct 18, 2018

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

@miq-bot miq-bot added the wip label Oct 18, 2018
@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 18, 2018

@miq-bot add_label hammer/yes, bug, blocker, gaprindashvili/yes
but please don't backport, will need to open a whole new PR for gap
@miq-bot add_reviewer @tinaafitz
@miq-bot add_reviewer @bdunne
@miq-bot add_reviewer @kbrock

@d-m-u d-m-u force-pushed the adding_object_retirement_requester branch 3 times, most recently from 09341ab to ae70343 Compare October 19, 2018 12:44
@d-m-u d-m-u changed the title [WIP] Add object retirement_requester Add object retirement_requester Oct 19, 2018
@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 19, 2018

@miq-bot remove_label wip

@miq-bot miq-bot removed the wip label Oct 19, 2018
@d-m-u d-m-u mentioned this pull request Oct 19, 2018
@d-m-u d-m-u force-pushed the adding_object_retirement_requester branch from ae70343 to 14cb00b Compare October 19, 2018 13:36
Copy link
Member

@tinaafitz tinaafitz left a comment

Choose a reason for hiding this comment

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

@d-m-u Looks good.
@mkanoor Please review.

@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 19, 2018

@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)
Copy link
Member

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.

Copy link
Contributor Author

@d-m-u d-m-u Oct 22, 2018

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!

@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 22, 2018

@miq-bot add_reviewer @mkanoor

@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 22, 2018

Anyone? Anyone? I know you all are 👻 s but it's 12 lines of code.

Copy link
Member

@kbrock kbrock left a 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)
Copy link
Member

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|
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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

@d-m-u d-m-u force-pushed the adding_object_retirement_requester branch from 14cb00b to 94a72f8 Compare October 22, 2018 17:03
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?
Copy link
Member

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?

@miq-bot miq-bot requested a review from mkanoor October 22, 2018 17:24
Copy link
Member

@kbrock kbrock left a 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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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?
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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}")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_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}")

@d-m-u d-m-u force-pushed the adding_object_retirement_requester branch from 94a72f8 to 2168b96 Compare October 22, 2018 17:48
@miq-bot
Copy link
Member

miq-bot commented Oct 22, 2018

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
4 files checked, 1 offense detected

app/models/mixins/retirement_mixin.rb

Copy link
Member

@kbrock kbrock left a 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| ... })

@kbrock kbrock assigned kbrock and unassigned gmcculloug Oct 22, 2018
@kbrock kbrock added this to the Sprint 97 Ending Oct 22, 2018 milestone Oct 22, 2018
@kbrock kbrock merged commit aaf424f into ManageIQ:master Oct 22, 2018
@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 22, 2018

@simaishi It's g/yes but can't be backported, will be opening another for the gap branch.

don't backport me to g, please

though h is fine...

simaishi pushed a commit that referenced this pull request Oct 22, 2018
@simaishi
Copy link
Contributor

Hammer backport details:

$ git log -1
commit c7715ec2ef78f24933420868fa2c1dc2fb2e4711
Author: Keenan Brock <[email protected]>
Date:   Mon Oct 22 14:39:22 2018 -0400

    Merge pull request #18113 from d-m-u/adding_object_retirement_requester
    
    Add object retirement_requester
    
    (cherry picked from commit aaf424f04def8ce40be7e639730782c9f8f38042)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1638502

@simaishi
Copy link
Contributor

As per @d-m-u this PR is no longer needed in gaprindashvili branch, removing the label.

@d-m-u d-m-u deleted the adding_object_retirement_requester branch February 1, 2019 20:48
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.

8 participants