Skip to content

Commit

Permalink
Merge pull request #17027 from bzwei/vm_migration_status
Browse files Browse the repository at this point in the history
Update vm transformation status in a plan
  • Loading branch information
gmcculloug authored Feb 21, 2018
2 parents ed35828 + c50a2f0 commit 68544e0
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/models/service_template_provision_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def after_ae_delivery(ae_result)
def update_and_notify_parent(*args)
prev_state = state
super
task_finished if state == "finished" && prev_state != "finished"
try("task_#{state}") if prev_state != state
end

def task_finished
Expand Down
2 changes: 1 addition & 1 deletion app/models/service_template_transformation_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def transformation_mapping
service_resources.find_by(:resource_type => 'TransformationMapping').resource
end

def vm_requests
def vm_resources
service_resources.where(:resource_type => 'VmOrTemplate')
end

Expand Down
12 changes: 6 additions & 6 deletions app/models/service_template_transformation_plan_request.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
class ServiceTemplateTransformationPlanRequest < ServiceTemplateProvisionRequest
TASK_DESCRIPTION = 'VM Transformations'.freeze

delegate :transformation_mapping, :vm_requests, :to => :source
delegate :transformation_mapping, :vm_resources, :to => :source

def requested_task_idx
vm_requests.where(:status => 'Approved')
vm_resources.where(:status => 'Approved')
end

def customize_request_task_attributes(req_task_attrs, vm_request)
req_task_attrs[:source] = vm_request.resource
def customize_request_task_attributes(req_task_attrs, vm_resource)
req_task_attrs[:source] = vm_resource.resource
end

def source_vms
vm_requests.where(:status => %w(Queued Failed)).pluck(:resource_id)
vm_resources.where(:status => %w(Queued Failed)).pluck(:resource_id)
end

def validate_vm(_vm_id)
Expand All @@ -21,6 +21,6 @@ def validate_vm(_vm_id)
end

def approve_vm(vm_id)
vm_requests.find_by(:resource_id => vm_id).update_attributes!(:status => 'Approved')
vm_resources.find_by(:resource_id => vm_id).update_attributes!(:status => 'Approved')
end
end
15 changes: 15 additions & 0 deletions app/models/service_template_transformation_plan_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,19 @@ def update_transformation_progress(progress)
options[:progress] = (options[:progress] || {}).merge(progress)
save
end

def task_finished
# update the status of vm transformation status in the plan
vm_resource.update_attributes(:status => status == 'Ok' ? 'Completed' : 'Failed')
end

def task_active
vm_resource.update_attributes(:status => 'Active')
end

private

def vm_resource
miq_request.vm_resources.find_by(:resource => source)
end
end
4 changes: 2 additions & 2 deletions spec/models/service_template_transformation_plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

expect(service_template.name).to eq('Transformation Plan')
expect(service_template.transformation_mapping).to eq(transformation_mapping)
expect(service_template.vm_requests.collect(&:resource)).to match_array([vm1, vm2])
expect(service_template.vm_requests.collect(&:status)).to eq(%w(Queued Queued))
expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2])
expect(service_template.vm_resources.collect(&:status)).to eq(%w(Queued Queued))
expect(service_template.config_info).to eq(catalog_item_options[:config_info])
expect(service_template.resource_actions.first).to have_attributes(
:action => 'Provision',
Expand Down
19 changes: 17 additions & 2 deletions spec/models/service_template_transformation_plan_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
context 'populated request and task' do
let(:src) { FactoryGirl.create(:ems_cluster) }
let(:dst) { FactoryGirl.create(:ems_cluster) }
let(:vm) { FactoryGirl.create(:vm_or_template) }
let(:mapping) do
FactoryGirl.create(
:transformation_mapping,
Expand All @@ -28,15 +29,15 @@
:description => 'a description',
:config_info => {
:transformation_mapping_id => mapping.id,
:vm_ids => [FactoryGirl.create(:vm_or_template).id],
:vm_ids => [vm.id],
}
}
end

let(:plan) { ServiceTemplateTransformationPlan.create_catalog_item(catalog_item_options) }

let(:request) { FactoryGirl.create(:service_template_transformation_plan_request, :source => plan) }
let(:task) { FactoryGirl.create(:service_template_transformation_plan_task, :miq_request => request, :request_type => 'transformation_plan') }
let(:task) { FactoryGirl.create(:service_template_transformation_plan_task, :miq_request => request, :request_type => 'transformation_plan', :source => vm) }

describe '#resource_action' do
it 'has a resource action points to the entry point for transformation' do
Expand All @@ -57,5 +58,19 @@
expect(task.options[:progress]).to eq(:vm_percent => '80')
end
end

describe 'task_active' do
it 'sets vm_request status to Started' do
task.task_active
expect(plan.vm_resources.first.status).to eq('Active')
end
end

describe 'task_finished' do
it 'sets vm_request status to Completed' do
task.task_finished
expect(plan.vm_resources.first.status).to eq('Completed')
end
end
end
end

0 comments on commit 68544e0

Please sign in to comment.