From 4f8e8992a8691d215d65fc1757cb66c3b4ca30bf Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Fri, 24 May 2019 17:44:28 +0200 Subject: [PATCH] fix(fedora): honor working directory & service name --- openvpn/config.sls | 6 +++++- openvpn/service.sls | 7 ++++++- test/integration/default/controls/config_spec.rb | 14 ++++++++++++-- test/integration/default/controls/services_spec.rb | 8 +++++++- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/openvpn/config.sls b/openvpn/config.sls index b3ba173..aa7fa96 100644 --- a/openvpn/config.sls +++ b/openvpn/config.sls @@ -19,7 +19,11 @@ include: {% set service_id = "openvpn_{0}_service".format(name) if map.multi_services else "openvpn_service" %} -{% set config_dir = config.conf_dir if config.conf_dir is defined else map.conf_dir %} +{%- set config_dir = config.conf_dir if config.conf_dir is defined else map.conf_dir %} +{%- if grains.os == "Fedora" %} +{#- Fedora uses /etc/openvpn/{client,server} as their working directory #} +{%- set config_dir = config_dir ~ '/' ~ type %} +{%- endif %} {% set config_file = "{0}/openvpn_{1}.conf".format(config_dir, name) if map.multi_services and grains['os_family'] == 'FreeBSD' else "{0}/{1}.{2}".format(config_dir, name, map.conf_ext) %} diff --git a/openvpn/service.sls b/openvpn/service.sls index 74a1696..e97c76d 100644 --- a/openvpn/service.sls +++ b/openvpn/service.sls @@ -12,7 +12,12 @@ # How to name the service (instance)? {% if salt['grains.has_value']('systemd') %} -{% set service_name = map.service ~ '@' ~ name %} +{%- if grains.os == "Fedora" %} +{#- Fedora uses /etc/openvpn/{client,server} as their working directory #} +{% set service_name = map.service ~ '-' ~ type ~ '@' ~ name %} +{%- else %} +{% set service_name = map.service ~ '@' ~ name %} +{%- endif %} {% else %} {% set service_name = map.service ~ '_' ~ name %} {% endif %} diff --git a/test/integration/default/controls/config_spec.rb b/test/integration/default/controls/config_spec.rb index a5b3b85..2071ebd 100644 --- a/test/integration/default/controls/config_spec.rb +++ b/test/integration/default/controls/config_spec.rb @@ -5,7 +5,12 @@ control 'OpenVPN server configuration' do title 'should match desired lines' - describe file('/etc/openvpn/myserver1.conf') do + cfgfile = case os[:name] + when 'fedora' then '/etc/openvpn/server/myserver1.conf' + else '/etc/openvpn/myserver1.conf' + end + + describe file(cfgfile) do it { should be_file } it { should be_owned_by user } it { should be_grouped_into group } @@ -23,7 +28,12 @@ control 'OpenVPN client configuration' do title 'should match desired lines' - describe file('/etc/openvpn/myclient1.conf') do + cfgfile = case os[:name] + when 'fedora' then '/etc/openvpn/client/myclient1.conf' + else '/etc/openvpn/myclient1.conf' + end + + describe file(cfgfile) do it { should be_file } it { should be_owned_by user } it { should be_grouped_into group } diff --git a/test/integration/default/controls/services_spec.rb b/test/integration/default/controls/services_spec.rb index f7091e9..a68e22b 100644 --- a/test/integration/default/controls/services_spec.rb +++ b/test/integration/default/controls/services_spec.rb @@ -17,7 +17,13 @@ # multiple services else %w(server client).each do |role| - describe service("openvpn@my#{role}1.service") do + + prefix = case os[:name] + when 'fedora' then "openvpn-#{role}" + else 'openvpn' + end + + describe service("#{prefix}@my#{role}1.service") do it { should be_enabled } it { should be_running } end