15 rubocop left... good! :)

This commit is contained in:
Guilhem Lettron
2014-02-05 23:25:29 +01:00
parent 9ebd1c3dc7
commit 9e094db14d
10 changed files with 50 additions and 56 deletions

View File

@@ -1,14 +1,14 @@
require 'ipaddr'
require 'json'
def is_crowbar?
def crowbar?
!defined?(Chef::Recipe::Barclamp).nil?
end
def get_mon_nodes(extra_search = nil)
if is_crowbar?
if crowbar?
mon_roles = search(:role, 'name:crowbar-* AND run_list:role\[ceph-mon\]')
if not mon_roles.empty?
unless mon_roles.empty?
search_string = mon_roles.map { |role_object| "roles:" + role_object.name }.join(' OR ')
search_string = "(#{search_string}) AND ceph_config_environment:#{node['ceph']['config']['environment']}"
end
@@ -43,11 +43,11 @@ def find_node_ip_in_network(network, nodeish=nil)
nil
end
def get_mon_addresses
def mon_addresses
mon_ips = []
if File.exists?("/var/run/ceph/ceph-mon.#{node['hostname']}.asok")
mon_ips = get_quorum_members_ips
mon_ips = quorum_members_ips
else
mons = []
# make sure if this node runs ceph-mon, it's always included even if
@@ -56,7 +56,7 @@ def get_mon_addresses
mons << node if node['ceph']['is_mon']
mons += get_mon_nodes
if is_crowbar?
if crowbar?
mon_ips = mons.map { |node| Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin").address }
else
if node['ceph']['config']['global'] && node['ceph']['config']['global']['public network']
@@ -69,7 +69,7 @@ def get_mon_addresses
mon_ips.reject { |m| m.nil? }.uniq
end
def get_quorum_members_ips
def quorum_members_ips
mon_ips = []
cmd = Mixlib::ShellOut.new("ceph --admin-daemon /var/run/ceph/ceph-mon.#{node['hostname']}.asok mon_status")
cmd.run_command

View File

@@ -45,7 +45,7 @@ def load_current_resource
get_new_content = method(:get_new_key)
@current_resource.filename(@new_resource.filename || "/etc/ceph/ceph.client.#{current_resource.name}.#{node['hostname']}.secret")
end
if @current_resource.caps == @new_resource.caps and
if @current_resource.caps == @new_resource.caps &&
get_saved_key_file(@current_resource.filename) == get_new_content.call(@current_resource.keyname)
@current_resource.exists = true
end
@@ -80,26 +80,24 @@ end
def auth_set_key(keyname, caps)
# find the monitor secret
mon_secret = ""
mons = get_mon_nodes()
if not mons.empty?
mons = get_mon_nodes
if !mons.empty?
mon_secret = mons[0]["ceph"]["monitor-secret"]
elsif mons.empty? and node["ceph"]["monitor-secret"]
elsif mons.empty? && node["ceph"]["monitor-secret"]
mon_secret = node["ceph"]["monitor-secret"]
else
Chef::Log.warn("No monitor secret found")
end
# try to add the key
set_cmd = "ceph auth get-or-create #{keyname} #{caps} --name mon. --key='#{mon_secret}'"
set_cmd = Mixlib::ShellOut.new(set_cmd)
cmd = set_cmd.run_command
if cmd.stderr.scan(/EINVAL.*but cap.*does not match/)
cmd = "ceph auth get-or-create #{keyname} #{caps} --name mon. --key='#{mon_secret}'"
get_or_create = Mixlib::ShellOut.new(cmd)
get_or_create.run_command
if get_or_create.stderr.scan(/EINVAL.*but cap.*does not match/)
Chef::Log.info("Deleting old key with incorrect caps")
# delete an old key if it exists and is wrong
Mixlib::ShellOut.new("ceph auth del #{keyname}").run_command
# try to create again
set_cmd = "ceph auth get-or-create #{keyname} #{caps} --name mon. --key='#{mon_secret}'"
set_cmd = Mixlib::ShellOut.new(set_cmd)
cmd = set_cmd.run_command
get_or_create.run_command
end
cmd = set_cmd.error!
get_or_create.error!
end

View File

@@ -29,7 +29,7 @@ ceph_client name do
as_keyring false
end
mons = get_mon_addresses.join(",") + ":/"
mons = mon_addresses.join(",") + ":/"
directory node['ceph']['cephfs_mount']

View File

@@ -1,8 +1,6 @@
fail "fsid must be set in config" if node["ceph"]["config"]['fsid'].nil?
fail "mon_initial_members must be set in config" if node["ceph"]["config"]['mon_initial_members'].nil?
mon_addresses = get_mon_addresses
is_rgw = node['roles'].include?('ceph-radosgw')
directory "/etc/ceph" do

View File

@@ -37,17 +37,17 @@ directory "/var/lib/ceph/mon/ceph-#{node["hostname"]}" do
action :create
end
# TODO cluster name
# TODO: cluster name
cluster = 'ceph'
unless File.exists?("/var/lib/ceph/mon/ceph-#{node["hostname"]}/done")
keyring = "#{Chef::Config[:file_cache_path]}/#{cluster}-#{node['hostname']}.mon.keyring"
monitor_secret = if node['ceph']['encrypted_data_bags']
if node['ceph']['encrypted_data_bags']
secret = Chef::EncryptedDataBagItem.load_secret(node["ceph"]["mon"]["secret_file"])
Chef::EncryptedDataBagItem.load("ceph", "mon", secret)["secret"]
monitor_secret = Chef::EncryptedDataBagItem.load("ceph", "mon", secret)["secret"]
else
node["ceph"]["monitor-secret"]
monitor_secret = node["ceph"]["monitor-secret"]
end
execute "format as keyring" do
@@ -62,7 +62,7 @@ unless File.exists?("/var/lib/ceph/mon/ceph-#{node["hostname"]}/done")
ruby_block "finalise" do
block do
["done", service_type].each do |ack|
File.open("/var/lib/ceph/mon/ceph-#{node["hostname"]}/#{ack}", "w").close()
::File.open("/var/lib/ceph/mon/ceph-#{node["hostname"]}/#{ack}", "w").close
end
end
end
@@ -92,7 +92,7 @@ service "ceph_mon" do
action [:enable, :start]
end
get_mon_addresses().each do |addr|
mon_addresses.each do |addr|
execute "peer #{addr}" do
command "ceph --admin-daemon '/var/run/ceph/ceph-mon.#{node['hostname']}.asok' add_bootstrap_peer_hint #{addr}"
ignore_failure true

View File

@@ -71,7 +71,7 @@ else
creates "/var/lib/ceph/bootstrap-osd/#{cluster}.keyring"
end
if is_crowbar?
if crowbar?
ruby_block "select new disks for ceph osd" do
block do
do_trigger = false
@@ -81,7 +81,7 @@ else
system 'ceph-disk-prepare', \
"/dev/#{disk}"
raise 'ceph-disk-prepare failed' unless $?.exitstatus == 0
fail 'ceph-disk-prepare failed' unless $?.exitstatus == 0
do_trigger = true
@@ -95,7 +95,7 @@ else
"trigger", \
"--subsystem-match=block", \
"--action=add"
raise 'udevadm trigger failed' unless $?.exitstatus == 0
fail 'udevadm trigger failed' unless $?.exitstatus == 0
end
end
@@ -110,16 +110,15 @@ else
# osd/$cluster-$id)
# - $cluster should always be ceph
# - The --dmcrypt option will be available starting w/ Cuttlefish
unless node["ceph"]["osd_devices"].nil?
if !node["ceph"]["osd_devices"].nil?
node["ceph"]["osd_devices"].each_with_index do |osd_device, index|
if !osd_device["status"].nil?
unless osd_device["status"].nil?
Log.info("osd: osd_device #{osd_device} has already been setup.")
next
end
dmcrypt = ""
if osd_device["encrypted"] == true
dmcrypt = "--dmcrypt"
end
dmcrypt = osd_device["encrypted"] == true ? "--dmcrypt" : ""
create_cmd = "ceph-disk-prepare #{dmcrypt} #{osd_device['device']} #{osd_device['journal']}"
if osd_device["type"] == "directory"
directory osd_device["device"] do

View File

@@ -43,7 +43,7 @@ end
include_recipe "ceph::conf"
unless File.exists?("/var/lib/ceph/radosgw/ceph-radosgw.#{node['hostname']}/done")
if !::File.exists?("/var/lib/ceph/radosgw/ceph-radosgw.#{node['hostname']}/done")
if node["ceph"]["radosgw"]["webserver_companion"]
include_recipe "ceph::radosgw_#{node["ceph"]["radosgw"]["webserver_companion"]}"
end

View File

@@ -12,8 +12,8 @@ when "rhel"
end
branch = node['ceph']['branch']
if branch == "dev" and platform_family != "centos" and platform_family != "fedora"
raise "Dev branch for #{platform_family} is not yet supported"
if branch == "dev" && platform_family != "centos" && platform_family != "fedora"
fail "Dev branch for #{platform_family} is not yet supported"
end
repo = node['ceph'][platform_family][branch]['repository']

View File

@@ -22,7 +22,6 @@ when "debian"
packages = %w{
tgt
}
when "rhel", "fedora"
packages = %w{
scsi-target-utils