Add current node to mon_hosts, if it has role ceph-mon.

This shortcircuits the search logic, so ceph-mon --mkfs will always
see itself in ceph-mon, and thus won't end up with an empty monmap.
Empty monmap would prevent it from initializing properly, and the
peer hints aren't enough to help.

Search is not reliable for this, as the search index updates lazily,
and e.g. the "roles:" field, holding the expanded run_list, is only
set at the end of a successful chef-client run.

Crowbar creates a special-purpose role, one per node, and assigns the
actual roles to that role. We work around this by doing the search in
two phases, when running under Crowbar.

Thanks to Tyler Brekke.
This commit is contained in:
Tommi Virtanen 2012-07-20 14:32:18 -07:00
parent 6a4616f9f7
commit 19da747700

View File

@ -3,12 +3,33 @@ def is_crowbar?()
end end
def get_mon_addresses() def get_mon_addresses()
if is_crowbar? mons = []
mon_addresses = search(:node, "role:ceph-mon AND ceph_config_environment:#{node['ceph']['config']['environment']}").map { |node| Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin").address + ":6789" }
else # make sure if this node runs ceph-mon, it's always included even if
mon_addresses = search(:node, "role:ceph-mon AND chef_environment:#{node.chef_environment}").map { |node| node["ipaddress"] + ":6789" } # search is laggy; put it first in the hopes that clients will talk
# primarily to local node
if node['roles'].include? 'ceph-mon'
mons << node
end end
return mon_addresses
if is_crowbar?
mon_roles = search(:role, 'name:crowbar-* AND run_list:role\[ceph-mon\]')
if not mon_roles.empty?
search_string = mon_roles.map { |role_object| "role:"+role_object.name }.join(' OR ')
mons += search(:node, "(#{search_string}) AND ceph_config_environment:#{node['ceph']['config']['environment']}")
end
else
mons += search(:node, "role:ceph-mon AND chef_environment:#{node.chef_environment}")
end
if is_crowbar?
mon_addresses = mons.map { |node| Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin").address }
else
mon_addresses = mons.map { |node| node["ipaddress"] }
end
mon_addresses = mon_addresses.map { |ip| ip + ":6789" }
return mon_addresses.uniq
end end
QUORUM_STATES = ['leader', 'peon'] QUORUM_STATES = ['leader', 'peon']