apt_spec.rb 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. require 'spec_helper'
  2. describe 'apt', :type => :class do
  3. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
  4. context 'defaults' do
  5. it { should contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({
  6. 'ensure' => 'present',
  7. 'path' => '/etc/apt/sources.list',
  8. 'owner' => 'root',
  9. 'group' => 'root',
  10. 'mode' => '0644',
  11. 'notify' => 'Exec[apt_update]',
  12. })}
  13. it { should contain_file('sources.list.d').that_notifies('Exec[apt_update]').only_with({
  14. 'ensure' => 'directory',
  15. 'path' => '/etc/apt/sources.list.d',
  16. 'owner' => 'root',
  17. 'group' => 'root',
  18. 'purge' => false,
  19. 'recurse' => false,
  20. 'notify' => 'Exec[apt_update]',
  21. })}
  22. it { should contain_file('preferences.d').only_with({
  23. 'ensure' => 'directory',
  24. 'path' => '/etc/apt/preferences.d',
  25. 'owner' => 'root',
  26. 'group' => 'root',
  27. 'purge' => false,
  28. 'recurse' => false,
  29. })}
  30. it { should contain_file('01proxy').that_notifies('Exec[apt_update]').only_with({
  31. 'ensure' => 'absent',
  32. 'path' => '/etc/apt/apt.conf.d/01proxy',
  33. 'notify' => 'Exec[apt_update]',
  34. })}
  35. it 'should lay down /etc/apt/apt.conf.d/15update-stamp' do
  36. should contain_file('/etc/apt/apt.conf.d/15update-stamp').with({
  37. 'group' => 'root',
  38. 'mode' => '0644',
  39. 'owner' => 'root',
  40. }).with_content('APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};')
  41. end
  42. it { should contain_file('old-proxy-file').that_notifies('Exec[apt_update]').only_with({
  43. 'ensure' => 'absent',
  44. 'path' => '/etc/apt/apt.conf.d/proxy',
  45. 'notify' => 'Exec[apt_update]',
  46. })}
  47. it { should contain_exec('apt_update').with({
  48. 'refreshonly' => 'true',
  49. })}
  50. end
  51. context 'lots of non-defaults' do
  52. let :params do
  53. {
  54. :always_apt_update => true,
  55. :disable_keys => true,
  56. :proxy_host => 'foo',
  57. :proxy_port => '9876',
  58. :purge_sources_list => true,
  59. :purge_sources_list_d => true,
  60. :purge_preferences => true,
  61. :purge_preferences_d => true,
  62. :update_timeout => '1',
  63. :update_tries => '3',
  64. :fancy_progress => true,
  65. }
  66. end
  67. it { should contain_file('sources.list').with({
  68. 'content' => "# Repos managed by puppet.\n"
  69. })}
  70. it { should contain_file('sources.list.d').with({
  71. 'purge' => 'true',
  72. 'recurse' => 'true',
  73. })}
  74. it { should contain_file('apt-preferences').only_with({
  75. 'ensure' => 'absent',
  76. 'path' => '/etc/apt/preferences',
  77. })}
  78. it { should contain_file('preferences.d').with({
  79. 'purge' => 'true',
  80. 'recurse' => 'true',
  81. })}
  82. it { should contain_file('99progressbar').only_with({
  83. 'ensure' => 'present',
  84. 'content' => 'Dpkg::Progress-Fancy "1";',
  85. 'path' => '/etc/apt/apt.conf.d/99progressbar',
  86. })}
  87. it { should contain_file('99unauth').only_with({
  88. 'ensure' => 'present',
  89. 'content' => "APT::Get::AllowUnauthenticated 1;\n",
  90. 'path' => '/etc/apt/apt.conf.d/99unauth',
  91. })}
  92. it { should contain_file('01proxy').that_notifies('Exec[apt_update]').only_with({
  93. 'ensure' => 'present',
  94. 'path' => '/etc/apt/apt.conf.d/01proxy',
  95. 'content' => "Acquire::http::Proxy \"http://foo:9876\";\n",
  96. 'notify' => 'Exec[apt_update]',
  97. 'mode' => '0644',
  98. 'owner' => 'root',
  99. 'group' => 'root'
  100. })}
  101. it { should contain_exec('apt_update').with({
  102. 'refreshonly' => 'false',
  103. 'timeout' => '1',
  104. 'tries' => '3',
  105. })}
  106. end
  107. context 'more non-default' do
  108. let :params do
  109. {
  110. :fancy_progress => false,
  111. :disable_keys => false,
  112. }
  113. end
  114. it { should contain_file('99progressbar').only_with({
  115. 'ensure' => 'absent',
  116. 'path' => '/etc/apt/apt.conf.d/99progressbar',
  117. })}
  118. it { should contain_file('99unauth').only_with({
  119. 'ensure' => 'absent',
  120. 'path' => '/etc/apt/apt.conf.d/99unauth',
  121. })}
  122. end
  123. context 'with sources defined on valid osfamily' do
  124. let :facts do
  125. { :osfamily => 'Debian',
  126. :lsbdistcodename => 'precise',
  127. :lsbdistid => 'Debian',
  128. }
  129. end
  130. let(:params) { { :sources => {
  131. 'debian_unstable' => {
  132. 'location' => 'http://debian.mirror.iweb.ca/debian/',
  133. 'release' => 'unstable',
  134. 'repos' => 'main contrib non-free',
  135. 'required_packages' => 'debian-keyring debian-archive-keyring',
  136. 'key' => '55BE302B',
  137. 'key_server' => 'subkeys.pgp.net',
  138. 'pin' => '-10',
  139. 'include_src' => true
  140. },
  141. 'puppetlabs' => {
  142. 'location' => 'http://apt.puppetlabs.com',
  143. 'repos' => 'main',
  144. 'key' => '4BD6EC30',
  145. 'key_server' => 'pgp.mit.edu',
  146. }
  147. } } }
  148. it {
  149. should contain_file('debian_unstable.list').with({
  150. 'ensure' => 'present',
  151. 'path' => '/etc/apt/sources.list.d/debian_unstable.list',
  152. 'owner' => 'root',
  153. 'group' => 'root',
  154. 'mode' => '0644',
  155. 'notify' => 'Exec[apt_update]',
  156. })
  157. }
  158. it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
  159. it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
  160. it {
  161. should contain_file('puppetlabs.list').with({
  162. 'ensure' => 'present',
  163. 'path' => '/etc/apt/sources.list.d/puppetlabs.list',
  164. 'owner' => 'root',
  165. 'group' => 'root',
  166. 'mode' => '0644',
  167. 'notify' => 'Exec[apt_update]',
  168. })
  169. }
  170. it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
  171. it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) }
  172. end
  173. describe 'failing tests' do
  174. context 'bad purge_sources_list' do
  175. let :params do
  176. {
  177. 'purge_sources_list' => 'foo'
  178. }
  179. end
  180. it do
  181. expect {
  182. should compile
  183. }.to raise_error(Puppet::Error)
  184. end
  185. end
  186. context 'bad purge_sources_list_d' do
  187. let :params do
  188. {
  189. 'purge_sources_list_d' => 'foo'
  190. }
  191. end
  192. it do
  193. expect {
  194. should compile
  195. }.to raise_error(Puppet::Error)
  196. end
  197. end
  198. context 'bad purge_preferences' do
  199. let :params do
  200. {
  201. 'purge_preferences' => 'foo'
  202. }
  203. end
  204. it do
  205. expect {
  206. should compile
  207. }.to raise_error(Puppet::Error)
  208. end
  209. end
  210. context 'bad purge_preferences_d' do
  211. let :params do
  212. {
  213. 'purge_preferences_d' => 'foo'
  214. }
  215. end
  216. it do
  217. expect {
  218. should compile
  219. }.to raise_error(Puppet::Error)
  220. end
  221. end
  222. context 'with unsupported osfamily' do
  223. let :facts do
  224. { :osfamily => 'Darwin', }
  225. end
  226. it do
  227. expect {
  228. should compile
  229. }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)
  230. end
  231. end
  232. end
  233. end