Skip to content

Commit

Permalink
rename vm_request to vm_resource for less confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
bzwei committed Feb 21, 2018
1 parent 1b885b6 commit c50a2f0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
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
8 changes: 4 additions & 4 deletions app/models/service_template_transformation_plan_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ def update_transformation_progress(progress)

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

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

private

def vm_request
miq_request.vm_requests.find_by(:resource => source)
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
4 changes: 2 additions & 2 deletions spec/models/service_template_transformation_plan_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@
describe 'task_active' do
it 'sets vm_request status to Started' do
task.task_active
expect(plan.vm_requests.first.status).to eq('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_requests.first.status).to eq('Completed')
expect(plan.vm_resources.first.status).to eq('Completed')
end
end
end
Expand Down

0 comments on commit c50a2f0

Please sign in to comment.