Skip to content

Commit 125affc

Browse files
committed
chore: use semantic-release cross-formula standard structure
* Automated using `ssf-formula` (v0.1.0-rc.2)
2 parents df61837 + b48eff7 commit 125affc

File tree

9 files changed

+155
-51
lines changed

9 files changed

+155
-51
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ coverage.xml
4848
.kitchen
4949
.kitchen.local.yml
5050
kitchen.local.yml
51+
junit-*.xml
5152

5253
# Translations
5354
*.mo
@@ -103,5 +104,19 @@ ENV/
103104
# mypy
104105
.mypy_cache/
105106

107+
# Bundler
108+
Gemfile.lock
109+
106110
# copied `.md` files used for conversion to `.rst` using `m2r`
107111
docs/*.md
112+
113+
# Vim
114+
*.sw?
115+
116+
## Collected when centralising formulas (check and sort)
117+
# `collectd-formula`
118+
.pytest_cache/
119+
/.idea/
120+
Dockerfile.*_*
121+
ignore/
122+
tmp/

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
14
stages:
25
- test
36
- commitlint
@@ -7,6 +10,7 @@ stages:
710
sudo: required
811
cache: bundler
912
language: ruby
13+
dist: xenial
1014

1115
services:
1216
- docker
@@ -29,19 +33,15 @@ env:
2933
# - INSTANCE: default-ubuntu-1604-2018-3-py2
3034
# - INSTANCE: default-centos-7-2018-3-py2
3135
# - INSTANCE: default-fedora-29-2018-3-py2
32-
# TODO: Use this when fixed instead of `opensuse-leap-42`
33-
# Ref: https://github.com/netmanagers/salt-image-builder/issues/2
34-
# - INSTANCE: default-opensuse-leap-15-2018-3-py2
3536
- INSTANCE: default-opensuse-leap-42-2018-3-py2
3637
# - INSTANCE: default-debian-8-2017-7-py2
3738
# - INSTANCE: default-ubuntu-1604-2017-7-py2
38-
# TODO: Enable after improving the formula to work with other than `systemd`
3939
- INSTANCE: default-centos-6-2017-7-py2
4040
# - INSTANCE: default-fedora-28-2017-7-py2
4141
# - INSTANCE: default-opensuse-leap-42-2017-7-py2
4242

4343
script:
44-
- bundle exec kitchen verify ${INSTANCE}
44+
- bin/kitchen verify ${INSTANCE}
4545

4646
jobs:
4747
include:

bin/kitchen

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'kitchen' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
14+
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
16+
17+
if File.file?(bundle_binstub)
18+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19+
load(bundle_binstub)
20+
else
21+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23+
end
24+
end
25+
26+
require "rubygems"
27+
require "bundler/setup"
28+
29+
load Gem.bin_path("test-kitchen", "kitchen")

chrony/libtofs.jinja

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,25 @@
8383
{%- for fs in fsl %}
8484
{%- for src_file in src_files %}
8585
{%- if fs %}
86-
{%- set fs_dir = salt['config.get'](fs, fs) %}
86+
{%- set fs_dirs = salt['config.get'](fs, fs) %}
8787
{%- else %}
88-
{%- set fs_dir = salt['config.get'](tplroot ~ ':tofs:dirs:default', 'default') %}
88+
{%- set fs_dirs = salt['config.get'](tplroot ~ ':tofs:dirs:default', 'default') %}
8989
{%- endif %}
90-
{%- set url = '- salt://' ~ '/'.join([
91-
path_prefix_inc_ext,
92-
files_dir,
93-
fs_dir,
94-
src_file.lstrip('/')
95-
]) %}
90+
{#- Force the `config.get` lookup result as a list where necessary #}
91+
{#- since we need to also handle grains that are lists #}
92+
{%- if fs_dirs is string %}
93+
{%- set fs_dirs = [fs_dirs] %}
94+
{%- endif %}
95+
{%- for fs_dir in fs_dirs %}
96+
{%- set url = [
97+
'- salt:/',
98+
path_prefix_inc_ext.strip('/'),
99+
files_dir.strip('/'),
100+
fs_dir.strip('/'),
101+
src_file.strip('/'),
102+
] | select | join('/') %}
96103
{{ url | indent(indent_width, true) }}
104+
{%- endfor %}
97105
{%- endfor %}
98106
{%- endfor %}
99107
{%- endfor %}

docs/CONTRIBUTING.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,5 @@ An example of that:
155155
156156
BREAKING CHANGE: With the removal of all of the `.sls` files under
157157
`template package`, this formula no longer supports the installation of
158-
packages.
158+
packages.
159+

docs/TOFS_pattern.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Using SaltStack is a simple and effective way to implement configuration managem
3939

4040
To avoid this situation we can use the `pillar mechanism <http://docs.saltstack.com/en/latest/topics/pillar/>`_, which is designed to provide controlled access to data from the minions based on some selection rules. As pillar data could be easily integrated in the `Jinja <http://docs.saltstack.com/en/latest/topics/tutorials/pillar.html>`_ templates, it is a good mechanism to store values to be used in the final rendering of state files and templates.
4141

42-
There are a variety of approaches on the usage of pillar and templates as seen in the `saltstack-formulas <https://github.com/saltstack-formulas>`_' repositories. `Some <https://github.com/saltstack-formulas/nginx-formula/pull/18>`_ `developments <https://github.com/saltstack-formulas/php-formula/pull/14>`_ stress the initial purpose of pillar data into a storage for most of the possible variables for a determined system configuration. This, in my opinion, is shifting too much load from the original template files approach. Adding up some `non-trivial Jinja <https://github.com/spsoit/nginx-formula/blob/81de880fe0276dd9488ffa15bc78944c0fc2b919/nginx/ng/files/nginx.conf>`_ code as essential part of composing the state file definitely makes SaltStack state files (hence formulas) more difficult to read. The extreme of this approach is that we could end up with a new render mechanism, implemented in Jinja, storing everything needed in pillar data to compose configurations. Additionally, we are establishing a strong dependency with the Jinja renderer.
42+
There are a variety of approaches on the usage of pillar and templates as seen in the `saltstack-formulas <https://github.com/saltstack-formulas>`_' repositories. `Some <https://github.com/saltstack-formulas/nginx-formula/pull/18>`_ `developments <https://github.com/saltstack-formulas/php-formula/pull/14>`_ stress the initial purpose of pillar data into a storage for most of the possible variables for a determined system configuration. This, in my opinion, is shifting too much load from the original template files approach. Adding up some `non-trivial Jinja <https://github.com/saltstack-formulas/nginx-formula/blob/f74254c07e188bd448eaf1c5f9c802d78c4c005e/nginx/files/default/nginx.conf>`_ code as essential part of composing the state file definitely makes SaltStack state files (hence formulas) more difficult to read. The extreme of this approach is that we could end up with a new render mechanism, implemented in Jinja, storing everything needed in pillar data to compose configurations. Additionally, we are establishing a strong dependency with the Jinja renderer.
4343

4444
In opposition to the *put the code in file_roots and the data in pillars* approach, there is the *pillar as a store for a set of key-values* approach. A full-blown configuration file abstracted in pillar and jinja is complicated to develop, understand and maintain. I think a better and simpler approach is to keep a configuration file templated using just a basic (non-extensive but extensible) set of pillar values.
4545

@@ -325,6 +325,7 @@ We can simplify the ``conf.sls`` with the new ``files_switch`` macro to use in t
325325
326326
327327
* This uses ``config.get``, searching for ``ntp:tofs:source_files:Configure NTP`` to determine the list of template files to use.
328+
* If this returns a result, the default of ``['/etc/ntp.conf.jinja']`` will be appended to it.
328329
* If this does not yield any results, the default of ``['/etc/ntp.conf.jinja']`` will be used.
329330

330331
In ``libtofs.jinja``, we define this new macro ``files_switch``.
@@ -426,18 +427,20 @@ The list of ``source_files`` can be given:
426427
tofs:
427428
source_files:
428429
Configure NTP:
429-
- '/etc/ntp.conf.jinja'
430430
- '/etc/ntp.conf_alt.jinja'
431431
432432
Resulting in:
433433

434434
.. code-block:: sls
435-
435+
436436
- source:
437-
- salt://ntp/files/theminion/etc/ntp.conf.jinja
438437
- salt://ntp/files/theminion/etc/ntp.conf_alt.jinja
439-
- salt://ntp/files/Debian/etc/ntp.conf.jinja
438+
- salt://ntp/files/theminion/etc/ntp.conf.jinja
440439
- salt://ntp/files/Debian/etc/ntp.conf_alt.jinja
441-
- salt://ntp/files/default/etc/ntp.conf.jinja
440+
- salt://ntp/files/Debian/etc/ntp.conf.jinja
442441
- salt://ntp/files/default/etc/ntp.conf_alt.jinja
442+
- salt://ntp/files/default/etc/ntp.conf.jinja
443+
444+
Note: This does *not* override the default value.
445+
Rather, the value from the pillar/config is prepended to the default.
443446

kitchen.yml

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ platforms:
4444
- sh bootstrap-salt.sh -XdPbfrq -x python3 git develop
4545
run_command: /usr/lib/systemd/systemd
4646

47-
## SALT 2019.2
47+
## SALT `2019.2`
4848
- name: debian-9-2019-2-py3
4949
driver:
5050
image: netmanagers/salt-2019.2-py3:debian-9
@@ -62,7 +62,7 @@ platforms:
6262
image: netmanagers/salt-2019.2-py3:opensuse-leap-15
6363
run_command: /usr/lib/systemd/systemd
6464

65-
## SALT 2018.3
65+
## SALT `2018.3`
6666
- name: debian-9-2018-3-py2
6767
driver:
6868
image: netmanagers/salt-2018.3-py2:debian-9
@@ -75,25 +75,18 @@ platforms:
7575
- name: fedora-29-2018-3-py2
7676
driver:
7777
image: netmanagers/salt-2018.3-py2:fedora-29
78-
# TODO: Use this when fixed instead of `opensuse-leap-42`
79-
# Ref: https://github.com/netmanagers/salt-image-builder/issues/2
80-
# - name: opensuse-leap-15-2018-3-py2
81-
# driver:
82-
# image: netmanagers/salt-2018.3-py2:opensuse-leap-15
83-
# run_command: /usr/lib/systemd/systemd
8478
- name: opensuse-leap-42-2018-3-py2
8579
driver:
8680
image: netmanagers/salt-2018.3-py2:opensuse-leap-42
8781
run_command: /usr/lib/systemd/systemd
8882

89-
## SALT 2017.7
83+
## SALT `2017.7`
9084
- name: debian-8-2017-7-py2
9185
driver:
9286
image: netmanagers/salt-2017.7-py2:debian-8
9387
- name: ubuntu-1604-2017-7-py2
9488
driver:
9589
image: netmanagers/salt-2017.7-py2:ubuntu-16.04
96-
# TODO: Modify the formula to work for non-`systemd` platforms
9790
- name: centos-6-2017-7-py2
9891
driver:
9992
image: netmanagers/salt-2017.7-py2:centos-6
@@ -115,17 +108,6 @@ provisioner:
115108
salt_copy_filter:
116109
- .kitchen
117110
- .git
118-
state_top:
119-
base:
120-
'*':
121-
- chrony
122-
pillars:
123-
top.sls:
124-
base:
125-
'*':
126-
- chrony
127-
pillars_from_files:
128-
chrony.sls: pillar.example
129111

130112
verifier:
131113
# https://www.inspec.io/
@@ -134,8 +116,21 @@ verifier:
134116
# cli, documentation, html, progress, json, json-min, json-rspec, junit
135117
reporter:
136118
- cli
137-
inspec_tests:
138-
- path: test/integration/default
139119

140120
suites:
141121
- name: default
122+
provisioner:
123+
state_top:
124+
base:
125+
'*':
126+
- chrony
127+
pillars:
128+
top.sls:
129+
base:
130+
'*':
131+
- chrony
132+
pillars_from_files:
133+
chrony.sls: pillar.example
134+
verifier:
135+
inspec_tests:
136+
- path: test/integration/default

test/integration/default/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# InSpec Profile: `default`
2+
3+
This shows the implementation of the `default` InSpec [profile](https://github.com/inspec/inspec/blob/master/docs/profiles.md).
4+
5+
## Verify a profile
6+
7+
InSpec ships with built-in features to verify a profile structure.
8+
9+
```bash
10+
$ inspec check default
11+
Summary
12+
-------
13+
Location: default
14+
Profile: profile
15+
Controls: 4
16+
Timestamp: 2019-06-24T23:09:01+00:00
17+
Valid: true
18+
19+
Errors
20+
------
21+
22+
Warnings
23+
--------
24+
```
25+
26+
## Execute a profile
27+
28+
To run all **supported** controls on a local machine use `inspec exec /path/to/profile`.
29+
30+
```bash
31+
$ inspec exec default
32+
..
33+
34+
Finished in 0.0025 seconds (files took 0.12449 seconds to load)
35+
8 examples, 0 failures
36+
```
37+
38+
## Execute a specific control from a profile
39+
40+
To run one control from the profile use `inspec exec /path/to/profile --controls name`.
41+
42+
```bash
43+
$ inspec exec default --controls package
44+
.
45+
46+
Finished in 0.0025 seconds (files took 0.12449 seconds to load)
47+
1 examples, 0 failures
48+
```
49+
50+
See an [example control here](https://github.com/inspec/inspec/blob/master/examples/profile/controls/example.rb).
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
name: chrony
2-
title: Chrony Formula
3-
maintainer: Your Name
1+
name: default
2+
title: chrony formula
3+
maintainer: SaltStack Formulas
44
license: Apache-2.0
55
summary: Verify that the chrony formula is setup and configured correctly
66
supports:
7-
- os-name: debian
8-
- os-name: ubuntu
9-
- os-name: centos
10-
- os-name: fedora
11-
- os-name: opensuse
7+
- platform-name: debian
8+
- platform-name: ubuntu
9+
- platform-name: centos
10+
- platform-name: fedora
11+
- platform-name: opensuse
12+
- platform-name: suse
13+
- platform-name: freebsd
14+
- platform-name: amazon

0 commit comments

Comments
 (0)