Skip to content

Commit

Permalink
test(inspec): expand unittests for archive format
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmcloughlin committed Jun 16, 2019
1 parent 1f86f4a commit b074bd3
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 26 deletions.
1 change: 1 addition & 0 deletions pillar.example
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions prometheus/archive/install.sls
Expand Up @@ -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:
Expand All @@ -21,3 +28,8 @@ prometheus-package-archive-install-archive-extracted:
until: True
interval: 60
splay: 10
- user: root
- group: root
- recurse:
- user
- group
41 changes: 24 additions & 17 deletions prometheus/config/clean.sls
Expand Up @@ -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 }}
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:
- sls: {{ sls_service_clean }}
- sls: {{ sls_archive_clean }}
{%- if salt['grains.get']('os_family') == 'FreeBSD' %}
{%- for parameter in ['args', 'data_dir'] %}
prometheus-service-args-{{ parameter }}:
sysrc.absent:
- name: prometheus_{{ parameter }}
{% 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:
- service: prometheus-service-clean-service-dead
{%- endfor %}
{%- endif %}
- sls: {{ sls_archive_clean }}
{% endfor %}
{%- endif %}
69 changes: 66 additions & 3 deletions prometheus/config/init.sls
@@ -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 changes: 2 additions & 0 deletions prometheus/defaults.yaml
Expand Up @@ -2,6 +2,8 @@
# vim: ft=yaml
---
prometheus:
dir:
root: /opt
version: '2.10.0'
pkg:
name: prometheus
Expand Down
50 changes: 50 additions & 0 deletions test/integration/default/README.md
@@ -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 changes: 12 additions & 0 deletions test/integration/default/controls/environ_spec.rb
@@ -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
12 changes: 6 additions & 6 deletions test/integration/default/inspec.yml
Expand Up @@ -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

0 comments on commit b074bd3

Please sign in to comment.