ppa_spec.rb 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. require 'spec_helper'
  2. describe 'apt::ppa' do
  3. let :pre_condition do
  4. 'class { "apt": }'
  5. end
  6. describe 'defaults' do
  7. let :facts do
  8. {
  9. :lsbdistrelease => '11.04',
  10. :lsbdistcodename => 'natty',
  11. :operatingsystem => 'Ubuntu',
  12. :osfamily => 'Debian',
  13. :lsbdistid => 'Ubuntu',
  14. :puppetversion => Puppet.version,
  15. }
  16. end
  17. let(:title) { 'ppa:needs/such.substitution/wow+type' }
  18. it { is_expected.to_not contain_package('python-software-properties') }
  19. it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow+type').that_notifies('Class[Apt::Update]').with({
  20. :environment => [],
  21. :command => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow+type',
  22. :unless => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow_type-natty.list',
  23. :user => 'root',
  24. :logoutput => 'on_failure',
  25. })
  26. }
  27. end
  28. describe 'Ubuntu 15.10 sources.list filename' do
  29. let :facts do
  30. {
  31. :lsbdistrelease => '15.10',
  32. :lsbdistcodename => 'wily',
  33. :operatingsystem => 'Ubuntu',
  34. :osfamily => 'Debian',
  35. :lsbdistid => 'Ubuntu',
  36. :puppetversion => Puppet.version,
  37. }
  38. end
  39. let(:title) { 'ppa:user/foo' }
  40. it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
  41. :environment => [],
  42. :command => '/usr/bin/add-apt-repository -y ppa:user/foo',
  43. :unless => '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list',
  44. :user => 'root',
  45. :logoutput => 'on_failure',
  46. })
  47. }
  48. end
  49. describe 'ppa depending on ppa, MODULES-1156' do
  50. let :pre_condition do
  51. 'class { "apt": }'
  52. end
  53. end
  54. describe 'package_name => software-properties-common' do
  55. let :pre_condition do
  56. 'class { "apt": }'
  57. end
  58. let :params do
  59. {
  60. :package_name => 'software-properties-common',
  61. :package_manage => true,
  62. }
  63. end
  64. let :facts do
  65. {
  66. :lsbdistrelease => '11.04',
  67. :lsbdistcodename => 'natty',
  68. :operatingsystem => 'Ubuntu',
  69. :osfamily => 'Debian',
  70. :lsbdistid => 'Ubuntu',
  71. :puppetversion => Puppet.version,
  72. }
  73. end
  74. let(:title) { 'ppa:needs/such.substitution/wow' }
  75. it { is_expected.to contain_package('software-properties-common') }
  76. it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with({
  77. 'environment' => [],
  78. 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
  79. 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
  80. 'user' => 'root',
  81. 'logoutput' => 'on_failure',
  82. })
  83. }
  84. it { is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with({
  85. 'ensure' => 'file',
  86. })
  87. }
  88. end
  89. describe 'package_manage => true, multiple ppas, MODULES-2873' do
  90. let :pre_condition do
  91. 'class { "apt": }
  92. apt::ppa {"ppa:user/foo":
  93. package_manage => true
  94. }'
  95. end
  96. let :facts do
  97. {
  98. :lsbdistrelease => '11.04',
  99. :lsbdistcodename => 'natty',
  100. :operatingsystem => 'Ubuntu',
  101. :osfamily => 'Debian',
  102. :lsbdistid => 'Ubuntu',
  103. :puppetversion => Puppet.version,
  104. }
  105. end
  106. let :params do
  107. {
  108. :package_manage => true,
  109. }
  110. end
  111. let(:title) { 'ppa:user/bar' }
  112. it { is_expected.to contain_package('python-software-properties') }
  113. it { is_expected.to contain_exec('add-apt-repository-ppa:user/bar').that_notifies('Class[Apt::Update]').with({
  114. 'environment' => [],
  115. 'command' => '/usr/bin/add-apt-repository -y ppa:user/bar',
  116. 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/user-bar-natty.list',
  117. 'user' => 'root',
  118. 'logoutput' => 'on_failure',
  119. })
  120. }
  121. it { is_expected.to contain_file('/etc/apt/sources.list.d/user-bar-natty.list').that_requires('Exec[add-apt-repository-ppa:user/bar]').with({
  122. 'ensure' => 'file',
  123. })
  124. }
  125. end
  126. describe 'package_manage => false' do
  127. let :pre_condition do
  128. 'class { "apt": }'
  129. end
  130. let :facts do
  131. {
  132. :lsbdistrelease => '11.04',
  133. :lsbdistcodename => 'natty',
  134. :operatingsystem => 'Ubuntu',
  135. :osfamily => 'Debian',
  136. :lsbdistid => 'Ubuntu',
  137. :puppetversion => Puppet.version,
  138. }
  139. end
  140. let :params do
  141. {
  142. :package_manage => false,
  143. }
  144. end
  145. let(:title) { 'ppa:needs/such.substitution/wow' }
  146. it { is_expected.to_not contain_package('python-software-properties') }
  147. it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with({
  148. 'environment' => [],
  149. 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
  150. 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
  151. 'user' => 'root',
  152. 'logoutput' => 'on_failure',
  153. })
  154. }
  155. it { is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with({
  156. 'ensure' => 'file',
  157. })
  158. }
  159. end
  160. describe 'apt included, no proxy' do
  161. let :pre_condition do
  162. 'class { "apt": }
  163. apt::ppa { "ppa:user/foo2": }
  164. '
  165. end
  166. let :facts do
  167. {
  168. :lsbdistrelease => '14.04',
  169. :lsbdistcodename => 'trusty',
  170. :operatingsystem => 'Ubuntu',
  171. :lsbdistid => 'Ubuntu',
  172. :osfamily => 'Debian',
  173. :puppetversion => Puppet.version,
  174. }
  175. end
  176. let :params do
  177. {
  178. :options => '',
  179. :package_manage => true,
  180. :require => 'Apt::Ppa[ppa:user/foo2]',
  181. }
  182. end
  183. let(:title) { 'ppa:user/foo' }
  184. it { is_expected.to compile.with_all_deps }
  185. it { is_expected.to contain_package('software-properties-common') }
  186. it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
  187. :environment => [],
  188. :command => '/usr/bin/add-apt-repository ppa:user/foo',
  189. :unless => '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
  190. :user => 'root',
  191. :logoutput => 'on_failure',
  192. })
  193. }
  194. end
  195. describe 'apt included, proxy host' do
  196. let :pre_condition do
  197. 'class { "apt":
  198. proxy => { "host" => "localhost" },
  199. }'
  200. end
  201. let :facts do
  202. {
  203. :lsbdistrelease => '14.04',
  204. :lsbdistcodename => 'trusty',
  205. :operatingsystem => 'Ubuntu',
  206. :lsbdistid => 'Ubuntu',
  207. :osfamily => 'Debian',
  208. :puppetversion => Puppet.version,
  209. }
  210. end
  211. let :params do
  212. {
  213. 'options' => '',
  214. 'package_manage' => true,
  215. }
  216. end
  217. let(:title) { 'ppa:user/foo' }
  218. it { is_expected.to contain_package('software-properties-common') }
  219. it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
  220. :environment => ['http_proxy=http://localhost:8080'],
  221. :command => '/usr/bin/add-apt-repository ppa:user/foo',
  222. :unless => '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
  223. :user => 'root',
  224. :logoutput => 'on_failure',
  225. })
  226. }
  227. end
  228. describe 'apt included, proxy host and port' do
  229. let :pre_condition do
  230. 'class { "apt":
  231. proxy => { "host" => "localhost", "port" => 8180 },
  232. }'
  233. end
  234. let :facts do
  235. {
  236. :lsbdistrelease => '14.04',
  237. :lsbdistcodename => 'trusty',
  238. :operatingsystem => 'Ubuntu',
  239. :lsbdistid => 'Ubuntu',
  240. :osfamily => 'Debian',
  241. :puppetversion => Puppet.version,
  242. }
  243. end
  244. let :params do
  245. {
  246. :options => '',
  247. :package_manage => true,
  248. }
  249. end
  250. let(:title) { 'ppa:user/foo' }
  251. it { is_expected.to contain_package('software-properties-common') }
  252. it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
  253. :environment => ['http_proxy=http://localhost:8180'],
  254. :command => '/usr/bin/add-apt-repository ppa:user/foo',
  255. :unless => '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
  256. :user => 'root',
  257. :logoutput => 'on_failure',
  258. })
  259. }
  260. end
  261. describe 'apt included, proxy host and port and https' do
  262. let :pre_condition do
  263. 'class { "apt":
  264. proxy => { "host" => "localhost", "port" => 8180, "https" => true },
  265. }'
  266. end
  267. let :facts do
  268. {
  269. :lsbdistrelease => '14.04',
  270. :lsbdistcodename => 'trusty',
  271. :operatingsystem => 'Ubuntu',
  272. :lsbdistid => 'Ubuntu',
  273. :osfamily => 'Debian',
  274. :puppetversion => Puppet.version,
  275. }
  276. end
  277. let :params do
  278. {
  279. :options => '',
  280. :package_manage => true,
  281. }
  282. end
  283. let(:title) { 'ppa:user/foo' }
  284. it { is_expected.to contain_package('software-properties-common') }
  285. it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
  286. :environment => ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'],
  287. :command => '/usr/bin/add-apt-repository ppa:user/foo',
  288. :unless => '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
  289. :user => 'root',
  290. :logoutput => 'on_failure',
  291. })
  292. }
  293. end
  294. describe 'ensure absent' do
  295. let :pre_condition do
  296. 'class { "apt": }'
  297. end
  298. let :facts do
  299. {
  300. :lsbdistrelease => '14.04',
  301. :lsbdistcodename => 'trusty',
  302. :operatingsystem => 'Ubuntu',
  303. :lsbdistid => 'Ubuntu',
  304. :osfamily => 'Debian',
  305. :puppetversion => Puppet.version,
  306. }
  307. end
  308. let(:title) { 'ppa:user/foo' }
  309. let :params do
  310. {
  311. :ensure => 'absent'
  312. }
  313. end
  314. it { is_expected.to contain_file('/etc/apt/sources.list.d/user-foo-trusty.list').that_notifies('Class[Apt::Update]').with({
  315. :ensure => 'absent',
  316. })
  317. }
  318. end
  319. context 'validation' do
  320. describe 'no release' do
  321. let :facts do
  322. {
  323. :lsbdistrelease => '14.04',
  324. :operatingsystem => 'Ubuntu',
  325. :lsbdistid => 'Ubuntu',
  326. :osfamily => 'Debian',
  327. :lsbdistcodeanme => nil,
  328. :puppetversion => Puppet.version,
  329. }
  330. end
  331. let(:title) { 'ppa:user/foo' }
  332. it do
  333. expect {
  334. subject.call
  335. }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
  336. end
  337. end
  338. describe 'not ubuntu' do
  339. let :facts do
  340. {
  341. :lsbdistrelease => '6.0.7',
  342. :lsbdistcodename => 'wheezy',
  343. :operatingsystem => 'Debian',
  344. :lsbdistid => 'debian',
  345. :osfamily => 'Debian',
  346. :puppetversion => Puppet.version,
  347. }
  348. end
  349. let(:title) { 'ppa:user/foo' }
  350. it do
  351. expect {
  352. subject.call
  353. }.to raise_error(Puppet::Error, /not currently supported on Debian/)
  354. end
  355. end
  356. end
  357. end