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

Allow lists in config values #189

Merged
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
22 changes: 13 additions & 9 deletions source/lib/vagrant-openstack-provider/config_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,21 @@ def resolve_volume_from_hash(volume, volume_list, volume_ids)
{ id: volume_id, device: device }
end

# This method finds a matching _thing_ in a collection of
# _things_. This works matching if the ID or NAME equals to
# `name`. Or, if `name` is a regexp, a partial match is chosen
# This method finds any matching _thing_ from a list of names
# in a collection of _things_. The first to match is the returned
# one. Names in list can be a regexp, a partial match is chosen
# as well.
def find_matching(collection, name)
collection.each do |single|
return single if single.id == name
return single if single.name == name
return single if name.is_a?(Regexp) && name =~ single.name

def find_matching(collection, name_or_names)
name_or_names = [name_or_names] if name_or_names.class != Array
name_or_names.each do |name|
collection.each do |single|
return single if single.id == name
return single if single.name == name
return single if name.is_a?(Regexp) && name =~ single.name
end
end
@logger.error "Element '#{name}' not found in collection #{collection}"
@logger.error "No element of '#{name_or_names}' found in collection #{collection}"
nil
end
end
Expand Down
10 changes: 10 additions & 0 deletions source/spec/vagrant-openstack-provider/config_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@
@action.resolve_flavor(env).should eq(Flavor.new('fl-002', 'flavor-02', 4, 2048, 50))
end
end
context 'with list' do
it 'returns the first matching flavor' do
config.stub(:flavor) { %w(not-existing flavor-02 flavor-01) }
nova.stub(:get_all_flavors).with(anything) do
[Flavor.new('fl-001', 'flavor-01', 2, 1024, 10),
Flavor.new('fl-002', 'flavor-02', 4, 2048, 50)]
end
@action.resolve_flavor(env).should eq(Flavor.new('fl-002', 'flavor-02', 4, 2048, 50))
end
end
context 'with invalid identifier' do
it 'raise an error' do
config.stub(:flavor) { 'not-existing' }
Expand Down