-
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 policy check to Vm retirement. #19064
Conversation
9ed931d
to
0b8c5a2
Compare
0718c2a
to
bb7af00
Compare
it "policy passes" do | ||
expect(VmRetireRequest).to receive(:make_request) | ||
|
||
allow(MiqAeEngine).to receive_messages(:deliver => ['ok', 'sucess', MiqAeEngine::MiqAeWorkspaceRuntime.new]) |
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.
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.
@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]) |
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.
@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]) |
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.
@lfu sucess?
bb7af00
to
511dfa1
Compare
@lfu |
511dfa1
to
e823e50
Compare
@d-m-u Please review. |
@gmcculloug Please review. |
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.
yeah, looks okay to me
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 |
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.
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
app/models/vm_or_template.rb
Outdated
end | ||
|
||
def retire_request_after_policy_check(*src_ids, userid, initiated_by: 'user') | ||
klass = VmRetireRequest |
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.
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?
d5630d1
to
5976230
Compare
@lfu Please review test failures. |
5976230
to
710fecf
Compare
Checked commit lfu@710fecf with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0 |
Method @lfu Do you have idea how to fix it ? it is about 2 specs in context in api repo:
and the method |
@tinaafitz This PR requires API code change. |
Yeah, I'm just here to say that Libor's right and the API spec failure's due to this PR |
Not sure why these label were not applied. @miq-bot add_label hammer/yes, ivanchuk/yes, changelog/yes |
@lfu There are multiple conflicts in the spec file for backporting to |
@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 |
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