test(inspec): expand unittests for archive format
This commit is contained in:
parent
1f86f4a27c
commit
b074bd3dee
@ -4,6 +4,7 @@
|
||||
prometheus:
|
||||
pkg:
|
||||
name: prometheus
|
||||
use_upstream_archive: False
|
||||
archive:
|
||||
source: https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz
|
||||
source_hash: f4233783826f18606b79e5cef0686e4a9c2030146a3c7ce134f0add09f5adcb7
|
||||
|
@ -9,9 +9,16 @@
|
||||
prometheus-package-archive-install-file-directory:
|
||||
file.directory:
|
||||
- name: {{ prometheus.pkg.archive.name }}
|
||||
- user: root
|
||||
- group: root
|
||||
- mode: 755
|
||||
- makedirs: True
|
||||
- require_in:
|
||||
- archive: prometheus-package-archive-install-archive-extracted
|
||||
- recurse:
|
||||
- user
|
||||
- group
|
||||
- mode
|
||||
|
||||
prometheus-package-archive-install-archive-extracted:
|
||||
archive.extracted:
|
||||
@ -21,3 +28,8 @@ prometheus-package-archive-install-archive-extracted:
|
||||
until: True
|
||||
interval: 60
|
||||
splay: 10
|
||||
- user: root
|
||||
- group: root
|
||||
- recurse:
|
||||
- user
|
||||
- group
|
||||
|
@ -3,26 +3,33 @@
|
||||
|
||||
{#- Get the `tplroot` from `tpldir` #}
|
||||
{%- set tplroot = tpldir.split('/')[0] %}
|
||||
{%- set sls_service_clean = tplroot ~ '.service.clean' %}
|
||||
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
|
||||
{%- from tplroot ~ "/map.jinja" import golang 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:
|
||||
- {{ 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' %}
|
||||
{%- for parameter in ['args', 'data_dir'] %}
|
||||
prometheus-service-args-{{ parameter }}:
|
||||
sysrc.absent:
|
||||
- name: prometheus_{{ parameter }}
|
||||
golang-package-archive-remove-home-alternative-remove:
|
||||
alternatives.remove:
|
||||
- name: golang-home
|
||||
- path: {{ golang.base_dir }}/go
|
||||
- onlyif: update-alternatives --get-selections |grep ^golang-home
|
||||
- require:
|
||||
- service: prometheus-service-clean-service-dead
|
||||
{%- endfor %}
|
||||
{%- endif %}
|
||||
- sls: {{ sls_archive_clean }}
|
||||
|
||||
{% 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 %}
|
||||
|
@ -1,7 +1,70 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# 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:
|
||||
- .args
|
||||
- .file
|
||||
- .environ
|
||||
- {{ sls_archive_install }}
|
||||
|
||||
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 %}
|
||||
|
@ -2,6 +2,8 @@
|
||||
# vim: ft=yaml
|
||||
---
|
||||
prometheus:
|
||||
dir:
|
||||
root: /opt
|
||||
version: '2.10.0'
|
||||
pkg:
|
||||
name: prometheus
|
||||
|
50
test/integration/default/README.md
Normal file
50
test/integration/default/README.md
Normal 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).
|
12
test/integration/default/controls/environ_spec.rb
Normal file
12
test/integration/default/controls/environ_spec.rb
Normal 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
|
@ -4,9 +4,9 @@ maintainer: Alexander Weidinger
|
||||
license: Apache-2.0
|
||||
summary: Verify that the prometheus formula is setup and configured correctly
|
||||
supports:
|
||||
- os-name: debian
|
||||
- os-name: ubuntu
|
||||
- os-name: centos
|
||||
- os-name: fedora
|
||||
- os-name: opensuse
|
||||
- os-name: freebsd
|
||||
- platform-name: debian
|
||||
- platform-name: ubuntu
|
||||
- platform-name: centos
|
||||
- platform-name: fedora
|
||||
- platform-name: opensuse
|
||||
- platform-name: freebsd
|
||||
|
Loading…
Reference in New Issue
Block a user