2 # Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
4 # Author: Emilien Macchi <emilien.macchi@enovance.com>
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
18 # Unit tests for nova::compute::rbd class
23 describe 'nova::compute::rbd' do
26 { :libvirt_rbd_user => 'nova',
27 :libvirt_rbd_secret_uuid => false,
28 :libvirt_images_rbd_pool => 'rbd',
29 :libvirt_images_rbd_ceph_conf => '/etc/ceph/ceph.conf' }
32 shared_examples_for 'nova compute rbd' do
34 it { should contain_class('nova::params') }
36 it 'configure nova.conf with default parameters' do
37 should contain_nova_config('libvirt/images_type').with_value('rbd')
38 should contain_nova_config('libvirt/images_rbd_pool').with_value('rbd')
39 should contain_nova_config('libvirt/images_rbd_ceph_conf').with_value('/etc/ceph/ceph.conf')
40 should contain_nova_config('libvirt/rbd_user').with_value('nova')
43 context 'when overriding default parameters' do
46 :libvirt_rbd_user => 'joe',
47 :libvirt_rbd_secret_uuid => false,
48 :libvirt_images_rbd_pool => 'AnotherPool',
49 :libvirt_images_rbd_ceph_conf => '/tmp/ceph.conf'
53 it 'configure nova.conf with overridden parameters' do
54 should contain_nova_config('libvirt/images_type').with_value('rbd')
55 should contain_nova_config('libvirt/images_rbd_pool').with_value('AnotherPool')
56 should contain_nova_config('libvirt/images_rbd_ceph_conf').with_value('/tmp/ceph.conf')
57 should contain_nova_config('libvirt/rbd_user').with_value('joe')
61 context 'when using cephx' do
64 :libvirt_rbd_secret_uuid => 'UUID',
65 :rbd_keyring => 'client.rbd_test'
69 it 'configure nova.conf with RBD secret UUID' do
70 should contain_nova_config('libvirt/rbd_secret_uuid').with_value('UUID')
73 it 'configure ceph on compute nodes' do
74 verify_contents(subject, '/etc/nova/secret.xml', [
75 "<secret ephemeral=\'no\' private=\'no\'>",
76 " <usage type=\'ceph\'>",
77 " <name>client.rbd_test secret</name>",
82 should contain_exec('get-or-set virsh secret').with(
83 :command => '/usr/bin/virsh secret-define --file /etc/nova/secret.xml | /usr/bin/awk \'{print $2}\' | sed \'/^$/d\' > /etc/nova/virsh.secret',
84 :creates => '/etc/nova/virsh.secret',
85 :require => 'File[/etc/nova/secret.xml]'
88 should contain_exec('set-secret-value virsh').with(
89 :command => "/usr/bin/virsh secret-set-value --secret UUID --base64 $(ceph auth get-key client.rbd_test)"
94 context 'when using cephx and passing libvirt_rbd_secret_key' do
97 :libvirt_rbd_secret_uuid => 'UUID',
98 :libvirt_rbd_secret_key => 'LIBVIRT/SECRET/KEY',
102 it 'set libvirt secret key from passed key' do
103 should contain_exec('set-secret-value virsh').with(
104 :command => "/usr/bin/virsh secret-set-value --secret #{params[:libvirt_rbd_secret_uuid]} --base64 #{params[:libvirt_rbd_secret_key]}"
111 context 'on Debian platforms' do
113 { :osfamily => 'Debian' }
116 it_configures 'nova compute rbd'
119 context 'on RedHat platforms' do
121 { :osfamily => 'RedHat' }
124 it_configures 'nova compute rbd'