nova_migration_libvirt_spec.rb 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #
  2. # Copyright (C) 2013 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::migration::libvirt class
  19. #
  20. require 'spec_helper'
  21. describe 'nova::migration::libvirt' do
  22. generate = {}
  23. before(:each) {
  24. Puppet::Parser::Functions.newfunction(:generate, :type => :rvalue) {
  25. |args| generate.call()
  26. }
  27. generate.stubs(:call).returns('0000-111-111')
  28. }
  29. let :pre_condition do
  30. 'include nova
  31. include nova::compute
  32. include nova::compute::libvirt'
  33. end
  34. shared_examples_for 'nova migration with libvirt' do
  35. context 'with default params' do
  36. it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf listen_tls').with(:line => "listen_tls = 0") }
  37. it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf listen_tcp').with(:line => "listen_tcp = 1") }
  38. it { is_expected.not_to contain_file_line('/etc/libvirt/libvirtd.conf auth_tls')}
  39. it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf auth_tcp').with(:line => "auth_tcp = \"none\"") }
  40. it { is_expected.to contain_nova_config('libvirt/live_migration_tunnelled').with_value('<SERVICE DEFAULT>') }
  41. it { is_expected.to contain_nova_config('libvirt/live_migration_completion_timeout').with_value('<SERVICE DEFAULT>') }
  42. it { is_expected.to contain_nova_config('libvirt/live_migration_progress_timeout').with_value('<SERVICE DEFAULT>') }
  43. end
  44. context 'with override_uuid enabled' do
  45. let :params do
  46. {
  47. :override_uuid => true,
  48. }
  49. end
  50. it { is_expected.to contain_file('/etc/libvirt/libvirt_uuid').with({
  51. :content => '0000-111-111',
  52. }).that_requires('Package[libvirt]') }
  53. it { is_expected.to contain_augeas('libvirt-conf-uuid').with({
  54. :context => '/files/etc/libvirt/libvirtd.conf',
  55. :changes => [ "set host_uuid 0000-111-111" ],
  56. }).that_requires('Package[libvirt]').that_notifies('Service[libvirt]') }
  57. end
  58. context 'with tls enabled' do
  59. let :params do
  60. {
  61. :use_tls => true,
  62. }
  63. end
  64. it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf listen_tls').with(:line => "listen_tls = 1") }
  65. it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf listen_tcp').with(:line => "listen_tcp = 0") }
  66. it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf auth_tls').with(:line => "auth_tls = \"none\"") }
  67. it { is_expected.not_to contain_file_line('/etc/libvirt/libvirtd.conf auth_tcp')}
  68. it { is_expected.to contain_nova_config('libvirt/live_migration_uri').with_value('qemu+tls://%s/system')}
  69. end
  70. context 'with migration flags set' do
  71. let :params do
  72. {
  73. :live_migration_tunnelled => true,
  74. :live_migration_completion_timeout => '1500',
  75. :live_migration_progress_timeout => '1500',
  76. }
  77. end
  78. it { is_expected.to contain_nova_config('libvirt/live_migration_tunnelled').with(:value => true) }
  79. it { is_expected.to contain_nova_config('libvirt/live_migration_completion_timeout').with_value('1500') }
  80. it { is_expected.to contain_nova_config('libvirt/live_migration_progress_timeout').with_value('1500') }
  81. end
  82. context 'with auth set to sasl' do
  83. let :params do
  84. {
  85. :auth => 'sasl',
  86. }
  87. end
  88. it { is_expected.not_to contain_file_line('/etc/libvirt/libvirtd.conf auth_tls')}
  89. it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf auth_tcp').with(:line => "auth_tcp = \"sasl\"") }
  90. end
  91. context 'with auth set to sasl and tls enabled' do
  92. let :params do
  93. {
  94. :auth => 'sasl',
  95. :use_tls => true
  96. }
  97. end
  98. it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf auth_tls').with(:line => "auth_tls = \"sasl\"") }
  99. it { is_expected.not_to contain_file_line('/etc/libvirt/libvirtd.conf auth_tcp')}
  100. end
  101. context 'with auth set to an invalid setting' do
  102. let :params do
  103. {
  104. :auth => 'inexistent_auth',
  105. }
  106. end
  107. it { expect { is_expected.to contain_class('nova::compute::libvirt') }.to \
  108. raise_error(Puppet::Error, /Valid options for auth are none and sasl./) }
  109. end
  110. context 'when not configuring libvirt' do
  111. let :params do
  112. {
  113. :configure_libvirt => false
  114. }
  115. end
  116. it { is_expected.not_to contain_file_line('/etc/libvirt/libvirtd.conf listen_tls') }
  117. end
  118. context 'when not configuring nova and tls enabled' do
  119. let :params do
  120. {
  121. :configure_nova => false,
  122. :use_tls => true,
  123. }
  124. end
  125. it { is_expected.not_to contain_nova_config('libvirt/live_migration_uri').with_value('qemu+tls://%s/system') }
  126. end
  127. end
  128. # TODO (degorenko): switch to on_supported_os function when we got Xenial
  129. context 'on Debian platforms with Ubuntu release 16' do
  130. let :facts do
  131. @default_facts.merge({
  132. :osfamily => 'Debian',
  133. :operatingsystem => 'Ubuntu',
  134. :operatingsystemmajrelease => '16'
  135. })
  136. end
  137. it_configures 'nova migration with libvirt'
  138. it { is_expected.to contain_file_line('/etc/default/libvirtd libvirtd opts').with(:line => 'libvirtd_opts="-l"') }
  139. end
  140. context 'on Debian platforms release' do
  141. let :facts do
  142. @default_facts.merge({
  143. :osfamily => 'Debian',
  144. :operatingsystem => 'Debian',
  145. :operatingsystemmajrelease => '8'
  146. })
  147. end
  148. it_configures 'nova migration with libvirt'
  149. it { is_expected.to contain_file_line('/etc/default/libvirtd libvirtd opts').with(:line => 'libvirtd_opts="-d -l"') }
  150. end
  151. context 'on RedHat platforms' do
  152. let :facts do
  153. @default_facts.merge({
  154. :osfamily => 'RedHat',
  155. :operatingsystem => 'CentOS',
  156. :operatingsystemmajrelease => '7.0'
  157. })
  158. end
  159. it_configures 'nova migration with libvirt'
  160. it { is_expected.to contain_file_line('/etc/sysconfig/libvirtd libvirtd args').with(:line => 'LIBVIRTD_ARGS="--listen"') }
  161. end
  162. end