diff --git a/.rubocop.yml b/.rubocop.yml index c739e34..efd8686 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 diff --git a/.travis.yml b/.travis.yml index 232d1a5..44f0647 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ sudo: false cache: bundler bundler_args: --without kitchen_common kitchen_vagrant rvm: - - 2.0 - 2.1 - 2.2 script: diff --git a/Gemfile b/Gemfile index 55080da..fec5311 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/libraries/default.rb b/libraries/default.rb index 297da37..e51ac7c 100644 --- a/libraries/default.rb +++ b/libraries/default.rb @@ -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 @@ -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 diff --git a/providers/client.rb b/providers/client.rb index 548b76b..25e3716 100644 --- a/providers/client.rb +++ b/providers/client.rb @@ -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) diff --git a/providers/pool.rb b/providers/pool.rb index 182c450..eee9649 100644 --- a/providers/pool.rb +++ b/providers/pool.rb @@ -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}" @@ -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}" diff --git a/recipes/apt.rb b/recipes/apt.rb index b5720fb..278a7ff 100644 --- a/recipes/apt.rb +++ b/recipes/apt.rb @@ -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 '*' diff --git a/recipes/osd.rb b/recipes/osd.rb index d07f161..5b4e490 100644 --- a/recipes/osd.rb +++ b/recipes/osd.rb @@ -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 @@ -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 diff --git a/recipes/tgt.rb b/recipes/tgt.rb index eb353e9..821262d 100644 --- a/recipes/tgt.rb +++ b/recipes/tgt.rb @@ -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 diff --git a/resources/pool.rb b/resources/pool.rb index 2e3052e..1667c38 100644 --- a/resources/pool.rb +++ b/resources/pool.rb @@ -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