Add remaining alex-z changes
diff --git a/cookiecutter.json b/cookiecutter.json
index b632d92..ac6cdce 100644
--- a/cookiecutter.json
+++ b/cookiecutter.json
@@ -1,8 +1,8 @@
{
"service_name": "some_service",
"role_name": "server",
- "initial_version": "2017.6",
- "copyright_year": "2017",
+ "initial_version": "2018.1",
+ "copyright_year": "2018",
"copyright_holder": "Your Name et al.",
"author_name": "John Doe",
"author_contact": "jdoe@domain.com",
diff --git "a/\173\173cookiecutter.project_name\175\175/.travis.yml" "b/\173\173cookiecutter.project_name\175\175/.travis.yml"
new file mode 100644
index 0000000..15fd7bc
--- /dev/null
+++ "b/\173\173cookiecutter.project_name\175\175/.travis.yml"
@@ -0,0 +1,42 @@
+sudo: required
+services:
+ - docker
+
+install:
+ - git fetch --unshallow --tags
+ - pip install PyYAML
+ - pip install virtualenv
+ - pip install reno
+ - |
+ 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=trevorj/salty-whales:trusty
+ - PLATFORM=trevorj/salty-whales:xenial
+
+before_script:
+ - set -o pipefail
+ - make test | tail
+ - reno lint $PWD | tail
+
+script:
+ - test ! -e .kitchen.yml || bundle exec kitchen test -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
diff --git "a/\173\173cookiecutter.project_name\175\175/CHANGELOG.rst" "b/\173\173cookiecutter.project_name\175\175/CHANGELOG.rst"
index e3224e5..d5bebfb 100644
--- "a/\173\173cookiecutter.project_name\175\175/CHANGELOG.rst"
+++ "b/\173\173cookiecutter.project_name\175\175/CHANGELOG.rst"
@@ -1,6 +1,6 @@
{{cookiecutter.service_name}} formula
-=========================================
+=====================================
-0.1 (2015-08-22)
+{{cookiecutter.initial_version}} ({% now 'local', '%Y-%m-%d' %})
- Initial formula setup
diff --git "a/\173\173cookiecutter.project_name\175\175/LICENSE" "b/\173\173cookiecutter.project_name\175\175/LICENSE"
index e7019f4..f52f95a 100644
--- "a/\173\173cookiecutter.project_name\175\175/LICENSE"
+++ "b/\173\173cookiecutter.project_name\175\175/LICENSE"
@@ -1,4 +1,4 @@
-Copyright (c) 2014-2015 {{cookiecutter.license_holder}}
+Copyright (c) {{cookiecutter.copyright_year}} {{cookiecutter.copyright_holder}}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git "a/\173\173cookiecutter.project_name\175\175/Makefile" "b/\173\173cookiecutter.project_name\175\175/Makefile"
index fa15e0f..7747ec1 100644
--- "a/\173\173cookiecutter.project_name\175\175/Makefile"
+++ "b/\173\173cookiecutter.project_name\175\175/Makefile"
@@ -2,6 +2,12 @@
SALTENVDIR=/usr/share/salt-formulas/env
RECLASSDIR=/usr/share/salt-formulas/reclass
FORMULANAME=$(shell grep name: metadata.yml|head -1|cut -d : -f 2|grep -Eo '[a-z0-9\-\_]*')
+VERSION=$(shell grep version: metadata.yml|head -1|cut -d : -f 2|grep -Eo '[a-z0-9\.\-\_]*')
+VERSION_MAJOR := $(shell echo $(VERSION)|cut -d . -f 1-2)
+VERSION_MINOR := $(shell echo $(VERSION)|cut -d . -f 3)
+
+NEW_MAJOR_VERSION ?= $(shell date +%Y.%m|sed 's,\.0,\.,g')
+NEW_MINOR_VERSION ?= $(shell /bin/bash -c 'echo $$[ $(VERSION_MINOR) + 1 ]')
MAKE_PID := $(shell echo $$PPID)
JOB_FLAG := $(filter -j%, $(subst -j ,-j,$(shell ps T | grep "^\s*$(MAKE_PID).*$(MAKE)")))
@@ -21,9 +27,14 @@
all:
@echo "make install - Install into DESTDIR"
+ @echo "make lint - Run lint tests"
@echo "make test - Run tests"
@echo "make kitchen - Run Kitchen CI tests (create, converge, verify)"
@echo "make clean - Cleanup after tests run"
+ @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
@@ -31,32 +42,82 @@
cp -a $(FORMULANAME) $(DESTDIR)/$(SALTENVDIR)/
[ ! -d _modules ] || cp -a _modules $(DESTDIR)/$(SALTENVDIR)/
[ ! -d _states ] || cp -a _states $(DESTDIR)/$(SALTENVDIR)/ || true
+ [ ! -d _grains ] || cp -a _grains $(DESTDIR)/$(SALTENVDIR)/ || true
# Metadata
[ -d $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME) ] || mkdir -p $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
cp -a metadata/service/* $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
+lint:
+ [ ! -d tests ] || (cd tests; ./run_tests.sh lint)
+
test:
[ ! -d tests ] || (cd tests; ./run_tests.sh)
-kitchen: kitchen-create kitchen-converge kitchen-verify kitchen-list
+test-model-validate:
+ # TODO make it actually fail
+ [ ! -d $(FORMULANAME)/schemas/ ] || (cd tests; ./run_tests.sh model-validate)
-kitchen-create:
+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)
+ echo "$(NEW_MAJOR_VERSION)" > VERSION
+ sed -i 's,version: .*,version: "$(NEW_MAJOR_VERSION)",g' metadata.yml
+ [ ! -f debian/changelog ] || dch -v $(NEW_MAJOR_VERSION) -m --force-distribution -D `dpkg-parsechangelog -S Distribution` "New version"
+ make genchangelog-$(NEW_MAJOR_VERSION)
+ (git add -u; git commit -m "Version $(NEW_MAJOR_VERSION)")
+ git tag -s -m $(NEW_MAJOR_VERSION) $(NEW_MAJOR_VERSION)
+
+release-minor: check-changes
+ @echo "Current version is $(VERSION), new version is $(VERSION_MAJOR).$(NEW_MINOR_VERSION)"
+ echo "$(VERSION_MAJOR).$(NEW_MINOR_VERSION)" > VERSION
+ sed -i 's,version: .*,version: "$(VERSION_MAJOR).$(NEW_MINOR_VERSION)",g' metadata.yml
+ [ ! -f debian/changelog ] || dch -v $(VERSION_MAJOR).$(NEW_MINOR_VERSION) -m --force-distribution -D `dpkg-parsechangelog -S Distribution` "New version"
+ make genchangelog-$(VERSION_MAJOR).$(NEW_MINOR_VERSION)
+ (git add -u; git commit -m "Version $(VERSION_MAJOR).$(NEW_MINOR_VERSION)")
+ git tag -s -m $(NEW_MAJOR_VERSION) $(VERSION_MAJOR).$(NEW_MINOR_VERSION)
+
+check-changes:
+ @git log --pretty=oneline --decorate $(VERSION)..HEAD | grep -Eqc '.*' || (echo "No new changes since version $(VERSION)"; exit 1)
+
+changelog:
+ git log --pretty=short --invert-grep --grep="Merge pull request" --decorate $(VERSION)..HEAD
+
+genchangelog: genchangelog-$(VERSION_MAJOR).$(NEW_MINOR_VERSION)
+
+genchangelog-%:
+ $(eval NEW_VERSION := $(patsubst genchangelog-%,%,$@))
+ (echo "=========\nChangelog\n=========\n"; \
+ (echo $(NEW_VERSION);git tag) | sort -r | grep -E '^[0-9\.]+' | while read i; do \
+ cur=$$i; \
+ test $$i = $(NEW_VERSION) && i=HEAD; \
+ prev=`(echo $(NEW_VERSION);git tag)|sort|grep -E '^[0-9\.]+'|grep -B1 "$$cur\$$"|head -1`; \
+ echo "Version $$cur\n=============================\n"; \
+ git log --pretty=short --invert-grep --grep="Merge pull request" --decorate $$prev..$$i; \
+ echo; \
+ done) > CHANGELOG.rst
+
+kitchen-check:
+ @[ -e $(KITCHEN_LOCAL_YAML) ] || (echo "Kitchen tests not available, there's no $(KITCHEN_LOCAL_YAML)." && exit 1)
+
+kitchen: kitchen-check kitchen-create kitchen-converge kitchen-verify kitchen-list
+
+kitchen-create: kitchen-check
kitchen create ${KITCHEN_OPTS} ${KITCHEN_OPTS_CREATE}
[ "$(shell echo $(KITCHEN_LOCAL_YAML)|grep -Eo docker)" = "docker" ] || sleep 120
-kitchen-converge:
+kitchen-converge: kitchen-check
kitchen converge ${KITCHEN_OPTS} ${KITCHEN_OPTS_CONVERGE} &&\
kitchen converge ${KITCHEN_OPTS} ${KITCHEN_OPTS_CONVERGE}
-kitchen-verify:
+kitchen-verify: kitchen-check
[ ! -d tests/integration ] || kitchen verify -t tests/integration ${KITCHEN_OPTS} ${KITCHEN_OPTS_VERIFY}
[ -d tests/integration ] || kitchen verify ${KITCHEN_OPTS} ${KITCHEN_OPTS_VERIFY}
-kitchen-test:
+kitchen-test: kitchen-check
[ ! -d tests/integration ] || kitchen test -t tests/integration ${KITCHEN_OPTS} ${KITCHEN_OPTS_TEST}
[ -d tests/integration ] || kitchen test ${KITCHEN_OPTS} ${KITCHEN_OPTS_TEST}
-kitchen-list:
+kitchen-list: kitchen-check
kitchen list
clean:
diff --git "a/\173\173cookiecutter.project_name\175\175/README.rst" "b/\173\173cookiecutter.project_name\175\175/README.rst"
index 50931f1..5b32da7 100644
--- "a/\173\173cookiecutter.project_name\175\175/README.rst"
+++ "b/\173\173cookiecutter.project_name\175\175/README.rst"
@@ -1,11 +1,12 @@
==================================
-{{cookiecutter.service_name}}
+{{cookiecutter.service_name}} Formula
==================================
Service {{cookiecutter.service_name}} description
-Sample pillars
+
+Sample Pillars
==============
Single {{cookiecutter.service_name}} service
@@ -15,43 +16,44 @@
{{cookiecutter.service_name}}:
{{cookiecutter.role_name}}:
enabled: true
- version: icehouse
-Development and testing
-=======================
+More Information
+================
-Development and test workflow with `Test Kitchen <http://kitchen.ci>`_ and
-`kitchen-salt <https://github.com/simonmcc/kitchen-salt>`_ provisioner plugin.
-
-Test Kitchen is a test harness tool to execute your configured code on one or more platforms in isolation.
-There is a ``.kitchen.yml`` in main directory that defines *platforms* to be tested and *suites* to execute on them.
-
-Kitchen CI can spin instances locally or remote, based on used *driver*.
-For local development ``.kitchen.yml`` defines a `vagrant <https://github.com/test-kitchen/kitchen-vagrant>`_ or
-`docker <https://github.com/test-kitchen/kitchen-docker>`_ driver.
-
-To use backend drivers or implement your CI follow the section `INTEGRATION.rst#Continuous Integration`__.
-
-The `Busser <https://github.com/test-kitchen/busser>`_ *Verifier* is used to setup and run tests
-implementated in `<repo>/test/integration`. It installs the particular driver to tested instance
-(`Serverspec <https://github.com/neillturner/kitchen-verifier-serverspec>`_,
-`InSpec <https://github.com/chef/kitchen-inspec>`_, Shell, Bats, ...) prior the verification is executed.
-
-Usage:
-
-.. code-block:: shell
-
- # list instances and status
- kitchen list
-
- # manually execute integration tests
- kitchen [test || [create|converge|verify|exec|login|destroy|...]] [instance] -t tests/integration
-
- # use with provided Makefile (ie: within CI pipeline)
- make kitchen
+* A link to project home
+Documentation and Bugs
+======================
+
+To learn how to install and update salt-formulas, consult the documentation
+available online at:
+
+ http://salt-formulas.readthedocs.io/
+
+In the unfortunate event that bugs are discovered, they should be reported to
+the appropriate issue tracker. Use GitHub issue tracker for specific salt
+formula:
+
+ https://github.com/salt-formulas/salt-formula-{{cookiecutter.service_name}}/issues
+
+For feature requests, bug reports or blueprints affecting entire ecosystem,
+use Launchpad salt-formulas project:
+
+ https://launchpad.net/salt-formulas
+
+Developers wishing to work on the salt-formulas projects should always base
+their work on master branch and submit pull request against specific formula.
+
+You should also subscribe to mailing list (salt-formulas@freelists.org):
+
+ https://www.freelists.org/list/salt-formulas
+
+Any questions or feedback is always welcome so feel free to join our IRC
+channel:
+
+ #salt-formulas @ irc.freenode.net
Read more
=========
diff --git "a/\173\173cookiecutter.project_name\175\175/VERSION" "b/\173\173cookiecutter.project_name\175\175/VERSION"
index 49d5957..5b33a9c 100644
--- "a/\173\173cookiecutter.project_name\175\175/VERSION"
+++ "b/\173\173cookiecutter.project_name\175\175/VERSION"
@@ -1 +1 @@
-0.1
+{{cookiecutter.initial_version}}
diff --git "a/\173\173cookiecutter.project_name\175\175/debian/changelog" "b/\173\173cookiecutter.project_name\175\175/debian/changelog"
index 2e8ba14..0250323 100644
--- "a/\173\173cookiecutter.project_name\175\175/debian/changelog"
+++ "b/\173\173cookiecutter.project_name\175\175/debian/changelog"
@@ -1,5 +1,5 @@
-salt-formula-{{cookiecutter.service_name}} (0.1) trusty; urgency=medium
+salt-formula-{{cookiecutter.service_name}} ({{cookiecutter.initial_version}}) {{cookiecutter.debian_version}}; urgency=medium
* Initial release
- -- {{cookiecutter.author_contact}} Thu, 13 Aug 2015 23:23:41 +0200
+ -- {{cookiecutter.author_name}} {{cookiecutter.author_contact}} {% now "Europe/London", "%a, %d %b %Y %I:%M:%S %Z" %}
diff --git "a/\173\173cookiecutter.project_name\175\175/debian/control" "b/\173\173cookiecutter.project_name\175\175/debian/control"
index 73e5156..2ec3bc1 100644
--- "a/\173\173cookiecutter.project_name\175\175/debian/control"
+++ "b/\173\173cookiecutter.project_name\175\175/debian/control"
@@ -1,12 +1,12 @@
Source: salt-formula-{{cookiecutter.service_name}}
-Maintainer: {{cookiecutter.author_contact}}
+Maintainer: {{cookiecutter.author_name}} {{cookiecutter.author_contact}}
Section: admin
Priority: optional
Build-Depends: debhelper (>= 9), salt-master, python, python-yaml
Standards-Version: 3.9.6
-Homepage: http://www.tcpcloud.eu
-Vcs-Browser: https://github.com/tcpcloud/salt-formula-{{cookiecutter.service_name}}
-Vcs-Git: https://github.com/tcpcloud/salt-formula-{{cookiecutter.service_name}}.git
+Homepage: {{cookiecutter.homepage}}
+Vcs-Browser: https://github.com/salt-formulas/salt-formula-{{cookiecutter.service_name}}
+Vcs-Git: https://github.com/salt-formulas/salt-formula-{{cookiecutter.service_name}}.git
Package: salt-formula-{{cookiecutter.service_name}}
Architecture: all
diff --git "a/\173\173cookiecutter.project_name\175\175/debian/copyright" "b/\173\173cookiecutter.project_name\175\175/debian/copyright"
index 044d80e..67fa9c6 100644
--- "a/\173\173cookiecutter.project_name\175\175/debian/copyright"
+++ "b/\173\173cookiecutter.project_name\175\175/debian/copyright"
@@ -1,12 +1,12 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: salt-formula-{{cookiecutter.service_name}}
-Upstream-Contact:
-Source: https://github.com/tcpcloud/salt-formula-{{cookiecutter.service_name}}
+Upstream-Contact: salt-formulas@freelists.org
+Source: https://github.com/salt-formulas/salt-formula-{{cookiecutter.service_name}}
Files: *
-Copyright: 2014-2015 {{cookiecutter.license_holder}}
+Copyright: {{cookiecutter.copyright_year}} {{cookiecutter.copyright_holder}}
License: Apache-2.0
- Copyright (C) 2014-2015 {{cookiecutter.license_holder}}
+ Copyright (C) {{cookiecutter.copyright_year}} {{cookiecutter.copyright_holder}}
.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git "a/\173\173cookiecutter.project_name\175\175/doc/source/conf.py" "b/\173\173cookiecutter.project_name\175\175/doc/source/conf.py"
index 1f6e363..c79a195 100644
--- "a/\173\173cookiecutter.project_name\175\175/doc/source/conf.py"
+++ "b/\173\173cookiecutter.project_name\175\175/doc/source/conf.py"
@@ -36,7 +36,7 @@
# General information about the project.
project = u'salt-formula-{{cookiecutter.service_name}}'
-copyright = u'2016, {{cookiecutter.license_holder}}'
+copyright = u'2016, {{cookiecutter.copyright_holder}}'
# If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = True
diff --git "a/\173\173cookiecutter.project_name\175\175/metadata.yml" "b/\173\173cookiecutter.project_name\175\175/metadata.yml"
index f99a548..125046e 100644
--- "a/\173\173cookiecutter.project_name\175\175/metadata.yml"
+++ "b/\173\173cookiecutter.project_name\175\175/metadata.yml"
@@ -1,3 +1,3 @@
name: "{{cookiecutter.service_name}}"
-version: "0.1"
-source: "https://github.com/tcpcloud/salt-formula-{{cookiecutter.service_name}}"
+version: "{{cookiecutter.initial_version}}"
+source: "https://github.com/salt-formulas/salt-formula-{{cookiecutter.service_name}}"
diff --git "a/\173\173cookiecutter.project_name\175\175/releasenotes/config.yaml" "b/\173\173cookiecutter.project_name\175\175/releasenotes/config.yaml"
new file mode 100644
index 0000000..fe5bc11
--- /dev/null
+++ "b/\173\173cookiecutter.project_name\175\175/releasenotes/config.yaml"
@@ -0,0 +1,59 @@
+---
+# Usage:
+#
+# reno list
+# reno new slug-title --edit
+# reno report --no-show-source
+
+# Change prelude_section_name to 'summary' from default value prelude
+prelude_section_name: summary
+show_source: False
+sections:
+ # summary/prelude section is always included
+ - [features, New Features]
+ - [issues, Known Issues]
+ - [fixes, Bug Fixes]
+ - [other, Other Notes]
+template: |
+ ---
+ # Author the following sections or remove the section if it is not related.
+ # Use one release note per a feature.
+ #
+ # If you miss a section from the list below, please first submit a review
+ # adding it to releasenotes/config.yaml.
+ #
+ summary: >
+ This section is not mandatory. Use it to highlight the change.
+
+ features:
+ - Use list to record summary of features.
+ - |
+ Provide detailed description with examples.
+ Format with reStructuredText.
+
+ .. code-block:: text
+
+ provide model/formula pillar snippets
+
+ issues:
+ - Use list to record known limitations.
+
+ fixes:
+ - Use list to record summary of fixes.
+ Quick and dirty `git log --oneline`.
+
+ other:
+ - Author additional notes for the release.
+ - Format with reStructuredText.
+ - |
+ Use this section if note is not related to one of the common sections:
+ features, issues, upgrade, deprecations, security, fixes, api, cli
+
+ * list item 1
+ * list item 2
+
+ .. code-block:: yaml
+
+ formula:
+ example:
+ enabled: true
diff --git "a/\173\173cookiecutter.project_name\175\175/releasenotes/notes/add-releasenotes-9c076c7ee8fbe2a4.yaml" "b/\173\173cookiecutter.project_name\175\175/releasenotes/notes/add-releasenotes-9c076c7ee8fbe2a4.yaml"
new file mode 100644
index 0000000..7e96d63
--- /dev/null
+++ "b/\173\173cookiecutter.project_name\175\175/releasenotes/notes/add-releasenotes-9c076c7ee8fbe2a4.yaml"
@@ -0,0 +1,13 @@
+---
+summary: >
+ Add "reno", an releasenotes configuration tool to record release notes.
+ Documentation: https://docs.openstack.org/reno/latest
+
+ To list/create/show release notes, run following commands:
+
+ .. code-block:: shell
+
+ reno list
+ reno new releasenote-slug-title --edit
+ # git add/commit releasenotes/*
+ reno report --no-show-source
diff --git "a/\173\173cookiecutter.project_name\175\175/tests/pillar/single.sls" "b/\173\173cookiecutter.project_name\175\175/tests/pillar/single.sls"
new file mode 100644
index 0000000..61ab117
--- /dev/null
+++ "b/\173\173cookiecutter.project_name\175\175/tests/pillar/single.sls"
@@ -0,0 +1,5 @@
+{{cookiecutter.service_name}}:
+ {{cookiecutter.role_name}}:
+ enabled: true
+ bind:
+ address: 0.0.0.0
diff --git "a/\173\173cookiecutter.project_name\175\175/tests/run_tests.sh" "b/\173\173cookiecutter.project_name\175\175/tests/run_tests.sh"
index 3f42101..9993b8d 100755
--- "a/\173\173cookiecutter.project_name\175\175/tests/run_tests.sh"
+++ "b/\173\173cookiecutter.project_name\175\175/tests/run_tests.sh"
@@ -1,24 +1,31 @@
#!/usr/bin/env bash
+###
+# Script requirments:
+# apt-get install -y python-yaml virtualenv git
set -e
[ -n "$DEBUG" ] && set -x
CURDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
METADATA=${CURDIR}/../metadata.yml
FORMULA_NAME=$(cat $METADATA | python -c "import sys,yaml; print yaml.load(sys.stdin)['name']")
+FORMULA_META_DIR=${CURDIR}/../${FORMULA_NAME}/meta
## Overrideable parameters
PILLARDIR=${PILLARDIR:-${CURDIR}/pillar}
BUILDDIR=${BUILDDIR:-${CURDIR}/build}
VENV_DIR=${VENV_DIR:-${BUILDDIR}/virtualenv}
+MOCK_BIN_DIR=${MOCK_BIN_DIR:-${CURDIR}/mock_bin}
DEPSDIR=${BUILDDIR}/deps
+SCHEMARDIR=${SCHEMARDIR:-"${CURDIR}/../${FORMULA_NAME}/schemas/"}
SALT_FILE_DIR=${SALT_FILE_DIR:-${BUILDDIR}/file_root}
SALT_PILLAR_DIR=${SALT_PILLAR_DIR:-${BUILDDIR}/pillar_root}
SALT_CONFIG_DIR=${SALT_CONFIG_DIR:-${BUILDDIR}/salt}
SALT_CACHE_DIR=${SALT_CACHE_DIR:-${SALT_CONFIG_DIR}/cache}
+SALT_CACHE_EXTMODS_DIR=${SALT_CACHE_EXTMODS_DIR:-${SALT_CONFIG_DIR}/cache_master_extmods}
-SALT_OPTS="${SALT_OPTS} --retcode-passthrough --local -c ${SALT_CONFIG_DIR}"
+SALT_OPTS="${SALT_OPTS} --retcode-passthrough --local -c ${SALT_CONFIG_DIR} --log-file=/dev/null"
if [ "x${SALT_VERSION}" != "x" ]; then
PIP_SALT_VERSION="==${SALT_VERSION}"
@@ -26,11 +33,11 @@
## Functions
log_info() {
- echo "[INFO] $*"
+ echo -e "[INFO] $*"
}
log_err() {
- echo "[ERROR] $*" >&2
+ echo -e "[ERROR] $*" >&2
}
setup_virtualenv() {
@@ -38,12 +45,25 @@
virtualenv $VENV_DIR
source ${VENV_DIR}/bin/activate
pip install salt${PIP_SALT_VERSION}
+ if [[ -f ${CURDIR}/pip_requirements.txt ]]; then
+ pip install -r ${CURDIR}/pip_requirements.txt
+ fi
+}
+
+setup_mock_bin() {
+ # If some state requires a binary, a lightweight replacement for
+ # such binary can be put into MOCK_BIN_DIR for test purposes
+ if [ -d "${MOCK_BIN_DIR}" ]; then
+ PATH="${MOCK_BIN_DIR}:$PATH"
+ export PATH
+ fi
}
setup_pillar() {
[ ! -d ${SALT_PILLAR_DIR} ] && mkdir -p ${SALT_PILLAR_DIR}
echo "base:" > ${SALT_PILLAR_DIR}/top.sls
for pillar in ${PILLARDIR}/*; do
+ grep ${FORMULA_NAME}: ${pillar} &>/dev/null || continue
state_name=$(basename ${pillar%.sls})
echo -e " ${state_name}:\n - ${state_name}" >> ${SALT_PILLAR_DIR}/top.sls
done
@@ -53,9 +73,11 @@
[ ! -d ${SALT_FILE_DIR} ] && mkdir -p ${SALT_FILE_DIR}
[ ! -d ${SALT_CONFIG_DIR} ] && mkdir -p ${SALT_CONFIG_DIR}
[ ! -d ${SALT_CACHE_DIR} ] && mkdir -p ${SALT_CACHE_DIR}
+ [ ! -d ${SALT_CACHE_EXTMODS_DIR} ] && mkdir -p ${SALT_CACHE_EXTMODS_DIR}
echo "base:" > ${SALT_FILE_DIR}/top.sls
for pillar in ${PILLARDIR}/*.sls; do
+ grep ${FORMULA_NAME}: ${pillar} &>/dev/null || continue
state_name=$(basename ${pillar%.sls})
echo -e " ${state_name}:\n - ${FORMULA_NAME}" >> ${SALT_FILE_DIR}/top.sls
done
@@ -63,13 +85,14 @@
cat << EOF > ${SALT_CONFIG_DIR}/minion
file_client: local
cachedir: ${SALT_CACHE_DIR}
+extension_modules: ${SALT_CACHE_EXTMODS_DIR}
verify_env: False
+minion_id_caching: False
file_roots:
base:
- ${SALT_FILE_DIR}
- ${CURDIR}/..
- - /usr/share/salt-formulas/env
pillar_roots:
base:
@@ -79,13 +102,13 @@
}
fetch_dependency() {
+ # example: fetch_dependency "linux:https://github.com/salt-formulas/salt-formula-linux"
dep_name="$(echo $1|cut -d : -f 1)"
dep_source="$(echo $1|cut -d : -f 2-)"
dep_root="${DEPSDIR}/$(basename $dep_source .git)"
dep_metadata="${dep_root}/metadata.yml"
- [ -d /usr/share/salt-formulas/env/${dep_name} ] && log_info "Dependency $dep_name already present in system-wide salt env" && return 0
- [ -d $dep_root ] && log_info "Dependency $dep_name already fetched" && return 0
+ [ -d $dep_root ] && { log_info "Dependency $dep_name already fetched"; return 0; }
log_info "Fetching dependency $dep_name"
[ ! -d ${DEPSDIR} ] && mkdir -p ${DEPSDIR}
@@ -95,6 +118,19 @@
METADATA="${dep_metadata}" install_dependencies
}
+link_modules(){
+ # Link modules *.py files to temporary salt-root
+ local SALT_ROOT=${1:-$SALT_FILE_DIR}
+ local SALT_ENV=${2:-$DEPSDIR}
+
+ mkdir -p "${SALT_ROOT}/_modules/"
+ # from git, development versions
+ find ${SALT_ENV} -maxdepth 3 -mindepth 3 -path '*_modules*' -iname "*.py" -type f -print0 | while read -d $'\0' file; do
+ ln -fs $(readlink -e ${file}) "$SALT_ROOT"/_modules/$(basename ${file}) ;
+ done
+ salt_run saltutil.sync_all
+}
+
install_dependencies() {
grep -E "^dependencies:" ${METADATA} >/dev/null || return 0
(python - | while read dep; do fetch_dependency "$dep"; done) << EOF
@@ -110,23 +146,72 @@
}
salt_run() {
- [ -e ${VEN_DIR}/bin/activate ] && source ${VENV_DIR}/bin/activate
+ [ -e ${VENV_DIR}/bin/activate ] && source ${VENV_DIR}/bin/activate
salt-call ${SALT_OPTS} $*
}
prepare() {
[ -d ${BUILDDIR} ] && mkdir -p ${BUILDDIR}
- which salt-call || setup_virtualenv
+ [[ ! -f "${VENV_DIR}/bin/activate" ]] && setup_virtualenv
+ setup_mock_bin
setup_pillar
setup_salt
install_dependencies
}
+lint_releasenotes() {
+ [[ ! -f "${VENV_DIR}/bin/activate" ]] && setup_virtualenv
+ source ${VENV_DIR}/bin/activate
+ pip install reno
+ reno lint ${CURDIR}/../
+}
+
+lint() {
+# lint_releasenotes
+ log_err "TODO: lint_releasenotes"
+}
+
run() {
for pillar in ${PILLARDIR}/*.sls; do
+ grep ${FORMULA_NAME}: ${pillar} &>/dev/null || continue
state_name=$(basename ${pillar%.sls})
+ salt_run grains.set 'noservices' False force=True
+
+ echo "Checking state ${FORMULA_NAME}.${state_name} ..."
salt_run --id=${state_name} state.show_sls ${FORMULA_NAME} || (log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1)
+
+ # Check that all files in 'meta' folder can be rendered using any valid pillar
+ for meta in `find ${FORMULA_META_DIR} -type f`; do
+ meta_name=$(basename ${meta})
+ echo "Checking meta ${meta_name} ..."
+ salt_run --out=quiet --id=${state_name} cp.get_template ${meta} ${SALT_CACHE_DIR}/${meta_name} \
+ || { log_err "Failed to render meta ${meta} using pillar ${FORMULA_NAME}.${state_name}"; exit 1; }
+ cat ${SALT_CACHE_DIR}/${meta_name}
+ done
+ done
+}
+
+real_run() {
+ for pillar in ${PILLARDIR}/*.sls; do
+ state_name=$(basename ${pillar%.sls})
+ salt_run --id=${state_name} state.sls ${FORMULA_NAME} || { log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1; }
+ done
+}
+
+run_model_validate(){
+ [[ -d ${SCHEMARDIR} ]] || { log_err "${SCHEMARDIR} not found!"; return 1; }
+ # model validator require py modules
+ fetch_dependency "salt:https://github.com/salt-formulas/salt-formula-salt"
+ link_modules
+ # Rendered Example:
+ # salt-call --local -c /test1/maas/tests/build/salt --id=maas_cluster modelschema.model_validate maas cluster
+ for role in ${SCHEMARDIR}/*.yaml; do
+ state_name=$(basename "${role%*.yaml}")
+ minion_id="${state_name}"
+ # in case debug-reruns, usefull to make cleanup
+ [ -n "$DEBUG" ] && { salt_run saltutil.clear_cache; salt_run saltutil.refresh_pillar; salt_run saltutil.sync_all; }
+ salt_run --id=${minion_id} modelschema.model_validate ${FORMULA_NAME} ${state_name} || { log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1 ; }
done
}
@@ -152,11 +237,23 @@
prepare)
prepare
;;
+ lint)
+ lint
+ ;;
run)
run
;;
+ real-run)
+ real_run
+ ;;
+ model-validate)
+ prepare
+ run_model_validate
+ ;;
*)
prepare
+# lint
run
+ run_model_validate
;;
esac
diff --git "a/\173\173cookiecutter.project_name\175\175/\173\173cookiecutter.service_name\175\175/map.jinja" "b/\173\173cookiecutter.project_name\175\175/\173\173cookiecutter.service_name\175\175/map.jinja"
index 59e04a5..55fce88 100644
--- "a/\173\173cookiecutter.project_name\175\175/\173\173cookiecutter.service_name\175\175/map.jinja"
+++ "b/\173\173cookiecutter.project_name\175\175/\173\173cookiecutter.service_name\175\175/map.jinja"
@@ -1,29 +1,10 @@
{% raw %}
-{%- set {% endraw %}source_engine = salt['pillar.get']('{{cookiecutter.service_name}}:{{cookiecutter.role_name}}:source:engine'){% raw %} %}
-
{%- load_yaml as base_defaults %}
-{%- if source_engine == 'git' %}
-{% endraw %}Debian:
- pkgs:
- - python-psycopg2
- dir:
- base: /srv/{{cookiecutter.service_name}}/venv
- home: /var/lib/{{cookiecutter.service_name}}
- workspace: /srv/{{cookiecutter.service_name}}/workspace
-RedHat:
- pkgs:
- - python-psycopg2
- dir:
- base: /srv/{{cookiecutter.service_name}}/venv
- home: /var/lib/{{cookiecutter.service_name}}
- workspace: /srv/{{cookiecutter.service_name}}/workspace
-{% raw %}{%- else %}{% endraw %}
+{% endraw %}
Debian:
pkgs:
- {{cookiecutter.service_name}}
- dir:
- base: /usr/lib/{{cookiecutter.service_name}}
-{% raw %}{%- endif %}
+{% raw %}
{%- endload %}
-{%-{% endraw %} set {{cookiecutter.role_name}} = salt['grains.filter_by'](base_defaults, merge=salt['pillar.get']('{{cookiecutter.service_name}}:{{cookiecutter.role_name}}')) {% raw %}%}{% endraw %}
\ No newline at end of file
+{%-{% endraw %} set {{cookiecutter.role_name}} = salt['grains.filter_by'](base_defaults, merge=salt['pillar.get']('{{cookiecutter.service_name}}:{{cookiecutter.role_name}}')) {% raw %}%}{% endraw %}