diff --git a/.rubocop.yml b/.rubocop.yml index 8ddc446..1ebbd9a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,16 @@ +AllCops: + Excludes: + - vendor/** + +AlignParameters: + Enabled: false +Encoding: + Enabled: false +HashSyntax: + Enabled: false StringLiterals: Enabled: false - LineLength: Enabled: false +MethodLength: + Max: 30 diff --git a/attributes/radosgw.rb b/attributes/radosgw.rb index 6bc5278..5fb3171 100644 --- a/attributes/radosgw.rb +++ b/attributes/radosgw.rb @@ -16,11 +16,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # + default["ceph"]["radosgw"]["api_fqdn"] = "localhost" default["ceph"]["radosgw"]["admin_email"] = "admin@example.com" default["ceph"]["radosgw"]["rgw_addr"] = "*:80" default["ceph"]["radosgw"]["rgw_port"] = false -default["ceph"]["radosgw"]["webserver_companion"] = "apache2" #can be false +default["ceph"]["radosgw"]["webserver_companion"] = "apache2" # can be false default['ceph']["radosgw"]['use_apache_fork'] = true case node['platform'] when 'ubuntu' diff --git a/attributes/repo.rb b/attributes/repo.rb index 803a22a..b58fb12 100644 --- a/attributes/repo.rb +++ b/attributes/repo.rb @@ -7,7 +7,7 @@ default['ceph']['extras_repo_url'] = "http://ceph.com/packages/ceph-extras" case node['platform_family'] when "debian" - #Debian/Ubuntu default repositories + # Debian/Ubuntu default repositories default['ceph']['debian']['stable']['repository'] = "#{node['ceph']['repo_url']}/debian-#{node['ceph']['version']}/" default['ceph']['debian']['stable']['repository_key'] = "https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc" default['ceph']['debian']['testing']['repository'] = "#{node['ceph']['repo_url']}/debian-testing/" @@ -17,7 +17,7 @@ when "debian" default['ceph']['debian']['extras']['repository'] = "#{node['ceph']['extras_repo_url']}/debian/" default['ceph']['debian']['extras']['repository_key'] = "https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc" when "rhel" - #Redhat/CentOS default repositories + # Redhat/CentOS default repositories default['ceph']['rhel']['stable']['repository'] = "#{node['ceph']['repo_url']}/rpm-#{node['ceph']['version']}/el6/noarch/ceph-release-1-0.el6.noarch.rpm" default['ceph']['rhel']['testing']['repository'] = "#{node['ceph']['repo_url']}/rpm-testing/el6/x86_64/ceph-release-1-0.el6.noarch.rpm" default['ceph']['rhel']['dev']['repository'] = "http://gitbuilder.ceph.com/ceph-rpm-centos6-x86_64-basic/ref/#{node['ceph']['version']}/x86_64/" @@ -25,7 +25,7 @@ when "rhel" default['ceph']['rhel']['extras']['repository'] = "#{node['ceph']['extras_repo_url']}/rpm/rhel6/x86_64/" default['ceph']['rhel']['extras']['repository_key'] = "https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/autobuild.asc" when "fedora" - #Fedora default repositories + # Fedora default repositories default['ceph']['fedora']['stable']['repository'] = "#{node['ceph']['repo_url']}/rpm-#{node['ceph']['version']}/fc#{node['platform_version']}/x86_64/ceph-release-1-0.fc#{node['platform_version']}.noarch.rpm" default['ceph']['fedora']['testing']['repository'] = "#{node['ceph']['repo_url']}/rpm-testing/fc#{node['platform_version']}/x86_64/ceph-release-1-0.fc#{node['platform_version']}.noarch.rpm" default['ceph']['fedora']['dev']['repository'] = "http://gitbuilder.ceph.com/ceph-rpm-fc#{node['platform_version']}-x86_64-basic/ref/#{node['ceph']['version']}/RPMS/x86_64/" @@ -33,9 +33,9 @@ when "fedora" default['ceph']['fedora']['extras']['repository'] = "#{node['ceph']['extras_repo_url']}/rpm/fedora#{node['platform_version']}/x86_64/" default['ceph']['fedora']['extras']['repository_key'] = "https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/autobuild.asc" when "suse" - #(Open)SuSE default repositories + # (Open)SuSE default repositories # Chef doesn't make a difference between suse and opensuse - suse = %x[ head -n1 /etc/SuSE-release| awk '{print $1}' ].chomp.downcase #can be suse or opensuse + suse = %x[ head -n1 /etc/SuSE-release| awk '{print $1}' ].chomp.downcase # can be suse or opensuse suse = "sles" if suse == "suse" suse_version = suse << %x[ grep VERSION /etc/SuSE-release | awk -F'= ' '{print $2}' ].chomp diff --git a/libraries/default.rb b/libraries/default.rb index ec4e9bf..a9d98eb 100644 --- a/libraries/default.rb +++ b/libraries/default.rb @@ -1,26 +1,25 @@ require 'ipaddr' require 'json' -def is_crowbar?() - return defined?(Chef::Recipe::Barclamp) != nil +def is_crowbar? + !defined?(Chef::Recipe::Barclamp).nil? end def get_mon_nodes(extra_search=nil) 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| "roles:"+role_object.name }.join(' OR ') + 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 else search_string = "role:ceph-mon AND chef_environment:#{node.chef_environment}" end - if not extra_search.nil? + unless extra_search.nil? search_string = "(#{search_string}) AND (#{extra_search})" end - mons = search(:node, search_string) - return mons + search(:node, search_string) end # If public_network is specified @@ -64,21 +63,19 @@ def find_node_ip_in_network(network, nodeish=nil) nil end -def get_mon_addresses() +def get_mon_addresses mon_ips = [] if File.exists?("/var/run/ceph/ceph-mon.#{node['hostname']}.asok") - mon_ips = get_quorum_members_ips() + mon_ips = get_quorum_members_ips else mons = [] # make sure if this node runs ceph-mon, it's always included even if # 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 + mons << node if node['roles'].include?('ceph-mon') - mons += get_mon_nodes() + mons += get_mon_nodes if is_crowbar? mon_ips = mons.map { |node| Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin").address } else @@ -89,35 +86,38 @@ def get_mon_addresses() end end end - mon_ips = mon_ips.reject{|m|m.nil?} - return mon_ips.uniq + mon_ips.reject { |m| m.nil? }.uniq end -def get_quorum_members_ips() +def get_quorum_members_ips mon_ips = [] - mon_status = %x[ceph --admin-daemon /var/run/ceph/ceph-mon.#{node['hostname']}.asok mon_status] - raise 'getting quorum members failed' unless $?.exitstatus == 0 + cmd = Mixlib::ShellOut.new("ceph --admin-daemon /var/run/ceph/ceph-mon.#{node['hostname']}.asok mon_status") + cmd.run_command + cmd.error! - mons = JSON.parse(mon_status)['monmap']['mons'] + mons = JSON.parse(cmd.stdout)['monmap']['mons'] mons.each do |k| mon_ips.push(k['addr'][0..-3]) end - return mon_ips + mon_ips end -QUORUM_STATES = ['leader', 'peon'] -def have_quorum?() - # "ceph auth get-or-create-key" would hang if the monitor wasn't - # in quorum yet, which is highly likely on the first run. This - # helper lets us delay the key generation into the next - # chef-client run, instead of hanging. - # - # Also, as the UNIX domain socket connection has no timeout logic - # in the ceph tool, this exits immediately if the ceph-mon is not - # running for any reason; trying to connect via TCP/IP would wait - # for a relatively long timeout. - mon_status = %x[ceph --admin-daemon /var/run/ceph/ceph-mon.#{node['hostname']}.asok mon_status] - raise 'getting monitor state failed' unless $?.exitstatus == 0 - state = JSON.parse(mon_status)['state'] - return QUORUM_STATES.include?(state) +QUORUM_STATES = %w(leader, peon) +def have_quorum? + # "ceph auth get-or-create-key" would hang if the monitor wasn't + # in quorum yet, which is highly likely on the first run. This + # helper lets us delay the key generation into the next + # chef-client run, instead of hanging. + # + # Also, as the UNIX domain socket connection has no timeout logic + # in the ceph tool, this exits immediately if the ceph-mon is not + # running for any reason; trying to connect via TCP/IP would wait + # for a relatively long timeout. + + cmd = Mixlib::ShellOut.new("ceph --admin-daemon /var/run/ceph/ceph-mon.#{node['hostname']}.asok mon_status") + cmd.run_command + cmd.error! + + state = JSON.parse(cmd.stdout)['state'] + QUORUM_STATES.include?(state) end diff --git a/recipes/apt.rb b/recipes/apt.rb index 67c5819..3704e9a 100644 --- a/recipes/apt.rb +++ b/recipes/apt.rb @@ -1,3 +1,4 @@ + include_recipe "apt" branch = node['ceph']['branch'] diff --git a/recipes/cephfs.rb b/recipes/cephfs.rb index 3bd6839..741b7a3 100644 --- a/recipes/cephfs.rb +++ b/recipes/cephfs.rb @@ -25,7 +25,7 @@ filename = "/etc/ceph/ceph.client.#{client_name}.secret" ceph_client name do filename filename - caps ({"mon" => "allow r", "osd" => "allow rw", "mds" => "allow"}) + caps ({ "mon" => "allow r", "osd" => "allow rw", "mds" => "allow" }) as_keyring false end diff --git a/recipes/osd.rb b/recipes/osd.rb index 58858c0..7f74cf6 100644 --- a/recipes/osd.rb +++ b/recipes/osd.rb @@ -40,7 +40,7 @@ end package 'cryptsetup' do action :upgrade - not_if { search(:node,"hostname:#{node['hostname']} AND dmcrypt:true").empty? } + not_if { search(:node, "hostname:#{node['hostname']} AND dmcrypt:true").empty? } end service_type = node["ceph"]["osd"]["init_style"] @@ -59,11 +59,11 @@ else # TODO: cluster name cluster = 'ceph' - osd_secret = if node['ceph']['encrypted_data_bags'] + if node['ceph']['encrypted_data_bags'] secret = Chef::EncryptedDataBagItem.load_secret(node["ceph"]["osd"]["secret_file"]) - Chef::EncryptedDataBagItem.load("ceph", "osd", secret)["secret"] + osd_secret = Chef::EncryptedDataBagItem.load("ceph", "osd", secret)["secret"] else - mons[0]["ceph"]["bootstrap_osd_key"] + osd_secret = mons[0]["ceph"]["bootstrap_osd_key"] end execute "format as keyring" do diff --git a/resources/client.rb b/resources/client.rb index 26d8995..0ca1436 100644 --- a/resources/client.rb +++ b/resources/client.rb @@ -2,7 +2,7 @@ actions :add default_action :add attribute :name, :kind_of => String, :name_attribute => true -attribute :caps, :kind_of => Hash, :default => {"mon" => "allow r", "osd" => "allow r"} +attribute :caps, :kind_of => Hash, :default => { "mon" => "allow r", "osd" => "allow r" } # Whether to store the secret in a keyring file or a plain secret file attribute :as_keyring, :kind_of => [TrueClass, FalseClass], :default => true