Skip to content

Commit

Permalink
fix(fedora): honor working directory & service name
Browse files Browse the repository at this point in the history
  • Loading branch information
alxwr committed May 24, 2019
1 parent 6077d4e commit 75f85bd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
6 changes: 5 additions & 1 deletion openvpn/config.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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) %}
Expand Down
7 changes: 6 additions & 1 deletion openvpn/service.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
14 changes: 12 additions & 2 deletions test/integration/default/controls/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down
8 changes: 7 additions & 1 deletion test/integration/default/controls/services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 75f85bd

Please sign in to comment.