Skip to content

Commit

Permalink
Merge pull request #14641 from lfu/prevent_retirement_request
Browse files Browse the repository at this point in the history
Add policy checking for retirement request.
  • Loading branch information
gmcculloug authored Apr 7, 2017
2 parents 3579c51 + 67db0f4 commit 302e14c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion db/fixtures/miq_event_definition_sets.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ vm_operational,VM Operation
vm_configurational,VM Configuration
vm_process,VM Lifecycle
service_process,Service Lifecycle
orchestration_process,Orchestration Lifecycle
storage_operational,Datastore Operation
auth_validation,Authentication Validation
container_operations,Container Operation
container_operations,Container Operation
5 changes: 5 additions & 0 deletions db/fixtures/miq_event_definitions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ service_started,Service Started,Default,service_process
request_service_stop,Service Stop Request,Default,service_process
service_stopped,Service Stopped,Default,service_process

#
# Orchestration
#
request_orchestration_stack_retire,Orchestration Stack Retire Request,Default,orchestration_process

#
# Container Operations
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ def self.miq_event_enforce_policy(obj, _inputs)
event_object_from_workspace(obj).process_evm_event
end

def self.miq_check_policy_prevent(obj, _inputs)
event = event_object_from_workspace(obj)
if event.full_data && event.full_data[:policy][:prevented]
msg = "Event #{event.event_type} for #{event.target} was terminated: #{event.message}"
raise MiqAeException::StopInstantiation, msg
end
end

def self.event_object_from_workspace(obj)
event = obj.workspace.get_obj_from_path("/")['event_stream']
raise MiqAeException::MethodParmMissing, "Event not specified" if event.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class MiqAeServiceEventStream < MiqAeServiceModelBase
expose :dest_vm, :association => true, :method => :dest_vm_or_template
expose :dest_host, :association => true
expose :service, :association => true
expose :target, :association => true

def event_namespace
object_class.name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe MiqAeEngine::MiqAeBuiltinMethod do
describe '.miq_check_policy_prevent' do
let(:event) { FactoryGirl.create(:miq_event) }
let(:svc_event) { MiqAeMethodService::MiqAeServiceEventStream.find(event.id) }
let(:workspace) { double('WORKSPACE', :get_obj_from_path => { 'event_stream' => svc_event }) }
let(:obj) { double('OBJ', :workspace => workspace) }

subject { described_class.send(:miq_check_policy_prevent, obj, {}) }

it 'with policy not prevented' do
expect { subject }.not_to raise_error
end

it 'with policy prevented' do
event.update_attributes(:full_data => {:policy => {:prevented => true}})
expect { subject }.to raise_error(MiqAeException::StopInstantiation)
end
end
end

0 comments on commit 302e14c

Please sign in to comment.