Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade formula to new standards #23

Merged
merged 15 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
before_install: skip
script:
# Install and run `yamllint`
- pip install --user yamllint
# yamllint disable-line rule:line-length
- yamllint -s . .yamllint pillar.example pillar.debian.example
# Need at least `v1.17.0` for the `yaml-files` setting
- pip install --user yamllint>=1.17.0
- yamllint -s .
# Install and run `commitlint`
- npm install @commitlint/config-conventional -D
- npm install @commitlint/travis-cli -D
Expand Down
14 changes: 14 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,24 @@ extends: default

# Files to ignore completely
# 1. All YAML files under directory `node_modules/`, introduced during the Travis run
# 2. Any SLS files under directory `test/`, which are actually state files
ignore: |
node_modules/
test/**/states/**/*.sls
yaml-files:
# Default settings
- '*.yaml'
- '*.yml'
- .yamllint
# SaltStack Formulas additional settings
- '*.example'
- test/**/*.sls

rules:
empty-values:
forbid-in-block-mappings: true
forbid-in-flow-mappings: true
line-length:
# Increase from default of `80`
# Based on https://github.com/PyCQA/flake8-bugbear#opinionated-warnings (`B950`)
Expand Down
30 changes: 17 additions & 13 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,18 @@ 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.

``syslog_ng.config``
^^^^^^^^^^^^^^^^^^^^
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
-------

Expand All @@ -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.
25 changes: 22 additions & 3 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -129,10 +144,14 @@ 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
log_level: info
log_level: debug
salt_install: none
require_chef: false
formula: syslog_ng
Expand All @@ -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
15 changes: 0 additions & 15 deletions syslog_ng/config.sls

This file was deleted.

23 changes: 23 additions & 0 deletions syslog_ng/config/file.sls
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions syslog_ng/config/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .file
8 changes: 8 additions & 0 deletions syslog_ng/defaults.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 0 additions & 4 deletions syslog_ng/defaults.yml

This file was deleted.

8 changes: 6 additions & 2 deletions syslog_ng/files/syslog-ng.conf
Original file line number Diff line number Diff line change
@@ -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') }}

Expand Down
16 changes: 6 additions & 10 deletions syslog_ng/init.sls
Original file line number Diff line number Diff line change
@@ -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
56 changes: 42 additions & 14 deletions syslog_ng/map.jinja
Original file line number Diff line number Diff line change
@@ -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 %}
20 changes: 0 additions & 20 deletions syslog_ng/os_family_map.yml

This file was deleted.

Loading