Skip to content
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

Add service_restart option to prevent automatic service reload #728

Merged
merged 1 commit into from
Oct 3, 2018

Conversation

spuder
Copy link
Contributor

@spuder spuder commented Sep 26, 2018

Pull Request (PR) description

Make the restart optional since it is dangerous to do an uncontrolled rolling restart. We lost many messages this way.
It has been many years since I have written any puppet code so I don't have high confidence that I did this entirely correct. It is based off of how the kafka module prevents rolling restarts https://github.com/voxpupuli/puppet-kafka/search?q=service_restart&unscoped_q=service_restart

This Pull Request (PR) fixes the following issues

Fixes #727

Copy link
Contributor

@wyardley wyardley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See one comment. I think the basic idea is right from a quick once-over, but we’ll need spec tests to be added for the case where it’s disabled, and any failing tests should also be updated

if ($service_restart) {
$service_to_restart = Class['rabbitmq::service'],
} else {
$service_to_rstart = undef
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be restart here

@spuder
Copy link
Contributor Author

spuder commented Sep 26, 2018

I've fixed the failing tests. I'm not able to get a valid test to check this. Any help appreciated

not working

      describe 'service with service_restart equal to false' do
        let :params do
          { service_restart: false }
        end

        it { is_expected.not_to contain_file('rabbitmq.config').that_notifies("Class[rabbitmq::service]") }
      end

@wyardley
Copy link
Contributor

wyardley commented Sep 27, 2018

@spuder You could try on IRC or in the #testing channel on Puppet Slack. I haven't been working with Puppet or rspec that much recently. I'm not sure that's the best way to test this... but if I invert your test, it passes:

$ bundle install
$ bundle exec rake spec_prep
$ bundle exec rspec spec/classes/rabbitmq_spec.rb:1459
--- a/spec/classes/rabbitmq_spec.rb
+++ b/spec/classes/rabbitmq_spec.rb
@@ -1455,6 +1455,15 @@ describe 'rabbitmq' do
 
         it { is_expected.not_to contain_service('rabbitmq-server') }
       end
+
+      describe 'service with service_restart equal to false' do
+        let :params do
+          { service_restart: false }
+        end
+
+        it { is_expected.to contain_file('rabbitmq.config').that_notifies('Class[rabbitmq::service]') }
+      end
+
     end
   end
 end
  on redhat-7-x86_64
    service with service_restart equal to false
      should contain File[rabbitmq.config] that notifies Class[rabbitmq::service]

So I think that because there's a class level notify (via the squiggly arrow), you need to make this logic happen at that level, and the notify statements in the config class should all be redundant.

  -> Class['rabbitmq::config']
  ~> Class['rabbitmq::service']

I think you can handle the logic here, and then it will also be easier to test the class relationships directly. As a plus, we'll remove some cruft from the codebase too.

@wyardley wyardley added the enhancement New feature or request label Sep 27, 2018
@wyardley wyardley changed the title Prevent services from restarting automatically. Add service_restart option to prevent automatic service reload Sep 27, 2018
@wyardley
Copy link
Contributor

wyardley commented Sep 28, 2018

@spuder I PRed your PR - let me know if that works. I changed what the test is as well. There might be a more elegant way, but I think it works.

  if ($service_restart) {
    Class['rabbitmq::config'] ~> Class['rabbitmq::service']
  }

  Class['rabbitmq::install']
  -> Class['rabbitmq::config']
  -> Class['rabbitmq::service']
  -> Class['rabbitmq::management']

If that looks good, can you merge my PR, then squash those commits down your branch, and I'll get one other person to review? It's fine to either squash my commit in and leave it separate; either way, squash down the other commits if you know how. (should be something like git rebase -i HEAD~5, change 'pick' to 'fix' for the commits you want to squash, then git push --force-with-lease).

@spuder
Copy link
Contributor Author

spuder commented Sep 28, 2018

Thanks for the help. Tests are passing and everything looks correct. I squashed the commits (inadvertently including your commit). If the travis tests pass I believe this would be good to merge.

@wyardley
Copy link
Contributor

@bastelfreak @ekohl: I know you're both busy, but if either of you has a chance to review, would appreciate it.

Copy link
Contributor

@wyardley wyardley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this, but I also suggested some of the changes, let's get one more +1 on here too.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know https://github.com/puppetlabs/puppetlabs-postgresql has a mechanism to reload. Would that that work here?

@@ -146,6 +146,7 @@
# @param service_ensure The state of the service.
# @param service_manage Determines if the service is managed.
# @param service_name The name of the service to manage.
# @param $service_restart. Default defined in param.pp. This option will prevent config changes from restarting rabbitmq
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be phrased a bit clearer. How about:
Whether to restart the service on config change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

manifests/init.pp Show resolved Hide resolved
@wyardley
Copy link
Contributor

I know https://github.com/puppetlabs/puppetlabs-postgresql has a mechanism to reload. Would that
that work here?

It's been a little, but I think not. From a quick look, at least, it would seem that reload and restart both will restart the service.

@wyardley wyardley merged commit 4bf60b2 into voxpupuli:master Oct 3, 2018
@wyardley
Copy link
Contributor

wyardley commented Oct 3, 2018

Thanks for the contribution (and patience)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make restarting services optional
4 participants