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

Add timeout to ceph_pool resource #225

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ MethodLength:
Enabled: false
SignalException:
Enabled: false
TrailingComma:
Enabled: false
WordArray:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
ConditionalAssignment:
Enabled: false
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ sudo: false
cache: bundler
bundler_args: --without kitchen_common kitchen_vagrant
rvm:
- 2.0
- 2.1
- 2.2
script:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source 'https://rubygems.org'

group :lint do
gem 'foodcritic', '~> 4.0'
gem 'rubocop', '~> 0.33'
gem 'rubocop', '~> 0.40.0'
end

group :unit do
Expand Down
21 changes: 10 additions & 11 deletions libraries/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ def ip6_address_in_network?(ip, params, net)

def ip_address_to_ceph_address(ip, params)
if params['family'].eql?('inet')
return "#{ip}:6789"
"#{ip}:6789"
elsif params['family'].eql?('inet6')
return "[#{ip}]:6789"
"[#{ip}]:6789"
end
nil
end

def mon_addresses
Expand All @@ -110,15 +111,13 @@ def mon_addresses
mons << node if node['ceph']['is_mon']

mons += mon_nodes
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']
mon_ips = mons.map { |nodeish| find_node_ip_in_network(node['ceph']['config']['global']['public network'], nodeish) }
else
mon_ips = mons.map { |node| node['ipaddress'] + ':6789' }
end
end
mon_ips = if crowbar?
mons.map { |node| Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, 'admin').address }
elsif node['ceph']['config']['global'] && node['ceph']['config']['global']['public network']
mons.map { |nodeish| find_node_ip_in_network(node['ceph']['config']['global']['public network'], nodeish) }
else
mons.map { |node| node['ipaddress'] + ':6789' }
end
end
mon_ips.reject(&:nil?).uniq
end
Expand Down
2 changes: 1 addition & 1 deletion providers/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def load_current_resource
@current_resource.key(get_key(@current_resource.keyname))
@current_resource.caps_match = @current_resource.caps == @new_resource.caps
@current_resource.keys_match = @new_resource.key.nil? || (@current_resource.key == @new_resource.key)
@current_resource.exists = ! (@current_resource.key.nil? || @current_resource.key.empty?)
@current_resource.exists = !(@current_resource.key.nil? || @current_resource.key.empty?)
end

def file_content(keyname, key, as_keyring)
Expand Down
7 changes: 4 additions & 3 deletions providers/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ def whyrun_supported?
def load_current_resource
@current_resource = Chef::Resource::CephPool.new(@new_resource.name)
@current_resource.name(@new_resource.name)
@current_resource.timeout(@new_resource.timeout)
@current_resource.exists = pool_exists?(@current_resource.name)
end

def create_pool
cmd_text = "ceph osd pool create #{new_resource.name} #{new_resource.pg_num}"
cmd_text << " #{new_resource.create_options}" if new_resource.create_options
cmd = Mixlib::ShellOut.new(cmd_text)
cmd = Mixlib::ShellOut.new(cmd_text, :timeout => new_resource.timeout)
cmd.run_command
cmd.error!
Chef::Log.debug "Pool created: #{cmd.stderr}"
Expand All @@ -50,14 +51,14 @@ def delete_pool
cmd_text = "ceph osd pool delete #{new_resource.name}"
cmd_text << " #{new_resource.name} --yes-i-really-really-mean-it" if
new_resource.force
cmd = Mixlib::ShellOut.new(cmd_text)
cmd = Mixlib::ShellOut.new(cmd_text, :timeout => new_resource.timeout)
cmd.run_command
cmd.error!
Chef::Log.debug "Pool deleted: #{cmd.stderr}"
end

def pool_exists?(name)
cmd = Mixlib::ShellOut.new("ceph osd pool get #{name} size")
cmd = Mixlib::ShellOut.new("ceph osd pool get #{name} size", :timeout => current_resource.timeout)
cmd.run_command
cmd.error!
Chef::Log.debug "Pool exists: #{cmd.stdout}"
Expand Down
8 changes: 4 additions & 4 deletions recipes/apt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
branch = node['ceph']['branch']

distribution_codename =
case node['lsb']['codename']
when 'jessie' then 'sid'
else node['lsb']['codename']
end
case node['lsb']['codename']
when 'jessie' then 'sid'
else node['lsb']['codename']
end

apt_preference 'ceph_repo' do
glob '*'
Expand Down
91 changes: 45 additions & 46 deletions recipes/osd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
command 'udevadm trigger --subsystem-match=block --action=add'
action :nothing
end
else

# Calling ceph-disk-prepare is sufficient for deploying an OSD
# After ceph-disk-prepare finishes, the new device will be caught
# by udev which will run ceph-disk-activate on it (udev will map
Expand All @@ -91,60 +91,59 @@
# osd/$cluster-$id)
# - $cluster should always be ceph
# - The --dmcrypt option will be available starting w/ Cuttlefish
if node['ceph']['osd_devices']
devices = node['ceph']['osd_devices']
elsif node['ceph']['osd_devices']
devices = node['ceph']['osd_devices']

devices = Hash[(0...devices.size).zip devices] unless devices.is_a? Hash
devices = Hash[(0...devices.size).zip devices] unless devices.is_a? Hash

devices.each do |index, osd_device|
unless osd_device['status'].nil?
Log.info("osd: osd_device #{osd_device} has already been setup.")
next
end
devices.each do |index, osd_device|
unless osd_device['status'].nil?
Log.info("osd: osd_device #{osd_device} has already been setup.")
next
end

directory osd_device['device'] do # ~FC022
owner 'root'
group 'root'
recursive true
only_if { osd_device['type'] == 'directory' }
end
directory osd_device['device'] do # ~FC022
owner 'root'
group 'root'
recursive true
only_if { osd_device['type'] == 'directory' }
end

dmcrypt = osd_device['encrypted'] == true ? '--dmcrypt' : ''
dmcrypt = osd_device['encrypted'] == true ? '--dmcrypt' : ''

execute "ceph-disk-prepare on #{osd_device['device']}" do
command "ceph-disk-prepare #{dmcrypt} #{osd_device['device']} #{osd_device['journal']}"
action :run
notifies :create, "ruby_block[save osd_device status #{index}]", :immediately
end
execute "ceph-disk-prepare on #{osd_device['device']}" do
command "ceph-disk-prepare #{dmcrypt} #{osd_device['device']} #{osd_device['journal']}"
action :run
notifies :create, "ruby_block[save osd_device status #{index}]", :immediately
end

execute "ceph-disk-activate #{osd_device['device']}" do
only_if { osd_device['type'] == 'directory' }
end
execute "ceph-disk-activate #{osd_device['device']}" do
only_if { osd_device['type'] == 'directory' }
end

# we add this status to the node env
# so that we can implement recreate
# and/or delete functionalities in the
# future.
ruby_block "save osd_device status #{index}" do
block do
node.normal['ceph']['osd_devices'][index]['status'] = 'deployed'
node.save
end
action :nothing
# we add this status to the node env
# so that we can implement recreate
# and/or delete functionalities in the
# future.
ruby_block "save osd_device status #{index}" do
block do
node.normal['ceph']['osd_devices'][index]['status'] = 'deployed'
node.save
end
action :nothing
end
service 'ceph_osd' do
case service_type
when 'upstart'
service_name 'ceph-osd-all-starter'
provider Chef::Provider::Service::Upstart
else
service_name 'ceph'
end
action [:enable, :start]
supports :restart => true
end
service 'ceph_osd' do
case service_type
when 'upstart'
service_name 'ceph-osd-all-starter'
provider Chef::Provider::Service::Upstart
else
service_name 'ceph'
end
else
Log.info('node["ceph"]["osd_devices"] empty')
action [:enable, :start]
supports :restart => true
end
else
Log.info('node["ceph"]["osd_devices"] empty')
end
4 changes: 1 addition & 3 deletions recipes/tgt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@
if node['platform'] == 'ubuntu'
# The ceph version of tgt does not provide an Upstart script
provider Chef::Provider::Service::Init::Debian
service_name 'tgt'
else
service_name 'tgt'
end
service_name 'tgt'
supports :restart => true
action [:enable, :start]
end
3 changes: 3 additions & 0 deletions resources/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
# Optional arguments for pool creation
attribute :create_options, :kind_of => String

# The number of seconds before a timeout occurs during pool creation
attribute :timeout, :kind_of => Integer

# Forces a non-empty pool to be deleted.
attribute :force, :kind_of => [TrueClass, FalseClass], :default => false

Expand Down