-
Notifications
You must be signed in to change notification settings - Fork 900
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
Map Amazon labels to tags #14436
Merged
Merged
Map Amazon labels to tags #14436
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eaf2277
Map labels to tags.
djberg96 668adfd
Initial commit.
djberg96 93937df
Did some refactoring, added some tests.
djberg96 90d0f39
Restore backwards compatibility with original Container handling.
djberg96 ccd3f0f
Rubocop fixes.
djberg96 27eff65
Updated variable names and comments.
djberg96 e733440
More rubocop fixes.
djberg96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
spec/models/ems_refresh/save_inventory/save_tags_inventory_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
context "save_tags_inventory" do | ||
before(:each) do | ||
@zone = FactoryGirl.create(:zone) | ||
@ems = FactoryGirl.create(:ems_amazon, :zone => @zone) | ||
|
||
@vm = FactoryGirl.create(:vm, :ext_management_system => @ems) | ||
@node = FactoryGirl.create(:container_node, :ext_management_system => @ems) | ||
|
||
@tag1 = FactoryGirl.create(:tag, :name => '/managed/amazon:vm:owner') | ||
@tag2 = FactoryGirl.create(:tag, :name => '/managed/kubernetes:container_node:stuff') | ||
@tag3 = FactoryGirl.create(:tag, :name => '/managed/kubernetes:foo') # All | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Completely doesn't matter in this test: An actual "All" mapping would use |
||
|
||
@cat1 = FactoryGirl.create(:category, :description => 'amazon_vm_owner', :tag => @tag1) | ||
@cat2 = FactoryGirl.create(:category, :description => 'department', :tag => @tag2) | ||
@cat3 = FactoryGirl.create(:category, :description => 'location', :tag => @tag3) | ||
end | ||
|
||
# This is what ContainerLabelTagMapping.map_labels(cache, 'Type', labels) would | ||
# return in the refresh parser. Note that we don't explicitly test the mapping | ||
# creation here, the assumption is that these were the generated mappings. | ||
# | ||
let(:data) do | ||
{ | ||
:tags => [ | ||
{ | ||
:category_tag_id => @cat1.tag_id, | ||
:entry_name => 'owner', | ||
:entry_description => 'Daniel' | ||
}, | ||
{ | ||
:category_tag_id => @cat2.tag_id, | ||
:entry_name => 'stuff', | ||
:entry_description => 'Ladas' | ||
}, | ||
{ | ||
:category_tag_id => @cat3.tag_id, | ||
:entry_name => 'foo', | ||
:entry_description => 'Bronagh' | ||
} | ||
] | ||
} | ||
end | ||
|
||
# Note that in these tests we're explicitly passing the object, so that's | ||
# why the object type may not match what you would expect from the tag | ||
# name type above. | ||
|
||
it "creates the expected number of taggings" do | ||
EmsRefresh.save_tags_inventory(@vm, data) | ||
taggings = Tagging.all | ||
expect(taggings.size).to eql(3) | ||
expect(@vm.tags.size).to eql(3) | ||
end | ||
|
||
it "creates the expected taggings for a VM" do | ||
EmsRefresh.save_tags_inventory(@vm, data) | ||
taggings = Tagging.all | ||
expect(taggings.all? { |e| e.taggable_id == @vm.id }).to be true | ||
expect(taggings.map(&:taggable_type).all? { |e| e == 'VmOrTemplate' }).to be true | ||
expect(@vm.tags.map(&:id).sort).to eql(taggings.map(&:tag_id).sort) | ||
end | ||
|
||
it "creates the expected taggings for a container node" do | ||
EmsRefresh.save_tags_inventory(@node, data) | ||
taggings = Tagging.all | ||
expect(taggings.all? { |e| e.taggable_id == @node.id }).to be true | ||
expect(taggings.map(&:taggable_type).all? { |e| e == 'ContainerNode' }).to be true | ||
expect(@node.tags.map(&:id).sort).to eql(taggings.map(&:tag_id).sort) | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little surprised you need to deal with {:tags => ...} form, IIUC ManageIQ/manageiq-providers-amazon#183 creates :labels and :tags on same level, you have :labels and :tags in child keys on same level, and
save_child_inventory
callssave_#{k}_inventory
onhashes[k]
so I'd expectsave_tags_inventory
to not see the :tags, just the value.But I don't mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cben This is something we plan to refactor in the future, i.e. generate the tags on the core side rather than the refresher side.