diff --git a/kitchen.yml b/kitchen.yml index cd8b570..1ab0a09 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -347,11 +347,16 @@ verifier: suites: - name: default provisioner: + dependencies: + - name: states + path: ./test/salt state_top: base: '*': - rng-tools._mapdata - rng-tools + 'G@init:systemd and ( G@os:Fedora or G@os:Gentoo or G@os:SUSE )': + - states.custom_systemd_service pillars: top.sls: base: diff --git a/rng-tools/service/running.sls b/rng-tools/service/running.sls index 5fc3dd1..7fe8afe 100644 --- a/rng-tools/service/running.sls +++ b/rng-tools/service/running.sls @@ -9,15 +9,8 @@ include: - {{ sls_config_file }} -{%- set service_state = 'running' %} -{#- Do not attempt to run the service in a container where the service is configured with #} -{#- `ConditionVirtualization=!container` or similar (e.g. via. `kitchen-salt`) #} -{%- if grains.os_family in ['Suse'] and - salt['grains.get']('virtual_subtype', '') in ['Docker', 'LXC', 'kubernetes', 'libpod'] %} -{%- set service_state = 'dead' %} -{%- endif %} -rng-tools/service/{{ service_state }}: - service.{{ service_state }}: +rng-tools/service/running: + service.running: - name: {{ rng_tools.service.name }} - enable: true - watch: diff --git a/test/integration/default/controls/service_spec.rb b/test/integration/default/controls/service_spec.rb index 0696f25..c35a73f 100644 --- a/test/integration/default/controls/service_spec.rb +++ b/test/integration/default/controls/service_spec.rb @@ -19,12 +19,6 @@ describe service(service) do it { should be_installed } it { should be_enabled } - if %w[suse].include?(platform[:family]) - # Unable to run the service in a container due to its - # `ConditionVirtualization` setting - it { should_not be_running } - else - it { should be_running } - end + it { should be_running } end end diff --git a/test/salt/states/custom_systemd_service.sls b/test/salt/states/custom_systemd_service.sls new file mode 100644 index 0000000..3845fb7 --- /dev/null +++ b/test/salt/states/custom_systemd_service.sls @@ -0,0 +1,29 @@ +# This state is used to prepare environment for formula testing + +# In distros that have a systemd unit, make sure the service is +# started even if running in a containerized environment + +{%- set sls_config_file = 'rng-tools.config.file' %} +{%- set service_file = { + 'Fedora': '/usr/lib/systemd/system/rngd.service', + 'Gentoo': '/lib/systemd/system/rngd.service', + 'SUSE': '/usr/lib/systemd/system/rng-tools.service', + }.get(grains.os, '') %} + +test-salt-states-custom-systemd-service-file-replace: + file.replace: + - name: {{ service_file }} + - pattern: 'ConditionVirtualization=!container' + - repl: '' + - show_changes: True + - require: + - sls: {{ sls_config_file }} + +test-salt-states-custom-systemd-service-cmd-wait: + cmd.wait: + - name: systemctl daemon-reload + - runas: root + - watch: + - file: test-salt-states-custom-systemd-service-file-replace + - require_in: + - service: rng-tools/service/running