puppet 4.1.0 → 4.2.0

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 (117) hide show
  1. data/ext/osx/puppet.plist +32 -0
  2. data/ext/redhat/client.init +3 -6
  3. data/ext/redhat/client.sysconfig +1 -10
  4. data/ext/suse/client.init +3 -6
  5. data/ext/systemd/puppet.service +2 -1
  6. data/lib/puppet.rb +1 -1
  7. data/lib/puppet/agent.rb +4 -19
  8. data/lib/puppet/application/apply.rb +22 -6
  9. data/lib/puppet/configurer.rb +3 -2
  10. data/lib/puppet/configurer/plugin_handler.rb +6 -2
  11. data/lib/puppet/face/plugin.rb +7 -14
  12. data/lib/puppet/forge/repository.rb +1 -2
  13. data/lib/puppet/indirector/catalog/compiler.rb +4 -3
  14. data/lib/puppet/indirector/facts/facter.rb +8 -0
  15. data/lib/puppet/module.rb +17 -12
  16. data/lib/puppet/network/http/factory.rb +8 -4
  17. data/lib/puppet/node/environment.rb +11 -7
  18. data/lib/puppet/parser/ast/pops_bridge.rb +5 -0
  19. data/lib/puppet/parser/functions/fqdn_rand.rb +2 -2
  20. data/lib/puppet/parser/scope.rb +39 -13
  21. data/lib/puppet/pops.rb +1 -0
  22. data/lib/puppet/pops/evaluator/runtime3_converter.rb +1 -1
  23. data/lib/puppet/pops/evaluator/runtime3_support.rb +31 -0
  24. data/lib/puppet/pops/parser/epp_support.rb +4 -2
  25. data/lib/puppet/property/ensure.rb +1 -1
  26. data/lib/puppet/provider.rb +5 -0
  27. data/lib/puppet/provider/augeas/augeas.rb +5 -0
  28. data/lib/puppet/provider/group/pw.rb +1 -0
  29. data/lib/puppet/provider/group/windows_adsi.rb +9 -0
  30. data/lib/puppet/provider/mount/parsed.rb +15 -1
  31. data/lib/puppet/provider/package.rb +6 -2
  32. data/lib/puppet/provider/package/gem.rb +16 -0
  33. data/lib/puppet/provider/package/openbsd.rb +7 -7
  34. data/lib/puppet/provider/package/pacman.rb +9 -8
  35. data/lib/puppet/provider/package/pip.rb +1 -1
  36. data/lib/puppet/provider/package/pip3.rb +18 -0
  37. data/lib/puppet/provider/package/pkgdmg.rb +4 -2
  38. data/lib/puppet/provider/package/pkgin.rb +3 -3
  39. data/lib/puppet/provider/package/rpm.rb +8 -14
  40. data/lib/puppet/provider/package/yum.rb +5 -4
  41. data/lib/puppet/provider/service/base.rb +3 -2
  42. data/lib/puppet/provider/service/bsd.rb +7 -7
  43. data/lib/puppet/provider/service/debian.rb +2 -1
  44. data/lib/puppet/provider/service/freebsd.rb +1 -1
  45. data/lib/puppet/provider/service/systemd.rb +75 -6
  46. data/lib/puppet/provider/service/upstart.rb +1 -1
  47. data/lib/puppet/provider/user/pw.rb +1 -0
  48. data/lib/puppet/resource/catalog.rb +1 -1
  49. data/lib/puppet/resource/status.rb +9 -0
  50. data/lib/puppet/resource/type.rb +4 -2
  51. data/lib/puppet/settings.rb +43 -16
  52. data/lib/puppet/transaction.rb +27 -13
  53. data/lib/puppet/type/augeas.rb +1 -0
  54. data/lib/puppet/type/exec.rb +11 -2
  55. data/lib/puppet/type/group.rb +9 -1
  56. data/lib/puppet/type/mount.rb +2 -0
  57. data/lib/puppet/type/package.rb +13 -2
  58. data/lib/puppet/type/service.rb +9 -0
  59. data/lib/puppet/util.rb +8 -3
  60. data/lib/puppet/util/execution.rb +2 -2
  61. data/lib/puppet/util/http_proxy.rb +60 -0
  62. data/lib/puppet/util/log.rb +1 -1
  63. data/lib/puppet/util/splayer.rb +18 -0
  64. data/lib/puppet/version.rb +1 -1
  65. data/spec/fixtures/unit/provider/package/yum/yum-check-update-obsoletes.txt +195 -0
  66. data/spec/integration/application/apply_spec.rb +72 -30
  67. data/spec/integration/indirector/facts/facter_spec.rb +38 -0
  68. data/spec/integration/parser/scope_spec.rb +20 -2
  69. data/spec/integration/provider/mount_spec.rb +23 -36
  70. data/spec/integration/transaction_spec.rb +40 -1
  71. data/spec/integration/type/file_spec.rb +36 -0
  72. data/spec/integration/type/package_spec.rb +65 -0
  73. data/spec/lib/matchers/include_in_order.rb +0 -1
  74. data/spec/lib/puppet_spec/files.rb +14 -0
  75. data/spec/unit/agent_spec.rb +0 -38
  76. data/spec/unit/application/apply_spec.rb +13 -0
  77. data/spec/unit/configurer/plugin_handler_spec.rb +42 -13
  78. data/spec/unit/configurer_spec.rb +5 -0
  79. data/spec/unit/face/plugin_spec.rb +33 -4
  80. data/spec/unit/file_serving/configuration/parser_spec.rb +25 -30
  81. data/spec/unit/indirector/catalog/compiler_spec.rb +16 -0
  82. data/spec/unit/indirector/facts/facter_spec.rb +2 -1
  83. data/spec/unit/module_spec.rb +0 -23
  84. data/spec/unit/network/http/factory_spec.rb +14 -0
  85. data/spec/unit/parser/functions/fqdn_rand_spec.rb +6 -2
  86. data/spec/unit/parser/functions/generate_spec.rb +3 -12
  87. data/spec/unit/parser/scope_spec.rb +9 -0
  88. data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +19 -0
  89. data/spec/unit/pops/evaluator/variables_spec.rb +1 -1
  90. data/spec/unit/pops/parser/lexer2_spec.rb +35 -3
  91. data/spec/unit/provider/augeas/augeas_spec.rb +9 -0
  92. data/spec/unit/provider/group/windows_adsi_spec.rb +5 -0
  93. data/spec/unit/provider/package/aptrpm_spec.rb +2 -2
  94. data/spec/unit/provider/package/base_spec.rb +18 -0
  95. data/spec/unit/provider/package/gem_spec.rb +70 -0
  96. data/spec/unit/provider/package/pacman_spec.rb +55 -0
  97. data/spec/unit/provider/package/pip3_spec.rb +257 -0
  98. data/spec/unit/provider/package/pip_spec.rb +1 -1
  99. data/spec/unit/provider/package/pkgdmg_spec.rb +18 -0
  100. data/spec/unit/provider/package/pkgin_spec.rb +23 -13
  101. data/spec/unit/provider/package/yum_spec.rb +11 -0
  102. data/spec/unit/provider/service/bsd_spec.rb +130 -0
  103. data/spec/unit/provider/service/debian_spec.rb +12 -1
  104. data/spec/unit/provider/service/freebsd_spec.rb +16 -0
  105. data/spec/unit/provider/service/systemd_spec.rb +84 -7
  106. data/spec/unit/provider/service/upstart_spec.rb +1 -0
  107. data/spec/unit/provider/zone/solaris_spec.rb +45 -12
  108. data/spec/unit/puppet_spec.rb +1 -1
  109. data/spec/unit/resource/catalog_spec.rb +5 -0
  110. data/spec/unit/type/mount_spec.rb +8 -0
  111. data/spec/unit/type/service_spec.rb +5 -0
  112. data/spec/unit/util/http_proxy_spec.rb +87 -0
  113. data/spec/unit/util/log_spec.rb +12 -1
  114. data/spec/unit/util/splayer_spec.rb +45 -0
  115. metadata +3057 -3035
  116. checksums.yaml +0 -7
  117. data/ext/systemd/puppetmaster.service +0 -11
@@ -258,7 +258,7 @@ describe provider_class do
258
258
  @provider.expects(:pip).with('freeze').raises(NoMethodError)
259
259
  @provider.expects(:which).with(pip_cmd).returns(nil)
260
260
  expect { @provider.method(:lazy_pip).call("freeze") }.
261
- to raise_error(NoMethodError, 'Could not locate the pip command.')
261
+ to raise_error(NoMethodError, "Could not locate the #{pip_cmd} command.")
262
262
  end
263
263
 
264
264
  end
@@ -77,6 +77,7 @@ describe Puppet::Type.type(:package).provider(:pkgdmg) do
77
77
  end
78
78
 
79
79
  it "should use an http proxy host and port if specified" do
80
+ Puppet::Util::HttpProxy.expects(:no_proxy?).returns false
80
81
  Puppet::Util::HttpProxy.expects(:http_proxy_host).returns 'some_host'
81
82
  Puppet::Util::HttpProxy.expects(:http_proxy_port).returns 'some_port'
82
83
  Dir.expects(:mktmpdir).returns tmpdir
@@ -92,6 +93,7 @@ describe Puppet::Type.type(:package).provider(:pkgdmg) do
92
93
  end
93
94
 
94
95
  it "should use an http proxy host only if specified" do
96
+ Puppet::Util::HttpProxy.expects(:no_proxy?).returns false
95
97
  Puppet::Util::HttpProxy.expects(:http_proxy_host).returns 'some_host'
96
98
  Puppet::Util::HttpProxy.expects(:http_proxy_port).returns nil
97
99
  Dir.expects(:mktmpdir).returns tmpdir
@@ -106,6 +108,22 @@ describe Puppet::Type.type(:package).provider(:pkgdmg) do
106
108
  provider.install
107
109
  end
108
110
 
111
+ it "should not use the configured proxy if no_proxy contains a match for the destination" do
112
+ Puppet::Util::HttpProxy.expects(:no_proxy?).returns true
113
+ Puppet::Util::HttpProxy.expects(:http_proxy_host).never
114
+ Puppet::Util::HttpProxy.expects(:http_proxy_port).never
115
+ Dir.expects(:mktmpdir).returns tmpdir
116
+ Dir.stubs(:entries).returns ["foo.pkg"]
117
+ described_class.expects(:curl).with do |*args|
118
+ expect(args).not_to be_include 'some_host:some_port'
119
+ expect(args).not_to be_include '--proxy'
120
+ true
121
+ end
122
+ described_class.stubs(:hdiutil).returns fake_hdiutil_plist
123
+ described_class.expects(:installpkg)
124
+
125
+ provider.install
126
+ end
109
127
  end
110
128
  end
111
129
 
@@ -41,7 +41,7 @@ describe provider_class do
41
41
 
42
42
  describe "#instances" do
43
43
  let(:pkgin_ls_output) do
44
- "zlib-1.2.3 General purpose data compression library\nzziplib-0.13.59 Library for ZIP archive handling\n"
44
+ "zlib-1.2.3;General purpose data compression library\nzziplib-0.13.59;Library for ZIP archive handling\n"
45
45
  end
46
46
 
47
47
  before do
@@ -72,7 +72,7 @@ describe provider_class do
72
72
 
73
73
  context "when the package is installed" do
74
74
  let(:pkgin_search_output) do
75
- "vim-7.2.446 = Vim editor (vi clone) without GUI\nvim-share-7.2.446 = Data files for the vim editor (vi clone)\n\n=: package is installed and up-to-date\n<: package is installed but newer version is available\n>: installed package has a greater version than available package\n"
75
+ "vim-7.2.446;=;Vim editor (vi clone) without GUI\nvim-share-7.2.446;=;Data files for the vim editor (vi clone)\n\n=: package is installed and up-to-date\n<: package is installed but newer version is available\n>: installed package has a greater version than available package\n"
76
76
  end
77
77
 
78
78
  it "returns installed version" do
@@ -83,7 +83,7 @@ describe provider_class do
83
83
 
84
84
  context "when the package is out of date" do
85
85
  let(:pkgin_search_output) do
86
- "vim-7.2.447 < Vim editor (vi clone) without GUI\nvim-share-7.2.447 < Data files for the vim editor (vi clone)\n\n=: package is installed and up-to-date\n<: package is installed but newer version is available\n>: installed package has a greater version than available package\n"
86
+ "vim-7.2.447;<;Vim editor (vi clone) without GUI\nvim-share-7.2.447;<;Data files for the vim editor (vi clone)\n\n=: package is installed and up-to-date\n<: package is installed but newer version is available\n>: installed package has a greater version than available package\n"
87
87
  end
88
88
 
89
89
  it "returns the version to be installed" do
@@ -93,7 +93,7 @@ describe provider_class do
93
93
 
94
94
  context "when the package is ahead of date" do
95
95
  let(:pkgin_search_output) do
96
- "vim-7.2.446 > Vim editor (vi clone) without GUI\nvim-share-7.2.446 > Data files for the vim editor (vi clone)\n\n=: package is installed and up-to-date\n<: package is installed but newer version is available\n>: installed package has a greater version than available package\n"
96
+ "vim-7.2.446;>;Vim editor (vi clone) without GUI\nvim-share-7.2.446;>;Data files for the vim editor (vi clone)\n\n=: package is installed and up-to-date\n<: package is installed but newer version is available\n>: installed package has a greater version than available package\n"
97
97
  end
98
98
 
99
99
  it "returns current version" do
@@ -105,12 +105,12 @@ describe provider_class do
105
105
  context "when multiple candidates do exists" do
106
106
  let(:pkgin_search_output) do
107
107
  <<-SEARCH
108
- vim-7.1 > Vim editor (vi clone) without GUI
109
- vim-share-7.1 > Data files for the vim editor (vi clone)
110
- vim-7.2.446 = Vim editor (vi clone) without GUI
111
- vim-share-7.2.446 = Data files for the vim editor (vi clone)
112
- vim-7.3 < Vim editor (vi clone) without GUI
113
- vim-share-7.3 < Data files for the vim editor (vi clone)
108
+ vim-7.1;>;Vim editor (vi clone) without GUI
109
+ vim-share-7.1;>;Data files for the vim editor (vi clone)
110
+ vim-7.2.446;=;Vim editor (vi clone) without GUI
111
+ vim-share-7.2.446;=;Data files for the vim editor (vi clone)
112
+ vim-7.3;<;Vim editor (vi clone) without GUI
113
+ vim-share-7.3;<;Data files for the vim editor (vi clone)
114
114
 
115
115
  =: package is installed and up-to-date
116
116
  <: package is installed but newer version is available
@@ -137,7 +137,7 @@ SEARCH
137
137
 
138
138
  describe "#parse_pkgin_line" do
139
139
  context "with an installed package" do
140
- let(:package) { "vim-7.2.446 = Vim editor (vi clone) without GUI" }
140
+ let(:package) { "vim-7.2.446;=;Vim editor (vi clone) without GUI" }
141
141
 
142
142
  it "extracts the name and status" do
143
143
  expect(provider_class.parse_pkgin_line(package)).to eq({ :name => "vim" ,
@@ -147,7 +147,7 @@ SEARCH
147
147
  end
148
148
 
149
149
  context "with an installed package with a hyphen in the name" do
150
- let(:package) { "ruby18-puppet-0.25.5nb1 > Configuration management framework written in Ruby" }
150
+ let(:package) { "ruby18-puppet-0.25.5nb1;>;Configuration management framework written in Ruby" }
151
151
 
152
152
  it "extracts the name and status" do
153
153
  expect(provider_class.parse_pkgin_line(package)).to eq({ :name => "ruby18-puppet",
@@ -156,8 +156,18 @@ SEARCH
156
156
  end
157
157
  end
158
158
 
159
+ context "with an installed package with a hyphen in the name and package description" do
160
+ let(:package) { "ruby200-facter-2.4.3nb1;=;Cross-platform Ruby library for retrieving facts from OS" }
161
+
162
+ it "extracts the name and status" do
163
+ expect(provider_class.parse_pkgin_line(package)).to eq({ :name => "ruby200-facter",
164
+ :status => "=" ,
165
+ :ensure => "2.4.3nb1" })
166
+ end
167
+ end
168
+
159
169
  context "with a package not yet installed" do
160
- let(:package) { "vim-7.2.446 Vim editor (vi clone) without GUI" }
170
+ let(:package) { "vim-7.2.446;Vim editor (vi clone) without GUI" }
161
171
 
162
172
  it "extracts the name and status" do
163
173
  expect(provider_class.parse_pkgin_line(package)).to eq({ :name => "vim" ,
@@ -471,6 +471,17 @@ describe provider_class do
471
471
  expect(output['libpcap']).to eq([{:name => 'libpcap', :epoch => '14', :version => '1.4.0', :release => '1.20130826git2dbcaa1.el6', :arch => 'x86_64'}])
472
472
  end
473
473
  end
474
+
475
+ describe "with obsoleted packages" do
476
+ let(:check_update) { File.read(my_fixture('yum-check-update-obsoletes.txt')) }
477
+ let(:output) { described_class.parse_updates(check_update) }
478
+
479
+ it "ignores all entries including and after 'Obsoleting Packages'" do
480
+ expect(output).not_to include("Obsoleting")
481
+ expect(output).not_to include("NetworkManager-bluetooth.x86_64")
482
+ expect(output).not_to include("1:1.0.0-14.git20150121.b4ea599c.el7")
483
+ end
484
+ end
474
485
  end
475
486
 
476
487
  describe "parsing a line from yum check-update" do
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'spec_helper'
4
+
5
+ provider_class = Puppet::Type.type(:service).provider(:bsd)
6
+
7
+ describe provider_class, :unless => Puppet.features.microsoft_windows? do
8
+ before :each do
9
+ Puppet::Type.type(:service).stubs(:defaultprovider).returns described_class
10
+ Facter.stubs(:value).with(:operatingsystem).returns :netbsd
11
+ Facter.stubs(:value).with(:osfamily).returns 'NetBSD'
12
+ described_class.stubs(:defpath).returns('/etc/rc.conf.d')
13
+ @provider = provider_class.new
14
+ @provider.stubs(:initscript)
15
+ end
16
+
17
+ describe "#instances" do
18
+ it "should have an instances method" do
19
+ expect(described_class).to respond_to :instances
20
+ end
21
+
22
+ it "should use defpath" do
23
+ expect(described_class.instances).to be_all { |provider| provider.get(:path) == described_class.defpath }
24
+ end
25
+ end
26
+
27
+ describe "#disable" do
28
+ it "should have a disable method" do
29
+ expect(@provider).to respond_to(:disable)
30
+ end
31
+
32
+ it "should remove a service file to disable" do
33
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
34
+ Puppet::FileSystem.stubs(:exist?).with('/etc/rc.conf.d/sshd').returns(true)
35
+ Puppet::FileSystem.expects(:exist?).with('/etc/rc.conf.d/sshd').returns(true)
36
+ File.stubs(:delete).with('/etc/rc.conf.d/sshd')
37
+ provider.disable
38
+ end
39
+
40
+ it "should not remove a service file if it doesn't exist" do
41
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
42
+ File.stubs(:exist?).with('/etc/rc.conf.d/sshd').returns(false)
43
+ Puppet::FileSystem.expects(:exist?).with('/etc/rc.conf.d/sshd').returns(false)
44
+ provider.disable
45
+ end
46
+ end
47
+
48
+ describe "#enable" do
49
+ it "should have an enable method" do
50
+ expect(@provider).to respond_to(:enable)
51
+ end
52
+
53
+ it "should set the proper contents to enable" do
54
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
55
+ Dir.stubs(:mkdir).with('/etc/rc.conf.d')
56
+ fh = stub 'fh'
57
+ File.stubs(:open).with('/etc/rc.conf.d/sshd', File::WRONLY | File::APPEND | File::CREAT, 0644).yields(fh)
58
+ fh.expects(:<<).with("sshd_enable=\"YES\"\n")
59
+ provider.enable
60
+ end
61
+
62
+ it "should set the proper contents to enable when disabled" do
63
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
64
+ Dir.stubs(:mkdir).with('/etc/rc.conf.d')
65
+ File.stubs(:read).with('/etc/rc.conf.d/sshd').returns("sshd_enable=\"NO\"\n")
66
+ fh = stub 'fh'
67
+ File.stubs(:open).with('/etc/rc.conf.d/sshd', File::WRONLY | File::APPEND | File::CREAT, 0644).yields(fh)
68
+ fh.expects(:<<).with("sshd_enable=\"YES\"\n")
69
+ provider.enable
70
+ end
71
+ end
72
+
73
+ describe "#enabled?" do
74
+ it "should have an enabled? method" do
75
+ expect(@provider).to respond_to(:enabled?)
76
+ end
77
+
78
+ it "should return false if the service file does not exist" do
79
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
80
+ Puppet::FileSystem.stubs(:exist?).with('/etc/rc.conf.d/sshd').returns(false)
81
+ # File.stubs(:read).with('/etc/rc.conf.d/sshd').returns("sshd_enable=\"NO\"\n")
82
+ expect(provider.enabled?).to eq(:false)
83
+ end
84
+
85
+ it "should return true if the service file exists" do
86
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
87
+ Puppet::FileSystem.stubs(:exist?).with('/etc/rc.conf.d/sshd').returns(true)
88
+ # File.stubs(:read).with('/etc/rc.conf.d/sshd').returns("sshd_enable=\"YES\"\n")
89
+ expect(provider.enabled?).to eq(:true)
90
+ end
91
+ end
92
+
93
+ describe "#startcmd" do
94
+ it "should have a startcmd method" do
95
+ expect(@provider).to respond_to(:startcmd)
96
+ end
97
+
98
+ it "should use the supplied start command if specified" do
99
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :start => '/bin/foo'))
100
+ provider.expects(:execute).with(['/bin/foo'], :failonfail => true, :override_locale => false, :squelch => false, :combine => true)
101
+ provider.start
102
+ end
103
+
104
+ it "should start the serviced directly otherwise" do
105
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
106
+ provider.expects(:execute).with(['/etc/rc.d/sshd', :onestart], :failonfail => true, :override_locale => false, :squelch => false, :combine => true)
107
+ provider.expects(:search).with('sshd').returns('/etc/rc.d/sshd')
108
+ provider.start
109
+ end
110
+ end
111
+
112
+ describe "#stopcmd" do
113
+ it "should have a stopcmd method" do
114
+ expect(@provider).to respond_to(:stopcmd)
115
+ end
116
+
117
+ it "should use the supplied stop command if specified" do
118
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd', :stop => '/bin/foo'))
119
+ provider.expects(:execute).with(['/bin/foo'], :failonfail => true, :override_locale => false, :squelch => false, :combine => true)
120
+ provider.stop
121
+ end
122
+
123
+ it "should stop the serviced directly otherwise" do
124
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
125
+ provider.expects(:execute).with(['/etc/rc.d/sshd', :onestop], :failonfail => true, :override_locale => false, :squelch => false, :combine => true)
126
+ provider.expects(:search).with('sshd').returns('/etc/rc.d/sshd')
127
+ provider.stop
128
+ end
129
+ end
130
+ end
@@ -35,7 +35,10 @@ describe provider_class do
35
35
  operatingsystem = [ 'Debian', 'CumulusLinux' ]
36
36
  operatingsystem.each do |os|
37
37
  it "should be the default provider on #{os}" do
38
- Facter.expects(:value).with(:operatingsystem).returns(os)
38
+ Facter.expects(:value).with(:operatingsystem).at_least_once.returns(os)
39
+ if os == 'Debian'
40
+ Facter.expects(:value).with(:operatingsystemmajrelease).returns('7')
41
+ end
39
42
  expect(provider_class.default?).to be_truthy
40
43
  end
41
44
  end
@@ -119,6 +122,14 @@ describe provider_class do
119
122
  it_should_behave_like "manually queries service status", 105
120
123
  end
121
124
 
125
+ context "when invoke-rc.d exits with 101 status" do
126
+ it_should_behave_like "manually queries service status", 101
127
+ end
128
+
129
+ context "when invoke-rc.d exits with 105 status" do
130
+ it_should_behave_like "manually queries service status", 105
131
+ end
132
+
122
133
  # pick a range of non-[104.106] numbers, strings and booleans to test with.
123
134
  [-100, -1, 0, 1, 100, "foo", "", :true, :false].each do |exitstatus|
124
135
  it "should return false when invoke-rc.d exits with #{exitstatus} status" do
@@ -44,6 +44,22 @@ OUTPUT
44
44
  expect(@provider.rcvar).to eq(['# ntpd', 'ntpd=YES'])
45
45
  end
46
46
 
47
+ it 'should parse service names with a description' do
48
+ @provider.stubs(:execute).returns <<OUTPUT
49
+ # local_unbound : local caching forwarding resolver
50
+ local_unbound_enable="YES"
51
+ OUTPUT
52
+ expect(@provider.service_name).to eq('local_unbound')
53
+ end
54
+
55
+ it 'should parse service names without a description' do
56
+ @provider.stubs(:execute).returns <<OUTPUT
57
+ # local_unbound
58
+ local_unbound="YES"
59
+ OUTPUT
60
+ expect(@provider.service_name).to eq('local_unbound')
61
+ end
62
+
47
63
  it "should find the right rcvar_value for FreeBSD < 7" do
48
64
  @provider.stubs(:rcvar).returns(['# ntpd', 'ntpd_enable=YES'])
49
65
 
@@ -35,7 +35,7 @@ describe Puppet::Type.type(:service).provider(:systemd) do
35
35
  # In Ruby 1.8.7, the order of hash elements differs from 1.9+ and
36
36
  # caused short-circuiting of the logic used by default.all? in the
37
37
  # provider. As a workaround we need to use stubs() instead of
38
- # expects() here.
38
+ # expects() here.
39
39
  Facter.expects(:value).with(:osfamily).at_least_once.returns(:redhat)
40
40
  Facter.stubs(:value).with(:operatingsystem).returns(:redhat)
41
41
  Facter.stubs(:value).with(:operatingsystemmajrelease).returns("#{ver}")
@@ -51,7 +51,7 @@ describe Puppet::Type.type(:service).provider(:systemd) do
51
51
  expect(described_class.default?).to be_truthy
52
52
  end
53
53
  end
54
-
54
+
55
55
  it "should be the default provider on sles12" do
56
56
  Facter.expects(:value).with(:osfamily).at_least_once.returns(:suse)
57
57
  Facter.expects(:value).with(:operatingsystemmajrelease).at_least_once.returns("12")
@@ -66,10 +66,40 @@ describe Puppet::Type.type(:service).provider(:systemd) do
66
66
 
67
67
  it "should not be the default provider on sles11" do
68
68
  Facter.expects(:value).with(:osfamily).at_least_once.returns(:suse)
69
+ Facter.expects(:value).with(:operatingsystem).at_least_once.returns(:suse)
69
70
  Facter.expects(:value).with(:operatingsystemmajrelease).at_least_once.returns("11")
70
71
  expect(described_class.default?).not_to be_truthy
71
72
  end
72
73
 
74
+ it "should not be the default provider on debian7" do
75
+ Facter.expects(:value).with(:osfamily).at_least_once.returns(:debian)
76
+ Facter.expects(:value).with(:operatingsystem).at_least_once.returns(:debian)
77
+ Facter.expects(:value).with(:operatingsystemmajrelease).at_least_once.returns("7")
78
+ expect(described_class.default?).not_to be_truthy
79
+ end
80
+
81
+ it "should be the default provider on debian8" do
82
+ Facter.expects(:value).with(:osfamily).at_least_once.returns(:debian)
83
+ Facter.expects(:value).with(:operatingsystem).at_least_once.returns(:debian)
84
+ Facter.expects(:value).with(:operatingsystemmajrelease).at_least_once.returns("8")
85
+ expect(described_class.default?).to be_truthy
86
+ end
87
+
88
+ it "should not be the default provider on ubuntu14.04" do
89
+ Facter.expects(:value).with(:osfamily).at_least_once.returns(:debian)
90
+ Facter.expects(:value).with(:operatingsystem).at_least_once.returns(:ubuntu)
91
+ Facter.expects(:value).with(:operatingsystemmajrelease).at_least_once.returns("14.04")
92
+ expect(described_class.default?).not_to be_truthy
93
+ end
94
+
95
+ it "should be the default provider on ubuntu15.04" do
96
+ Facter.expects(:value).with(:osfamily).at_least_once.returns(:debian)
97
+ Facter.expects(:value).with(:operatingsystem).at_least_once.returns(:ubuntu)
98
+ Facter.expects(:value).with(:operatingsystemmajrelease).at_least_once.returns("15.04")
99
+ expect(described_class.default?).to be_truthy
100
+ end
101
+
102
+
73
103
  [:enabled?, :enable, :disable, :start, :stop, :status, :restart].each do |method|
74
104
  it "should have a #{method} method" do
75
105
  expect(provider).to respond_to(method)
@@ -124,20 +154,57 @@ describe Puppet::Type.type(:service).provider(:systemd) do
124
154
  describe "#enabled?" do
125
155
  it "should return :true if the service is enabled" do
126
156
  provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service'))
127
- provider.expects(:systemctl).with('is-enabled', 'sshd.service').returns 'enabled'
157
+ provider.expects(:systemctl).with(
158
+ 'show',
159
+ 'sshd.service',
160
+ '--property', 'LoadState',
161
+ '--property', 'UnitFileState',
162
+ '--no-pager'
163
+ ).returns "LoadState=loaded\nUnitFileState=enabled\n"
128
164
  expect(provider.enabled?).to eq(:true)
129
165
  end
130
166
 
131
167
  it "should return :false if the service is disabled" do
132
168
  provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service'))
133
- provider.expects(:systemctl).with('is-enabled', 'sshd.service').raises Puppet::ExecutionFailure, "Execution of '/bin/systemctl is-enabled sshd.service' returned 1: disabled"
169
+ provider.expects(:systemctl).with(
170
+ 'show',
171
+ 'sshd.service',
172
+ '--property', 'LoadState',
173
+ '--property', 'UnitFileState',
174
+ '--no-pager'
175
+ ).returns "LoadState=loaded\nUnitFileState=disabled\n"
134
176
  expect(provider.enabled?).to eq(:false)
135
177
  end
178
+
179
+ it "should return :false if the service is masked and the resource is attempting to be disabled" do
180
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service', :enable => false))
181
+ provider.expects(:systemctl).with(
182
+ 'show',
183
+ 'sshd.service',
184
+ '--property', 'LoadState',
185
+ '--property', 'UnitFileState',
186
+ '--no-pager'
187
+ ).returns "LoadState=masked\nUnitFileState=\n"
188
+ expect(provider.enabled?).to eq(:false)
189
+ end
190
+
191
+ it "should return :mask if the service is masked and the resource is attempting to be masked" do
192
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service', :enable => 'mask'))
193
+ provider.expects(:systemctl).with(
194
+ 'show',
195
+ 'sshd.service',
196
+ '--property', 'LoadState',
197
+ '--property', 'UnitFileState',
198
+ '--no-pager'
199
+ ).returns "LoadState=masked\nUnitFileState=\n"
200
+ expect(provider.enabled?).to eq(:mask)
201
+ end
136
202
  end
137
203
 
138
204
  describe "#enable" do
139
205
  it "should run systemctl enable to enable a service" do
140
206
  provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service'))
207
+ provider.expects(:systemctl).with('unmask', 'sshd.service')
141
208
  provider.expects(:systemctl).with('enable', 'sshd.service')
142
209
  provider.enable
143
210
  end
@@ -151,6 +218,18 @@ describe Puppet::Type.type(:service).provider(:systemd) do
151
218
  end
152
219
  end
153
220
 
221
+ describe "#mask" do
222
+ it "should run systemctl to disable and mask a service" do
223
+ provider = described_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service'))
224
+ # :disable is the only call in the provider that uses a symbol instead of
225
+ # a string.
226
+ # This should be made consistent in the future and all tests updated.
227
+ provider.expects(:systemctl).with(:disable, 'sshd.service')
228
+ provider.expects(:systemctl).with('mask', 'sshd.service')
229
+ provider.mask
230
+ end
231
+ end
232
+
154
233
  # Note: systemd provider does not care about hasstatus or a custom status
155
234
  # command. I just assume that it does not make sense for systemd.
156
235
  describe "#status" do
@@ -185,8 +264,6 @@ describe Puppet::Type.type(:service).provider(:systemd) do
185
264
  end
186
265
 
187
266
  it "(#16451) has command systemctl without being fully qualified" do
188
- expect(described_class.instance_variable_get(:@commands)).
189
- to include(:systemctl => 'systemctl')
267
+ expect(described_class.instance_variable_get(:@commands)).to include(:systemctl => 'systemctl')
190
268
  end
191
-
192
269
  end