-
-
Notifications
You must be signed in to change notification settings - Fork 151
Unit_file: Add notify_service #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I think there's no such thing as it { is_expected.not_to contain_service(title).with_subscribes_to("File[/etc/systemd/system/#{title}]") Slight nuance is that it's also true if the service is not contained in the catalog. Perhaps a possible enhancement for https://github.com/puppetlabs/rspec-puppet? |
22328b4
to
27a5103
Compare
Hello @ekohl Thank it's look good ! I've also create an issue here puppetlabs/rspec-puppet#28 Regards, |
let(:params) { { enable: true, notify_service: false } } | ||
|
||
it do | ||
is_expected.not_to contain_service(title).with_subscribes_to( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with_subscribes_to
expects a property to be set, like
service { $title:
subscribes_to => File[$file],
}
That's never going to be true. This checks the compiled catalog (which mirrors the check on line 210 for example):
is_expected.not_to contain_service(title).with_subscribes_to( | |
is_expected.not_to contain_service(title).that_subscribes_to( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That not work, but something like this look ok:
let(:params) { { enable: true, notify_service: false } }
it do
- is_expected.not_to contain_service(title).with_subscribes_to(
- "File[/etc/systemd/system/#{title}]"
+ is_expected.not_to contain_file("/etc/systemd/system/#{title}").with(
+ notify: /Service\[#{title}\]/
)
end
end
It's good for you ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that's not the same. Please see https://rspec-puppet.com/documentation/classes/#testing-relationships-between-resources for the background. Where with
doesn't doesn't take ~>
into account, that_...
does.
Your suggestion would fail on this:
file { "/etc/systemd/system/${title}":
notify => Service[$title],
}
It would not fail on:
file { "/etc/systemd/system/${title}":
}
File["/etc/systemd/system/${title}"] ~> Service[$title]
The reason it now fails is a transitive property. See rodjek/rspec-puppet#821 for more discussion, but there's a chain:
File["/etc/systemd/system/${name}"] ~> Systemd::Daemon_reload[$name] ~> Service[$name]
rspec-puppet thinks this implies:
File["/etc/systemd/system/${name}"] ~> Service[$name]
https://puppet.com/docs/puppet/7/lang_relationships.html#lang_rel_chaining_arrows is unclear about this. However, now in practice it probably is. Because the daemon reload is notified, that probably triggers a service restart anyway. So if $daemon_reload
is true (default value), I don't think your patch is valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've try before, with my path when it's true that fail correctly:
diff --git a/spec/defines/unit_file_spec.rb b/spec/defines/unit_file_spec.rb
index a0521aa..6dde40a 100644
--- a/spec/defines/unit_file_spec.rb
+++ b/spec/defines/unit_file_spec.rb
@@ -272,8 +272,18 @@ describe 'systemd::unit_file' do
let(:params) { { enable: true, notify_service: false } }
it do
- is_expected.not_to contain_service(title).with_subscribes_to(
- "File[/etc/systemd/system/#{title}]"
+ is_expected.not_to contain_file("/etc/systemd/system/#{title}").with(
+ notify: /Service\[#{title}\]/
+ )
+ end
+ end
+
+ context 'notify_service => true' do
+ let(:params) { { enable: true, notify_service: true } }
+
+ it do
+ is_expected.not_to contain_file("/etc/systemd/system/#{title}").with(
+ notify: /Service\[#{title}\]/
)
end
end
...
21) systemd::unit_file supported operating systems on centos-8-x86_64 notify_service => true is expected not to contain File[/etc/systemd/system/test.service] with notify =~ /Service\[test.service\]/
Failure/Error:
is_expected.not_to contain_file("/etc/systemd/system/#{title}").with(
notify: /Service\[#{title}\]/
)
expected that the catalogue would not contain File[/etc/systemd/system/test.service]
# ./spec/defines/unit_file_spec.rb:285:in `block (6 levels) in <top (required)>'
Finished in 1 minute 49.83 seconds (files took 54.25 seconds to load)
609 examples, 21 failures
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello,
Any update/idea about this test ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't know what the proper behavior is: puppetlabs/rspec-puppet#35 is still open. It may well be that with your current implementation it's impossible to prevent a notification to propagate to the service.
27a5103
to
cc1b158
Compare
implemented in #433 |
Pull Request (PR) description
Hello,
I had add new parameters for Unit_file define,
notify_service
. This params I can use for disable the service notify. Very useful for not restart an in memory service for space or a new comment.I've try to add spec but that not work. I've try something like that:
or
Can you help me for this part ?
This Pull Request (PR) fixes the following issues
Regards,