mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Update Servers#find_servers to not throw exception on unknown roles; instead return no servers so :on_no_matching_servers can determine whether to complain for the task or not.
This commit is contained in:
parent
216f3b966b
commit
84506c06e3
2 changed files with 8 additions and 8 deletions
|
@ -54,13 +54,14 @@ module Capistrano
|
|||
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 @@ module Capistrano
|
|||
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
|
||||
|
|
|
@ -39,11 +39,11 @@ class ConfigurationServersTest < Test::Unit::TestCase
|
|||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue