Skip to content

Commit

Permalink
Merge pull request #33 from salt-formulas/add-kitchen-test
Browse files Browse the repository at this point in the history
Add kitchen tests to formula
  • Loading branch information
epcim authored Jun 1, 2018
2 parents 5f47959 + 8a0d52e commit b24817b
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 13 deletions.
86 changes: 86 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
driver:
name: docker
hostname: maas.ci.local
#socket: tcp://127.0.0.1:2376
use_sudo: false



provisioner:
name: salt_solo
salt_install: bootstrap
salt_bootstrap_url: https://bootstrap.saltstack.com
salt_version: latest
require_chef: false
formula: maas
log_level: info
state_top:
base:
"*":
- rsyslog
- postgresql
- maas
pillars:
top.sls:
base:
"*":
- rsyslog
- postgresql
- linux
- maas

pillars-from-files:
postgresql.sls: tests/pillar/postgresql.sls
rsyslog.sls: tests/pillar/rsyslog.sls
linux.sls: tests/pillar/linux.sls

grains:
noservices: False
kitchen-test: True

dependencies:
- name: postgresql
repo: git
source: https://github.com/salt-formulas/salt-formula-postgresql
- name: rsyslog
repo: git
source: https://github.com/salt-formulas/salt-formula-rsyslog


platforms:
- name: <%=ENV['PLATFORM'] || 'saltstack-ubuntu-xenial-salt-stable' %>
driver_config:
image: <%=ENV['PLATFORM'] || 'epcim/salt-formulas:saltstack-ubuntu-xenial-salt-stable'%>
platform: ubuntu


verifier:
name: inspec
sudo: true


suites:


- name: maas_cluster
provisioner:
pillars-from-files:
maas.sls: tests/pillar/maas_cluster.sls

#- name: disk_layout
#provisioner:
#pillars-from-files:
#maas.sls: tests/pillar/disk_layout.sls

#- name: maas_mirror
#provisioner:
#pillars-from-files:
#maas.sls: tests/pillar/maas_mirror.sls

#- name: maas_region
#provisioner:
#pillars-from-files:
#maas.sls: tests/pillar/maas_region.sls

# vim: ft=yaml sw=2 ts=2 sts=2 tw=125
46 changes: 46 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
sudo: required
services:
- docker

addons:
apt:
packages:
- apt-transport-https

install:
- pip install PyYAML
- pip install virtualenv
- |
test -e Gemfile || cat <<EOF > Gemfile
source 'https://rubygems.org'
gem 'rake'
gem 'test-kitchen'
gem 'kitchen-docker'
gem 'kitchen-inspec'
gem 'inspec'
gem 'kitchen-salt' #, :git => 'https://github.com/salt-formulas/kitchen-salt.git'
- bundle install

env:
- PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2016.3
- PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2017.7
- PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-stable

before_script:
- set -o pipefail
- make test | tail

script:
- test ! -e .kitchen.yml || bundle exec kitchen converge ${SUITE} || true
- test ! -e .kitchen.yml || bundle exec kitchen verify ${SUITE} -t tests/integration

notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/6123573504759330786b
on_success: change # options: [always|never|change] default: always
on_failure: never # options: [always|never|change] default: always
on_start: never # options: [always|never|change] default: always
on_cancel: never # options: [always|never|change] default: always
on_error: never # options: [always|never|change] default: always
email: false
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ all:
@echo "make release-major - Generate new major release"
@echo "make release-minor - Generate new minor release"
@echo "make changelog - Show changes since last release"
@echo "make test-model-validate - Run salt jsonschema validation"

install:
# Formula
[ -d $(DESTDIR)/$(SALTENVDIR) ] || mkdir -p $(DESTDIR)/$(SALTENVDIR)
cp -a $(FORMULANAME) $(DESTDIR)/$(SALTENVDIR)/
[ ! -d _modules ] || cp -a _modules $(DESTDIR)/$(SALTENVDIR)/
[ ! -d _states ] || cp -a _states $(DESTDIR)/$(SALTENVDIR)/ || true
[ ! -d _engines ] || cp -a _engines $(DESTDIR)/$(SALTENVDIR)/ || true
[ ! -d _grains ] || cp -a _grains $(DESTDIR)/$(SALTENVDIR)/ || true
# Metadata
[ -d $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME) ] || mkdir -p $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
Expand All @@ -52,6 +54,10 @@ lint:
test:
[ ! -d tests ] || (cd tests; ./run_tests.sh)

test-model-validate:
# TODO make it actually fail
[ ! -d $(FORMULANAME)/schemas/ ] || (cd tests; ./run_tests.sh model-validate)

release-major: check-changes
@echo "Current version is $(VERSION), new version is $(NEW_MAJOR_VERSION)"
@[ $(VERSION_MAJOR) != $(NEW_MAJOR_VERSION) ] || (echo "Major version $(NEW_MAJOR_VERSION) already released, nothing to do. Do you want release-minor?" && exit 1)
Expand Down
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,14 @@ MAAS region service with backup data
source: cfg01.local
host: 192.168.0.11
Test pillars
==============

Mind the postgresql and rsyslog `.sls`. Database and syslog service are required for MAAS to properly install and work.

* https://github.com/salt-formulas/salt-formula-rsyslog/tree/master/tests/pillar


Module function's example:
==========================

Expand Down
3 changes: 3 additions & 0 deletions maas/cluster.sls
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,8 @@ maas_cluster_services:
- file: /etc/maas/rackd.conf
- watch:
- file: /etc/maas/rackd.conf
{%- if grains.get('kitchen-test') %}
- onlyif: /bin/false
{%- endif %}
{%- endif %}
28 changes: 26 additions & 2 deletions maas/region.sls
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ maas_apache_headers:
- require:
- pkg: maas_region_packages
/root/.pgpass:
Configure /root/.pgpass for MAAS:
file.managed:
- name: /root/.pgpass
- source: salt://maas/files/pgpass
- template: jinja
- user: root
Expand All @@ -125,30 +126,50 @@ maas_region_services:
- cmd: maas_region_syncdb
- watch:
- file: /etc/maas/regiond.conf
{%- if grains.get('kitchen-test') %}
- onlyif: /bin/false
{%- endif %}
maas_region_syncdb:
cmd.run:
- names:
- maas-region syncdb
- maas-region syncdb --noinput
- require:
- file: /etc/maas/regiond.conf
{%- if grains['saltversioninfo'][0] >= 2017 and grains['saltversioninfo'][1] >= 7 %}
- retry:
attempts: 3
interval: 5
splay: 5
{%- endif %}
maas_set_admin_password:
cmd.run:
- name: "maas createadmin --username {{ region.admin.username }} --password {{ region.admin.password }} --email {{ region.admin.email }} && touch /var/lib/maas/.setup_admin"
- creates: /var/lib/maas/.setup_admin
- require:
- service: maas_region_services
{%- if grains.get('kitchen-test') %}
- onlyif: /bin/false
{%- endif %}
maas_login_admin:
cmd.run:
- name: "maas-region apikey --username {{ region.admin.username }} > /var/lib/maas/.maas_credentials"
- require:
- cmd: maas_set_admin_password
{%- if grains.get('kitchen-test') %}
- onlyif: /bin/false
{%- endif %}
maas_config:
module.run:
- name: maas.process_maas_config
- require:
- cmd: maas_login_admin
{%- if grains.get('kitchen-test') %}
- onlyif: /bin/false
{%- endif %}
{%- if region.get('boot_sources', False) %}
maas_boot_sources:
Expand Down Expand Up @@ -243,6 +264,9 @@ maas_domain:
- name: maas.process_domain
- require:
- module: maas_config
{%- if grains.get('kitchen-test') %}
- onlyif: /bin/false
{%- endif %}
{%- if region.fabrics is defined %}
{%- for fabric_name, fabric in region.fabrics.iteritems() %}
Expand Down
5 changes: 5 additions & 0 deletions metadata.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
name: "maas"
version: "0.1"
source: "https://github.com/salt-formulas/salt-formula-maas"
dependencies:
- name: postgresql
source: "https://github.com/salt-formulas/salt-formula-postgresql"
- name: rsyslog
source: "https://github.com/salt-formulas/salt-formula-rsyslog"
3 changes: 3 additions & 0 deletions tests/pillar/linux.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
linux:
system:
domain: ci.local
39 changes: 37 additions & 2 deletions tests/pillar/maas_cluster.sls
Original file line number Diff line number Diff line change
@@ -1,11 +1,46 @@
maas:
cluster:
enabled: true
role: master
region:
port: 80
host: localhost
role: slave
saltstack_repo_key: |
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2
mQENBFOpvpgBCADkP656H41i8fpplEEB8IeLhugyC2rTEwwSclb8tQNY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6wkHE92kGPG2GmoRD3ALjmCvN1E
PsIsQGnwpcXsRpYVCoW7e2nW4wUf7IkFZ94yOCmUq6WreWI4NggRcFC5ABEBAAGJ
AR8EGAECAAkFAlOpvpgCGwwACgkQDgihSd5Xv74/NggA08kEdBkiWWwJZUZEy7cK
WWcgjnRuOHd4rPeT+vQbOWGu6x4bxuVf9aTiYkf7ZjVF2lPn97EXOEGFWPZeZbH4
vdRFH9jMtP+rrLt6+3c9j0M8SIJYwBL1+CNpEC/BuHj/Ra/cmnG5ZNhYebm76h5f
T9iPW9fFww36FzFka4VPlvA4oB7ebBtquFg3sdQNU/MmTVV4jPFWXxh4oRDDR+8N
1bcPnbB11b5ary99F/mqr7RgQ+YFF0uKRE3SKa7a+6cIuHEZ7Za+zhPaQlzAOZlx
fuBmScum8uQTrEF5+Um5zkwC7EXTdH1co/+/V/fpOtxIg4XO4kcugZefVm5ERfVS
MA==
=dtMN
-----END PGP PUBLIC KEY BLOCK-----
saltstack_repo_trusty: "http://repo.saltstack.com/apt/ubuntu/14.04/amd64/2016.3/ trusty main"
saltstack_repo_xenial: "http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/ xenial main"
region:
theme: theme
theme: mirantis
bind:
host: localhost
port: 80
Expand Down
20 changes: 20 additions & 0 deletions tests/pillar/postgresql.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postgresql:
server:
enabled: true
clients:
- 127.0.0.1
bind:
address: 127.0.0.1
port: 5432
protocol: tcp
database:
maasdb:
enabled: true
encoding: 'UTF8'
locale: 'en_US'
users:
- name: maas
password: password
host: localhost
createdb: true
rights: all privileges
13 changes: 13 additions & 0 deletions tests/pillar/rsyslog.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
rsyslog:
#server:
#enabled: true
client:
enabled: true
#output:
#file:
#/var/log/syslog:
#filter: "*.*;auth,authpriv.none"
#owner: syslog
#group: adm
#createmode: 0640
#umask: 0022
Loading

0 comments on commit b24817b

Please sign in to comment.