1005
1008
describe "deprecations" do
1006
context "in puppet.conf" do
1008
def assert_puppet_conf_deprecation(setting, matches)
1009
Puppet.expects(:deprecation_warning).with(regexp_matches(matches), anything)
1011
val = "/you/can/set/this/but/will/get/warning"
1015
Puppet.settings.parse_config(text)
1018
it "warns when manifest is set" do
1019
assert_puppet_conf_deprecation('manifest', /manifest.*puppet.conf/)
1022
it "warns when modulepath is set" do
1023
assert_puppet_conf_deprecation('modulepath', /modulepath.*puppet.conf/)
1026
it "warns when config_version is set" do
1027
assert_puppet_conf_deprecation('config_version', /config_version.*puppet.conf/)
1030
it "warns when manifestdir is set" do
1031
assert_puppet_conf_deprecation('manifestdir', /Setting manifestdir.*is.*deprecated/)
1034
it "warns when templatedir is set" do
1035
assert_puppet_conf_deprecation('templatedir', /Setting templatedir.*is.*deprecated/)
1039
context "on the command line" do
1040
def assert_command_line_deprecation(setting, message)
1041
Puppet.expects(:deprecation_warning).with(message, anything)
1043
args = ["--#{setting}", "/some/value"]
1044
Puppet.settings.send(:parse_global_options, args)
1047
def assert_command_line_not_deprecated(setting)
1009
let(:settings) { Puppet::Settings.new }
1010
let(:app_defaults) {
1012
:logdir => "/dev/null",
1013
:confdir => "/dev/null",
1014
:vardir => "/dev/null",
1018
def assert_accessing_setting_is_deprecated(settings, setting)
1019
Puppet.expects(:deprecation_warning).with("Accessing '#{setting}' as a setting is deprecated. See http://links.puppetlabs.com/env-settings-deprecations")
1020
Puppet.expects(:deprecation_warning).with("Modifying '#{setting}' as a setting is deprecated. See http://links.puppetlabs.com/env-settings-deprecations")
1021
settings[setting.intern] = apath = File.expand_path('foo')
1022
expect(settings[setting.intern]).to eq(apath)
1026
settings.define_settings(:main, {
1027
:logdir => { :default => 'a', :desc => 'a' },
1028
:confdir => { :default => 'b', :desc => 'b' },
1029
:vardir => { :default => 'c', :desc => 'c' },
1033
context "complete" do
1034
let(:completely_deprecated_settings) do
1035
settings.define_settings(:main, {
1038
:desc => 'a deprecated setting',
1039
:deprecated => :completely,
1045
it "warns when set in puppet.conf" do
1046
Puppet.expects(:deprecation_warning).with(regexp_matches(/manifestdir is deprecated\./), 'setting-manifestdir')
1048
completely_deprecated_settings.parse_config(<<-CONF)
1049
manifestdir='should warn'
1051
completely_deprecated_settings.initialize_app_defaults(app_defaults)
1054
it "warns when set on the commandline" do
1055
Puppet.expects(:deprecation_warning).with(regexp_matches(/manifestdir is deprecated\./), 'setting-manifestdir')
1057
args = ["--manifestdir", "/some/value"]
1058
completely_deprecated_settings.send(:parse_global_options, args)
1059
completely_deprecated_settings.initialize_app_defaults(app_defaults)
1062
it "warns when set in code" do
1063
assert_accessing_setting_is_deprecated(completely_deprecated_settings, 'manifestdir')
1067
context "partial" do
1068
let(:partially_deprecated_settings) do
1069
settings.define_settings(:main, {
1072
:desc => 'a partially deprecated setting',
1073
:deprecated => :allowed_on_commandline,
1079
it "warns for a deprecated setting allowed on the command line set in puppet.conf" do
1080
Puppet.expects(:deprecation_warning).with(regexp_matches(/modulepath is deprecated in puppet\.conf/), 'puppet-conf-setting-modulepath')
1081
partially_deprecated_settings.parse_config(<<-CONF)
1082
modulepath='should warn'
1084
partially_deprecated_settings.initialize_app_defaults(app_defaults)
1087
it "does not warn when manifest is set on command line" do
1048
1088
Puppet.expects(:deprecation_warning).never
1050
args = ["--#{setting}", "/some/value"]
1051
Puppet.settings.send(:parse_global_options, args)
1054
it "does not warn when manifest is set on command line" do
1055
assert_command_line_not_deprecated('manifest')
1058
it "does not warn when modulepath is set on command line" do
1059
assert_command_line_not_deprecated('modulepath')
1062
it "does not warn when config_version is set on command line" do
1063
assert_command_line_not_deprecated('config_version')
1066
it "warns when manifestdir is set on command line" do
1067
assert_command_line_deprecation('manifestdir', "Setting manifestdir is deprecated. See http://links.puppetlabs.com/env-settings-deprecations")
1070
it "warns when templatedir is set on command line" do
1071
assert_command_line_deprecation('templatedir', "Setting templatedir is deprecated. See http://links.puppetlabs.com/env-settings-deprecations")
1075
context "as settings in the code base" do
1076
def assert_accessing_setting_is_deprecated(setting)
1077
Puppet.expects(:deprecation_warning).with("Accessing '#{setting}' as a setting is deprecated. See http://links.puppetlabs.com/env-settings-deprecations")
1078
Puppet.expects(:deprecation_warning).with("Modifying '#{setting}' as a setting is deprecated. See http://links.puppetlabs.com/env-settings-deprecations")
1079
Puppet[setting.intern] = apath = File.expand_path('foo')
1080
expect(Puppet[setting.intern]).to eq(apath)
1083
it "warns when attempt to access a 'manifest' setting" do
1084
assert_accessing_setting_is_deprecated('manifest')
1087
it "warns when attempt to access a 'modulepath' setting" do
1088
assert_accessing_setting_is_deprecated('modulepath')
1090
it "warns when attempt to access a 'config_version' setting" do
1091
assert_accessing_setting_is_deprecated('config_version')
1094
it "warns when attempt to access a 'manifestdir' setting" do
1095
assert_accessing_setting_is_deprecated('manifestdir')
1098
it "warns when attempt to access a 'templatedir' setting" do
1099
assert_accessing_setting_is_deprecated('templatedir')
1090
args = ["--modulepath", "/some/value"]
1091
partially_deprecated_settings.send(:parse_global_options, args)
1092
partially_deprecated_settings.initialize_app_defaults(app_defaults)
1095
it "warns when set in code" do
1096
assert_accessing_setting_is_deprecated(partially_deprecated_settings, 'modulepath')
1375
describe "adding default directory environment to the catalog" do
1376
let(:tmpenv) { tmpdir("envs") }
1377
let(:default_path) { "#{tmpenv}/environments" }
1379
@settings.define_settings :main,
1380
:environment => { :default => "production", :desc => "env"},
1381
:environmentpath => { :type => :path, :default => default_path, :desc => "envpath"}
1384
it "adds if environmentpath exists" do
1385
envpath = "#{tmpenv}/custom_envpath"
1386
@settings[:environmentpath] = envpath
1388
catalog = @settings.to_catalog
1389
expect(catalog.resource_keys).to include(["File", "#{envpath}/production"])
1392
it "adds the first directory of environmentpath" do
1393
envdir = "#{tmpenv}/custom_envpath"
1394
envpath = "#{envdir}#{File::PATH_SEPARATOR}/some/other/envdir"
1395
@settings[:environmentpath] = envpath
1397
catalog = @settings.to_catalog
1398
expect(catalog.resource_keys).to include(["File", "#{envdir}/production"])
1401
it "handles a non-existent environmentpath" do
1402
catalog = @settings.to_catalog
1403
expect(catalog.resource_keys).to be_empty
1406
it "handles a default environmentpath" do
1407
Dir.mkdir(default_path)
1408
catalog = @settings.to_catalog
1409
expect(catalog.resource_keys).to include(["File", "#{default_path}/production"])
1412
it "does not add if the path to the default directory environment exists as a symlink", :if => Puppet.features.manages_symlinks? do
1413
Dir.mkdir(default_path)
1414
Puppet::FileSystem.symlink("#{tmpenv}/nowhere", File.join(default_path, 'production'))
1415
catalog = @settings.to_catalog
1416
expect(catalog.resource_keys).to_not include(["File", "#{default_path}/production"])
1369
1420
describe "when adding users and groups to the catalog" do
1371
1422
Puppet.features.stubs(:root?).returns true
1475
1526
:maindir => { :type => :directory, :default => make_absolute("/maindir"), :desc => "a" },
1476
1527
:seconddir => { :type => :directory, :default => make_absolute("/seconddir"), :desc => "a"}
1477
1528
@settings.define_settings :main, :user => { :default => "suser", :desc => "doc" }, :group => { :default => "sgroup", :desc => "doc" }
1478
@settings.define_settings :other, :otherdir => {:type => :directory, :default => make_absolute("/otherdir"), :desc => "a", :owner => "service", :group => "service", :mode => 0755}
1529
@settings.define_settings :other, :otherdir => {:type => :directory, :default => make_absolute("/otherdir"), :desc => "a", :owner => "service", :group => "service", :mode => '0755'}
1479
1530
@settings.define_settings :third, :thirddir => { :type => :directory, :default => make_absolute("/thirddir"), :desc => "b"}
1480
@settings.define_settings :files, :myfile => {:type => :file, :default => make_absolute("/myfile"), :desc => "a", :mode => 0755}
1531
@settings.define_settings :files, :myfile => {:type => :file, :default => make_absolute("/myfile"), :desc => "a", :mode => '0755'}
1483
1534
it "should provide a method that creates directories with the correct modes" do
1484
1535
Puppet::Util::SUIDManager.expects(:asuser).with("suser", "sgroup").yields
1485
Dir.expects(:mkdir).with(make_absolute("/otherdir"), 0755)
1536
Dir.expects(:mkdir).with(make_absolute("/otherdir"), '0755')
1486
1537
@settings.mkdir(:otherdir)