test(inspec): expand unittests for archive format

This commit is contained in:
N 2019-06-16 01:22:14 +01:00
parent 1f86f4a27c
commit b074bd3dee
No known key found for this signature in database
GPG Key ID: 55A292EAB4E54067
8 changed files with 174 additions and 27 deletions

View File

@ -4,6 +4,7 @@
prometheus: prometheus:
pkg: pkg:
name: prometheus name: prometheus
use_upstream_archive: False
archive: archive:
source: https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz source: https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz
source_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7 source_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7

View File

@ -9,9 +9,16 @@
prometheus-package-archive-install-file-directory: prometheus-package-archive-install-file-directory:
file.directory: file.directory:
- name: {{ prometheus.pkg.archive.name }} - name: {{ prometheus.pkg.archive.name }}
- user: root
- group: root
- mode: 755
- makedirs: True - makedirs: True
- require_in: - require_in:
- archive: prometheus-package-archive-install-archive-extracted - archive: prometheus-package-archive-install-archive-extracted
- recurse:
- user
- group
- mode
prometheus-package-archive-install-archive-extracted: prometheus-package-archive-install-archive-extracted:
archive.extracted: archive.extracted:
@ -21,3 +28,8 @@ prometheus-package-archive-install-archive-extracted:
until: True until: True
interval: 60 interval: 60
splay: 10 splay: 10
- user: root
- group: root
- recurse:
- user
- group

View File

@ -3,26 +3,33 @@
{#- Get the `tplroot` from `tpldir` #} {#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %} {%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_service_clean = tplroot ~ '.service.clean' %} {%- from tplroot ~ "/map.jinja" import golang with context %}
{%- from tplroot ~ "/map.jinja" import prometheus with context %} {%- set sls_archive_clean = tplroot ~ '.archive.clean' %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
{%- if grains.kernel|lower == 'linux' and golang.linux.altpriority|int > 0 %}
include: include:
- {{ sls_service_clean }} - {{ sls_archive_clean }}
prometheus-config-clean-file-absent:
file.absent:
- names:
- {{ prometheus.config_file }}
- {{ prometheus.environ_file }}
- require:
- sls: {{ sls_service_clean }}
{%- if salt['grains.get']('os_family') == 'FreeBSD' %} golang-package-archive-remove-home-alternative-remove:
{%- for parameter in ['args', 'data_dir'] %} alternatives.remove:
prometheus-service-args-{{ parameter }}: - name: golang-home
sysrc.absent: - path: {{ golang.base_dir }}/go
- name: prometheus_{{ parameter }} - onlyif: update-alternatives --get-selections |grep ^golang-home
- require: - require:
- service: prometheus-service-clean-service-dead - sls: {{ sls_archive_clean }}
{%- endfor %}
{%- endif %} {% for i in ['go', 'godoc', 'gofmt'] %}
golang-package-archive-remove-{{ i }}-alternative-remove:
alternatives.remove:
- name: link-{{ i }}
- path: {{ golang.base_dir }}/go/bin/{{ i }}
- onlyif: update-alternatives --get-selections |grep ^link-{{ i }}
- require:
- sls: {{ sls_archive_clean }}
{% endfor %}
{%- endif %}

View File

@ -1,7 +1,70 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vim: ft=sls # vim: ft=sls
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import golang with context %}
{%- set sls_archive_install = tplroot ~ '.archive.install' %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
{%- if grains.kernel|lower == 'linux' and golang.linux.altpriority|int > 0 %}
include: include:
- .args - {{ sls_archive_install }}
- .file
- .environ golang-package-archive-install-home-alternative-install:
cmd.run:
- name: update-alternatives --install {{ golang.go_root }} golang-home {{ golang.base_dir }}/go {{ golang.linux.altpriority }}
- watch:
- archive: golang-package-archive-install-archive-extracted
- require:
- sls: {{ sls_archive_install }}
- onlyif: {{ grains.os_family in ('Suse',) }}
alternatives.install:
- name: golang-home
- link: {{ golang.go_root }}
- path: {{ golang.base_dir }}/go
- priority: {{ golang.linux.altpriority }}
- order: 10
- watch:
- archive: golang-package-archive-install-archive-extracted
- unless: {{ grains.os_family in ('Suse',) }}
- require:
- sls: {{ sls_archive_install }}
golang-package-archive-install-home-alternative-set:
alternatives.set:
- name: golang-home
- path: {{ golang.base_dir }}/go
- require:
- alternatives: golang-package-archive-install-home-alternative-install
- unless: {{ grains.os_family in ('Suse',) }}
{% for i in ['go', 'godoc', 'gofmt'] %}
golang-package-archive-install-{{ i }}-alternative-install:
cmd.run:
- name: update-alternatives --install /usr/bin/{{i}} link-{{i}} {{ golang.base_dir }}/go/bin/{{i}} {{golang.linux.altpriority}}
- require:
- cmd: golang-package-archive-install-home-alternative-install
- onlyif: {{ grains.os_family in ('Suse',) }}
alternatives.install:
- name: link-{{ i }}
- link: /usr/bin/{{ i }}
- path: {{ golang.base_dir }}/go/bin/{{ i }}
- priority: {{ golang.linux.altpriority }}
- order: 10
- require:
- alternatives: golang-package-archive-install-home-alternative-install
- unless: {{ grains.os_family in ('Suse',) }}
golang-package-archive-install-{{ i }}-alternative-set:
alternatives.set:
- name: link-{{ i }}
- path: {{ golang.base_dir }}/go/bin/{{ i }}
- require:
- alternatives: golang-package-archive-install-{{ i }}-alternative-install
- unless: {{ grains.os_family in ('Suse',) }}
{% endfor %}
{%- endif %}

View File

@ -2,6 +2,8 @@
# vim: ft=yaml # vim: ft=yaml
--- ---
prometheus: prometheus:
dir:
root: /opt
version: '2.10.0' version: '2.10.0'
pkg: pkg:
name: prometheus name: prometheus

View File

@ -0,0 +1,50 @@
# Default InSpec Profile
This shows the implementation of the Default InSpec [profile](https://github.com/inspec/inspec/blob/master/docs/profiles.md).
## Verify a profile
InSpec ships with built-in features to verify a profile structure.
```bash
$ inspec check default
Summary
-------
Location: default
Profile: profile
Controls: 4
Timestamp: 2019-06-24T23:09:01+00:00
Valid: true
Errors
------
Warnings
--------
```
## Execute a profile
To run all **supported** controls on a local machine use `inspec exec /path/to/profile`.
```bash
$ inspec exec default
..
Finished in 0.0025 seconds (files took 0.12449 seconds to load)
8 examples, 0 failures
```
## Execute a specific control from a profile
To run one control from the profile use `inspec exec /path/to/profile --controls name`.
```bash
$ inspec exec default --controls package
.
Finished in 0.0025 seconds (files took 0.12449 seconds to load)
1 examples, 0 failures
```
See an [example control here](https://github.com/inspec/inspec/blob/master/examples/profile/controls/example.rb).

View File

@ -0,0 +1,12 @@
control 'template configuration environment' do
title 'should match desired lines'
describe file('/etc/default/prometheus.sh') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its('mode') { should cmp '0644' }
its('content') { should include 'Your changes may be overwritten' }
its('content') { should include 'export PATH=${PATH}:/opt/prometheus-2.10.0.linux-amd64' }
end
end

View File

@ -4,9 +4,9 @@ maintainer: Alexander Weidinger
license: Apache-2.0 license: Apache-2.0
summary: Verify that the prometheus formula is setup and configured correctly summary: Verify that the prometheus formula is setup and configured correctly
supports: supports:
- os-name: debian - platform-name: debian
- os-name: ubuntu - platform-name: ubuntu
- os-name: centos - platform-name: centos
- os-name: fedora - platform-name: fedora
- os-name: opensuse - platform-name: opensuse
- os-name: freebsd - platform-name: freebsd