Skip to content

Commit

Permalink
fix(container): respect ConditionVirtualization service setting
Browse files Browse the repository at this point in the history
* E.g. `opensuse-leap-151`:

```bash
kitchen@0e066e43d255:~> systemctl status ntpd
WARNING: terminal is not fully functional
-  (press RETURN)● ntpd.service - NTP Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
Condition: start condition failed at Sat 2019-10-26 04:11:32 UTC; 13min ago
           └─ ConditionVirtualization=!container was not met
     Docs: man:ntpd(1)
```

* Check for `Docker` for the time being (other containers _are_ possible) --
  replace earlier method of checking for the `kitchen` user:
  - `salt['environ.get']('SUDO_USER', '') == 'kitchen'`
  • Loading branch information
myii committed Oct 29, 2019
1 parent 250ee2c commit 8711b24
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 7 additions & 1 deletion ntp/ng/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ ntpd_conf:
{% endif %}
{% if 'ntpd' in ntp.settings %}
{% set service_state = service.get(ntp.settings.ntpd) %}
{# 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['config.get']('virtual_subtype', '') in ['Docker'] %}
{% set service_state = 'dead' %}
{% endif %}
ntpd:
service.{{ service.get(ntp.settings.ntpd) }}:
service.{{ service_state }}:
- name: {{ ntp.lookup.service }}
- enable: {{ ntp.settings.ntpd }}
{%- if 'init_delay' in ntp.settings %}
Expand Down
16 changes: 15 additions & 1 deletion test/integration/default/controls/services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@
'ntpd'
end

control 'ntp service' do
control 'ntp service (installed)' do
impact 0.5
title 'should be installed and enabled'

describe service(service_name) do
it { should be_installed }
it { should be_enabled }
end
end

control 'ntp service (running)' do
impact 0.5
title 'should be running'
only_if(
'unable to run the service in a container due to its '\
'`ConditionVirtualization` setting'
) do
platform[:family] != 'suse'
end

describe service(service_name) do
it { should be_running }
end
end

0 comments on commit 8711b24

Please sign in to comment.