Skip to content

Commit

Permalink
Merge pull request #47 from myii/test/add_yaml_dump
Browse files Browse the repository at this point in the history
test(yaml_dump): add functionality, initial tests & add to Kitchen
  • Loading branch information
myii committed Apr 6, 2020
2 parents 4aab7db + 76d43f5 commit b589a09
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
16 changes: 16 additions & 0 deletions dhcpd/yaml_dump/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# vim: ft=sls
---
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import dhcpd as map with context %}
{%- set output_file = '/tmp/salt_yaml_dump.yaml' %}
yaml-dump-{{ tplroot }}:
file.managed:
- name: {{ output_file }}
- source: salt://{{ tplroot }}/yaml_dump/yaml_dump.jinja
- template: jinja
- context:
map: {{ map | yaml }}
4 changes: 4 additions & 0 deletions dhcpd/yaml_dump/yaml_dump.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# yamllint disable rule:indentation rule:line-length
# {{ grains.get('osfinger', grains.os) }}-{{ grains.saltversion }}-py{{ grains.pythonversion[0] }}
---
{{ map|yaml(False)|trim }}
1 change: 1 addition & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ suites:
state_top:
base:
'*':
- dhcpd.yaml_dump
- dhcpd.config
pillars:
top.sls:
Expand Down
59 changes: 59 additions & 0 deletions test/integration/default/controls/yaml_dump_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

control 'DHCPD `map.jinja` YAML dump' do
title 'should contain the lines'

config = '/etc/dhcp/dhcpd.conf'
enable = 'false'
server = 'dhcp'
service = 'dhcpd'
yaml_dump = "---\n"
yaml_dump +=
case platform[:family]
when 'debian'
<<~YAML_DUMP.chomp
config: #{config}
enable: #{enable}
server: isc-dhcp-server
service: isc-dhcp-server
service_config: /etc/default/isc-dhcp-server
YAML_DUMP
when 'redhat', 'fedora'
<<~YAML_DUMP.chomp
config: #{config}
enable: #{enable}
server: #{server}
service: #{service}
service_config: /etc/systemd/system/dhcpd.service.d/override.conf
YAML_DUMP
when 'suse'
<<~YAML_DUMP.chomp
config: /etc/dhcpd.conf
enable: #{enable}
server: dhcp-server
service: dhcpd
YAML_DUMP
when 'freebsd'
<<~YAML_DUMP.chomp
config: /usr/local/etc/dhcpd.conf
enable: #{enable}
server: isc-dhcp43-server
service: isc-dhcpd
service_config: /etc/rc.conf.d/dhcpd
YAML_DUMP
when 'linux'
case platform[:name]
when 'arch'
<<~YAML_DUMP.chomp
config: /etc/dhcpd.conf
enable: #{enable}
server: dhcp
service: dhcpd4
YAML_DUMP
end
end

describe file('/tmp/salt_yaml_dump.yaml') do
its('content') { should include yaml_dump }
end
end

0 comments on commit b589a09

Please sign in to comment.