puppet 3.0.2 → 3.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (320) hide show
  1. data/Gemfile +13 -11
  2. data/README.md +9 -7
  3. data/README_DEVELOPER.md +21 -30
  4. data/bin/extlookup2hiera +0 -0
  5. data/conf/auth.conf +42 -26
  6. data/conf/fileserver.conf +41 -0
  7. data/conf/tagmail.conf +16 -0
  8. data/examples/hiera/modules/data/manifests/common.pp +2 -1
  9. data/examples/hiera/modules/ntp/manifests/config.pp +4 -3
  10. data/examples/hiera/modules/ntp/manifests/data.pp +2 -1
  11. data/examples/hiera/modules/users/manifests/common.pp +2 -1
  12. data/examples/hiera/modules/users/manifests/dc1.pp +2 -1
  13. data/examples/hiera/modules/users/manifests/development.pp +2 -1
  14. data/examples/hiera/site.pp +1 -1
  15. data/ext/debian/fileserver.conf +39 -15
  16. data/ext/envpuppet +2 -0
  17. data/ext/gentoo/puppet/fileserver.conf +41 -12
  18. data/ext/ips/puppet-agent +1 -6
  19. data/ext/ips/puppetagent.xml +0 -4
  20. data/ext/osx/postflight.erb +109 -0
  21. data/ext/project_data.yaml +2 -2
  22. data/ext/redhat/fileserver.conf +41 -12
  23. data/ext/redhat/puppet.spec.erb +8 -13
  24. data/install.rb +2 -5
  25. data/lib/puppet.rb +30 -13
  26. data/lib/puppet/application.rb +34 -16
  27. data/lib/puppet/application/agent.rb +4 -4
  28. data/lib/puppet/application/master.rb +25 -5
  29. data/lib/puppet/defaults.rb +11 -7
  30. data/lib/puppet/dsl.rb +7 -3
  31. data/lib/puppet/dsl/actions.rb +283 -0
  32. data/lib/puppet/dsl/blank_slate.rb +55 -0
  33. data/lib/puppet/dsl/context.rb +393 -0
  34. data/lib/puppet/dsl/parser.rb +57 -0
  35. data/lib/puppet/dsl/resource_decorator.rb +56 -0
  36. data/lib/puppet/dsl/resource_reference.rb +95 -0
  37. data/lib/puppet/dsl/type_reference.rb +102 -0
  38. data/lib/puppet/error.rb +1 -1
  39. data/lib/puppet/face/help.rb +2 -4
  40. data/lib/puppet/face/man.rb +8 -2
  41. data/lib/puppet/feature/pson.rb +1 -3
  42. data/lib/puppet/indirector/catalog/active_record.rb +3 -0
  43. data/lib/puppet/indirector/catalog/compiler.rb +1 -2
  44. data/lib/puppet/indirector/catalog/queue.rb +4 -0
  45. data/lib/puppet/indirector/catalog/static_compiler.rb +30 -0
  46. data/lib/puppet/indirector/catalog/store_configs.rb +3 -0
  47. data/lib/puppet/indirector/certificate_request/rest.rb +1 -0
  48. data/lib/puppet/indirector/certificate_revocation_list/rest.rb +1 -0
  49. data/lib/puppet/indirector/certificate_status/file.rb +4 -0
  50. data/lib/puppet/indirector/certificate_status/rest.rb +1 -0
  51. data/lib/puppet/indirector/facts/active_record.rb +3 -0
  52. data/lib/puppet/indirector/facts/couch.rb +3 -0
  53. data/lib/puppet/indirector/facts/inventory_active_record.rb +4 -0
  54. data/lib/puppet/indirector/facts/store_configs.rb +3 -0
  55. data/lib/puppet/indirector/file_metadata/rest.rb +2 -0
  56. data/lib/puppet/indirector/instrumentation_data/local.rb +3 -0
  57. data/lib/puppet/indirector/instrumentation_data/rest.rb +3 -0
  58. data/lib/puppet/indirector/instrumentation_listener/local.rb +3 -0
  59. data/lib/puppet/indirector/instrumentation_listener/rest.rb +3 -0
  60. data/lib/puppet/indirector/instrumentation_probe/local.rb +3 -0
  61. data/lib/puppet/indirector/instrumentation_probe/rest.rb +3 -0
  62. data/lib/puppet/indirector/node/active_record.rb +3 -0
  63. data/lib/puppet/indirector/node/rest.rb +2 -2
  64. data/lib/puppet/indirector/node/store_configs.rb +3 -0
  65. data/lib/puppet/indirector/node/write_only_yaml.rb +32 -0
  66. data/lib/puppet/indirector/queue.rb +0 -1
  67. data/lib/puppet/indirector/request.rb +1 -2
  68. data/lib/puppet/indirector/resource/active_record.rb +4 -0
  69. data/lib/puppet/indirector/resource/ral.rb +3 -0
  70. data/lib/puppet/indirector/resource/rest.rb +3 -0
  71. data/lib/puppet/indirector/resource/store_configs.rb +3 -0
  72. data/lib/puppet/indirector/run/local.rb +3 -0
  73. data/lib/puppet/indirector/ssl_file.rb +16 -14
  74. data/lib/puppet/indirector/status/local.rb +3 -0
  75. data/lib/puppet/indirector/status/rest.rb +4 -0
  76. data/lib/puppet/interface.rb +78 -3
  77. data/lib/puppet/interface/action.rb +39 -3
  78. data/lib/puppet/interface/action_builder.rb +74 -1
  79. data/lib/puppet/interface/action_manager.rb +33 -3
  80. data/lib/puppet/interface/documentation.rb +116 -5
  81. data/lib/puppet/interface/face_collection.rb +6 -7
  82. data/lib/puppet/interface/option.rb +10 -1
  83. data/lib/puppet/interface/option_builder.rb +29 -1
  84. data/lib/puppet/interface/option_manager.rb +21 -6
  85. data/lib/puppet/metatype/manager.rb +47 -9
  86. data/lib/puppet/module_tool.rb +0 -1
  87. data/lib/puppet/network/formats.rb +0 -2
  88. data/lib/puppet/node.rb +2 -3
  89. data/lib/puppet/node/environment.rb +14 -1
  90. data/lib/puppet/parameter.rb +309 -44
  91. data/lib/puppet/parameter/package_options.rb +5 -0
  92. data/lib/puppet/parameter/path.rb +26 -3
  93. data/lib/puppet/parameter/value.rb +30 -6
  94. data/lib/puppet/parameter/value_collection.rb +82 -20
  95. data/lib/puppet/parser.rb +3 -0
  96. data/lib/puppet/parser/ast/definition.rb +2 -5
  97. data/lib/puppet/parser/ast/hostclass.rb +2 -3
  98. data/lib/puppet/parser/ast/node.rb +2 -5
  99. data/lib/puppet/parser/ast/resourceparam.rb +1 -1
  100. data/lib/puppet/parser/compiler.rb +10 -0
  101. data/lib/puppet/parser/functions.rb +111 -7
  102. data/lib/puppet/parser/functions/create_resources.rb +23 -2
  103. data/lib/puppet/parser/functions/defined.rb +1 -1
  104. data/lib/puppet/parser/functions/extlookup.rb +2 -1
  105. data/lib/puppet/parser/functions/fail.rb +1 -1
  106. data/lib/puppet/parser/functions/file.rb +1 -1
  107. data/lib/puppet/parser/functions/fqdn_rand.rb +1 -1
  108. data/lib/puppet/parser/functions/generate.rb +1 -1
  109. data/lib/puppet/parser/functions/hiera.rb +1 -1
  110. data/lib/puppet/parser/functions/hiera_array.rb +1 -1
  111. data/lib/puppet/parser/functions/hiera_hash.rb +1 -1
  112. data/lib/puppet/parser/functions/hiera_include.rb +1 -1
  113. data/lib/puppet/parser/functions/include.rb +1 -1
  114. data/lib/puppet/parser/functions/inline_template.rb +1 -1
  115. data/lib/puppet/parser/functions/md5.rb +1 -1
  116. data/lib/puppet/parser/functions/realize.rb +1 -1
  117. data/lib/puppet/parser/functions/regsubst.rb +54 -57
  118. data/lib/puppet/parser/functions/require.rb +1 -0
  119. data/lib/puppet/parser/functions/search.rb +1 -1
  120. data/lib/puppet/parser/functions/sha1.rb +1 -1
  121. data/lib/puppet/parser/functions/shellquote.rb +1 -1
  122. data/lib/puppet/parser/functions/split.rb +1 -2
  123. data/lib/puppet/parser/functions/sprintf.rb +7 -10
  124. data/lib/puppet/parser/functions/tag.rb +1 -1
  125. data/lib/puppet/parser/functions/tagged.rb +1 -1
  126. data/lib/puppet/parser/functions/template.rb +1 -1
  127. data/lib/puppet/parser/functions/versioncmp.rb +1 -5
  128. data/lib/puppet/parser/parser_support.rb +11 -27
  129. data/lib/puppet/parser/scope.rb +48 -4
  130. data/lib/puppet/parser/type_loader.rb +31 -7
  131. data/lib/puppet/property.rb +304 -70
  132. data/lib/puppet/property/ensure.rb +14 -1
  133. data/lib/puppet/property/keyvalue.rb +17 -8
  134. data/lib/puppet/property/list.rb +3 -0
  135. data/lib/puppet/property/ordered_list.rb +7 -0
  136. data/lib/puppet/provider.rb +275 -53
  137. data/lib/puppet/provider/augeas/augeas.rb +17 -3
  138. data/lib/puppet/provider/confiner.rb +30 -1
  139. data/lib/puppet/provider/group/pw.rb +2 -2
  140. data/lib/puppet/provider/package/pip.rb +0 -1
  141. data/lib/puppet/provider/package/pkgin.rb +2 -0
  142. data/lib/puppet/provider/service/bsd.rb +1 -1
  143. data/lib/puppet/provider/service/freebsd.rb +10 -6
  144. data/lib/puppet/provider/service/init.rb +1 -1
  145. data/lib/puppet/provider/service/service.rb +1 -1
  146. data/lib/puppet/provider/user/pw.rb +2 -2
  147. data/lib/puppet/provider/user/useradd.rb +2 -3
  148. data/lib/puppet/reference/configuration.rb +6 -0
  149. data/lib/puppet/reports.rb +44 -4
  150. data/lib/puppet/reports/tagmail.rb +1 -1
  151. data/lib/puppet/resource.rb +38 -25
  152. data/lib/puppet/resource/type.rb +14 -6
  153. data/lib/puppet/settings.rb +66 -142
  154. data/lib/puppet/settings/config_file.rb +99 -0
  155. data/lib/puppet/settings/file_setting.rb +92 -24
  156. data/lib/puppet/settings/value_translator.rb +15 -0
  157. data/lib/puppet/ssl/certificate_authority/interface.rb +2 -2
  158. data/lib/puppet/test/test_helper.rb +8 -3
  159. data/lib/puppet/transaction.rb +1 -2
  160. data/lib/puppet/transaction/report.rb +122 -13
  161. data/lib/puppet/type.rb +763 -150
  162. data/lib/puppet/type/augeas.rb +4 -0
  163. data/lib/puppet/type/file/ensure.rb +1 -1
  164. data/lib/puppet/type/file/group.rb +1 -1
  165. data/lib/puppet/type/file/mode.rb +2 -0
  166. data/lib/puppet/type/file/selcontext.rb +1 -0
  167. data/lib/puppet/type/group.rb +12 -0
  168. data/lib/puppet/type/mount.rb +2 -2
  169. data/lib/puppet/type/notify.rb +1 -1
  170. data/lib/puppet/type/router.rb +1 -1
  171. data/lib/puppet/type/service.rb +1 -0
  172. data/lib/puppet/type/ssh_authorized_key.rb +3 -1
  173. data/lib/puppet/type/user.rb +8 -1
  174. data/lib/puppet/util.rb +8 -0
  175. data/lib/puppet/util/autoload.rb +7 -10
  176. data/lib/puppet/util/classgen.rb +58 -33
  177. data/lib/puppet/util/command_line.rb +120 -77
  178. data/lib/puppet/util/constant_inflector.rb +2 -0
  179. data/lib/puppet/util/execution.rb +63 -33
  180. data/lib/puppet/util/filetype.rb +1 -1
  181. data/lib/puppet/util/manifest_filetype_helper.rb +22 -0
  182. data/lib/puppet/util/methodhelper.rb +19 -0
  183. data/lib/puppet/util/monkey_patches.rb +46 -0
  184. data/lib/puppet/util/plugins.rb +2 -2
  185. data/lib/puppet/util/provider_features.rb +24 -8
  186. data/lib/puppet/util/rubygems.rb +8 -1
  187. data/lib/puppet/util/zaml.rb +1 -1
  188. data/lib/puppet/version.rb +74 -3
  189. data/spec/integration/application/apply_spec.rb +1 -1
  190. data/spec/integration/defaults_spec.rb +1 -0
  191. data/spec/integration/dsl/classes_spec.rb +191 -0
  192. data/spec/integration/dsl/defaults_spec.rb +38 -0
  193. data/spec/integration/dsl/definitions_spec.rb +73 -0
  194. data/spec/integration/dsl/functions_spec.rb +95 -0
  195. data/spec/integration/dsl/nodes_spec.rb +96 -0
  196. data/spec/integration/dsl/params_spec.rb +146 -0
  197. data/spec/integration/dsl/relationships_spec.rb +46 -0
  198. data/spec/integration/dsl/resources_spec.rb +202 -0
  199. data/spec/integration/dsl/type_loading_spec.rb +64 -0
  200. data/spec/integration/indirector/catalog/queue_spec.rb +1 -1
  201. data/spec/integration/network/formats_spec.rb +32 -45
  202. data/spec/integration/parser/collector_spec.rb +105 -25
  203. data/spec/integration/parser/scope_spec.rb +64 -1
  204. data/spec/integration/resource/catalog_spec.rb +2 -4
  205. data/spec/integration/type/package_spec.rb +1 -1
  206. data/spec/lib/matchers/catalog.rb +50 -0
  207. data/spec/lib/puppet_spec/compiler.rb +11 -0
  208. data/spec/lib/puppet_spec/dsl.rb +29 -0
  209. data/spec/spec_helper.rb +17 -3
  210. data/spec/unit/application/agent_spec.rb +0 -1
  211. data/spec/unit/application/apply_spec.rb +1 -1
  212. data/spec/unit/application/face_base_spec.rb +11 -4
  213. data/spec/unit/application/indirection_base_spec.rb +4 -8
  214. data/spec/unit/application/kick_spec.rb +5 -2
  215. data/spec/unit/application/master_spec.rb +0 -6
  216. data/spec/unit/application_spec.rb +38 -14
  217. data/spec/unit/dsl/actions_spec.rb +402 -0
  218. data/spec/unit/dsl/blank_slate_spec.rb +27 -0
  219. data/spec/unit/dsl/context_spec.rb +678 -0
  220. data/spec/unit/dsl/parser_spec.rb +56 -0
  221. data/spec/unit/dsl/resource_decorator_spec.rb +94 -0
  222. data/spec/unit/dsl/resource_reference_spec.rb +150 -0
  223. data/spec/unit/dsl/type_reference_spec.rb +164 -0
  224. data/spec/unit/face/help_spec.rb +5 -7
  225. data/spec/unit/indirector/certificate_request/rest_spec.rb +4 -0
  226. data/spec/unit/indirector/certificate_revocation_list/rest_spec.rb +4 -0
  227. data/spec/unit/indirector/certificate_status/rest_spec.rb +4 -0
  228. data/spec/unit/indirector/file_metadata/rest_spec.rb +5 -0
  229. data/spec/unit/indirector/hiera_spec.rb +3 -1
  230. data/spec/unit/indirector/queue_spec.rb +1 -7
  231. data/spec/unit/indirector/ssl_file_spec.rb +66 -39
  232. data/spec/unit/module_spec.rb +1 -1
  233. data/spec/unit/network/authstore_spec.rb +22 -1
  234. data/spec/unit/network/formats_spec.rb +1 -1
  235. data/spec/unit/node/environment_spec.rb +13 -0
  236. data/spec/unit/parser/collector_spec.rb +1 -1
  237. data/spec/unit/parser/compiler_spec.rb +26 -0
  238. data/spec/unit/parser/functions/create_resources_spec.rb +12 -1
  239. data/spec/unit/parser/functions/extlookup_spec.rb +4 -4
  240. data/spec/unit/parser/functions/hiera_array_spec.rb +1 -1
  241. data/spec/unit/parser/functions/hiera_hash_spec.rb +1 -1
  242. data/spec/unit/parser/functions/hiera_include_spec.rb +1 -1
  243. data/spec/unit/parser/functions/hiera_spec.rb +1 -1
  244. data/spec/unit/parser/functions/regsubst_spec.rb +4 -4
  245. data/spec/unit/parser/functions/split_spec.rb +4 -4
  246. data/spec/unit/parser/functions/sprintf_spec.rb +2 -2
  247. data/spec/unit/parser/functions/versioncmp_spec.rb +4 -4
  248. data/spec/unit/parser/functions_spec.rb +51 -1
  249. data/spec/unit/parser/parser_spec.rb +0 -14
  250. data/spec/unit/parser/type_loader_spec.rb +15 -1
  251. data/spec/unit/provider/augeas/augeas_spec.rb +31 -0
  252. data/spec/unit/provider/package/apt_spec.rb +0 -2
  253. data/spec/unit/provider/package/pip_spec.rb +12 -2
  254. data/spec/unit/provider/service/freebsd_spec.rb +8 -0
  255. data/spec/unit/provider/service/gentoo_spec.rb +20 -20
  256. data/spec/unit/provider/service/openrc_spec.rb +20 -20
  257. data/spec/unit/provider/service/src_spec.rb +4 -4
  258. data/spec/unit/provider/service/systemd_spec.rb +0 -8
  259. data/spec/unit/provider/service/windows_spec.rb +1 -1
  260. data/spec/unit/provider/user/useradd_spec.rb +2 -9
  261. data/spec/unit/relationship_spec.rb +2 -2
  262. data/spec/unit/resource/catalog_spec.rb +2 -2
  263. data/spec/unit/resource/type_spec.rb +49 -25
  264. data/spec/unit/resource_spec.rb +34 -2
  265. data/spec/unit/settings/config_file_spec.rb +100 -0
  266. data/spec/unit/settings/file_setting_spec.rb +87 -84
  267. data/spec/unit/settings/value_translator_spec.rb +77 -0
  268. data/spec/unit/settings_spec.rb +96 -29
  269. data/spec/unit/type/file/ensure_spec.rb +75 -36
  270. data/spec/unit/type/file_spec.rb +0 -68
  271. data/spec/unit/type/group_spec.rb +10 -0
  272. data/spec/unit/util/autoload_spec.rb +6 -0
  273. data/spec/unit/util/command_line_spec.rb +54 -62
  274. data/spec/unit/util/manifest_filetype_helper_spec.rb +29 -0
  275. data/spec/unit/util/metric_spec.rb +0 -9
  276. data/spec/unit/util/posix_spec.rb +0 -4
  277. data/spec/unit/util/rdoc_spec.rb +0 -12
  278. data/spec/unit/util/zaml_spec.rb +188 -130
  279. data/spec/unit/version_spec.rb +42 -0
  280. metadata +123 -90
  281. data/README_HIERA.md +0 -148
  282. data/conf/epm.list +0 -8
  283. data/conf/namespaceauth.conf +0 -20
  284. data/conf/puppet-queue.conf +0 -10
  285. data/examples/allatonce +0 -13
  286. data/examples/assignments +0 -11
  287. data/examples/components +0 -73
  288. data/examples/etc/init.d/sleeper +0 -70
  289. data/examples/etc/otherfile +0 -0
  290. data/examples/etc/puppet/fileserver.conf +0 -13
  291. data/examples/etc/puppet/namespaceauth.conf +0 -20
  292. data/examples/etc/puppet/puppet.conf +0 -10
  293. data/examples/etc/puppet/tagmail.conf +0 -1
  294. data/examples/execs +0 -16
  295. data/examples/file.bl +0 -11
  296. data/examples/filedefaults +0 -10
  297. data/examples/fileparsing +0 -116
  298. data/examples/filerecursion +0 -15
  299. data/examples/functions +0 -3
  300. data/examples/groups +0 -7
  301. data/examples/head +0 -30
  302. data/examples/importing +0 -8
  303. data/examples/mac_dscl.pp +0 -28
  304. data/examples/mac_dscl_revert.pp +0 -26
  305. data/examples/mac_pkgdmg.pp +0 -7
  306. data/examples/modules/sample_module.pp +0 -10
  307. data/examples/modules/sample_module/lib/puppet/parser/functions/hostname_to_dn.rb +0 -36
  308. data/examples/modules/sample_module/manifests/init.pp +0 -12
  309. data/examples/modules/sample_module/templates/sample.erb +0 -5
  310. data/examples/nodes +0 -20
  311. data/examples/one +0 -8
  312. data/examples/relationships +0 -34
  313. data/examples/selectors +0 -28
  314. data/examples/simpletests +0 -11
  315. data/examples/svncommit +0 -13
  316. data/lib/puppet/dsl/resource_api.rb +0 -120
  317. data/lib/puppet/dsl/resource_type_api.rb +0 -34
  318. data/spec/integration/parser/ruby_manifest_spec.rb +0 -127
  319. data/spec/unit/dsl/resource_api_spec.rb +0 -180
  320. data/spec/unit/dsl/resource_type_api_spec.rb +0 -53
@@ -0,0 +1,77 @@
1
+ #! /usr/bin/env ruby -S rspec
2
+ require 'spec_helper'
3
+ require 'puppet/settings/value_translator'
4
+
5
+ describe Puppet::Settings::ValueTranslator do
6
+ let(:translator) { Puppet::Settings::ValueTranslator.new }
7
+
8
+ context "booleans" do
9
+ it "translates strings representing booleans to booleans" do
10
+ translator['true'].should == true
11
+ translator['false'].should == false
12
+ end
13
+
14
+ it "translates boolean values into themselves" do
15
+ translator[true].should == true
16
+ translator[false].should == false
17
+ end
18
+
19
+ it "leaves a boolean string with whitespace as a string" do
20
+ translator[' true'].should == " true"
21
+ translator['true '].should == "true"
22
+
23
+ translator[' false'].should == " false"
24
+ translator['false '].should == "false"
25
+ end
26
+ end
27
+
28
+ context "numbers" do
29
+ it "translates integer strings to integers" do
30
+ translator["1"].should == 1
31
+ translator["2"].should == 2
32
+ end
33
+
34
+ it "translates numbers starting with a 0 as octal" do
35
+ translator["011"].should == 9
36
+ end
37
+
38
+ it "leaves hex numbers as strings" do
39
+ translator["0x11"].should == "0x11"
40
+ end
41
+ end
42
+
43
+ context "arbitrary strings" do
44
+ it "translates an empty string as the empty string" do
45
+ translator[""].should == ""
46
+ end
47
+
48
+
49
+ it "strips double quotes" do
50
+ translator['"a string"'].should == 'a string'
51
+ end
52
+
53
+ it "strips single quotes" do
54
+ translator["'a string'"].should == "a string"
55
+ end
56
+
57
+ it "does not strip preceeding whitespace" do
58
+ translator[" \ta string"].should == " \ta string"
59
+ end
60
+
61
+ it "strips trailing whitespace" do
62
+ translator["a string\t "].should == "a string"
63
+ end
64
+
65
+ it "leaves leading quote that is preceeded by whitespace" do
66
+ translator[" 'a string'"].should == " 'a string"
67
+ end
68
+
69
+ it "leaves trailing quote that is succeeded by whitespace" do
70
+ translator["'a string' "].should == "a string'"
71
+ end
72
+
73
+ it "leaves quotes that are not at the beginning or end of the string" do
74
+ translator["a st'\"ring"].should == "a st'\"ring"
75
+ end
76
+ end
77
+ end
@@ -85,14 +85,6 @@ describe Puppet::Settings do
85
85
  @settings.define_settings(:main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS)
86
86
  end
87
87
 
88
- it "should fail if someone attempts to initialize app defaults more than once" do
89
- @settings.initialize_app_defaults(default_values)
90
-
91
- expect {
92
- @settings.initialize_app_defaults(default_values)
93
- }.to raise_error(Puppet::DevError)
94
- end
95
-
96
88
  it "should fail if the app defaults hash is missing any required values" do
97
89
  incomplete_default_values = default_values.reject { |key, _| key == :confdir }
98
90
  expect {
@@ -676,6 +668,7 @@ describe Puppet::Settings do
676
668
  before do
677
669
  @settings = Puppet::Settings.new
678
670
  @settings.stubs(:service_user_available?).returns true
671
+ @settings.stubs(:service_group_available?).returns true
679
672
  @file = make_absolute("/some/file")
680
673
  @userconfig = make_absolute("/test/userconfigfile")
681
674
  @settings.define_settings :section, :user => { :default => "suser", :desc => "doc" }, :group => { :default => "sgroup", :desc => "doc" }
@@ -785,6 +778,33 @@ describe Puppet::Settings do
785
778
  @settings.metadata(:myfile).should == {:owner => "suser"}
786
779
  end
787
780
 
781
+ it "should support loading metadata (owner, group, or mode) from a run_mode section in the configuration file" do
782
+ default_values = {}
783
+ PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS.keys.each do |key|
784
+ default_values[key] = 'default value'
785
+ end
786
+ @settings.define_settings :main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS
787
+ @settings.define_settings :master, :myfile => { :type => :file, :default => make_absolute("/myfile"), :desc => "a" }
788
+
789
+ otherfile = make_absolute("/other/file")
790
+ text = "[master]
791
+ myfile = #{otherfile} {mode = 664}
792
+ "
793
+ @settings.expects(:read_file).returns(text)
794
+
795
+ # will start initialization as user
796
+ @settings.preferred_run_mode.should == :user
797
+ @settings.send(:parse_config_files)
798
+
799
+ # change app run_mode to master
800
+ @settings.initialize_app_defaults(default_values.merge(:run_mode => :master))
801
+ @settings.preferred_run_mode.should == :master
802
+
803
+ # initializing the app should have reloaded the metadata based on run_mode
804
+ @settings[:myfile].should == otherfile
805
+ @settings.metadata(:myfile).should == {:mode => "664"}
806
+ end
807
+
788
808
  it "should call hooks associated with values set in the configuration file" do
789
809
  values = []
790
810
  @settings.define_settings :section, :mysetting => {:default => "defval", :desc => "a", :hook => proc { |v| values << v }}
@@ -1245,6 +1265,7 @@ describe Puppet::Settings do
1245
1265
  before do
1246
1266
  @settings = Puppet::Settings.new
1247
1267
  @settings.stubs(:service_user_available?).returns true
1268
+ @settings.stubs(:service_group_available?).returns true
1248
1269
  @settings.define_settings :main, :noop => { :default => false, :desc => "", :type => :boolean }
1249
1270
  @settings.define_settings :main,
1250
1271
  :maindir => { :type => :directory, :default => make_absolute("/maindir"), :desc => "a" },
@@ -1282,12 +1303,6 @@ describe Puppet::Settings do
1282
1303
  @settings.use(:main, :other)
1283
1304
  end
1284
1305
 
1285
- it "should ignore tags and schedules when creating files and directories"
1286
-
1287
- it "should be able to provide all of its parameters in a format compatible with GetOpt::Long" do
1288
- pending "Not converted from test/unit yet"
1289
- end
1290
-
1291
1306
  it "should convert the created catalog to a RAL catalog" do
1292
1307
  @catalog = Puppet::Resource::Catalog.new("foo")
1293
1308
  @settings.expects(:to_catalog).with(:main).returns @catalog
@@ -1403,8 +1418,6 @@ describe Puppet::Settings do
1403
1418
  @settings.print_configs
1404
1419
  end
1405
1420
 
1406
- it "should print a whole bunch of stuff if :configprint = all"
1407
-
1408
1421
  it "should return true after printing" do
1409
1422
  @settings.stubs(:value).with(:configprint).returns("something")
1410
1423
  @settings.stubs(:include?).with("something").returns(true)
@@ -1460,35 +1473,89 @@ describe Puppet::Settings do
1460
1473
  end
1461
1474
 
1462
1475
  describe "when determining if the service user is available" do
1476
+ let(:settings) do
1477
+ settings = Puppet::Settings.new
1478
+ settings.define_settings :main, :user => { :default => nil, :desc => "doc" }
1479
+ settings
1480
+ end
1481
+
1482
+ def a_user_type_for(username)
1483
+ user = mock 'user'
1484
+ Puppet::Type.type(:user).expects(:new).with { |args| args[:name] == username }.returns user
1485
+ user
1486
+ end
1487
+
1463
1488
  it "should return false if there is no user setting" do
1464
- Puppet::Settings.new.should_not be_service_user_available
1489
+ settings.should_not be_service_user_available
1465
1490
  end
1466
1491
 
1467
1492
  it "should return false if the user provider says the user is missing" do
1468
- settings = Puppet::Settings.new
1469
- settings.define_settings :main, :user => { :default => "foo", :desc => "doc" }
1470
-
1471
- user = mock 'user'
1472
- user.expects(:exists?).returns false
1493
+ settings[:user] = "foo"
1473
1494
 
1474
- Puppet::Type.type(:user).expects(:new).with { |args| args[:name] == "foo" }.returns user
1495
+ a_user_type_for("foo").expects(:exists?).returns false
1475
1496
 
1476
1497
  settings.should_not be_service_user_available
1477
1498
  end
1478
1499
 
1479
1500
  it "should return true if the user provider says the user is present" do
1480
- settings = Puppet::Settings.new
1481
- settings.define_settings :main, :user => { :default => "foo", :desc => "doc" }
1501
+ settings[:user] = "foo"
1482
1502
 
1483
- user = mock 'user'
1484
- user.expects(:exists?).returns true
1503
+ a_user_type_for("foo").expects(:exists?).returns true
1485
1504
 
1486
- Puppet::Type.type(:user).expects(:new).with { |args| args[:name] == "foo" }.returns user
1505
+ settings.should be_service_user_available
1506
+ end
1507
+
1508
+ it "caches the result of determining if the user is present" do
1509
+ settings[:user] = "foo"
1510
+
1511
+ a_user_type_for("foo").expects(:exists?).returns true
1512
+ settings.should be_service_user_available
1487
1513
 
1488
1514
  settings.should be_service_user_available
1489
1515
  end
1516
+ end
1517
+
1518
+ describe "when determining if the service group is available" do
1519
+ let(:settings) do
1520
+ settings = Puppet::Settings.new
1521
+ settings.define_settings :main, :group => { :default => nil, :desc => "doc" }
1522
+ settings
1523
+ end
1490
1524
 
1491
- it "should cache the result"
1525
+ def a_group_type_for(groupname)
1526
+ group = mock 'group'
1527
+ Puppet::Type.type(:group).expects(:new).with { |args| args[:name] == groupname }.returns group
1528
+ group
1529
+ end
1530
+
1531
+ it "should return false if there is no group setting" do
1532
+ settings.should_not be_service_group_available
1533
+ end
1534
+
1535
+ it "should return false if the group provider says the group is missing" do
1536
+ settings[:group] = "foo"
1537
+
1538
+ a_group_type_for("foo").expects(:exists?).returns false
1539
+
1540
+ settings.should_not be_service_group_available
1541
+ end
1542
+
1543
+ it "should return true if the group provider says the group is present" do
1544
+ settings[:group] = "foo"
1545
+
1546
+ a_group_type_for("foo").expects(:exists?).returns true
1547
+
1548
+ settings.should be_service_group_available
1549
+ end
1550
+
1551
+ it "caches the result of determining if the group is present" do
1552
+ settings[:group] = "foo"
1553
+
1554
+ a_group_type_for("foo").expects(:exists?).returns true
1555
+ settings.should be_service_group_available
1556
+
1557
+ settings.should be_service_group_available
1558
+ end
1492
1559
  end
1493
1560
 
1494
1561
  describe "#writesub" do
@@ -1,84 +1,123 @@
1
1
  #! /usr/bin/env ruby
2
2
  require 'spec_helper'
3
+ require 'puppet/type/file/ensure'
3
4
 
4
- property = Puppet::Type.type(:file).attrclass(:ensure)
5
+ describe Puppet::Type::File::Ensure do
6
+ include PuppetSpec::Files
5
7
 
6
- describe property do
7
- before do
8
- # Wow that's a messy interface to the resource.
9
- @resource = stub 'resource', :[] => nil, :[]= => nil, :property => nil, :newattr => nil, :parameter => nil, :replace? => true
10
- @resource.stubs(:[]).returns "foo"
11
- @resource.stubs(:[]).with(:path).returns "/my/file"
12
- @ensure = property.new :resource => @resource
13
- end
8
+ let(:path) { tmpfile('file_ensure') }
9
+ let(:resource) { Puppet::Type.type(:file).new(:ensure => 'file', :path => path, :replace => true) }
10
+ let(:property) { resource.property(:ensure) }
14
11
 
15
12
  it "should be a subclass of Ensure" do
16
- property.superclass.must == Puppet::Property::Ensure
13
+ described_class.superclass.must == Puppet::Property::Ensure
17
14
  end
18
15
 
19
16
  describe "when retrieving the current state" do
20
17
  it "should return :absent if the file does not exist" do
21
- @ensure = property.new(:resource => @resource)
22
- @resource.expects(:stat).returns nil
18
+ resource.expects(:stat).returns nil
23
19
 
24
- @ensure.retrieve.should == :absent
20
+ property.retrieve.should == :absent
25
21
  end
26
22
 
27
23
  it "should return the current file type if the file exists" do
28
- @ensure = property.new(:resource => @resource)
29
24
  stat = mock 'stat', :ftype => "directory"
30
- @resource.expects(:stat).returns stat
25
+ resource.expects(:stat).returns stat
31
26
 
32
- @ensure.retrieve.should == :directory
27
+ property.retrieve.should == :directory
33
28
  end
34
29
  end
35
30
 
36
31
  describe "when testing whether :ensure is in sync" do
37
- before do
38
- @ensure = property.new(:resource => @resource)
39
- @stat = stub 'stat', :ftype => "file"
40
- end
41
-
42
32
  it "should always be in sync if replace is 'false' unless the file is missing" do
43
- @ensure.should = :file
44
- @resource.expects(:replace?).returns false
45
- @ensure.safe_insync?(:link).should be_true
33
+ property.should = :file
34
+ resource.expects(:replace?).returns false
35
+ property.safe_insync?(:link).should be_true
46
36
  end
47
37
 
48
38
  it "should be in sync if :ensure is set to :absent and the file does not exist" do
49
- @ensure.should = :absent
39
+ property.should = :absent
50
40
 
51
- @ensure.must be_safe_insync(:absent)
41
+ property.must be_safe_insync(:absent)
52
42
  end
53
43
 
54
44
  it "should not be in sync if :ensure is set to :absent and the file exists" do
55
- @ensure.should = :absent
45
+ property.should = :absent
56
46
 
57
- @ensure.should_not be_safe_insync(:file)
47
+ property.should_not be_safe_insync(:file)
58
48
  end
59
49
 
60
50
  it "should be in sync if a normal file exists and :ensure is set to :present" do
61
- @ensure.should = :present
51
+ property.should = :present
62
52
 
63
- @ensure.must be_safe_insync(:file)
53
+ property.must be_safe_insync(:file)
64
54
  end
65
55
 
66
56
  it "should be in sync if a directory exists and :ensure is set to :present" do
67
- @ensure.should = :present
57
+ property.should = :present
68
58
 
69
- @ensure.must be_safe_insync(:directory)
59
+ property.must be_safe_insync(:directory)
70
60
  end
71
61
 
72
62
  it "should be in sync if a symlink exists and :ensure is set to :present" do
73
- @ensure.should = :present
63
+ property.should = :present
74
64
 
75
- @ensure.must be_safe_insync(:link)
65
+ property.must be_safe_insync(:link)
76
66
  end
77
67
 
78
68
  it "should not be in sync if :ensure is set to :file and a directory exists" do
79
- @ensure.should = :file
69
+ property.should = :file
70
+
71
+ property.should_not be_safe_insync(:directory)
72
+ end
73
+ end
74
+
75
+ describe "#sync" do
76
+ context "directory" do
77
+ before :each do
78
+ resource[:ensure] = :directory
79
+ end
80
+
81
+ it "should raise if the parent directory doesn't exist" do
82
+ newpath = File.join(path, 'nonexistentparent', 'newdir')
83
+ resource[:path] = newpath
84
+
85
+ expect {
86
+ property.sync
87
+ }.to raise_error(Puppet::Error, /Cannot create #{newpath}; parent directory #{File.dirname(newpath)} does not exist/)
88
+ end
89
+
90
+ it "should accept octal mode as fixnum" do
91
+ resource[:mode] = 0700
92
+ resource.expects(:property_fix)
93
+ Dir.expects(:mkdir).with(path, 0700)
94
+
95
+ property.sync
96
+ end
97
+
98
+ it "should accept octal mode as string" do
99
+ resource[:mode] = "700"
100
+ resource.expects(:property_fix)
101
+ Dir.expects(:mkdir).with(path, 0700)
102
+
103
+ property.sync
104
+ end
105
+
106
+ it "should accept octal mode as string with leading zero" do
107
+ resource[:mode] = "0700"
108
+ resource.expects(:property_fix)
109
+ Dir.expects(:mkdir).with(path, 0700)
110
+
111
+ property.sync
112
+ end
113
+
114
+ it "should accept symbolic mode" do
115
+ resource[:mode] = "u=rwx,go=x"
116
+ resource.expects(:property_fix)
117
+ Dir.expects(:mkdir).with(path, 0711)
80
118
 
81
- @ensure.should_not be_safe_insync(:directory)
119
+ property.sync
120
+ end
82
121
  end
83
122
  end
84
123
  end
@@ -194,32 +194,6 @@ describe Puppet::Type.type(:file) do
194
194
  end
195
195
  end
196
196
 
197
- describe "#asuser" do
198
- before :each do
199
- # Mocha won't let me just stub SUIDManager.asuser to yield and return,
200
- # but it will do exactly that if we're not root.
201
- Puppet.features.stubs(:root?).returns false
202
- end
203
-
204
- it "should return the desired owner if they can write to the parent directory" do
205
- file[:owner] = 1001
206
- FileTest.stubs(:writable?).with(File.dirname file[:path]).returns true
207
-
208
- file.asuser.should == 1001
209
- end
210
-
211
- it "should return nil if the desired owner can't write to the parent directory" do
212
- file[:owner] = 1001
213
- FileTest.stubs(:writable?).with(File.dirname file[:path]).returns false
214
-
215
- file.asuser.should == nil
216
- end
217
-
218
- it "should return nil if not managing owner" do
219
- file.asuser.should == nil
220
- end
221
- end
222
-
223
197
  describe "#bucket" do
224
198
  it "should return nil if backup is off" do
225
199
  file[:backup] = false
@@ -288,48 +262,6 @@ describe Puppet::Type.type(:file) do
288
262
  end
289
263
  end
290
264
 
291
- describe "#bucket" do
292
- it "should return nil if backup is off" do
293
- file[:backup] = false
294
- file.bucket.should == nil
295
- end
296
-
297
- it "should return nil if using a file extension for backup" do
298
- file[:backup] = '.backup'
299
-
300
- file.bucket.should == nil
301
- end
302
-
303
- it "should return the default filebucket if using the 'puppet' filebucket" do
304
- file[:backup] = 'puppet'
305
- bucket = stub('bucket')
306
- file.stubs(:default_bucket).returns bucket
307
-
308
- file.bucket.should == bucket
309
- end
310
-
311
- it "should fail if using a remote filebucket and no catalog exists" do
312
- file.catalog = nil
313
- file[:backup] = 'my_bucket'
314
-
315
- expect { file.bucket }.to raise_error(Puppet::Error, "Can not find filebucket for backups without a catalog")
316
- end
317
-
318
- it "should fail if the specified filebucket isn't in the catalog" do
319
- file[:backup] = 'my_bucket'
320
-
321
- expect { file.bucket }.to raise_error(Puppet::Error, "Could not find filebucket my_bucket specified in backup")
322
- end
323
-
324
- it "should use the specified filebucket if it is in the catalog" do
325
- file[:backup] = 'my_bucket'
326
- filebucket = Puppet::Type.type(:filebucket).new(:name => 'my_bucket')
327
- catalog.add_resource(filebucket)
328
-
329
- file.bucket.should == filebucket.bucket
330
- end
331
- end
332
-
333
265
  describe "#exist?" do
334
266
  it "should be considered existent if it can be stat'ed" do
335
267
  file.expects(:stat).returns mock('stat')