Skip to content

Commit

Permalink
Rename TagMapping resource_type for Amazon Vms and Images
Browse files Browse the repository at this point in the history
The Amazon provider was the first cloud provider to participate in the
(originally) ContainerLabelTagMapping class.  It has since been expanded
to include many providers including Openstack, Azure, and VMware
vSphere.

This means that the original labeled_resource_type of "Vm" and "Image"
meaning Amazon VMs and Templates is quite confusing.
  • Loading branch information
agrare committed Nov 6, 2020
1 parent f0953eb commit e786e94
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class UpdateAmazonTagMapperResourceType < ActiveRecord::Migration[5.2]
class ProviderTagMapping < ActiveRecord::Base
end

def up
say_with_time("Update ProviderTagMapping Vm label") do
ProviderTagMapping.where(:labeled_resource_type => "Vm").update_all(:labeled_resource_type => "VmAmazon")
end
say_with_time("Update ProviderTagMapping Image label") do
ProviderTagMapping.where(:labeled_resource_type => "Image").update_all(:labeled_resource_type => "ImageAmazon")
end
end

def down
say_with_time("Update ProviderTagMapping VmAmazon label") do
ProviderTagMapping.where(:labeled_resource_type => "VmAmazon").update_all(:labeled_resource_type => "Vm")
end
say_with_time("Update ProviderTagMapping ImageAmazon label") do
ProviderTagMapping.where(:labeled_resource_type => "ImageAmazon").update_all(:labeled_resource_type => "Image")
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require_migration

describe UpdateAmazonTagMapperResourceType do
let(:provider_tag_mapping_stub) { migration_stub(:ProviderTagMapping) }

migration_context :up do
it "Converts Vm and Image to VmAmazon and ImageAmazon" do
vm_mapping = provider_tag_mapping_stub.create!(:labeled_resource_type => "Vm")
image_mapping = provider_tag_mapping_stub.create!(:labeled_resource_type => "Image")

migrate

expect(vm_mapping.reload.labeled_resource_type).to eq("VmAmazon")
expect(image_mapping.reload.labeled_resource_type).to eq("ImageAmazon")
end

it "Doesn't update other tag mappings" do
vm_mapping = provider_tag_mapping_stub.create!(:labeled_resource_type => "VmOpenstack")

migrate

expect(vm_mapping.reload.labeled_resource_type).to eq("VmOpenstack")
end
end

migration_context :down do
it "Converts VmAmazon and ImageAmazon to Vm and Image" do
vm_mapping = provider_tag_mapping_stub.create!(:labeled_resource_type => "VmAmazon")
image_mapping = provider_tag_mapping_stub.create!(:labeled_resource_type => "ImageAmazon")

migrate

expect(vm_mapping.reload.labeled_resource_type).to eq("Vm")
expect(image_mapping.reload.labeled_resource_type).to eq("Image")
end

it "Doesn't update other tag mappings" do
vm_mapping = provider_tag_mapping_stub.create!(:labeled_resource_type => "VmOpenstack")

migrate

expect(vm_mapping.reload.labeled_resource_type).to eq("VmOpenstack")
end
end
end

0 comments on commit e786e94

Please sign in to comment.