Преглед на файлове

Merge pull request #8 from saltstack-formulas/add_kitchen

Add Kitchen tests
tags/v0.2.0
Nitin Madhok преди 7 години
родител
ревизия
070ff2bb4d
No account linked to committer's email address
променени са 19 файла, в които са добавени 265 реда и са изтрити 108 реда
  1. +2
    -0
      .gitignore
  2. +55
    -0
      .kitchen.yml
  3. +15
    -0
      .travis.yml
  4. +8
    -0
      Gemfile
  5. +10
    -11
      LICENSE
  6. +17
    -0
      README.md
  7. +0
    -33
      README.rst
  8. +4
    -2
      pillar.example
  9. +0
    -1
      syslog_ng/config.sls
  10. +4
    -0
      syslog_ng/defaults.yml
  11. +20
    -39
      syslog_ng/files/syslog-ng.conf
  12. +0
    -1
      syslog_ng/init.sls
  13. +27
    -0
      syslog_ng/macro.jinja
  14. +21
    -20
      syslog_ng/map.jinja
  15. +35
    -0
      syslog_ng/os_codename_map.yml
  16. +20
    -0
      syslog_ng/os_family_map.yml
  17. +0
    -1
      syslog_ng/packages.sls
  18. +17
    -0
      test/integration/syslog_ng/controls/syslog_ng.rb
  19. +10
    -0
      test/integration/syslog_ng/inspec.yml

+ 2
- 0
.gitignore Целия файл

@@ -0,0 +1,2 @@
.kitchen/
Gemfile.lock

+ 55
- 0
.kitchen.yml Целия файл

@@ -0,0 +1,55 @@
<%
distrib, infos = ENV.fetch('DISTRIB', 'debian:stretch/9').split(':')
codename, version = infos.split('/')
%>
---
driver:
name: docker
use_sudo: false

provisioner:
name: salt_solo
formula: syslog_ng

# Install Salt from official repositories
salt_install: apt
salt_version: latest
salt_apt_repo: http://repo.saltstack.com/apt/<%= distrib %>/<%= version %>/amd64
salt_apt_repo_key: http://repo.saltstack.com/apt/<%= distrib %>/<%= version %>/amd64/latest/SALTSTACK-GPG-KEY.pub

# Don't install Chef
require_chef: false

# Configure Salt
state_top:
base:
'*':
- syslog_ng.config

<% if %w[wheezy jessie xenial].include?(codename) %>
pillars:
top.sls:
base:
'*':
- syslog_ng
syslog_ng.sls:
syslog_ng:
source:
- s_src:
- unix-stream:
- /dev/log
- internal: null
<% end %>

platforms:
- name: <%= distrib %>-<%= codename %>
driver_config:
image: "<%= distrib %>:<%= codename %>"
platform: <%= distrib %>

verifier:
name: inspec
format: progress

suites:
- name: syslog_ng

+ 15
- 0
.travis.yml Целия файл

@@ -0,0 +1,15 @@
language: ruby
sudo: required
cache: bundler
rvm:
- 2.3.5
services:
- docker
script:
- bundle exec kitchen test
env:
matrix:
- DISTRIB=debian:wheezy/7
- DISTRIB=debian:jessie/8
- DISTRIB=debian:stretch/9
- DISTRIB=ubuntu:xenial/16.04

+ 8
- 0
Gemfile Целия файл

@@ -0,0 +1,8 @@
source 'https://rubygems.org'
ruby '2.3.5'

gem 'test-kitchen'
gem 'kitchen-docker'
gem 'kitchen-salt'
gem 'kitchen-inspec'
gem 'rake'

+ 10
- 11
LICENSE Целия файл

@@ -1,14 +1,13 @@
Copyright (c) 2013-2015 Salt Stack Formulas
Copyright (c) 2013-2017 Salt Stack Formulas

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

+ 17
- 0
README.md Целия файл

@@ -0,0 +1,17 @@
# SyslogNG Salt Formula

[![Build Status](https://travis-ci.org/saltstack-formulas/syslog-ng-formula.svg?branch=master)](https://travis-ci.org/saltstack-formulas/syslog-ng-formula)

Install and configure the syslog-ng service.

Note: See the full [Salt Formulas installation and usage instructions](http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html).

## Available states

* `syslog_ng` : Installs the `syslog-ng` package
* `syslog_ng.config` : Installs and configures the `syslog-ng` package
* `syslog_ng.packages` : Install optional packages which may provide additional functionalities

## Available pillars

You can take a loot at [`pillar.example`](https://github.com/saltstack-formulas/syslog-ng-formula/blob/master/pillar.example) to configure SyslogNG with pillars.

+ 0
- 33
README.rst Целия файл

@@ -1,33 +0,0 @@
=========
syslog-ng
=========

Install and configure the syslog-ng service.

.. note::

See the full `Salt Formulas installation and usage instructions
<http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html>`_.

Available states
================

.. contents::
:local:

``syslog_ng``
-------

Install the ``syslog-ng`` package.

``syslog_ng.config``
-----------

Install and configure the ``syslog-ng`` package.

note: if the first character of a string is '=' the string is treated as a literal (not ecapsulated in quotes)

``syslog_ng.packages``
-----------

Install optional packages which may provide additional functionality.

+ 4
- 2
pillar.example Целия файл

@@ -2,7 +2,9 @@ syslog_ng:
module:
- tfson
include:
- /etc/syslog-ng/conf.d/
- scl.conf
last_include:
- /etc/syslog-ng/conf.d/*.conf
version: 3.5
options:
- threaded: yes
@@ -12,7 +14,7 @@ syslog_ng:
- chain_hostnames: no
- check_hostname: no
source:
- s_internal:
- s_internal:
- internal: null
- s_local:
- unix-stream: /dev/log

+ 0
- 1
syslog_ng/config.sls Целия файл

@@ -13,4 +13,3 @@ syslog_ng.conf:
- mode: 644
- watch_in:
- service: syslog_ng

+ 4
- 0
syslog_ng/defaults.yml Целия файл

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

syslog_ng: {}

+ 20
- 39
syslog_ng/files/syslog-ng.conf Целия файл

@@ -1,62 +1,43 @@
{%- set syslog_config = pillar.get('syslog_ng', {}) -%}

{%- macro rule_builder(rule) -%}
{%- if rule is none -%}
{%- elif rule is sameas true -%}
yes
{%- elif rule is sameas false -%}
no
{%- elif rule is number -%}
{{ rule }}
{%- elif rule is mapping -%}
{%- for k, v in rule.items() -%}
{{ k }}({{ rule_builder(v) }})
{%- endfor -%}
{%- elif rule is iterable and rule is not string -%}
{%- for v in rule -%}
{{ rule_builder(v) }}
{%- endfor -%}
{%- else -%}
{%- if rule[0] == '=' -%}
{{ rule[1:] }}
{%- else -%}
"{{ rule }}"
{%- endif -%}
{%- endif -%}
{%- endmacro -%}

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

{%- for module in syslog_config.get('module', []) %}
{%- from "syslog_ng/macro.jinja" import rule_builder -%}
{%- from "syslog_ng/map.jinja" import syslog_ng with context -%}

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

{%- for module in syslog_ng.get('module', []) %}
@module {{ rule_builder(module) }}
{%- endfor %}

{%- for inc in syslog_config.get('include', []) %}
{%- for inc in syslog_ng.get('include', []) %}
@include {{ rule_builder(inc) }}
{%- endfor %}

options {
{%- for rule in syslog_config.get('options', []) %}
{{ rule_builder(rule) }};
{%- for rule in syslog_ng.get('options', []) %}
{{ rule_builder(rule) }};
{%- endfor %}
};

{%- for obj in ('source', 'destination', 'filter', 'parser', 'rewrite', 'template') %}
{%- for params in syslog_config.get(obj, []) %}
{%- for params in syslog_ng.get(obj, []) %}
{% for name, rules in params.items() %}
{{ obj }} {{ name }} {
{%- for rule in rules %}
{{ rule_builder(rule) }};
{%- endfor %}
{%- for rule in rules %}
{{ rule_builder(rule) }};
{%- endfor %}
};
{%- endfor %}
{%- endfor %}
{%- endfor %}

{% for loggers in syslog_config.get('log', []) -%}
{% for loggers in syslog_ng.get('log', []) -%}
log {
{%- for rule in loggers %}
{{ rule_builder(rule) }};
{{ rule_builder(rule) }};
{%- endfor %}
};

{% endfor %}

{%- for inc in syslog_ng.get('last_include', []) %}
@include {{ rule_builder(inc) }}
{%- endfor %}

+ 0
- 1
syslog_ng/init.sls Целия файл

@@ -9,4 +9,3 @@ syslog_ng:
- name: {{ syslog_ng.service }}
- watch:
- pkg: syslog_ng


+ 27
- 0
syslog_ng/macro.jinja Целия файл

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# vim: ft=jinja

{%- macro rule_builder(rule) -%}
{%- if rule is none -%}
{%- elif rule is sameas true -%}
yes
{%- elif rule is sameas false -%}
no
{%- elif rule is number -%}
{{ rule }}
{%- elif rule is mapping -%}
{%- for k, v in rule.items() -%}
{{ k }}({{ rule_builder(v) }})
{%- endfor -%}
{%- elif rule is iterable and rule is not string -%}
{%- for v in rule -%}
{{ rule_builder(v) }}
{%- endfor -%}
{%- else -%}
{%- if rule[0] == '=' -%}
{{ rule[1:] }}
{%- else -%}
"{{ rule }}"
{%- endif -%}
{%- endif -%}
{%- endmacro -%}

+ 21
- 20
syslog_ng/map.jinja Целия файл

@@ -1,20 +1,21 @@
{% set syslog_ng = salt['grains.filter_by']({
'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',
},
}, merge=salt['pillar.get']('syslog_ng:lookup')) %}
# -*- 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 settings for the os_family grain #}
{% set osfam = salt['grains.filter_by'](os_family_map) or {} %}

{# 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 {} %}

{# merge the os family/os codename specific data over the defaults #}
{% do defaults.syslog_ng.update(oscode) %}

{# 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) %}

+ 35
- 0
syslog_ng/os_codename_map.yml Целия файл

@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml

# Debian
wheezy:
version: 3.3
include:
- scl.conf
- '`scl-root`/system/tty10.conf'
last_include:
- /etc/syslog-ng/conf.d/

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

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

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

+ 20
- 0
syslog_ng/os_family_map.yml Целия файл

@@ -0,0 +1,20 @@
# -*- 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

+ 0
- 1
syslog_ng/packages.sls Целия файл

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


include:
- syslog_ng


+ 17
- 0
test/integration/syslog_ng/controls/syslog_ng.rb Целия файл

@@ -0,0 +1,17 @@
# 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

+ 10
- 0
test/integration/syslog_ng/inspec.yml Целия файл

@@ -0,0 +1,10 @@
name: syslog_ng
title: SyslogNG Profile
maintainer: Nicolas Rodriguez
copyright: Nicolas Rodriguez
copyright_email: nicoladmin@free.fr
license: MIT
summary: SyslogNG Compliance Profile
version: 0.1.0
supports:
- os-name: debian

Loading…
Отказ
Запис