Skip to content

Commit

Permalink
Merge pull request #486 from AparnaKarve/post_body_changes_to_include…
Browse files Browse the repository at this point in the history
…_service_template_id

Post body changes for `validate_vms_resource ` to include service template_id
  • Loading branch information
bdunne authored Oct 24, 2018
2 parents 41b245d + 569bc98 commit 93b07cd
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/api/transformation_mappings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def edit_resource(type, id, data)

def validate_vms_resource(type, id, data = {})
transformation_mapping = resource_search(id, type, collection_class(type))
(transformation_mapping.search_vms_and_validate(data["import"]) || {}).tap do |res|
(transformation_mapping.search_vms_and_validate(data["import"], data["service_template_id"]) || {}).tap do |res|
%w(valid_vms invalid_vms conflict_vms).each do |key|
next unless res.key?(key)
res[key].each do |entry|
Expand Down
77 changes: 77 additions & 0 deletions spec/requests/transformation_mappings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,83 @@ def href_slug(obj)
expect(updated_mapping_destination).to match_array(reference_destination)
expect(transformation_mapping.transformation_mapping_items.count).to eq(TransformationMappingItem.all.count)
end

context "can validate vms with csv data and service_template_id are specified" do
it "vm belongs to the service_template record" do
api_basic_authorize(action_identifier(:transformation_mappings, :validate_vms, :resource_actions, :post))
ems_source = FactoryGirl.create(:ext_management_system)
ems_destination = FactoryGirl.create(:ext_management_system)
source_cluster = FactoryGirl.create(:ems_cluster, :ext_management_system => ems_source)
destination_cluster = FactoryGirl.create(:ems_cluster, :ext_management_system => ems_destination)
transformation_mapping =
FactoryGirl.create(:transformation_mapping,
:transformation_mapping_items => [TransformationMappingItem.new(:source => source_cluster, :destination => destination_cluster)])
vm = FactoryGirl.create(:vm_vmware, :ems_cluster => source_cluster, :ext_management_system => ems_source)
service_template = FactoryGirl.create(:service_template_transformation_plan)

FactoryGirl.create(
:service_resource,
:resource => vm,
:service_template => service_template,
:status => "Active"
)

request = {
"action" => "validate_vms",
"import" => [
{"name" => vm.name, "uid" => vm.uid_ems}
],
"service_template_id" => service_template.id.to_s
}
post(api_transformation_mapping_url(nil, transformation_mapping), :params => request)

expected = {
"valid" => [a_hash_including("name" => vm.name, "id" => vm.id.to_s, "status" => "ok", "reason" => "ok", "cluster" => source_cluster.name)],
"invalid" => [],
"conflicted" => []
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it "vm does not belong to the service_template record" do
api_basic_authorize(action_identifier(:transformation_mappings, :validate_vms, :resource_actions, :post))
source_ems = FactoryGirl.create(:ext_management_system)
source_cluster = FactoryGirl.create(:ems_cluster, :ext_management_system => source_ems)
destination_ems = FactoryGirl.create(:ext_management_system)
destination_cluster = FactoryGirl.create(:ems_cluster, :ext_management_system => destination_ems)
transformation_mapping =
FactoryGirl.create(:transformation_mapping,
:transformation_mapping_items => [TransformationMappingItem.new(:source => source_cluster, :destination => destination_cluster)])
vm = FactoryGirl.create(:vm_vmware, :ems_cluster => source_cluster, :ext_management_system => source_ems)
service_template = FactoryGirl.create(:service_template_transformation_plan)
service_template2 = FactoryGirl.create(:service_template_transformation_plan)

FactoryGirl.create(
:service_resource,
:resource => vm,
:service_template => service_template,
:status => "Active"
)

request = {
"action" => "validate_vms",
"import" => [
{"name" => vm.name, "uid" => vm.uid_ems}
],
"service_template_id" => service_template2.id.to_s
}
post(api_transformation_mapping_url(nil, transformation_mapping), :params => request)

expected = {
"valid" => [],
"invalid" => [a_hash_including("name" => vm.name, "reason" => "in_other_plan")],
"conflicted" => []
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end
end
end

Expand Down

0 comments on commit 93b07cd

Please sign in to comment.