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 policy check to Vm retirement. #19064

Merged
merged 1 commit into from
Aug 19, 2019

Conversation

lfu
Copy link
Member

@lfu lfu commented Jul 26, 2019

Vm retirement is handled as a request per #16933.

Depends on ManageIQ/manageiq-content#552.
https://bugzilla.redhat.com/show_bug.cgi?id=1702018

@miq-bot add_label bug, retirement, hammer/yes, ivanchuk/yes, changelog/yes
@miq-bot assign @tinaafitz

it "policy passes" do
expect(VmRetireRequest).to receive(:make_request)

allow(MiqAeEngine).to receive_messages(:deliver => ['ok', 'sucess', MiqAeEngine::MiqAeWorkspaceRuntime.new])
Copy link
Contributor

Choose a reason for hiding this comment

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

@lfu can you use

let(:ws) { MiqAeEngine::MiqAeWorkspaceRuntime.new }

and use it in the 2 tests

Copy link
Contributor

Choose a reason for hiding this comment

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

@lfu sucess should be success

event = {:attributes => {"full_data" => {:policy => {:prevented => true}}}}
ws = MiqAeEngine::MiqAeWorkspaceRuntime.new
allow(ws).to receive(:get_obj_from_path).with("/").and_return(:event_stream => event)
allow(MiqAeEngine).to receive_messages(:deliver => ['ok', 'sucess', ws])
Copy link
Contributor

Choose a reason for hiding this comment

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

@lfu sucess should be success

vm_with_owner.update_attributes(:retires_on => 90.days.ago, :retirement_warn => 60, :retirement_last_warn => nil)
expect(vm_with_owner.retirement_last_warn).to be_nil

allow(MiqAeEngine).to receive_messages(:deliver => ['ok', 'sucess', MiqAeEngine::MiqAeWorkspaceRuntime.new])
Copy link
Contributor

Choose a reason for hiding this comment

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

@lfu sucess?

@mkanoor
Copy link
Contributor

mkanoor commented Aug 13, 2019

@lfu
Looks good waiting for the conflicts to be resolved.

@lfu lfu force-pushed the prevent_retirement_1702018 branch from 511dfa1 to e823e50 Compare August 13, 2019 14:09
@tinaafitz
Copy link
Member

@d-m-u Please review.

@tinaafitz
Copy link
Member

@gmcculloug Please review.

Copy link
Contributor

@d-m-u d-m-u left a comment

Choose a reason for hiding this comment

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

yeah, looks okay to me

@tinaafitz
Copy link
Member

Hi @gmcculloug Please review. This is needed for the 5.10 build.


target.check_policy_prevent('request_vm_retire', "retire_request_after_policy_check", src_id, requester.userid, :initiated_by => initiated_by)
end
end
Copy link
Member

Choose a reason for hiding this comment

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

The find_by lookup could end up being expensive since it would hit the db for every Vm id passed in.

If we do not need the "missing VM" logging it could be simplified to:

def self.make_retire_request(*src_ids, requester, initiated_by: 'user')
  where(:id => src_ids).each do |target|
    target.check_policy_prevent('request_vm_retire', "retire_request_after_policy_check", src_id, requester.userid, :initiated_by => initiated_by)
  end
end

Otherwise, you can still use the ActiveRecord_Relation returned by where to determine the missing IDs as well as loop over the valid VMs:

def self.make_retire_request(*src_ids, requester, initiated_by: 'user')
  vms = where(:id => src_ids)

  missing_ids = (src_ids - vms.pluck(:id))
  _log.error("Retirement of [Vm] IDs: [#{missing_ids.join(', ')}] skipped - target(s) does not exist")

  vms.each do |target|
    target.check_policy_prevent('request_vm_retire', "retire_request_after_policy_check", src_id, requester.userid, :initiated_by => initiated_by)
  end
end

end

def retire_request_after_policy_check(*src_ids, userid, initiated_by: 'user')
klass = VmRetireRequest
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to put the class into a variable if it never modified?

Can we just call VmRetireRequest.request_types.first and VmRetireRequest.make_request directly in this method?

@lfu lfu force-pushed the prevent_retirement_1702018 branch 2 times, most recently from d5630d1 to 5976230 Compare August 19, 2019 14:25
@gmcculloug
Copy link
Member

@lfu Please review test failures.

@lfu lfu force-pushed the prevent_retirement_1702018 branch from 5976230 to 710fecf Compare August 19, 2019 16:14
@miq-bot
Copy link
Member

miq-bot commented Aug 19, 2019

Checked commit lfu@710fecf with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 👍

@gmcculloug gmcculloug merged commit 351f8f3 into ManageIQ:master Aug 19, 2019
@gmcculloug gmcculloug added this to the Sprint 118 Ending Aug 19, 2019 milestone Aug 19, 2019
@lpichler
Copy link
Contributor

lpichler commented Aug 21, 2019

Method make_retire_request overrides method with same name in RetirementMixin and it causes error in API repo

@lfu Do you have idea how to fix it ?
thanks!!

it is about 2 specs in context in api repo:

./spec/requests/vms_spec.rb:1098

and the method make_retire_request is called here in api

@lfu
Copy link
Member Author

lfu commented Aug 21, 2019

@tinaafitz This PR requires API code change.

@d-m-u
Copy link
Contributor

d-m-u commented Aug 23, 2019

Yeah, I'm just here to say that Libor's right and the API spec failure's due to this PR

@lpichler
Copy link
Contributor

thanks @d-m-u
fyi: we are working on fix with @lfu and work is in progress

@lfu
Copy link
Member Author

lfu commented Aug 27, 2019

Not sure why these label were not applied.

@miq-bot add_label hammer/yes, ivanchuk/yes, changelog/yes

@simaishi
Copy link
Contributor

@lfu There are multiple conflicts in the spec file for backporting to hammer branch. Can you please create a separate PR for hammer?

@simaishi
Copy link
Contributor

@lfu This PR conflicts backporting to invahcuk branch as well. If the conflict is same between hammer/ivanchuk, just 1 PR is needed (against ivanchuk) and that can be marked as hammer/yes.
If they're different, please create another PR for ivanchuk.

@simaishi
Copy link
Contributor

Backported to hammer via #19643
Backported to ivanchuk via #19647

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