nova_compute_rbd_spec.rb 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. require 'spec_helper'
  21. describe 'nova::compute::rbd' do
  22. let :params do
  23. { :libvirt_rbd_user => 'nova',
  24. :libvirt_rbd_secret_uuid => false,
  25. :libvirt_images_rbd_pool => 'rbd',
  26. :libvirt_images_rbd_ceph_conf => '/etc/ceph/ceph.conf',
  27. :ephemeral_storage => true }
  28. end
  29. shared_examples_for 'nova compute rbd' do
  30. it { is_expected.to contain_class('nova::params') }
  31. it 'configure nova.conf with default parameters' do
  32. is_expected.to contain_nova_config('libvirt/images_type').with_value('rbd')
  33. is_expected.to contain_nova_config('libvirt/images_rbd_pool').with_value('rbd')
  34. is_expected.to contain_nova_config('libvirt/images_rbd_ceph_conf').with_value('/etc/ceph/ceph.conf')
  35. is_expected.to contain_nova_config('libvirt/rbd_user').with_value('nova')
  36. end
  37. it 'installs client package' do
  38. is_expected.to contain_package('ceph-client-package').with(
  39. 'name' => platform_params[:ceph_client_package],
  40. 'ensure' => 'present'
  41. )
  42. end
  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. it 'configure nova.conf with overridden parameters' do
  53. is_expected.to contain_nova_config('libvirt/images_type').with_value('rbd')
  54. is_expected.to contain_nova_config('libvirt/images_rbd_pool').with_value('AnotherPool')
  55. is_expected.to contain_nova_config('libvirt/images_rbd_ceph_conf').with_value('/tmp/ceph.conf')
  56. is_expected.to contain_nova_config('libvirt/rbd_user').with_value('joe')
  57. end
  58. end
  59. context 'when using cephx' do
  60. before :each do
  61. params.merge!(
  62. :libvirt_rbd_secret_uuid => 'UUID',
  63. :rbd_keyring => 'client.rbd_test'
  64. )
  65. end
  66. it 'configure nova.conf with RBD secret UUID' do
  67. is_expected.to contain_nova_config('libvirt/rbd_secret_uuid').with_value('UUID')
  68. end
  69. it 'configure ceph on compute nodes' do
  70. verify_contents(catalogue, '/etc/nova/secret.xml', [
  71. "<secret ephemeral=\'no\' private=\'no\'>",
  72. " <usage type=\'ceph\'>",
  73. " <name>client.rbd_test secret</name>",
  74. " </usage>",
  75. " <uuid>UUID</uuid>",
  76. "</secret>"
  77. ])
  78. is_expected.to contain_exec('get-or-set virsh secret').with(
  79. :command => '/usr/bin/virsh secret-define --file /etc/nova/secret.xml | /usr/bin/awk \'{print $2}\' | sed \'/^$/d\' > /etc/nova/virsh.secret',
  80. :unless => '/usr/bin/virsh secret-list | grep UUID',
  81. :require => ['File[/etc/nova/secret.xml]', 'Service[libvirt]'],
  82. )
  83. is_expected.to contain_exec('set-secret-value virsh').with(
  84. :command => "/usr/bin/virsh secret-set-value --secret UUID --base64 $(ceph auth get-key client.rbd_test)"
  85. )
  86. end
  87. end
  88. context 'when using cephx and passing libvirt_rbd_secret_key' do
  89. before :each do
  90. params.merge!(
  91. :libvirt_rbd_secret_uuid => 'UUID',
  92. :libvirt_rbd_secret_key => 'LIBVIRT/SECRET/KEY',
  93. )
  94. end
  95. it 'set libvirt secret key from passed key' do
  96. is_expected.to contain_exec('set-secret-value virsh').with(
  97. :command => "/usr/bin/virsh secret-set-value --secret #{params[:libvirt_rbd_secret_uuid]} --base64 #{params[:libvirt_rbd_secret_key]}"
  98. )
  99. end
  100. end
  101. context 'when using cephx but disabling ephemeral storage' do
  102. before :each do
  103. params.merge!(
  104. :libvirt_rbd_secret_uuid => 'UUID',
  105. :rbd_keyring => 'client.rbd_test',
  106. :ephemeral_storage => false
  107. )
  108. end
  109. it 'should only set user and secret_uuid in nova.conf ' do
  110. is_expected.to_not contain_nova_config('libvirt/images_rbd_pool').with_value('rbd')
  111. is_expected.to_not contain_nova_config('libvirt/images_rbd_ceph_conf').with_value('/etc/ceph/ceph.conf')
  112. is_expected.to contain_nova_config('libvirt/rbd_user').with_value('nova')
  113. is_expected.to contain_nova_config('libvirt/rbd_secret_uuid').with_value('UUID')
  114. end
  115. it 'configure ceph on compute nodes' do
  116. verify_contents(catalogue, '/etc/nova/secret.xml', [
  117. "<secret ephemeral=\'no\' private=\'no\'>",
  118. " <usage type=\'ceph\'>",
  119. " <name>client.rbd_test secret</name>",
  120. " </usage>",
  121. " <uuid>UUID</uuid>",
  122. "</secret>"
  123. ])
  124. is_expected.to contain_exec('get-or-set virsh secret').with(
  125. :command => '/usr/bin/virsh secret-define --file /etc/nova/secret.xml | /usr/bin/awk \'{print $2}\' | sed \'/^$/d\' > /etc/nova/virsh.secret',
  126. :unless => '/usr/bin/virsh secret-list | grep UUID',
  127. :require => ['File[/etc/nova/secret.xml]', 'Service[libvirt]'],
  128. )
  129. is_expected.to contain_exec('set-secret-value virsh').with(
  130. :command => "/usr/bin/virsh secret-set-value --secret UUID --base64 $(ceph auth get-key client.rbd_test)"
  131. )
  132. end
  133. end
  134. context 'when not managing ceph client' do
  135. before :each do
  136. params.merge!(
  137. :manage_ceph_client => false
  138. )
  139. end
  140. it { is_expected.to_not contain_package('ceph-client-package') }
  141. end
  142. end
  143. on_supported_os({
  144. :supported_os => OSDefaults.get_supported_os
  145. }).each do |os,facts|
  146. context "on #{os}" do
  147. let (:facts) do
  148. facts.merge!(OSDefaults.get_facts())
  149. end
  150. let (:platform_params) do
  151. case facts[:osfamily]
  152. when 'Debian'
  153. { :ceph_client_package => 'ceph' }
  154. when 'RedHat'
  155. { :ceph_client_package => 'ceph-common' }
  156. end
  157. end
  158. it_configures 'nova compute rbd'
  159. end
  160. end
  161. end