Add ceph_client recipe

To use RBD as a block-storage backend, both the compute workers and the
cinder-api service need to be able to talk to the Ceph cluster.

Nova-compute makes use of the `rbd` CLI tool, cinder-api and libvirt use
librbd's Python binding.  Therefore, it might make sense to have this
"common" recipe provide the necessary infrastructure to a) reach the
ceph cluster and b) install ceph packages if need be.

Besides block storage, RBD can also be used for storing images, so
that's another reason to put this into openstack-common.

This commit also introduces a template, "ceph.client.keyring.erb", to
allow the creation of client keys from other recipes in a DRY way:

    template '/etc/ceph/client.cinder.keyring' do
      template 'ceph.client.keyring.erb'
      cookbook 'openstack-common'
      owner node['openstack']['block-storage']['user']
      group node['openstack']['block-storage']['group']
      mode '600'
      variables(
        name: rbd_user,
        key: rbd_key
      )
    end

A LWRP for this would be an improvement, but this should do for now.

Implements: blueprint rbd-for-block-storage

Change-Id: Icd046830c9542bd71fa3a1857c1f4d1bb3c41cec
This commit is contained in:
Stephan Renatus 2014-01-27 15:00:58 +01:00
parent 575e4af396
commit 104136bed7
5 changed files with 121 additions and 0 deletions

View File

@ -274,3 +274,23 @@ default['openstack']['memcached_servers'] = nil
# Default sysctl settings
default['openstack']['sysctl']['net.ipv4.conf.all.rp_filter'] = 0
default['openstack']['sysctl']['net.ipv4.conf.default.rp_filter'] = 0
# Default Ceph settings
default['openstack']['ceph']['key-url'] = 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc'
case platform
when 'ubuntu'
default['openstack']['ceph']['platform']['uri'] = 'http://ceph.com/debian-emperor'
when 'fedora', 'redhat', 'centos', 'suse' # :pragma-foodcritic: ~FC024 - won't fix this
default['openstack']['ceph']['platform']['uri'] = 'http://ceph.com/rpm-emperor'
end
default['openstack']['ceph']['global'] = {
fsid: '00000000-0000-0000-0000-000000000000',
mon_initial_members: [],
mon_host: [],
auth_cluster_required: 'cephx',
auth_service_required: 'cephx',
auth_client_required: 'cephx',
filestore_xattr_use_omap: true
}

46
recipes/ceph_client.rb Normal file
View File

@ -0,0 +1,46 @@
# encoding: UTF-8
#
# Cookbook Name:: openstack-common
# Recipe:: ceph_client
#
# Copyright 2014, x-ion GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
case node['platform']
when 'ubuntu'
apt_repository 'ceph' do
uri node['openstack']['ceph']['platform']['uri']
distribution node['lsb']['codename']
components ['main']
key node['openstack']['ceph']['key-url']
end
when 'fedora', 'redhat', 'centos', 'suse' # :pragma-foodcritic: ~FC024 - won't fix this
# TODO
end
directory '/etc/ceph' do
user 'root'
group 'root'
end
template '/etc/ceph/ceph.conf' do
source 'ceph.conf.erb'
user 'root'
group 'root'
mode '644'
variables(
global: node['openstack']['ceph']['global']
)
end

44
spec/ceph_spec.rb Normal file
View File

@ -0,0 +1,44 @@
# encoding: UTF-8
require_relative 'spec_helper'
describe 'openstack-common::ceph_client' do
describe 'ubuntu' do
before do
opts = ::UBUNTU_OPTS.merge(step_into: ['apt_repository'])
@chef_run = ::ChefSpec::Runner.new(opts) do |n|
n.set['openstack']['ceph']['global']['fsid'] = '9e5038a9-4329-4cad-8c24-0813a49d1125'
n.set['openstack']['ceph']['global']['mon_initial_members'] = %w{ 10.0.1.10 10.0.1.20 }
n.set['openstack']['ceph']['global']['mon_hosts'] = %w{ mon01 mon02 }
n.set['lsb']['codename'] = 'precise'
end
@filename = '/etc/ceph/ceph.conf'
@chef_run.converge 'openstack-common::ceph_client'
end
it 'configures ceph repository' do
file = '/etc/apt/sources.list.d/ceph.list'
expected = 'deb http://ceph.com/debian-emperor precise main'
expect(@chef_run).to render_file(file).with_content(expected)
end
it 'creates the /etc/ceph/ceph.conf file' do
expect(@chef_run).to create_template(@filename).with(
owner: 'root',
group: 'root',
mode: '644'
)
end
it 'configures ceph.conf' do
[/^\[global\]$/,
/^fsid = 9e5038a9-4329-4cad-8c24-0813a49d1125$/,
/^mon_initial_members = 10.0.1.10, 10.0.1.20$/,
/^mon_hosts = mon01, mon02$/].each do |content|
expect(@chef_run).to render_file(@filename).with_content(content)
end
end
end
end

View File

@ -0,0 +1,3 @@
[client.<%= @name -%>]
key = <%= @key %>

View File

@ -0,0 +1,8 @@
[global]
<% @global.each do |k,v| -%>
<% if v.is_a? Array -%>
<%= k %> = <%= v.join ", " %>
<% else -%>
<%= k %> = <%= v %>
<% end -%>
<% end -%>