Pārlūkot izejas kodu

Merge pull request #23 from n-rodriguez/wip/kitchen

Upgrade formula to new standards
tags/v0.4.0
Imran Iqbal pirms 5 gadiem
vecāks
revīzija
fa3260124e
Revīzijas autora e-pasta adrese nav piesaistīta nevienam kontam
27 mainītis faili ar 374 papildinājumiem un 123 dzēšanām
  1. +11
    -7
      .cirrus.yml
  2. +17
    -13
      docs/README.rst
  3. +21
    -2
      kitchen.yml
  4. +0
    -15
      syslog_ng/config.sls
  5. +23
    -0
      syslog_ng/config/file.sls
  6. +5
    -0
      syslog_ng/config/init.sls
  7. +8
    -0
      syslog_ng/defaults.yaml
  8. +0
    -4
      syslog_ng/defaults.yml
  9. +6
    -2
      syslog_ng/files/syslog-ng.conf
  10. +6
    -10
      syslog_ng/init.sls
  11. +42
    -14
      syslog_ng/map.jinja
  12. +0
    -20
      syslog_ng/os_family_map.yml
  13. +35
    -0
      syslog_ng/osarchmap.yaml
  14. +8
    -0
      syslog_ng/osfamilymap.yaml
  15. +30
    -4
      syslog_ng/osfingermap.yaml
  16. +13
    -0
      syslog_ng/osmap.yaml
  17. +5
    -0
      syslog_ng/package/init.sls
  18. +34
    -0
      syslog_ng/package/install.sls
  19. +0
    -15
      syslog_ng/packages.sls
  20. +5
    -0
      syslog_ng/service/init.sls
  21. +17
    -0
      syslog_ng/service/running.sls
  22. +31
    -0
      test/integration/default/controls/config_spec.rb
  23. +7
    -0
      test/integration/default/controls/package_spec.rb
  24. +16
    -0
      test/integration/default/controls/service_spec.rb
  25. +0
    -17
      test/integration/default/controls/syslog_ng.rb
  26. +1
    -0
      test/integration/default/inspec.yml
  27. +33
    -0
      test/salt/pillar/syslog_ng.sls

+ 11
- 7
.cirrus.yml Parādīt failu

@@ -6,29 +6,33 @@ docker_builder:
env:
matrix:
- INSTANCE: default-debian-10-develop-py3
- INSTANCE: default-ubuntu-1804-develop-py3
# - INSTANCE: default-ubuntu-1804-develop-py3
# - INSTANCE: default-centos-7-develop-py3
# - INSTANCE: default-fedora-30-develop-py3
# - INSTANCE: default-opensuse-leap-15-develop-py3
# - INSTANCE: default-amazonlinux-2-develop-py2
- INSTANCE: default-debian-9-2019-2-py3
# - INSTANCE: default-arch-base-latest-develop-py2
# - INSTANCE: default-debian-9-2019-2-py3
- INSTANCE: default-ubuntu-1804-2019-2-py3
# - INSTANCE: default-centos-7-2019-2-py3
# - INSTANCE: default-fedora-30-2019-2-py3
# - INSTANCE: default-opensuse-leap-15-2019-2-py3
# - INSTANCE: default-amazonlinux-2-2019-2-py2
- INSTANCE: default-debian-9-2018-3-py2
- INSTANCE: default-amazonlinux-2-2019-2-py2
- INSTANCE: default-arch-base-latest-2019-2-py2
# - INSTANCE: default-debian-9-2018-3-py2
# - INSTANCE: default-ubuntu-1604-2018-3-py2
# - INSTANCE: default-centos-7-2018-3-py2
# - INSTANCE: default-fedora-29-2018-3-py2
# - INSTANCE: default-opensuse-leap-15-2018-3-py2
- INSTANCE: default-fedora-29-2018-3-py2
- INSTANCE: default-opensuse-leap-15-2018-3-py2
# - INSTANCE: default-amazonlinux-2-2018-3-py2
# - INSTANCE: default-arch-base-latest-2018-3-py2
# - INSTANCE: default-debian-8-2017-7-py2
# - INSTANCE: default-ubuntu-1604-2017-7-py2
# - INSTANCE: default-centos-6-2017-7-py2
- INSTANCE: default-centos-6-2017-7-py2
# - INSTANCE: default-fedora-29-2017-7-py2
# - INSTANCE: default-opensuse-leap-15-2017-7-py2
# - INSTANCE: default-amazonlinux-2-2017-7-py2
# - INSTANCE: default-arch-base-latest-2017-7-py2
bundle_install_script: bundle install
verify_script:
- bin/kitchen verify ${INSTANCE}

+ 17
- 13
docs/README.rst Parādīt failu

@@ -49,7 +49,7 @@ Available states
^^^^^^^^^^^^^
Installs and configures the syslog_ng package.

``syslog_ng.packages``
``syslog_ng.package``
^^^^^^^^^^^^^^^^^^^^^^
Installs the syslog_ng package and optional packages which may provide additional functionalities.

@@ -57,6 +57,10 @@ Installs the syslog_ng package and optional packages which may provide additiona
^^^^^^^^^^^^^^^^^^^^
This state manages the file ``syslog_ng.conf`` under ``/etc/syslog-ng`` (template found in "syslog_ng/files"). The configuration is populated by values in "syslog_ng/map.jinja" based on the package's default values (and RedHat, Debian, Suse and Arch family distribution specific values), which can then be overridden by values of the same name in pillar.

``syslog_ng.service``
^^^^^^^^^^^^^^^^^^^^
Manages the startup and running state of the syslog_ng service.

Testing
-------

@@ -72,32 +76,32 @@ Requirements

$ gem install bundler
$ bundle install
$ bundle exec kitchen test [platform]
$ bin/kitchen test [platform]

Where ``[platform]`` is the platform name defined in ``kitchen.yml``,
e.g. ``debian-9-2019-2-py3``.

``kitchen converge``
^^^^^^^^^^^^^^^^^^^^
``bin/kitchen converge``
^^^^^^^^^^^^^^^^^^^^^^^^

Creates the docker instance and runs the ``template`` main state, ready for testing.
Creates the docker instance and runs the ``syslog_ng`` main state, ready for testing.

``kitchen verify``
^^^^^^^^^^^^^^^^^^
``bin/kitchen verify``
^^^^^^^^^^^^^^^^^^^^^^

Runs the ``inspec`` tests on the actual instance.

``kitchen destroy``
^^^^^^^^^^^^^^^^^^^
``bin/kitchen destroy``
^^^^^^^^^^^^^^^^^^^^^^^

Removes the docker instance.

``kitchen test``
^^^^^^^^^^^^^^^^
``bin/kitchen test``
^^^^^^^^^^^^^^^^^^^^

Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``verify`` + ``destroy``.

``kitchen login``
^^^^^^^^^^^^^^^^^
``bin/kitchen login``
^^^^^^^^^^^^^^^^^^^^^

Gives you SSH access to the instance for manual testing.

+ 21
- 2
kitchen.yml Parādīt failu

@@ -53,6 +53,13 @@ platforms:
provision_command:
- curl -o bootstrap-salt.sh -L https://bootstrap.saltstack.com
- sh bootstrap-salt.sh -XdPbfrq -x python2 git develop
- name: arch-base-latest-develop-py2
driver:
image: netmanagers/salt-develop-py2:arch-base-latest
provision_command:
- curl -o bootstrap-salt.sh -L https://bootstrap.saltstack.com
- sh bootstrap-salt.sh -XdPbfrq -x python2 git develop
run_command: /usr/lib/systemd/systemd

## SALT `2019.2`
- name: debian-9-2019-2-py3
@@ -78,6 +85,10 @@ platforms:
- name: amazonlinux-2-2019-2-py2
driver:
image: netmanagers/salt-2019.2-py2:amazonlinux-2
- name: arch-base-latest-2019-2-py2
driver:
image: netmanagers/salt-2019.2-py2:arch-base-latest
run_command: /usr/lib/systemd/systemd

## SALT `2018.3`
- name: debian-9-2018-3-py2
@@ -103,6 +114,10 @@ platforms:
- name: amazonlinux-2-2018-3-py2
driver:
image: netmanagers/salt-2018.3-py2:amazonlinux-2
- name: arch-base-latest-2018-3-py2
driver:
image: netmanagers/salt-2018.3-py2:arch-base-latest
run_command: /usr/lib/systemd/systemd

## SALT `2017.7`
- name: debian-8-2017-7-py2
@@ -129,6 +144,10 @@ platforms:
- name: amazonlinux-2-2017-7-py2
driver:
image: netmanagers/salt-2017.7-py2:amazonlinux-2
- name: arch-base-latest-2017-7-py2
driver:
image: netmanagers/salt-2017.7-py2:arch-base-latest
run_command: /usr/lib/systemd/systemd

provisioner:
name: salt_solo
@@ -154,14 +173,14 @@ suites:
state_top:
base:
'*':
- syslog_ng.config
- syslog_ng
pillars:
top.sls:
base:
'*':
- syslog_ng
pillars_from_files:
syslog_ng.sls: pillar.example
syslog_ng.sls: test/salt/pillar/syslog_ng.sls
verifier:
inspec_tests:
- path: test/integration/default

+ 0
- 15
syslog_ng/config.sls Parādīt failu

@@ -1,15 +0,0 @@
{% from "syslog_ng/map.jinja" import syslog_ng with context %}

include:
- syslog_ng

syslog_ng.conf:
file.managed:
- name: {{ syslog_ng.syslog_ng_config }}
- source: {{ syslog_ng.syslog_ng_config_src }}
- template: jinja
- user: root
- group: root
- mode: 644
- watch_in:
- service: syslog_ng

+ 23
- 0
syslog_ng/config/file.sls Parādīt failu

@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_package_install = tplroot ~ '.package.install' %}
{%- from tplroot ~ "/map.jinja" import syslog_ng with context %}

include:
- {{ sls_package_install }}

syslog_ng/config/install:
file.managed:
- name: {{ syslog_ng.syslog_ng_config }}
- source: {{ syslog_ng.syslog_ng_config_src }}
- template: jinja
- user: root
- group: root
- mode: 644
- require:
- sls: {{ sls_package_install }}
- context:
syslog_ng: {{ syslog_ng | json }}

+ 5
- 0
syslog_ng/config/init.sls Parādīt failu

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .file

+ 8
- 0
syslog_ng/defaults.yaml Parādīt failu

@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
syslog_ng:
package: syslog-ng
service: syslog-ng
syslog_ng_config: /etc/syslog-ng/syslog-ng.conf
syslog_ng_config_src: salt://syslog_ng/files/syslog-ng.conf

+ 0
- 4
syslog_ng/defaults.yml Parādīt failu

@@ -1,4 +0,0 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
syslog_ng: {}

+ 6
- 2
syslog_ng/files/syslog-ng.conf Parādīt failu

@@ -1,5 +1,9 @@
{%- from "syslog_ng/macro.jinja" import rule_builder -%}
{%- from "syslog_ng/map.jinja" import syslog_ng with context -%}
########################################################################
# File managed by Salt at <{{ source }}>.
# Your changes will be overwritten.
########################################################################

{%- from "syslog_ng/macro.jinja" import rule_builder %}

@version: {{ syslog_ng.get('version', '3.3') }}


+ 6
- 10
syslog_ng/init.sls Parādīt failu

@@ -1,11 +1,7 @@
{% from "syslog_ng/map.jinja" import syslog_ng with context %}
# -*- coding: utf-8 -*-
# vim: ft=sls

syslog_ng:
pkg.installed:
- name: {{ syslog_ng.package }}

service.running:
- enable: True
- name: {{ syslog_ng.service }}
- watch:
- pkg: syslog_ng
include:
- .package
- .config
- .service

+ 42
- 14
syslog_ng/map.jinja Parādīt failu

@@ -1,21 +1,49 @@
# -*- coding: utf-8 -*-
# vim: ft=jinja

{% import_yaml "syslog_ng/defaults.yml" as defaults %}
{% import_yaml "syslog_ng/os_family_map.yml" as os_family_map %}
{% import_yaml "syslog_ng/os_codename_map.yml" as os_codename_map %}
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{#- Start imports as #}
{%- import_yaml tplroot ~ "/defaults.yaml" as default_settings %}
{%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap %}
{%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap %}
{%- import_yaml tplroot ~ "/osmap.yaml" as osmap %}
{%- import_yaml tplroot ~ "/osfingermap.yaml" as osfingermap %}

{# get the settings for the os_family grain #}
{% set osfam = salt['grains.filter_by'](os_family_map) or {} %}
{#- Retrieve the config dict only once #}
{%- set _config = salt['config.get'](tplroot, default={}) %}

{# get the settings for the oscodename grain, os_family data will override oscodename data #}
{% set oscode = salt['grains.filter_by'](os_codename_map, grain='oscodename', merge=osfam) or {} %}
{%- set defaults = salt['grains.filter_by'](
default_settings,
default=tplroot,
merge=salt['grains.filter_by'](
osarchmap,
grain='osarch',
merge=salt['grains.filter_by'](
osfamilymap,
grain='os_family',
merge=salt['grains.filter_by'](
osmap,
grain='os',
merge=salt['grains.filter_by'](
osfingermap,
grain='osfinger',
merge=salt['grains.filter_by'](
_config,
default='lookup'
)
)
)
)
)
)
%}

{# merge the os family/os codename specific data over the defaults #}
{% do defaults.syslog_ng.update(oscode) %}
{%- set config = salt['grains.filter_by'](
{'defaults': defaults},
default='defaults',
merge=_config
)
%}

{# merge the pillar:lookup dict into the defaults/os specific dict #}
{% set lookup = salt['pillar.get']('syslog_ng:lookup', default=defaults.syslog_ng, merge=True) %}

{# merge the actual syslog_ng pillar into the above combined dict #}
{% set syslog_ng = salt['pillar.get']('syslog_ng', default=lookup, merge=True) %}
{%- set syslog_ng = config %}

+ 0
- 20
syslog_ng/os_family_map.yml Parādīt failu

@@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
Debian:
package: syslog-ng
service: syslog-ng
syslog_ng_config: /etc/syslog-ng/syslog-ng.conf
syslog_ng_config_src: salt://syslog_ng/files/syslog-ng.conf

Gentoo:
package: app-admin/syslog-ng
service: syslog-ng
syslog_ng_config: /etc/syslog-ng/syslog-ng.conf
syslog_ng_config_src: salt://syslog_ng/files/syslog-ng.conf

RedHat:
package: syslog-ng
service: syslog-ng
syslog_ng_config: /etc/syslog-ng/syslog-ng.conf
syslog_ng_config_src: salt://syslog_ng/files/syslog-ng.conf

+ 35
- 0
syslog_ng/osarchmap.yaml Parādīt failu

@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
#
# Setup variables using grains['osarch'] based logic.
# You just need to add the key:values for an `osarch` that differ
# from `defaults.yaml`.
# Only add an `osarch` which is/will be supported by the formula.
#
# If you do not need to provide defaults via the `osarch` grain,
# you will need to provide at least an empty dict in this file, e.g.
# osarch: {}
---
amd64:
arch: amd64

x86_64:
arch: amd64

386:
arch: 386

arm64:
arch: arm64

armv6l:
arch: armv6l

armv7l:
arch: armv7l

ppc64le:
arch: ppc64le

s390x:
arch: s390x

+ 8
- 0
syslog_ng/osfamilymap.yaml Parādīt failu

@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
Gentoo:
package: app-admin/syslog-ng

Arch:
service: syslog-ng@default.service

syslog_ng/os_codename_map.yml → syslog_ng/osfingermap.yaml Parādīt failu

@@ -2,7 +2,7 @@
# vim: ft=yaml
---
# Debian
wheezy:
Debian-7:
version: 3.3
include:
- scl.conf
@@ -10,7 +10,7 @@ wheezy:
last_include:
- /etc/syslog-ng/conf.d/

jessie:
Debian-8:
version: 3.5
include:
- scl.conf
@@ -18,18 +18,44 @@ jessie:
last_include:
- /etc/syslog-ng/conf.d/*.conf

stretch:
Debian-9:
version: 3.8
include:
- scl.conf
last_include:
- /etc/syslog-ng/conf.d/*.conf

Debian-10:
version: 3.12
include:
- scl.conf
last_include:
- /etc/syslog-ng/conf.d/*.conf

# Ubuntu
xenial:
Ubuntu-16.04:
version: 3.5
include:
- scl.conf
- '`scl-root`/system/tty10.conf'
last_include:
- /etc/syslog-ng/conf.d/*.conf

Ubuntu-18.04:
version: 3.13
include:
- scl.conf
last_include:
- /etc/syslog-ng/conf.d/*.conf

# Suse
Leap-15:
version: 3.19
include:
- scl.conf
last_include:
- /etc/syslog-ng/conf.d/

# CentOS
CentOS-6:
version: 3.2

+ 13
- 0
syslog_ng/osmap.yaml Parādīt failu

@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
#
# Setup variables using grains['os'] based logic.
# You just need to add the key:values for an `os` that differ
# from `defaults.yaml` + `osarch.yaml` + `os_family.yaml`.
# Only add an `os` which is/will be supported by the formula.
#
# If you do not need to provide defaults via the `os` grain,
# you will need to provide at least an empty dict in this file, e.g.
# osmap: {}
---
osmap: {}

+ 5
- 0
syslog_ng/package/init.sls Parādīt failu

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .install

+ 34
- 0
syslog_ng/package/install.sls Parādīt failu

@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import syslog_ng with context %}

{#- Simulating `grains.osfinger`, which is avoided since not available in all distros #}
{%- if [grains.os, grains.osrelease] == ['Amazon', '2'] %}
syslog_ng/package/repo:
pkgrepo.managed:
- name: epel
- humanname: Extra Packages for Enterprise Linux 7 - $basearch
- mirrorlist: https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
- enabled: 1
- gpgcheck: 1
- gpgkey: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
- failovermethod: priority
- require_in:
- pkg: syslog_ng/package/install
{%- endif %}

syslog_ng/package/install:
pkg.installed:
- name: {{ syslog_ng.package }}

{%- if syslog_ng.packages is defined and syslog_ng.packages %}
syslog_ng/packages/install:
pkg.installed:
- pkgs:
{%- for pkg in syslog_ng.packages %}
- {{ pkg.name }}{% if pkg.version is defined and pkg.version %}: '{{ pkg.version }}' {% endif %}
{%- endfor %}
{%- endif %}

+ 0
- 15
syslog_ng/packages.sls Parādīt failu

@@ -1,15 +0,0 @@
{% from "syslog_ng/map.jinja" import syslog_ng with context %}

include:
- syslog_ng

{%- if syslog_ng.packages is defined and syslog_ng.packages %}
syslog_ng_packages:
pkg.installed:
- pkgs:
{%- for pkg in syslog_ng.packages %}
- {{ pkg.name }}{% if pkg.version is defined and pkg.version %}: '{{ pkg.version }}' {% endif %}
{%- endfor %}
- watch_in:
- service: syslog_ng
{%- endif %}

+ 5
- 0
syslog_ng/service/init.sls Parādīt failu

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .running

+ 17
- 0
syslog_ng/service/running.sls Parādīt failu

@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_config_file = tplroot ~ '.config.file' %}
{%- from tplroot ~ "/map.jinja" import syslog_ng with context %}

include:
- {{ sls_config_file }}

syslog_ng/service/running:
service.running:
- name: {{ syslog_ng.service }}
- enable: true
- require:
- sls: {{ sls_config_file }}

+ 31
- 0
test/integration/default/controls/config_spec.rb Parādīt failu

@@ -0,0 +1,31 @@
control 'SyslogNG configuration' do
title 'should match desired lines'

str =
'''
source s_src {
internal();
};

destination d_syslog {
file("/var/log/syslog");
};

filter f_syslog3 {
not level(debug);
};

log {
source(s_src);
filter(f_syslog3);
destination(d_syslog);
};
'''

describe file('/etc/syslog-ng/syslog-ng.conf') do
it { should exist }

# Custom config from pillar
its('content') { should include str }
end
end

+ 7
- 0
test/integration/default/controls/package_spec.rb Parādīt failu

@@ -0,0 +1,7 @@
control 'SyslogNG package' do
title 'should be installed'

describe package('syslog-ng') do
it { should be_installed }
end
end

+ 16
- 0
test/integration/default/controls/service_spec.rb Parādīt failu

@@ -0,0 +1,16 @@
syslogng_service =
case platform[:name]
when 'arch'
'syslog-ng@default.service'
else
'syslog-ng'
end
control 'SyslogNG service' do
title 'should be running and enabled'

describe service(syslogng_service) do
it { should be_enabled }
it { should be_running }
end

end

+ 0
- 17
test/integration/default/controls/syslog_ng.rb Parādīt failu

@@ -1,17 +0,0 @@
# encoding: utf-8

title 'Test SyslogNG installation'

describe package('syslog-ng') do
it { should be_installed }
end

describe file('/etc/syslog-ng/syslog-ng.conf') do
it { should exist }
end

describe sysv_service('syslog-ng') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end

+ 1
- 0
test/integration/default/inspec.yml Parādīt failu

@@ -15,3 +15,4 @@ supports:
- platform-name: suse
- platform-name: freebsd
- platform-name: amazon
- platform-name: arch

+ 33
- 0
test/salt/pillar/syslog_ng.sls Parādīt failu

@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
syslog_ng:
options:
- chain_hostnames: false
- flush_lines: 0
- use_dns: false
- use_fqdn: false
- owner: root
- group: adm
- perm: =0640
- stats_freq: 0
- bad_hostname: "^gconfd$"

source:
- s_src:
- internal: null

destination:
- d_syslog:
- file:
- /var/log/syslog

filter:
- f_syslog3:
- =not level(debug)

log:
-
- source: =s_src
- filter: =f_syslog3
- destination: =d_syslog

Notiek ielāde…
Atcelt
Saglabāt