Skip to content

Commit

Permalink
compute: RBD backend support
Browse files Browse the repository at this point in the history
Since Havana, Nova is able to store VMs on RBD backend (ceph).

Change-Id: I17890a3e9e49572d989ad01383417b7256ef7e14
Signed-off-by: Emilien Macchi <[email protected]>
(cherry picked from commit 076d415ba560206ef1299b090c4eb474ffc2bdc4)
  • Loading branch information
Emilien Macchi committed Feb 27, 2014
1 parent 2251984 commit 49d1694
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 0 deletions.
85 changes: 85 additions & 0 deletions manifests/compute/rbd.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#
# Copyright (C) 2014 OpenStack Fondation
#
# Author: Emilien Macchi <[email protected]>
# Donald Talton <[email protected]>
#
# 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.

# Configure the neutron server to use the ML2 plugin.
# This configures the plugin for the API server, but does nothing
# about configuring the agents that must also run and share a config
# file with the OVS plugin if both are on the same machine.
#
# == Class: nova::compute::rbd
#
# Configure nova-compute to store virtual machines on RBD
#
# === Parameters
#
# [*libvirt_images_rbd_pool*]
# (optional) The RADOS pool in which rbd volumes are stored.
# Defaults to 'rbd'.
#
# [*libvirt_images_rbd_ceph_conf*]
# (optional) The path to the ceph configuration file to use.
# Defaults to '/etc/ceph/ceph.conf'.
#
# [*libvirt_rbd_user*]
# (Required) The RADOS client name for accessing rbd volumes.
#
# [*libvirt_rbd_secret_uuid*]
# (optional) The libvirt uuid of the secret for the rbd_user.
# Required to use cephx.
# Default to false.
#

class nova::compute::rbd (
$libvirt_rbd_user,
$libvirt_rbd_secret_uuid = false,
$libvirt_images_rbd_pool = 'rbd',
$libvirt_images_rbd_ceph_conf = '/etc/ceph/ceph.conf',
) {

include nova::params

nova_config {
'DEFAULT/libvirt_images_type': value => 'rbd';
'DEFAULT/libvirt_images_rbd_pool': value => $libvirt_images_rbd_pool;
'DEFAULT/libvirt_images_rbd_ceph_conf': value => $libvirt_images_rbd_ceph_conf;
'DEFAULT/rbd_user': value => $libvirt_rbd_user;
}

if $libvirt_rbd_secret_uuid {
nova_config {
'DEFAULT/rbd_secret_uuid': value => $libvirt_rbd_secret_uuid;
}

file { '/etc/nova/secret.xml':
content => template('nova/secret.xml-compute.erb')
}

exec { 'get-or-set virsh secret':
command => '/usr/bin/virsh secret-define --file /etc/ceph/secret.xml | /usr/bin/awk \'{print $2}\' | sed \'/^$/d\' > /etc/ceph/virsh.secret',
creates => '/etc/ceph/virsh.secret',
require => File['/etc/ceph/secret.xml']
}

exec { 'set-secret-value virsh':
command => '/usr/bin/virsh secret-set-value --secret $(cat /etc/ceph/virsh.secret) --base64 $(ceph auth get-key client.nova)',
require => Exec['get-or-set virsh secret']
}

}

}
109 changes: 109 additions & 0 deletions spec/classes/nova_compute_rbd_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#
# Copyright (C) 2014 eNovance SAS <[email protected]>
#
# Author: Emilien Macchi <[email protected]>
#
# 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.
#
# Unit tests for nova::compute::rbd class
#

require 'spec_helper'

describe 'nova::compute::rbd' do

let :params do
{ :libvirt_rbd_user => 'nova',
:libvirt_rbd_secret_uuid => false,
:libvirt_images_rbd_pool => 'rbd',
:libvirt_images_rbd_ceph_conf => '/etc/ceph/ceph.conf' }
end

shared_examples_for 'nova compute rbd' do

it { should contain_class('nova::params') }

it 'configure nova.conf with default parameters' do
should contain_nova_config('DEFAULT/libvirt_images_type').with_value('rbd')
should contain_nova_config('DEFAULT/libvirt_images_rbd_pool').with_value('rbd')
should contain_nova_config('DEFAULT/libvirt_images_rbd_ceph_conf').with_value('/etc/ceph/ceph.conf')
should contain_nova_config('DEFAULT/rbd_user').with_value('nova')
end

context 'when overriding default parameters' do
before :each do
params.merge!(
:libvirt_rbd_user => 'joe',
:libvirt_rbd_secret_uuid => false,
:libvirt_images_rbd_pool => 'AnotherPool',
:libvirt_images_rbd_ceph_conf => '/tmp/ceph.conf'
)
end

it 'configure nova.conf with overriden parameters' do
should contain_nova_config('DEFAULT/libvirt_images_type').with_value('rbd')
should contain_nova_config('DEFAULT/libvirt_images_rbd_pool').with_value('AnotherPool')
should contain_nova_config('DEFAULT/libvirt_images_rbd_ceph_conf').with_value('/tmp/ceph.conf')
should contain_nova_config('DEFAULT/rbd_user').with_value('joe')
end
end

context 'when using cephx' do
before :each do
params.merge!(
:libvirt_rbd_secret_uuid => 'UUID'
)
end

it 'configure nova.conf with RBD secret UUID' do
should contain_nova_config('DEFAULT/rbd_secret_uuid').with_value('UUID')
end

it 'configure ceph on compute nodes' do
verify_contents(subject, '/etc/nova/secret.xml', [
"<secret ephemeral=\'no\' private=\'no\'>",
" <usage type=\'ceph\'>",
" <name>client.nova secret</name>",
" </usage>",
" <uuid>UUID</uuid>",
"</secret>"
])
should contain_exec('get-or-set virsh secret').with(
:command => '/usr/bin/virsh secret-define --file /etc/ceph/secret.xml | /usr/bin/awk \'{print $2}\' | sed \'/^$/d\' > /etc/ceph/virsh.secret',
:creates => '/etc/ceph/virsh.secret'
)
should contain_exec('set-secret-value virsh').with(
:command => "/usr/bin/virsh secret-set-value --secret $(cat /etc/ceph/virsh.secret) --base64 $(ceph auth get-key client.nova)"
)
end
end

end

context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
end

it_configures 'nova compute rbd'
end

context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
end

it_configures 'nova compute rbd'
end

end
6 changes: 6 additions & 0 deletions templates/secret.xml-compute.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<secret ephemeral='no' private='no'>
<usage type='ceph'>
<name>client.nova secret</name>
</usage>
<uuid><%= @libvirt_rbd_secret_uuid %></uuid>
</secret>

0 comments on commit 49d1694

Please sign in to comment.