Skip to content

Commit

Permalink
feat(services): don't manage them in mode=none
Browse files Browse the repository at this point in the history
  • Loading branch information
javierbertoli committed Sep 18, 2020
1 parent 15d4810 commit e094946
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,38 @@ jobs:
# - env: INSTANCE=default-amazonlinux-1-2019-2-py2
# - env: INSTANCE=default-arch-base-latest-2019-2-py2

# - env: INSTANCE=mode-eq-none-debian-10-master-py3
# - env: INSTANCE=mode-eq-none-ubuntu-2004-master-py3
# - env: INSTANCE=mode-eq-none-ubuntu-1804-master-py3
# - env: INSTANCE=mode-eq-none-centos-8-master-py3
- env: INSTANCE=mode-eq-none-fedora-32-master-py3
# - env: INSTANCE=mode-eq-none-fedora-31-master-py3
# - env: INSTANCE=mode-eq-none-opensuse-leap-152-master-py3
# - env: INSTANCE=mode-eq-none-amazonlinux-2-master-py3
# - env: INSTANCE=mode-eq-none-debian-10-3000-3-py3
# - env: INSTANCE=mode-eq-none-debian-9-3000-3-py3
# - env: INSTANCE=mode-eq-none-ubuntu-1804-3000-3-py3
# - env: INSTANCE=mode-eq-none-centos-8-3000-3-py3
- env: INSTANCE=mode-eq-none-centos-7-3000-3-py3
# - env: INSTANCE=mode-eq-none-fedora-31-3000-3-py3
# - env: INSTANCE=mode-eq-none-opensuse-leap-152-3000-3-py3
# - env: INSTANCE=mode-eq-none-amazonlinux-2-3000-3-py3
# - env: INSTANCE=mode-eq-none-ubuntu-1804-3000-3-py2
# - env: INSTANCE=mode-eq-none-ubuntu-1604-3000-3-py2
# - env: INSTANCE=mode-eq-none-arch-base-latest-3000-3-py2
# - env: INSTANCE=mode-eq-none-debian-10-2019-2-py3
# - env: INSTANCE=mode-eq-none-debian-9-2019-2-py3
# - env: INSTANCE=mode-eq-none-ubuntu-1804-2019-2-py3
# - env: INSTANCE=mode-eq-none-ubuntu-1604-2019-2-py3
# - env: INSTANCE=mode-eq-none-centos-8-2019-2-py3
# - env: INSTANCE=mode-eq-none-centos-7-2019-2-py3
# - env: INSTANCE=mode-eq-none-fedora-31-2019-2-py3
# - env: INSTANCE=mode-eq-none-opensuse-leap-152-2019-2-py3
# - env: INSTANCE=mode-eq-none-amazonlinux-2-2019-2-py3
# - env: INSTANCE=mode-eq-none-centos-6-2019-2-py2
# - env: INSTANCE=mode-eq-none-amazonlinux-1-2019-2-py2
# - env: INSTANCE=mode-eq-none-arch-base-latest-2019-2-py2

## Define the release stage that runs `semantic-release`
- stage: 'release'
language: 'node_js'
Expand Down
3 changes: 2 additions & 1 deletion docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ NUT has *server* and *client* applications and packages are usually separated in
Special notes
-------------

None.
Following *NUT*'s configuration logic, when ``nut.mode: 'none'``, the ``.running`` states will do nothing and skip the services management.
Therefore, they'll be left as the OS packages set them.

Available states
----------------
Expand Down
16 changes: 16 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,19 @@ suites:
verifier:
inspec_tests:
- path: test/integration/default
- name: mode-eq-none
provisioner:
state_top:
base:
'*':
- nut
pillars:
top.sls:
base:
'*':
- nut
pillars_from_files:
nut.sls: test/salt/pillar/mode-eq-none.sls
verifier:
inspec_tests:
- path: test/integration/mode-eq-none
2 changes: 2 additions & 0 deletions nut/client/service/running.sls
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ nut-client-service-running-upsmon-service-running:
- enable: {{ nut.client.upsmon.service.enabled }}
- watch:
- sls: {{ sls_client_config_upsmon }}
# If the mode is 'none' we respect the package and do nothing
- unless: test "{{ nut.mode }}" = "none"
4 changes: 4 additions & 0 deletions nut/server/service/running.sls
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ nut-server-service-running-ups-service-running:
- sls: {{ sls_server_config_ups }}
- sls: {{ sls_server_config_upsd }}
- sls: {{ sls_server_config_users }}
# If the mode is 'none' we respect the package and do nothing
- unless: test "{{ nut.mode }}" = "none"
nut-server-service-running-upsd-service-running:
service.running:
Expand All @@ -36,3 +38,5 @@ nut-server-service-running-upsd-service-running:
- sls: {{ sls_server_config_ups }}
- sls: {{ sls_server_config_upsd }}
- sls: {{ sls_server_config_users }}
# If the mode is 'none' we respect the package and do nothing
- unless: test "{{ nut.mode }}" = "none"
50 changes: 50 additions & 0 deletions test/integration/mode-eq-none/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# InSpec Profile: `mode-eq-none`

This shows the implementation of the `mode-eq-none` InSpec [profile](https://github.com/inspec/inspec/blob/master/docs/profiles.md).

## Verify a profile

InSpec ships with built-in features to verify a profile structure.

```bash
$ inspec check mode-eq-none
Summary
-------
Location: mode-eq-none
Profile: profile
Controls: 4
Timestamp: 2019-06-24T23:09:01+00:00
Valid: true

Errors
------

Warnings
--------
```

## Execute a profile

To run all **supported** controls on a local machine use `inspec exec /path/to/profile`.

```bash
$ inspec exec mode-eq-none
..

Finished in 0.0025 seconds (files took 0.12449 seconds to load)
8 examples, 0 failures
```

## Execute a specific control from a profile

To run one control from the profile use `inspec exec /path/to/profile --controls name`.

```bash
$ inspec exec mode-eq-none --controls package
.

Finished in 0.0025 seconds (files took 0.12449 seconds to load)
1 examples, 0 failures
```

See an [example control here](https://github.com/inspec/inspec/blob/master/examples/profile/controls/example.rb).
20 changes: 20 additions & 0 deletions test/integration/mode-eq-none/controls/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

config_dir = '/etc/nut'
config_dir = '/etc/ups' if %w[redhat fedora suse].include? os.family

nut_user = nut_group = 'nut'
nut_user = nut_group = 'upsd' if %w[suse].include? os.family

control 'nut configuration' do
title 'should match desired lines'

describe file("#{config_dir}/nut.conf") do
it { should be_file }
it { should be_owned_by nut_user }
it { should be_grouped_into nut_group }
its('mode') { should cmp '0640' }
its('content') { should include '# Your changes will be overwritten.' }
its('content') { should match '^MODE=none' }
end
end
19 changes: 19 additions & 0 deletions test/integration/mode-eq-none/controls/services_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

control 'nut-server service' do
impact 0.5
title 'should not be running'

describe service('nut-server') do
it { should_not be_running }
end
end

control 'nut-monitor service' do
impact 0.5
title 'should not be running'

describe service('nut-monitor') do
it { should_not be_running }
end
end
17 changes: 17 additions & 0 deletions test/integration/mode-eq-none/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
name: mode-eq-none
title: nut formula
maintainer: SaltStack Formulas
license: Apache-2.0
summary: Verify that the nut services are not started in mode='none'
supports:
- platform-name: debian
- platform-name: ubuntu
- platform-name: centos
- platform-name: fedora
- platform-name: opensuse
- platform-name: suse
- platform-name: freebsd
- platform-name: arch
5 changes: 5 additions & 0 deletions test/salt/pillar/mode-eq-none.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
nut:
mode: none

0 comments on commit e094946

Please # to comment.