Skip to content
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

Post body changes for validate_vms_resource to include service template_id #486

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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