try again, with puppetforge modules, correctly included now
[mirror/dsa-puppet.git] / 3rdparty / modules / nova / spec / classes / nova_compute_rbd_spec.rb
1 #
2 # Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
3 #
4 # Author: Emilien Macchi <emilien.macchi@enovance.com>
5 #
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
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
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
16 # under the License.
17 #
18 # Unit tests for nova::compute::rbd class
19 #
20
21 require 'spec_helper'
22
23 describe 'nova::compute::rbd' do
24
25   let :params 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' }
30   end
31
32   shared_examples_for 'nova compute rbd' do
33
34     it { should contain_class('nova::params') }
35
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')
41     end
42
43     context 'when overriding default parameters' do
44       before :each do
45         params.merge!(
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'
50         )
51       end
52
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')
58       end
59     end
60
61     context 'when using cephx' do
62       before :each do
63         params.merge!(
64           :libvirt_rbd_secret_uuid => 'UUID',
65           :rbd_keyring             => 'client.rbd_test'
66         )
67       end
68
69       it 'configure nova.conf with RBD secret UUID' do
70           should contain_nova_config('libvirt/rbd_secret_uuid').with_value('UUID')
71       end
72
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>",
78           "  </usage>",
79           "  <uuid>UUID</uuid>",
80           "</secret>"
81         ])
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]'
86         )
87
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)"
90         )
91       end
92     end
93
94     context 'when using cephx and passing libvirt_rbd_secret_key' do
95       before :each do
96         params.merge!(
97           :libvirt_rbd_secret_uuid => 'UUID',
98           :libvirt_rbd_secret_key  => 'LIBVIRT/SECRET/KEY',
99         )
100       end
101
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]}"
105         )
106       end
107     end
108
109   end
110
111   context 'on Debian platforms' do
112     let :facts do
113       { :osfamily => 'Debian' }
114     end
115
116     it_configures 'nova compute rbd'
117   end
118
119   context 'on RedHat platforms' do
120     let :facts do
121       { :osfamily => 'RedHat' }
122     end
123
124     it_configures 'nova compute rbd'
125   end
126
127 end