database_ini_spec.rb 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. require 'spec_helper'
  2. describe 'puppetdb::server::database', :type => :class do
  3. context 'on a supported platform' do
  4. let(:facts) do
  5. {
  6. :osfamily => 'RedHat',
  7. :operatingsystem => 'RedHat',
  8. :operatingsystemrelease => '7.0',
  9. :fqdn => 'test.domain.local',
  10. }
  11. end
  12. it { should contain_class('puppetdb::server::database') }
  13. describe 'when using default values' do
  14. it { should contain_file('/etc/puppetlabs/puppetdb/conf.d/database.ini').
  15. with(
  16. 'ensure' => 'file',
  17. 'owner' => 'puppetdb',
  18. 'group' => 'puppetdb',
  19. 'mode' => '0600'
  20. )}
  21. it { should contain_ini_setting('puppetdb_psdatabase_username').
  22. with(
  23. 'ensure' => 'present',
  24. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  25. 'section' => 'database',
  26. 'setting' => 'username',
  27. 'value' => 'puppetdb'
  28. )}
  29. it { should contain_ini_setting('puppetdb_psdatabase_password').
  30. with(
  31. 'ensure' => 'present',
  32. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  33. 'section' => 'database',
  34. 'setting' => 'password',
  35. 'value' => 'puppetdb'
  36. )}
  37. it { should contain_ini_setting('puppetdb_classname').
  38. with(
  39. 'ensure' => 'present',
  40. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  41. 'section' => 'database',
  42. 'setting' => 'classname',
  43. 'value' => 'org.postgresql.Driver'
  44. )}
  45. it { should contain_ini_setting('puppetdb_subprotocol').
  46. with(
  47. 'ensure' => 'present',
  48. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  49. 'section' => 'database',
  50. 'setting' => 'subprotocol',
  51. 'value' => 'postgresql'
  52. )}
  53. it { should contain_ini_setting('puppetdb_subname').
  54. with(
  55. 'ensure' => 'present',
  56. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  57. 'section' => 'database',
  58. 'setting' => 'subname',
  59. 'value' => '//localhost:5432/puppetdb'
  60. )}
  61. it { should contain_ini_setting('puppetdb_gc_interval').
  62. with(
  63. 'ensure' => 'present',
  64. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  65. 'section' => 'database',
  66. 'setting' => 'gc-interval',
  67. 'value' => '60'
  68. )}
  69. it { should contain_ini_setting('puppetdb_node_ttl').
  70. with(
  71. 'ensure' => 'present',
  72. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  73. 'section' => 'database',
  74. 'setting' => 'node-ttl',
  75. 'value' => '0s'
  76. )}
  77. it { should contain_ini_setting('puppetdb_node_purge_ttl').
  78. with(
  79. 'ensure' => 'present',
  80. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  81. 'section' => 'database',
  82. 'setting' => 'node-purge-ttl',
  83. 'value' => '0s'
  84. )}
  85. it { should contain_ini_setting('puppetdb_report_ttl').
  86. with(
  87. 'ensure' => 'present',
  88. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  89. 'section' => 'database',
  90. 'setting' => 'report-ttl',
  91. 'value' => '14d'
  92. )}
  93. it { should contain_ini_setting('puppetdb_log_slow_statements').
  94. with(
  95. 'ensure' => 'present',
  96. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  97. 'section' => 'database',
  98. 'setting' => 'log-slow-statements',
  99. 'value' => 10
  100. )}
  101. it { should contain_ini_setting('puppetdb_conn_max_age').
  102. with(
  103. 'ensure' => 'present',
  104. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  105. 'section' => 'database',
  106. 'setting' => 'conn-max-age',
  107. 'value' => '60'
  108. )}
  109. it { should contain_ini_setting('puppetdb_conn_keep_alive').
  110. with(
  111. 'ensure' => 'present',
  112. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  113. 'section' => 'database',
  114. 'setting' => 'conn-keep-alive',
  115. 'value' => '45'
  116. )}
  117. it { should contain_ini_setting('puppetdb_conn_lifetime').
  118. with(
  119. 'ensure' => 'present',
  120. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  121. 'section' => 'database',
  122. 'setting' => 'conn-lifetime',
  123. 'value' => '0'
  124. )}
  125. it { should_not contain_ini_setting('puppetdb_database_max_pool_size') }
  126. end
  127. describe 'when using a legacy PuppetDB version' do
  128. let (:pre_condition) { 'class { "puppetdb::globals": version => "2.2.0", }' }
  129. it { should contain_ini_setting('puppetdb_psdatabase_username').
  130. with(
  131. 'ensure' => 'present',
  132. 'path' => '/etc/puppetdb/conf.d/database.ini',
  133. 'section' => 'database',
  134. 'setting' => 'username',
  135. 'value' => 'puppetdb'
  136. )}
  137. it { should contain_ini_setting('puppetdb_psdatabase_password').
  138. with(
  139. 'ensure' => 'present',
  140. 'path' => '/etc/puppetdb/conf.d/database.ini',
  141. 'section' => 'database',
  142. 'setting' => 'password',
  143. 'value' => 'puppetdb'
  144. )}
  145. it { should contain_ini_setting('puppetdb_classname').
  146. with(
  147. 'ensure' => 'present',
  148. 'path' => '/etc/puppetdb/conf.d/database.ini',
  149. 'section' => 'database',
  150. 'setting' => 'classname',
  151. 'value' => 'org.postgresql.Driver'
  152. )}
  153. it { should contain_ini_setting('puppetdb_subprotocol').
  154. with(
  155. 'ensure' => 'present',
  156. 'path' => '/etc/puppetdb/conf.d/database.ini',
  157. 'section' => 'database',
  158. 'setting' => 'subprotocol',
  159. 'value' => 'postgresql'
  160. )}
  161. it { should contain_ini_setting('puppetdb_subname').
  162. with(
  163. 'ensure' => 'present',
  164. 'path' => '/etc/puppetdb/conf.d/database.ini',
  165. 'section' => 'database',
  166. 'setting' => 'subname',
  167. 'value' => '//localhost:5432/puppetdb'
  168. )}
  169. it { should contain_ini_setting('puppetdb_gc_interval').
  170. with(
  171. 'ensure' => 'present',
  172. 'path' => '/etc/puppetdb/conf.d/database.ini',
  173. 'section' => 'database',
  174. 'setting' => 'gc-interval',
  175. 'value' => '60'
  176. )}
  177. it { should contain_ini_setting('puppetdb_node_ttl').
  178. with(
  179. 'ensure' => 'present',
  180. 'path' => '/etc/puppetdb/conf.d/database.ini',
  181. 'section' => 'database',
  182. 'setting' => 'node-ttl',
  183. 'value' => '0s'
  184. )}
  185. it { should contain_ini_setting('puppetdb_node_purge_ttl').
  186. with(
  187. 'ensure' => 'present',
  188. 'path' => '/etc/puppetdb/conf.d/database.ini',
  189. 'section' => 'database',
  190. 'setting' => 'node-purge-ttl',
  191. 'value' => '0s'
  192. )}
  193. it { should contain_ini_setting('puppetdb_report_ttl').
  194. with(
  195. 'ensure' => 'present',
  196. 'path' => '/etc/puppetdb/conf.d/database.ini',
  197. 'section' => 'database',
  198. 'setting' => 'report-ttl',
  199. 'value' => '14d'
  200. )}
  201. it { should contain_ini_setting('puppetdb_log_slow_statements').
  202. with(
  203. 'ensure' => 'present',
  204. 'path' => '/etc/puppetdb/conf.d/database.ini',
  205. 'section' => 'database',
  206. 'setting' => 'log-slow-statements',
  207. 'value' => 10
  208. )}
  209. it { should contain_ini_setting('puppetdb_conn_max_age').
  210. with(
  211. 'ensure' => 'present',
  212. 'path' => '/etc/puppetdb/conf.d/database.ini',
  213. 'section' => 'database',
  214. 'setting' => 'conn-max-age',
  215. 'value' => '60'
  216. )}
  217. it { should contain_ini_setting('puppetdb_conn_keep_alive').
  218. with(
  219. 'ensure' => 'present',
  220. 'path' => '/etc/puppetdb/conf.d/database.ini',
  221. 'section' => 'database',
  222. 'setting' => 'conn-keep-alive',
  223. 'value' => '45'
  224. )}
  225. it { should contain_ini_setting('puppetdb_conn_lifetime').
  226. with(
  227. 'ensure' => 'present',
  228. 'path' => '/etc/puppetdb/conf.d/database.ini',
  229. 'section' => 'database',
  230. 'setting' => 'conn-lifetime',
  231. 'value' => '0'
  232. )}
  233. it { should_not contain_ini_setting('puppetdb_database_max_pool_size') }
  234. end
  235. describe 'when overriding database_path for embedded' do
  236. let(:params) do
  237. {
  238. 'database' => 'embedded',
  239. 'database_embedded_path' => '/tmp/foo',
  240. }
  241. end
  242. it { should contain_ini_setting('puppetdb_subname').
  243. with(
  244. 'ensure' => 'present',
  245. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  246. 'section' => 'database',
  247. 'setting' => 'subname',
  248. 'value' => 'file:/tmp/foo;hsqldb.tx=mvcc;sql.syntax_pgs=true'
  249. )}
  250. end
  251. describe 'when setting max pool size' do
  252. context 'on current PuppetDB' do
  253. describe 'to a numeric value' do
  254. let(:params) do
  255. {
  256. 'database_max_pool_size' => 12345
  257. }
  258. end
  259. it { should contain_ini_setting('puppetdb_database_max_pool_size').
  260. with(
  261. 'ensure' => 'present',
  262. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  263. 'section' => 'database',
  264. 'setting' => 'maximum-pool-size',
  265. 'value' => '12345'
  266. )}
  267. end
  268. describe 'to absent' do
  269. let(:params) do
  270. {
  271. 'database_max_pool_size' => 'absent'
  272. }
  273. end
  274. it { should contain_ini_setting('puppetdb_database_max_pool_size').
  275. with(
  276. 'ensure' => 'absent',
  277. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  278. 'section' => 'database',
  279. 'setting' => 'maximum-pool-size'
  280. )}
  281. end
  282. end
  283. context 'on PuppetDB 3.2' do
  284. let (:pre_condition) { 'class { "puppetdb::globals": version => "3.2.0", }' }
  285. describe 'to a numeric value' do
  286. let(:params) do
  287. {
  288. 'database_max_pool_size' => 12345
  289. }
  290. end
  291. it { should contain_ini_setting('puppetdb_database_max_pool_size').
  292. with(
  293. 'ensure' => 'present',
  294. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  295. 'section' => 'database',
  296. 'setting' => 'partition-conn-max',
  297. 'value' => '12345'
  298. )}
  299. end
  300. describe 'to absent' do
  301. let(:params) do
  302. {
  303. 'database_max_pool_size' => 'absent'
  304. }
  305. end
  306. it { should contain_ini_setting('puppetdb_database_max_pool_size').
  307. with(
  308. 'ensure' => 'absent',
  309. 'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
  310. 'section' => 'database',
  311. 'setting' => 'partition-conn-max'
  312. )}
  313. end
  314. end
  315. context 'on a legacy PuppetDB version' do
  316. let (:pre_condition) { 'class { "puppetdb::globals": version => "2.2.0", }' }
  317. describe 'to a numeric value' do
  318. let(:params) do
  319. {
  320. 'database_max_pool_size' => 12345
  321. }
  322. end
  323. it { should_not contain_ini_setting('puppetdb_database_max_pool_size') }
  324. end
  325. describe 'to absent' do
  326. let(:params) do
  327. {
  328. 'database_max_pool_size' => 'absent'
  329. }
  330. end
  331. it { should_not contain_ini_setting('puppetdb_database_max_pool_size') }
  332. end
  333. end
  334. end
  335. end
  336. end