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 ability to stop the agent #562

Merged
merged 4 commits into from
Nov 23, 2018
Merged

Add ability to stop the agent #562

merged 4 commits into from
Nov 23, 2018

Conversation

mkilchhofer
Copy link
Contributor

Pull Request (PR) description

For our "IoT use case" we want to completely configure a mini server during the staging process. When a technician installs the device to its final position (in a vehicle), we want to activate the monitoring agent.

This PR adds the ability to start/stop the agent and to enable/disable the agents automatic startup during boot.

--> Could someone help me writing my first rspec tests for this feature?

E.g. to preconfigure a hosts agent and turn on the service
at a later time (when the server reaches production SLA)
@@ -228,6 +237,8 @@
$listenip = $zabbix::params::agent_listenip,
$startagents = $zabbix::params::agent_startagents,
$serveractive = $zabbix::params::agent_serveractive,
Enum['running','stopped'] $service_state = $zabbix::params::agent_service_state,
Copy link
Member

Choose a reason for hiding this comment

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

@bastelfreak bastelfreak added enhancement New feature or request needs-tests labels Nov 3, 2018
@bastelfreak
Copy link
Member

Hi @mkilchhofer, thanks for the contribution! Did you already check https://github.com/voxpupuli/puppet-zabbix/blob/master/spec/classes/agent_spec.rb? That is the file with all the related rspec-puppet tests for the agent. If you've any questions I suggest you join our slack channel at https://slack.puppet.com or our IRC channel #voxppuli on freenode. That would make it way easier to discuss proper testing and an rspec walkthrough.

@@ -239,6 +239,8 @@
$agent_refreshactivechecks = '120'
$agent_server = '127.0.0.1'
$agent_serveractive = undef
$agent_service_ensure = 'running'
Copy link
Member

Choose a reason for hiding this comment

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

can you fix the = alignment here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup :)

@mkilchhofer
Copy link
Contributor Author

Hi @mkilchhofer, thanks for the contribution! Did you already check https://github.com/voxpupuli/puppet-zabbix/blob/master/spec/classes/agent_spec.rb? That is the file with all the related rspec-puppet tests for the agent. If you've any questions I suggest you join our slack channel at https://slack.puppet.com or our IRC channel #voxppuli on freenode. That would make it way easier to discuss proper testing and an rspec walkthrough.

I will have a look into rspec tests in the next week. I had my problems to run them on the rhel machines at work (ruby2.0). But on my fedora laptop (ruby2.5+), your mentioned spec file works fine.

@bastelfreak
Copy link
Member

We don't support ruby2.0 and 2.1 anymore. Both are EOL since ages. Ruby2.2 and newer should work.

@mkilchhofer
Copy link
Contributor Author

Is something like this enough:

diff --git a/spec/classes/agent_spec.rb b/spec/classes/agent_spec.rb
index da00269..0be24d7 100644
--- a/spec/classes/agent_spec.rb
+++ b/spec/classes/agent_spec.rb
@@ -243,6 +243,25 @@ describe 'zabbix::agent' do
 
         it { is_expected.to contain_file(config_path).without_content %r{^ListenIP=} }
       end
+
+      context 'when declaring service_ensure is stopped and service_enable false' do
+        package = 'zabbix-agent'
+
+        let :params do
+          {
+            service_ensure: 'stopped',
+            service_enable: false
+          }
+        end
+
+        it do
+          is_expected.to contain_service('zabbix-agent').with(
+            ensure:     'stopped',
+            enable:     false,
+            require:    "Package[#{package}]"
+          )
+        end
+      end
     end
   end
 end

@bastelfreak
Copy link
Member

@mkilchhofer yes the test looks fine. I restarted the failed travis job.

@bastelfreak bastelfreak merged commit ddd7bb8 into voxpupuli:master Nov 23, 2018
@mkilchhofer mkilchhofer deleted the feature-start_stop-agent branch September 7, 2020 11:33
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.

2 participants