Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #84 from prevailhs/opt-out-no-matching-servers

Update Servers#find_servers to not throw exception on unknown roles
  • Loading branch information...
commit b5681adb244aed957c7b297d2e72de6e6caaae1f 2 parents 94ac218 + 84506c0
@leehambley leehambley authored
View
8 lib/capistrano/configuration/servers.rb
@@ -54,13 +54,14 @@ def find_servers(options={})
filter_server_list(hosts.uniq)
end
else
- roles = role_list_from(ENV['ROLES'] || options[:roles] || self.roles.keys)
- roles = roles & Array(options[:roles]) if preserve_roles && !options[:roles].nil?
+ roles = role_list_from(ENV['ROLES'] || options[:roles] || self.roles.keys)
+ roles = roles & Array(options[:roles]) if preserve_roles && !options[:roles].nil?
only = options[:only] || {}
except = options[:except] || {}
- servers = roles.inject([]) { |list, role| list.concat(self.roles[role]) }
+ # If we don't have a def for a role it means its bogus, skip it so higher level can handle
+ servers = roles.inject([]) { |list, role| list.concat(self.roles[role] || []) }
servers = servers.select { |server| only.all? { |key,value| server.options[key] == value } }
servers = servers.reject { |server| except.any? { |key,value| server.options[key] == value } }
@@ -103,7 +104,6 @@ def role_list_from(roles)
roles = build_list(roles)
roles.map do |role|
role = String === role ? role.strip.to_sym : role
- raise ArgumentError, "unknown role `#{role}'" unless self.roles.key?(role)
role
end
end
View
8 test/configuration/servers_test.rb
@@ -39,11 +39,11 @@ def test_task_with_single_role_should_apply_only_to_that_role
assert_equal %w(web1 web2).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort
end
- def test_task_with_unknown_role_should_raise_exception
+ # NOTE Rather than throw an error, as it used to, we return an
+ # empty array so that if a task is okay with a missing role it can continue on
+ def test_task_with_unknown_role_should_return_empty_array
task = new_task(:testing, @config, :roles => :bogus)
- assert_raises(ArgumentError) do
- @config.find_servers_for_task(task)
- end
+ assert_equal [], @config.find_servers_for_task(task)
end
def test_task_with_hosts_option_should_apply_only_to_those_hosts
Please sign in to comment.
Something went wrong with that request. Please try again.