Initial commit
Adding salt-formula for gnocchi 4.0. Two main roles are supported:
- server
- statsd
They could be installed on different nodes (and on same node too)
gnocchi:common class is used to provide common options for both.
Change-Id: I0e0c9dd4f6d0a1539b9e9aef0084282867012852
Related-Prod: https://mirantis.jira.com/browse/PROD-17704
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..aa8e42a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+.kitchen
+tests/build/
+*.swp
+*.pyc
+.ropeproject
diff --git a/.kitchen.yml b/.kitchen.yml
new file mode 100644
index 0000000..177281b
--- /dev/null
+++ b/.kitchen.yml
@@ -0,0 +1,83 @@
+---
+driver:
+ name: docker
+ hostname: gnocchi.ci.local
+ use_sudo: false
+
+provisioner:
+ name: salt_solo
+ salt_install: bootstrap
+ salt_bootstrap_url: https://bootstrap.saltstack.com
+ salt_version: latest
+ require_chef: false
+ log_level: error
+ formula: gnocchi
+ grains:
+ noservices: True
+ dependencies:
+ - name: linux
+ repo: git
+ source: https://github.com/salt-formulas/salt-formula-linux
+ - name: apache
+ repo: git
+ source: https://github.com/salt-formulas/salt-formula-apache
+ state_top:
+ base:
+ "*":
+ - linux.system
+ - apache
+ - gnocchi
+ pillars:
+ top.sls:
+ base:
+ "*":
+ - linux_repo_openstack
+ - gnocchi
+ - release
+ - storage
+ pillars-from-files:
+ linux_repo_openstack.sls: tests/pillar/repo_mcp_openstack_<%= ENV['OS_VERSION'] || 'pike' %>.sls
+
+verifier:
+ name: inspec
+ sudo: true
+
+platforms:
+ - name: <%= ENV['PLATFORM'] || 'ubuntu-xenial' %>
+ driver_config:
+ image: <%= ENV['PLATFORM'] || 'epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3' %>
+ platform: ubuntu
+
+suites:
+
+ - name: server_cluster
+ provisioner:
+ pillars-from-files:
+ gnocchi.sls: tests/pillar/server_cluster.sls
+ pillars:
+ release.sls:
+ gnocchi:
+ common:
+ version: <%= ENV['GNOCCHI_VERSION'] || '4.0' %>
+ storage.sls:
+ gnocchi:
+ common:
+ storage:
+ driver: <%= ENV['GNOCCHI_STORAGE'] || 'file' %>
+
+ - name: server_single
+ provisioner:
+ pillars-from-files:
+ gnocchi.sls: tests/pillar/server_single.sls
+ pillars:
+ release.sls:
+ gnocchi:
+ common:
+ version: <%= ENV['GNOCCHI_VERSION'] || '4.0' %>
+ storage.sls:
+ gnocchi:
+ common:
+ storage:
+ driver: <%= ENV['GNOCCHI_STORAGE'] || 'file' %>
+
+# vim: ft=yaml sw=2 ts=2 sts=2 tw=125
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..1fb0122
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,46 @@
+sudo: required
+services:
+ - docker
+
+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-formulas:saltstack-ubuntu-xenial-salt-2016.3 GNOCCHI_VERSION=4.0 GNOCCHI_STORAGE=file OS_VERSION=pike SUITE=server_cluster
+ - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 GNOCCHI_VERSION=4.0 GNOCCHI_STORAGE=redis OS_VERSION=pike SUITE=server_cluster
+ - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 GNOCCHI_VERSION=4.0 GNOCCHI_STORAGE=file OS_VERSION=pike SUITE=server_single
+ - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 GNOCCHI_VERSION=4.0 GNOCCHI_STORAGE=redis OS_VERSION=pike SUITE=server_single
+ - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7 GNOCCHI_VERSION=4.0 GNOCCHI_STORAGE=file OS_VERSION=pike SUITE=server_cluster
+ - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7 GNOCCHI_VERSION=4.0 GNOCCHI_STORAGE=redis OS_VERSION=pike SUITE=server_cluster
+ - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7 GNOCCHI_VERSION=4.0 GNOCCHI_STORAGE=file OS_VERSION=pike SUITE=server_single
+ - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7 GNOCCHI_VERSION=4.0 GNOCCHI_STORAGE=redis OS_VERSION=pike SUITE=server_single
+
+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
\ No newline at end of file
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
new file mode 100644
index 0000000..2c150fc
--- /dev/null
+++ b/CHANGELOG.rst
@@ -0,0 +1,6 @@
+gnocchi formula
+=====================================
+
+2018.1 (2018-01-23)
+
+- Initial formula setup
diff --git a/INTEGRATION.rst b/INTEGRATION.rst
new file mode 100644
index 0000000..6555079
--- /dev/null
+++ b/INTEGRATION.rst
@@ -0,0 +1,114 @@
+
+Continuous Integration
+======================
+
+We are using Jenkins to spin a kitchen instances in Docker or OpenStack environment.
+
+If you would like to repeat, then you may use ``.kitchen.<backend>.yml`` configuration yaml in the main directory
+to override ``.kitchen.yml`` at some points.
+Usage: ``KITCHEN_LOCAL_YAML=.kitchen.<driver>.yml kitchen verify server-ubuntu-1404 -t tests/integration``.
+Example: ``KITCHEN_LOCAL_YAML=.kitchen.docker.yml kitchen verify server-ubuntu-1404 -t tests/integration``.
+
+Be aware of fundamental differences of backends. The formula verification scripts are primarily tested with
+Vagrant driver.
+
+CI uses a tuned `make kitchen` target defined in `Makefile` to perform following (Kitchen Test) actions:
+
+1. *create*, provision an test instance (VM, container)
+2. *converge*, run a provisioner (shell script, kitchen-salt)
+3. *verify*, run a verification (inspec, other may be added)
+4. *destroy*
+
+
+Test Kitchen
+------------
+
+
+To install Test Kitchen is as simple as:
+
+.. code-block:: shell
+
+ # install kitchen
+ gem install test-kitchen
+
+ # install required plugins
+ gem install kitchen-vagrant kitchen-docker kitchen-salt
+
+ # install additional plugins & tools
+ gem install kitchen-openstack kitchen-inspec busser-serverspec
+
+ kitchen list
+ kitchen test
+
+of course you have to have installed Ruby and it's package manager `gem <https://rubygems.org/>`_ first.
+
+One may be satisfied installing it system-wide right from OS package manager which is preferred installation method.
+For advanced users or the sake of complex environments you may use `rbenv <https://github.com/rbenv/rbenv>`_ for user side ruby installation.
+
+ * https://github.com/rbenv/rbenv
+ * http://kitchen.ci/docs/getting-started/installing
+
+An example steps then might be:
+
+.. code-block:: shell
+
+ # get rbenv
+ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
+
+ # configure
+ cd ~/.rbenv && src/configure && make -C src # don't worry if it fails
+ echo 'export PATH="$HOME/.rbenv/bin:$PATH"'>> ~/.bash_profile
+ # Ubuntu Desktop note: Modify your ~/.bashrc instead of ~/.bash_profile.
+ cd ~/.rbenv; git fetch
+
+ # install ruby-build, which provides the rbenv install command
+ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
+
+ # list all available versions:
+ rbenv install -l
+
+ # install a Ruby version
+ # maybe you will need additional packages: libssl-dev, libreadline-dev, zlib1g-dev
+ rbenv install 2.0.0-p648
+
+ # activate
+ rbenv local 2.0.0-p648
+
+ # install test kitchen
+ gem install test-kitchen
+
+
+An optional ``Gemfile`` in the main directory may contain Ruby dependencies to be required for Test Kitchen workflow.
+To install them you have to install first ``gem install bundler`` and then run ``bundler install``.
+
+
+
+Verifier
+--------
+
+The `Busser <https://github.com/test-kitchen/busser>`_ *Verifier* goes with test-kitchen by default.
+It is used to setup and run tests implemented in `<repo>/test/integration`. It guess and installs the particular driver to tested instance.
+By default `InSpec <https://github.com/chef/kitchen-inspec>`_ is expected.
+
+You may avoid to install busser framework if you configure specific verifier in `.kitchen.yml` and install it kitchen plugin locally:
+
+ verifier:
+ name: serverspec
+
+If you would to write another verification scripts than InSpec store them in ``<repo>/tests/integration/<suite>/<busser>/*``.
+``Busser <https://github.com/test-kitchen/busser>`` is a test setup and execution framework under test kitchen.
+
+
+
+InSpec
+~~~~~~
+
+Implement integration tests under ``<repo>/tests/integration/<suite>/<busser>/*`` directory with ``_spec.rb`` filename
+suffix.
+
+Docs:
+
+* https://github.com/chef/inspec
+* https://github.com/chef/kitchen-inspec
+
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..2bb6c1a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,13 @@
+Copyright (c) 2018 Mykyta Karpin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
\ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d0e6fa4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,127 @@
+DESTDIR=/
+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)")))
+
+ifneq ($(subst -j,,$(JOB_FLAG)),)
+JOBS := $(subst -j,,$(JOB_FLAG))
+else
+JOBS := 1
+endif
+
+KITCHEN_LOCAL_YAML?=.kitchen.yml
+KITCHEN_OPTS?="--concurrency=$(JOBS)"
+KITCHEN_OPTS_CREATE?=""
+KITCHEN_OPTS_CONVERGE?=""
+KITCHEN_OPTS_VERIFY?=""
+KITCHEN_OPTS_TEST?=""
+
+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
+ [ -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 _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)
+
+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)
+ 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 $(VERSION_MAJOR) $(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-check
+ kitchen converge ${KITCHEN_OPTS} ${KITCHEN_OPTS_CONVERGE} &&\
+ kitchen converge ${KITCHEN_OPTS} ${KITCHEN_OPTS_CONVERGE}
+
+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-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-check
+ kitchen list
+
+clean:
+ [ ! -x "$(shell which kitchen)" ] || kitchen destroy
+ [ ! -d .kitchen ] || rm -rf .kitchen
+ [ ! -d tests/build ] || rm -rf tests/build
+ [ ! -d build ] || rm -rf build
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..984d971
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,270 @@
+
+==================================
+Gnocchi Formula
+==================================
+
+Service Gnocchi description
+
+Gnocchi is an open-source time series database. The problem that Gnocchi solves
+is the storage and indexing of time series data and resources at a large scale.
+This is useful in modern cloud platforms which are not only huge but also are
+dynamic and potentially multi-tenant. Gnocchi takes all of that into account.
+
+
+Sample Pillars
+==============
+
+.. note::
+ Before deploying gnocchi, Apache2 should be configured to serve wsgi vhost for Gnocchi API.
+ Example of Apache pillar with Gnocchi site:
+
+.. code-block:: yaml
+
+ apache:
+ server:
+ enabled: true
+ default_mpm: event
+ mpm:
+ prefork:
+ enabled: true
+ servers:
+ start: 5
+ spare:
+ min: 2
+ max: 10
+ max_requests: 0
+ max_clients: 20
+ limit: 20
+ site:
+ gnocchi:
+ enabled: false
+ available: true
+ type: wsgi
+ name: gnocchi
+ host:
+ name: gnocchi.site.com
+ address: 127.0.0.1
+ port: 8041
+ log:
+ custom:
+ format: >-
+ %v:%p %{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %D %O \"%{Referer}i\" \"%{User-Agent}i\"
+ wsgi:
+ daemon_process: gnocchi-api
+ processes: ${_param:gnocchi_api_workers}
+ threads: 10
+ user: gnocchi
+ group: gnocchi
+ display_name: '%{GROUP}'
+ script_alias: '/ /usr/bin/gnocchi-api'
+ application_group: '%{GLOBAL}'
+ authorization: 'On'
+ pkgs:
+ - apache2
+ modules:
+ - wsgi
+
+Single Gnocchi service with file storage backend
+
+ gnocchi:
+ server:
+ enabled: true
+ version: 4.0
+ database:
+ engine: mysql
+ host: 127.0.0.1
+ name: gnocchi
+ password: workshop
+ user: gnocchi
+ storage:
+ aggregation_workers: 2
+ driver: file
+ file_basepath: /var/lib/gnocchi
+ coordination_backend:
+ url: redis://127.0.0.1:6379/
+ bind:
+ address: 127.0.0.1
+ port: 8041
+ api:
+ auth_mode: keystone
+ identity:
+ engine: keystone
+ region: RegionOne
+ protocol: http
+ host: 127.0.0.1
+ port: 35357
+ user: gnocchi
+ password: 127.0.0.1
+ cache:
+ engine: memcached
+ members:
+ - host: 127.0.0.1
+ port: 11211
+
+Single Gnocchi service with redis storage backend
+
+.. code-block:: yaml
+
+ gnocchi:
+ server:
+ enabled: true
+ version: 4.0
+ database:
+ engine: mysql
+ host: 127.0.0.1
+ name: gnocchi
+ password: workshop
+ user: gnocchi
+ storage:
+ aggregation_workers: 2
+ driver: redis
+ redis_url: redis://127.0.0.1:6379/
+ coordination_backend:
+ url: redis://127.0.0.1:6379/
+ bind:
+ address: 127.0.0.1
+ port: 8041
+ api:
+ auth_mode: keystone
+ identity:
+ engine: keystone
+ region: RegionOne
+ protocol: http
+ host: 127.0.0.1
+ port: 35357
+ user: gnocchi
+ password: 127.0.0.1
+ cache:
+ engine: memcached
+ members:
+ - host: 127.0.0.1
+ port: 11211
+
+Single Gnocchi service with redis backend for incoming storage and file backend for aggregated storage
+
+.. code-block:: yaml
+
+ gnocchi:
+ server:
+ enabled: true
+ version: 4.0
+ database:
+ engine: mysql
+ host: 127.0.0.1
+ name: gnocchi
+ password: workshop
+ user: gnocchi
+ storage:
+ aggregation_workers: 2
+ driver: file
+ file_basepath: /var/lib/gnocchi
+ incoming:
+ driver: redis
+ redis_url: redis://127.0.0.1:6379/
+ coordination_backend:
+ url: redis://127.0.0.1:6379/
+ bind:
+ address: 127.0.0.1
+ port: 8041
+ api:
+ auth_mode: keystone
+ identity:
+ engine: keystone
+ region: RegionOne
+ protocol: http
+ host: 127.0.0.1
+ port: 35357
+ user: gnocchi
+ password: 127.0.0.1
+ cache:
+ engine: memcached
+ members:
+ - host: 127.0.0.1
+ port: 11211
+
+Single Gnocchi service with Gnocchi statsd on the same node:
+
+.. code-block:: yaml
+
+ gnocchi:
+ common:
+ version: 4.0
+ database:
+ engine: mysql
+ host: 127.0.0.1
+ name: gnocchi
+ password: workshop
+ user: gnocchi
+ storage:
+ aggregation_workers: 2
+ driver: redis
+ redis_url: redis://127.0.0.1/test
+ coordination_backend:
+ url: redis://127.0.0.1/test
+ server:
+ enabled: true
+ bind:
+ address: 127.0.0.1
+ port: 8041
+ api:
+ auth_mode: keystone
+ workers: 5
+ identity:
+ engine: keystone
+ region: RegionOne
+ protocol: http
+ host: 127.0.0.1
+ port: 35357
+ user: gnocchi
+ password: workshop
+ tenant: service
+ cache:
+ engine: memcached
+ members:
+ - host: 127.0.0.1
+ port: 11211
+ metricd:
+ workers: 5
+ statsd:
+ resource_id: 07f26121-5777-48ba-8a0b-d70468133dd9
+ enabled: true
+ bind:
+ address: 127.0.0.1
+ port: 8125
+
+More Information
+================
+
+* https://gnocchi.xyz/
+
+
+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-gnocchi/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
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..dba9043
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+2018.1
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..342ed57
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,5 @@
+salt-formula-gnocchi (2018.1) xenial; urgency=medium
+
+ * Initial release
+
+ -- Mykyta Karpin mkarpin@mirantis.com Tue, 23 Jan 2018 04:00:34 GMT
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..ec63514
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+9
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..fa9a869
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,15 @@
+Source: salt-formula-gnocchi
+Maintainer: Mykyta Karpin <mkarpin@mirantis.com>
+Section: admin
+Priority: optional
+Build-Depends: debhelper (>= 9), salt-master, python, python-yaml
+Standards-Version: 3.9.6
+Homepage: https://github.com/salt-formulas
+Vcs-Browser: https://github.com/salt-formulas/salt-formula-gnocchi
+Vcs-Git: https://github.com/salt-formulas/salt-formula-gnocchi.git
+
+Package: salt-formula-gnocchi
+Architecture: all
+Depends: ${misc:Depends}
+Description: gnocchi salt formula
+ Install and configure gnocchi.
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..8e46ab6
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,15 @@
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: salt-formula-gnocchi
+Upstream-Contact: salt-formulas@freelists.org
+Source: https://github.com/salt-formulas/salt-formula-gnocchi
+
+Files: *
+Copyright: 2018 Mykyta Karpin
+License: Apache-2.0
+ Copyright (C) 2018 Mykyta Karpin
+ .
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ .
+ On a Debian system you can find a copy of this license in
+ /usr/share/common-licenses/Apache-2.0.
diff --git a/debian/docs b/debian/docs
new file mode 100644
index 0000000..d585829
--- /dev/null
+++ b/debian/docs
@@ -0,0 +1,3 @@
+README.rst
+CHANGELOG.rst
+VERSION
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..abde6ef
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,5 @@
+#!/usr/bin/make -f
+
+%:
+ dh $@
+
diff --git a/debian/source/format b/debian/source/format
new file mode 100644
index 0000000..89ae9db
--- /dev/null
+++ b/debian/source/format
@@ -0,0 +1 @@
+3.0 (native)
diff --git a/doc/source/conf.py b/doc/source/conf.py
new file mode 100644
index 0000000..59b7dc3
--- /dev/null
+++ b/doc/source/conf.py
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import sys
+
+sys.path.insert(0, os.path.abspath('../..'))
+# -- General configuration ----------------------------------------------------
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+extensions = [
+ 'sphinx.ext.autodoc',
+]
+
+# autodoc generation is a bit aggressive and a nuisance when doing heavy
+# text edit cycles.
+# execute "export SPHINX_DEBUG=1" in your terminal to disable
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'salt-formula-gnocchi'
+copyright = u'2016, Mykyta Karpin'
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+add_module_names = True
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# -- Options for HTML output --------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. Major themes that come with
+# Sphinx are currently 'default' and 'sphinxdoc'.
+# html_theme_path = ["."]
+# html_theme = '_theme'
+# html_static_path = ['static']
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = '%sdoc' % project
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, documentclass
+# [howto/manual]).
+latex_documents = [
+ ('index',
+ '%s.tex' % project,
+ u'%s Documentation' % project,
+ u'OpenStack Foundation', 'manual'),
+]
+
+# Example configuration for intersphinx: refer to the Python standard library.
+# intersphinx_mapping = {'http://docs.python.org/': None}
diff --git a/doc/source/index.rst b/doc/source/index.rst
new file mode 100644
index 0000000..a6210d3
--- /dev/null
+++ b/doc/source/index.rst
@@ -0,0 +1 @@
+.. include:: ../../README.rst
diff --git a/gnocchi/_common.sls b/gnocchi/_common.sls
new file mode 100644
index 0000000..e9477b3
--- /dev/null
+++ b/gnocchi/_common.sls
@@ -0,0 +1,27 @@
+{%- from "gnocchi/map.jinja" import cfg with context %}
+
+gnocchi_common.pkgs:
+ pkg.installed:
+ - name: 'gnocchi-common'
+
+gnocchi_common_conf:
+ file.managed:
+ - name: /etc/gnocchi/gnocchi.conf
+ - source: salt://gnocchi/files/{{ cfg.version }}/gnocchi.conf
+ - template: jinja
+ - require:
+ - pkg: gnocchi_common.pkgs
+
+{%- if cfg.database.get('ssl',{}).get('enabled', False) %}
+mysql_ca_gnocchi_file:
+{%- if cfg.database.ssl.cacert is defined %}
+ file.managed:
+ - name: {{ cfg.databse.ssl.cacert_file }}
+ - contents_pillar: cfg.database:ssl:cacert
+ - mode: 0444
+ - makedirs: true
+{%- else %}
+ file.exists:
+ - name: {{ cfg.database.ssl.get('cacert_file', cfg.cacert_file) }}
+{%- endif %}
+{%- endif %}
\ No newline at end of file
diff --git a/gnocchi/client.sls b/gnocchi/client.sls
new file mode 100644
index 0000000..df89c5f
--- /dev/null
+++ b/gnocchi/client.sls
@@ -0,0 +1,8 @@
+{%- from "gnocchi/map.jinja" import client with context %}
+{%- if client.enabled %}
+
+gnocchi_client_packages:
+ pkg.installed:
+ - names: {{ client.pkgs }}
+
+{%- endif %}
\ No newline at end of file
diff --git a/gnocchi/files/4.0/gnocchi.conf b/gnocchi/files/4.0/gnocchi.conf
new file mode 100644
index 0000000..3346841
--- /dev/null
+++ b/gnocchi/files/4.0/gnocchi.conf
@@ -0,0 +1,168 @@
+{% from "gnocchi/map.jinja" import cfg,server,statsd with context %}
+{% set storage = cfg.get('storage', {}) %}
+[DEFAULT]
+
+debug = {{ cfg.debug }}
+
+[api]
+
+auth_mode = {{ server.identity.engine }}
+
+{%- if server.get('api', {}).max_limit is defined %}
+max_limit = {{ server.api.max_limit }}
+{%- endif %}
+
+{%- if server.get('api', {}).refresh_timeout is defined %}
+refresh_timeout = {{ server.api.refresh_timeout }}
+{%- endif %}
+
+
+[archive_policy]
+
+{%- if server.get('archive_policy', {}).default_aggregation_methods is defined %}
+default_aggregation_methods = {{ ','.join(server.archive_policy.default_aggregation_methods) }}
+{%- endif %}
+
+
+[incoming]
+
+{%- set _storage = storage.get('incoming', {}) %}
+{%- if _storage.driver is defined %}
+driver = {{ _storage.driver }}
+{% include "gnocchi/files/" + cfg.version|string + "/storage/_" + _storage.driver + ".conf" %}
+{%- endif %}
+
+[indexer]
+
+url = {{ cfg.database.engine }}+pymysql://{{ cfg.database.user }}:{{ cfg.database.password }}@{{ cfg.database.host }}/{{ cfg.database.name }}{%- if cfg.database.get('ssl',{}).get('enabled',False) %}?ssl_ca={{ cfg.database.ssl.get('cacert_file', cfg.cacert_file) }}{% endif %}
+
+
+[keystone_authtoken]
+
+{%- if server.identity.engine == 'keystone' %}
+user_domain_id = {{ server.identity.get('domain', 'default') }}
+project_domain_id = {{ server.identity.get('domain', 'default') }}
+project_name = {{ server.identity.tenant }}
+username = {{ server.identity.user }}
+password = {{ server.identity.password }}
+auth_uri = {{ server.identity.get('protocol', 'http') }}://{{ server.identity.host }}:{{ server.identity.private_port }}
+auth_url = {{ server.identity.protocol }}://{{ server.identity.host }}:{{ server.identity.port }}
+{%- if server.identity.protocol == 'https' %}
+cafile={{ server.identity.get('cacert_file', server.cacert_file) }}
+{%- endif %}
+
+{%- if server.identity.auth_type is defined %}
+auth_type = {{ server.identity.auth_type }}
+{%- endif %}
+
+{%- endif %}
+
+{%- if server.cache is defined %}
+memcached_servers={%- for member in server.cache.members %}{{ member.host }}:{{ member.port }}{% if not loop.last %},{% endif %}{%- endfor %}
+{%- endif %}
+
+{%- if server.get('cache', {}).token_cache_time is defined %}
+token_cache_time = {{ server.cache.token_cache_time }}
+{%- endif %}
+
+{%- if server.get('cache', {}).memcache_security_strategy is defined %}
+memcache_security_strategy = {{ server.cache.memcache_security_strategy }}
+{%- endif %}
+
+{%- if server.get('cache', {}).memcache_security_strategy is defined %}
+memcache_secret_key = {{ server.cache.memcache_secret_key }}
+{%- endif %}
+
+{%- if server.get('cache', {}).memcache_pool_dead_retry is defined %}
+memcache_pool_dead_retry = {{ server.cache.memcache_pool_dead_retry }}
+{%- endif %}
+
+{%- if server.get('cache', {}).memcache_pool_maxsize is defined %}
+memcache_pool_maxsize = {{ server.cache.memcache_pool_maxsize }}
+{%- endif %}
+
+{%- if server.get('cache', {}).memcache_pool_socket_timeout is defined %}
+memcache_pool_socket_timeout = {{ server.cache.memcache_pool_socket_timeout }}
+{%- endif %}
+
+{%- if server.get('cache', {}).memcache_pool_unused_timeout is defined %}
+memcache_pool_unused_timeout = {{ server.cache.memcache_pool_unused_timeout }}
+{%- endif %}
+
+{%- if server.get('cache', {}).memcache_pool_conn_get_timeout is defined %}
+memcache_pool_conn_get_timeout = {{ server.cache.memcache_pool_conn_get_timeout }}
+{%- endif %}
+
+[metricd]
+
+{%- if server.get('metricd', {}).workers is defined %}
+workers = {{ server.metricd.workers }}
+{%- endif %}
+
+{%- if server.get('metricd', {}).metric_processing_delay is defined %}
+metric_processing_delay = {{ server.metricd.metric_processing_delay }}
+{%- endif %}
+
+{%- if server.get('metricd', {}).metric_reporting_delay is defined %}
+metric_reporting_delay = {{ server.metricd.metric_reporting_delay }}
+{%- endif %}
+
+{%- if server.get('metricd', {}).metric_cleanup_delay is defined %}
+metric_cleanup_delay = {{ server.metricd.metric_cleanup_delay }}
+{%- endif %}
+
+{%- if server.get('metricd', {}).worker_sync_rate is defined %}
+worker_sync_rate = {{ server.metricd.worker_sync_rate }}
+{%- endif %}
+
+{%- if server.get('metricd', {}).processing_replicas is defined %}
+processing_replicas = {{ server.metricd.processing_replicas }}
+{%- endif %}
+
+
+[oslo_middleware]
+
+enable_proxy_headers_parsing = {{ server.enable_proxy_headers_parsing }}
+
+[statsd]
+
+{%- if statsd.get('bind', {}).address is defined %}
+host = {{ statsd.bind.address }}
+{%- endif %}
+
+{%- if statsd.get('bind', {}).port is defined %}
+port = {{ statsd.bind.port }}
+{%- endif %}
+
+{%- if statsd.get('enabled', False) %}
+resource_id = {{ statsd.resource_id }}
+{%- endif %}
+
+{%- if statsd.user_id is defined and statsd.project_id is defined %}
+creator = {{ statsd.user_id }}:{{ statsd.project_id }}
+{%- endif %}
+
+{%- if statsd.archive_policy_name is defined %}
+archive_policy_name = {{ statsd.archive_policy_name }}
+{%- endif %}
+
+{%- if statsd.flush_delay is defined %}
+flush_delay = {{ statsd.flush_delay }}
+{%- endif %}
+
+
+[storage]
+
+{%- set _storage = storage %}
+{%- if _storage.driver is defined %}
+driver = {{ _storage.driver }}
+{% include "gnocchi/files/" + cfg.version|string + "/storage/_" + _storage.driver + ".conf" %}
+{%- endif %}
+
+{%- if storage.aggregation_workers is defined %}
+aggregation_workers_number = {{ storage.aggregation_workers }}
+{%- endif %}
+
+{%- if cfg.coordination_backend is defined %}
+coordination_url = {{ cfg.coordination_backend.url }}
+{%- endif %}
diff --git a/gnocchi/files/4.0/storage/_ceph.conf b/gnocchi/files/4.0/storage/_ceph.conf
new file mode 100644
index 0000000..aad3b43
--- /dev/null
+++ b/gnocchi/files/4.0/storage/_ceph.conf
@@ -0,0 +1,23 @@
+{%- if _storage.ceph_pool is defined %}
+ceph_pool = {{ _storage.ceph_pool }}
+{%- endif %}
+
+{%- if _storage.ceph_username is defined %}
+ceph_username = {{ _storage.ceph_username }}
+{%- endif %}
+
+{%- if _storage.ceph_secret is defined %}
+ceph_secret = {{ _storage.ceph_secret }}
+{%- endif %}
+
+{%- if _storage.ceph_keyring is defined %}
+ceph_keyring = {{ _storage.ceph_keyring }}
+{%- endif %}
+
+{%- if _storage.ceph_timeout is defined %}
+ceph_timeout = {{ _storage.ceph_timeout }}
+{%- endif %}
+
+{%- if _storage.ceph_conf is defined %}
+ceph_conffile = {{ _storage.ceph_conf }}
+{%- endif %}
diff --git a/gnocchi/files/4.0/storage/_file.conf b/gnocchi/files/4.0/storage/_file.conf
new file mode 100644
index 0000000..a3d4de7
--- /dev/null
+++ b/gnocchi/files/4.0/storage/_file.conf
@@ -0,0 +1,3 @@
+{%- if _storage.file_basepath is defined %}
+file_basepath = {{ _storage.file_basepath }}
+{%- endif %}
\ No newline at end of file
diff --git a/gnocchi/files/4.0/storage/_redis.conf b/gnocchi/files/4.0/storage/_redis.conf
new file mode 100644
index 0000000..bede88b
--- /dev/null
+++ b/gnocchi/files/4.0/storage/_redis.conf
@@ -0,0 +1,3 @@
+{%- if _storage.redis_url is defined %}
+redis_url = {{ _storage.redis_url }}
+{%- endif %}
\ No newline at end of file
diff --git a/gnocchi/files/4.0/storage/_s3.conf b/gnocchi/files/4.0/storage/_s3.conf
new file mode 100644
index 0000000..b259cee
--- /dev/null
+++ b/gnocchi/files/4.0/storage/_s3.conf
@@ -0,0 +1,23 @@
+{%- if _storage.s3_endpoint_url is defined %}
+s3_endpoint_url = {{ _storage.s3_endpoint_url }}
+{%- endif %}
+
+{%- if _storage.s3_region_name is defined %}
+s3_region_name = {{ _storage.s3_region_name }}
+{%- endif %}
+
+{%- if _storage.s3_access_key_id is defined %}
+s3_access_key_id = {{ _storage.s3_access_key_id }}
+{%- endif %}
+
+{%- if _storage.s3_secret_access_key is defined %}
+s3_secret_access_key = {{ _storage.s3_secret_access_key }}
+{%- endif %}
+
+{%- if _storage.s3_bucket_prefix is defined %}
+s3_bucket_prefix = {{ _storage.s3_bucket_prefix }}
+{%- endif %}
+
+{%- if _storage.s3_check_consistency_timeout is defined %}
+s3_check_consistency_timeout = {{ _storage.s3_check_consistency_timeout }}
+{%- endif %}
\ No newline at end of file
diff --git a/gnocchi/files/4.0/storage/_swift.conf b/gnocchi/files/4.0/storage/_swift.conf
new file mode 100644
index 0000000..92d04dc
--- /dev/null
+++ b/gnocchi/files/4.0/storage/_swift.conf
@@ -0,0 +1,47 @@
+{%- if _storage.swift_auth_version %}
+swift_auth_version = {{ _storage.swift_auth_version }}
+{%- endif %}
+
+{%- if _storage.swift_preauthurl is defined %}
+swift_preauthurl = {{ _storage.swift_preauthurl }}
+{%- endif %}
+
+{%- if _storage.swift_authurl is defined %}
+swift_authurl = {{ _storage.swift_authurl }}
+{%- endif %}
+
+{%- if _storage.swift_preauthtoken is defined %}
+swift_preauthtoken = {{ _storage.swift_preauthtoken }}
+{%- endif %}
+
+{%- if _storage.swift_user is defined %}
+swift_user = {{ _storage.swift_user }}
+{%- endif %}
+
+{%- if _storage.swift_user_domain_name is defined %}
+swift_user_domain_name = {{ _storage.swift_user_domain_name }}
+{%- endif %}
+
+{%- if _storage.swift_key is defined %}
+swift_key = {{ _storage.swift_key }}
+{%- endif %}
+
+{%- if _storage.swift_project_name is defined %}
+swift_project_name = {{ _storage.swift_project_name }}
+{%- endif %}
+
+{%- if _storage.swift_project_domain_name is defined %}
+swift_project_domain_name = {{ _storage.swift_project_domain_name }}
+{%- endif %}
+
+{%- if _storage.swift_container_prefix is defined %}
+swift_container_prefix = {{ _storage.swift_container_prefix }}
+{%- endif %}
+
+{%- if _storage.swift_endpoint_type is defined %}
+swift_endpoint_type = {{ _storage.swift_endpoint_type }}
+{%- endif %}
+
+{%- if _storage.swift_timeout is defined %}
+swift_timeout = {{ _storage.swift_timeout }}
+{%- endif %}
\ No newline at end of file
diff --git a/gnocchi/init.sls b/gnocchi/init.sls
new file mode 100644
index 0000000..8a187a3
--- /dev/null
+++ b/gnocchi/init.sls
@@ -0,0 +1,12 @@
+{%- if pillar.gnocchi is defined %}
+include:
+{%- if pillar.gnocchi.server is defined %}
+- gnocchi.server
+{%- endif %}
+{%- if pillar.gnocchi.statsd is defined %}
+- gnocchi.statsd
+{%- endif %}
+{%- if pillar.gnocchi.client is defined %}
+- gnocchi.client
+{%- endif %}
+{%- endif %}
diff --git a/gnocchi/map.jinja b/gnocchi/map.jinja
new file mode 100644
index 0000000..69b5d50
--- /dev/null
+++ b/gnocchi/map.jinja
@@ -0,0 +1,59 @@
+{%- set default_params = {
+ 'cacert_file': salt['grains.filter_by']({
+ 'Debian': '/etc/ssl/certs/ca-certificates.crt',
+ })}
+%}
+
+{% set cfg = pillar.gnocchi.get('common', {}) %}
+
+{%- load_yaml as server_defaults %}
+BaseDefaults: {{ default_params }}
+Debian:
+ pkgs:
+ - gnocchi-api
+ - gnocchi-metricd
+ services:
+ - gnocchi-metricd
+ identity:
+ engine: keystone
+
+{%- endload %}
+
+{% set server = salt["grains.filter_by"](server_defaults, merge=pillar.gnocchi.get('server', {}), base='BaseDefaults') %}
+
+{%- if server.get('enabled', False) %}
+
+{% set cfg = salt['grains.filter_by']({
+ 'default': cfg,
+}, default='default', merge=server) %}
+
+{%- endif %}
+
+{%- load_yaml as statsd_defaults %}
+BaseDefaults: {{ default_params }}
+Debian:
+ pkgs:
+ - gnocchi-statsd
+ services:
+ - gnocchi-statsd
+
+{%- endload %}
+
+{% set statsd = salt["grains.filter_by"](statsd_defaults, merge=pillar.gnocchi.get('statsd', {}), base='BaseDefaults') %}
+
+{%- if statsd.get('enabled', False) %}
+
+{% set cfg = salt['grains.filter_by']({
+ 'default': cfg,
+}, default='default', merge=statsd) %}
+
+{%- endif %}
+
+{%- load_yaml as client_defaults %}
+BaseDefaults: {{ default_params }}
+Debian:
+ pkgs:
+ - python-gnocchiclient
+{%- endload %}
+
+{% set client = salt['grains.filter_by'](client_defaults, merge=pillar.gnocchi.get('client', {}), base='BaseDefaults') %}
diff --git a/gnocchi/meta/sensu.yml b/gnocchi/meta/sensu.yml
new file mode 100644
index 0000000..556100d
--- /dev/null
+++ b/gnocchi/meta/sensu.yml
@@ -0,0 +1,14 @@
+# Sample check
+check:
+ local_gnocchi_metricd_proc:
+ command: "PATH=$PATH:/usr/lib64/nagios/plugins:/usr/lib/nagios/plugins check_procs -C gnocchi-metricd -u gnocchi -c 1:1024"
+ interval: 60
+ occurrences: 1
+ subscribers:
+ - local-gnocchi-server
+ local_gnocchi_statsd_proc:
+ command: "PATH=$PATH:/usr/lib64/nagios/plugins:/usr/lib/nagios/plugins check_procs -C gnocchi-statsd -u gnocchi -c 1:1024"
+ interval: 60
+ occurrences: 1
+ subscribers:
+ - local-gnocchi-server
diff --git a/gnocchi/meta/sphinx.yml b/gnocchi/meta/sphinx.yml
new file mode 100644
index 0000000..1c0dcdc
--- /dev/null
+++ b/gnocchi/meta/sphinx.yml
@@ -0,0 +1,49 @@
+doc:
+ name: gnocchi
+ description: Gnocchi is an open-source time series database
+ role:
+ {%- if pillar.gnocchi.server is defined %}
+ {%- from "gnocchi/map.jinja" import cfg,server with context %}
+ server:
+ name: server
+ param:
+ debug: {{ server.debug }}
+ api_auth_mode:
+ name: "API authentication mode"
+ value: {{ server.identity.engine }}
+ {%- if server.get('api', {}).max_limit is defined %}
+ api_max_limit:
+ name: "The maximum number of items returned in a single response from a collection resource (integer value)"
+ value: {{ server.api.max_limit }}
+ {%- endif %}
+ {%- if server.get('api', {}).refresh_timeout is defined %}
+ api_refresh_timeout:
+ name: "Number of seconds before timeout when attempting to force refresh of metric. (integer value)"
+ value: {{ server.api.refresh_timeout }}
+ {%- endif %}
+ {%- if server.get('archive_policy', {}).default_aggregation_methods is defined %}
+ archive_policy_default_aggregation_methods:
+ name: "Default aggregation methods to use in created archive policies (list value)"
+ value: {{ ','.join(server.archive_policy.default_aggregation_methods) }}
+ {%- endif %}
+ {%- if server.identity.engine == 'keystone' %}
+ identity_auth_url:
+ name: "Identity auth url"
+ value: {{ server.identity.protocol }}://{{ server.identity.host }}:{{ server.identity.port }}
+ identity_auth_uri:
+ name: "Identity auth uri"
+ value: {{ server.identity.get('protocol', 'http') }}://{{ server.identity.host }}:5000
+ identity_username:
+ name: "Identity username"
+ value: {{ server.identity.user }}
+ identity_password:
+ name: "Identity password"
+ value: {{ server.identity.password }}
+ {%- endif %}
+ indexer_url:
+ name: "URL to indexer backend"
+ value: {{ cfg.database.engine }}+pymysql://{{ cfg.database.user }}:{{ cfg.database.password }}@{{ cfg.database.host }}/{{ cfg.database.name }}{%- if cfg.database.get('ssl',{}).get('enabled',False) %}?ssl_ca={{ cfg.database.ssl.get('cacert_file', cfg.cacert_file) }}{% endif %}
+ cache_memcached_servers:
+ name: "Memcached servers for token cache"
+ value: {%- for member in server.cache.members %}{{ member.host }}:{{ member.port }}{% if not loop.last %},{% endif %}{%- endfor %}
+ {%- endif %}
diff --git a/gnocchi/server.sls b/gnocchi/server.sls
new file mode 100644
index 0000000..c506c46
--- /dev/null
+++ b/gnocchi/server.sls
@@ -0,0 +1,56 @@
+{%- from "gnocchi/map.jinja" import server,cfg with context %}
+{%- if server.get('enabled', False) %}
+
+include:
+ - apache
+ - gnocchi._common
+
+gnocchi_server_packages:
+ pkg.installed:
+ - names: {{ server.pkgs }}
+
+gnocchi_upgrade:
+ cmd.run:
+ - name: gnocchi-upgrade
+ {%- if grains.get('noservices') %}
+ - onlyif: /bin/false
+ {%- endif %}
+ - runas: gnocchi
+ - require:
+ - file: gnocchi_common_conf
+
+apache_enable_gnocchi_wsgi:
+ apache_site.enabled:
+ - name: wsgi_gnocchi
+ {%- if grains.get('noservices') %}
+ - onlyif: /bin/false
+ {%- endif %}
+ - require:
+ - cmd: gnocchi_upgrade
+
+gnocchi_apache_restart:
+ service.running:
+ - name: apache2
+ - enable: true
+ {%- if grains.get('noservices') %}
+ - onlyif: /bin/false
+ {%- endif %}
+ - watch:
+ - apache_enable_gnocchi_wsgi
+
+gnocchi_server_services:
+ service.running:
+ - enable: true
+ - names: {{ server.services }}
+ {%- if grains.get('noservices') %}
+ - onlyif: /bin/false
+ {%- endif %}
+ - require:
+ - cmd: gnocchi_upgrade
+ - watch:
+ - gnocchi_common_conf
+{%- if cfg.database.get('ssl',{}).get('enabled', False) %}
+ - mysql_ca_gnocchi_file
+{%- endif %}
+
+{%- endif %}
diff --git a/gnocchi/statsd.sls b/gnocchi/statsd.sls
new file mode 100644
index 0000000..43ca50a
--- /dev/null
+++ b/gnocchi/statsd.sls
@@ -0,0 +1,27 @@
+{%- from "gnocchi/map.jinja" import statsd,cfg with context %}
+{%- if statsd.get('enabled', False) %}
+
+include:
+ - gnocchi._common
+
+gnocchi_statsd_packages:
+ pkg.installed:
+ - names: {{ statsd.pkgs }}
+
+gnocchi_statsd_services:
+ service.running:
+ - enable: true
+ - names: {{ statsd.services }}
+ {%- if grains.get('noservices') %}
+ - onlyif: /bin/false
+ {%- endif %}
+ - require:
+ - pkg: gnocchi_statsd_packages
+ - watch:
+ - gnocchi_common_conf
+{%- if cfg.database.get('ssl',{}).get('enabled', False) %}
+ - mysql_ca_gnocchi_file
+{%- endif %}
+
+
+{%- endif %}
diff --git a/metadata.yml b/metadata.yml
new file mode 100644
index 0000000..07b53fd
--- /dev/null
+++ b/metadata.yml
@@ -0,0 +1,6 @@
+name: "gnocchi"
+version: "2018.1"
+source: "https://github.com/salt-formulas/salt-formula-gnocchi"
+dependencies:
+ - name: apache
+ source: "https://github.com/salt-formulas/salt-formula-apache"
diff --git a/metadata/service/common/cluster.yml b/metadata/service/common/cluster.yml
new file mode 100644
index 0000000..51fde8a
--- /dev/null
+++ b/metadata/service/common/cluster.yml
@@ -0,0 +1,10 @@
+parameters:
+ gnocchi:
+ common:
+ version: ${_param:gnocchi_version}
+ database:
+ engine: mysql
+ host: ${_param:cluster_vip_address}
+ name: gnocchi
+ password: ${_param:mysql_gnocchi_password}
+ user: gnocchi
\ No newline at end of file
diff --git a/metadata/service/common/single.yml b/metadata/service/common/single.yml
new file mode 100644
index 0000000..cd892a6
--- /dev/null
+++ b/metadata/service/common/single.yml
@@ -0,0 +1,10 @@
+parameters:
+ gnocchi:
+ common:
+ version: ${_param:gnocchi_version}
+ database:
+ engine: mysql
+ host: ${_param:single_address}
+ name: gnocchi
+ password: ${_param:mysql_gnocchi_password}
+ user: gnocchi
\ No newline at end of file
diff --git a/metadata/service/server/cluster.yml b/metadata/service/server/cluster.yml
new file mode 100644
index 0000000..4b95b57
--- /dev/null
+++ b/metadata/service/server/cluster.yml
@@ -0,0 +1,31 @@
+applications:
+- gnocchi
+classes:
+- service.gnocchi.common.cluster
+- service.gnocchi.support
+parameters:
+ gnocchi:
+ server:
+ enabled: true
+ debug: false
+ api:
+ auth_mode: keystone
+ identity:
+ engine: keystone
+ region: RegionOne
+ protocol: http
+ host: ${_param:cluster_vip_address}
+ port: 35357
+ private_port: 5000
+ user: gnocchi
+ password: ${_param:keystone_gnocchi_password}
+ tenant: service
+ cache:
+ engine: memcached
+ members:
+ - host: ${_param:cluster_node01_address}
+ port: 11211
+ - host: ${_param:cluster_node02_address}
+ port: 11211
+ - host: ${_param:cluster_node03_address}
+ port: 11211
\ No newline at end of file
diff --git a/metadata/service/server/single.yml b/metadata/service/server/single.yml
new file mode 100644
index 0000000..fb9bf26
--- /dev/null
+++ b/metadata/service/server/single.yml
@@ -0,0 +1,29 @@
+applications:
+- gnocchi
+classes:
+- service.gnocchi.common.single
+- service.gnocchi.support
+parameters:
+ gnocchi:
+ server:
+ enabled: true
+ debug: false
+ enable_proxy_headers_parsing: true
+ api:
+ auth_mode: keystone
+ identity:
+ engine: keystone
+ region: RegionOne
+ protocol: http
+ host: ${_param:single_address}
+ port: 35357
+ private_port: 5000
+ user: gnocchi
+ password: ${_param:keystone_gnocchi_password}
+ tenant: service
+ auth_type: password
+ cache:
+ engine: memcached
+ members:
+ - host: ${_param:single_address}
+ port: 11211
\ No newline at end of file
diff --git a/metadata/service/statsd/cluster.yml b/metadata/service/statsd/cluster.yml
new file mode 100644
index 0000000..723acfa
--- /dev/null
+++ b/metadata/service/statsd/cluster.yml
@@ -0,0 +1,13 @@
+applications:
+- gnocchi
+classes:
+- service.gnocchi.common.cluster
+- service.gnocchi.support
+parameters:
+ gnocchi:
+ statsd:
+ enabled: true
+ resource_id: ${_param:gnocchi_statsd_resource_id}
+ bind:
+ address: ${_param:cluster_local_address}
+ port: 8125
diff --git a/metadata/service/statsd/single.yml b/metadata/service/statsd/single.yml
new file mode 100644
index 0000000..67bf0a5
--- /dev/null
+++ b/metadata/service/statsd/single.yml
@@ -0,0 +1,13 @@
+applications:
+- gnocchi
+classes:
+- service.gnocchi.common.single
+- service.gnocchi.support
+parameters:
+ gnocchi:
+ statsd:
+ enabled: true
+ resource_id: ${_param:gnocchi_statsd_resource_id}
+ bind:
+ address: ${_param:single_address}
+ port: 8125
diff --git a/metadata/service/support.yml b/metadata/service/support.yml
new file mode 100644
index 0000000..002c442
--- /dev/null
+++ b/metadata/service/support.yml
@@ -0,0 +1,11 @@
+parameters:
+ gnocchi:
+ _support:
+ collectd:
+ enabled: false
+ heka:
+ enabled: false
+ sensu:
+ enabled: false
+ sphinx:
+ enabled: true
diff --git a/releasenotes/config.yaml b/releasenotes/config.yaml
new file mode 100644
index 0000000..fe5bc11
--- /dev/null
+++ b/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/releasenotes/notes/add-releasenotes-9c076c7ee8fbe2a4.yaml b/releasenotes/notes/add-releasenotes-9c076c7ee8fbe2a4.yaml
new file mode 100644
index 0000000..7e96d63
--- /dev/null
+++ b/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/releasenotes/notes/initial-release-600545d40e6c102e.yaml b/releasenotes/notes/initial-release-600545d40e6c102e.yaml
new file mode 100644
index 0000000..2d44aa4
--- /dev/null
+++ b/releasenotes/notes/initial-release-600545d40e6c102e.yaml
@@ -0,0 +1,7 @@
+---
+summary: >
+ Initial release of salt-formula-gnocchi
+
+features:
+ - Supports deployment of statsd and server roles
+ - Gnocchi 4.0.X is supported
diff --git a/tests/pillar/repo_mcp_openstack_pike.sls b/tests/pillar/repo_mcp_openstack_pike.sls
new file mode 100644
index 0000000..789b907
--- /dev/null
+++ b/tests/pillar/repo_mcp_openstack_pike.sls
@@ -0,0 +1,12 @@
+linux:
+ system:
+ enabled: true
+ repo:
+ mirantis_openstack_repo:
+ source: "deb http://mirror.fuel-infra.org/mcp-repos/pike/{{ grains.get('oscodename') }} pike main"
+ architectures: amd64
+ key_url: "http://mirror.fuel-infra.org/mcp-repos/pike/{{ grains.get('oscodename') }}/archive-mcppike.key"
+ pin:
+ - pin: 'release a=pike'
+ priority: 1050
+ package: '*'
\ No newline at end of file
diff --git a/tests/pillar/server_cluster.sls b/tests/pillar/server_cluster.sls
new file mode 100644
index 0000000..8cdcf25
--- /dev/null
+++ b/tests/pillar/server_cluster.sls
@@ -0,0 +1,111 @@
+gnocchi:
+ common:
+ version: 4.0
+ database:
+ engine: mysql
+ host: 127.0.0.1
+ name: gnocchi
+ password: workshop
+ user: gnocchi
+ storage:
+ aggregation_workers: 2
+ driver: ceph
+ ceph_pool: gnocchi
+ ceph_username: gnocchi
+ ceph_secret: workshop
+ ceph_keyring: /etc/ceph/ceph.gnocchi.keyring
+ ceph_timeout: 20
+ ceph_conf: /etc/ceph/ceph.conf
+ redis_url: redis://127.0.0.2/test
+ file_basepath: /var/lib/gnocchi
+ incoming:
+ driver: redis
+ redis_url: redis://127.0.0.2/test_incoming
+ ceph_pool: gnocchi_incoming
+ ceph_username: gnocchi
+ ceph_secret: workshop
+ ceph_keyring: /etc/ceph/ceph.gnocchi.keyring
+ ceph_timeout: 30
+ ceph_conf: /etc/ceph/ceph.conf
+ file_basepath: /var/lib/gnocchi_incoming
+ coordination_backend:
+ url: redis://127.0.0.1/test
+ server:
+ enabled: true
+ debug: true
+ enable_proxy_headers_parsing: true
+ archive_policy:
+ default_aggregation_methods:
+ - mean
+ - max
+ identity:
+ engine: keystone
+ region: RegionOne
+ protocol: http
+ host: 127.0.0.1
+ port: 35357
+ private_port: 5000
+ user: gnocchi
+ password: workshop
+ tenant: service
+ auth_type: password
+ cache:
+ engine: memcached
+ members:
+ - host: 127.0.1.1
+ port: 11211
+ - host: 127.0.2.1
+ port: 11211
+ - host: 127.0.3.1
+ port: 11211
+ metricd:
+ workers: 5
+ statsd:
+ resource_id: 07f26121-5777-48ba-8a0b-d70468133dd9
+ enabled: true
+ bind:
+ address: 127.0.0.1
+ port: 8125
+apache:
+ server:
+ enabled: true
+ default_mpm: event
+ mpm:
+ prefork:
+ enabled: true
+ servers:
+ start: 5
+ spare:
+ min: 2
+ max: 10
+ max_requests: 0
+ max_clients: 20
+ limit: 20
+ site:
+ gnocchi:
+ enabled: false
+ available: true
+ type: wsgi
+ name: gnocchi
+ host:
+ name: gnocchi.ci.local
+ address: 127.0.0.1
+ port: 8041
+ log:
+ custom:
+ format: >-
+ %v:%p %{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %D %O \"%{Referer}i\" \"%{User-Agent}i\"
+ wsgi:
+ daemon_process: gnocchi-api
+ processes: 2
+ threads: 10
+ user: gnocchi
+ group: gnocchi
+ display_name: '%{GROUP}'
+ script_alias: '/ /usr/bin/gnocchi-api'
+ application_group: '%{GLOBAL}'
+ authorization: 'On'
+ pkgs:
+ - apache2
+ modules:
+ - wsgi
\ No newline at end of file
diff --git a/tests/pillar/server_single.sls b/tests/pillar/server_single.sls
new file mode 100644
index 0000000..d152355
--- /dev/null
+++ b/tests/pillar/server_single.sls
@@ -0,0 +1,107 @@
+gnocchi:
+ common:
+ version: 4.0
+ database:
+ engine: mysql
+ host: 127.0.0.1
+ name: gnocchi
+ password: workshop
+ user: gnocchi
+ storage:
+ aggregation_workers: 2
+ driver: ceph
+ ceph_pool: gnocchi
+ ceph_username: gnocchi
+ ceph_secret: workshop
+ ceph_keyring: /etc/ceph/ceph.gnocchi.keyring
+ ceph_timeout: 20
+ ceph_conf: /etc/ceph/ceph.conf
+ redis_url: redis://127.0.0.2/test
+ file_basepath: /var/lib/gnocchi
+ incoming:
+ driver: redis
+ redis_url: redis://127.0.0.2/test_incoming
+ ceph_pool: gnocchi_incoming
+ ceph_username: gnocchi
+ ceph_secret: workshop
+ ceph_keyring: /etc/ceph/ceph.gnocchi.keyring
+ ceph_timeout: 30
+ ceph_conf: /etc/ceph/ceph.conf
+ file_basepath: /var/lib/gnocchi_incoming
+ coordination_backend:
+ url: redis://127.0.0.1/test
+ server:
+ enabled: true
+ debug: true
+ enable_proxy_headers_parsing: true
+ archive_policy:
+ default_aggregation_methods:
+ - mean
+ - max
+ identity:
+ engine: keystone
+ region: RegionOne
+ protocol: http
+ host: 127.0.0.1
+ port: 35357
+ private_port: 5000
+ user: gnocchi
+ password: workshop
+ tenant: service
+ auth_type: password
+ cache:
+ engine: memcached
+ members:
+ - host: 127.0.0.1
+ port: 11211
+ metricd:
+ workers: 5
+ statsd:
+ resource_id: 07f26121-5777-48ba-8a0b-d70468133dd9
+ enabled: true
+ bind:
+ address: 127.0.0.1
+ port: 8125
+apache:
+ server:
+ enabled: true
+ default_mpm: event
+ mpm:
+ prefork:
+ enabled: true
+ servers:
+ start: 5
+ spare:
+ min: 2
+ max: 10
+ max_requests: 0
+ max_clients: 20
+ limit: 20
+ site:
+ gnocchi:
+ enabled: false
+ available: true
+ type: wsgi
+ name: gnocchi
+ host:
+ name: gnocchi.ci.local
+ address: 127.0.0.1
+ port: 8041
+ log:
+ custom:
+ format: >-
+ %v:%p %{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %D %O \"%{Referer}i\" \"%{User-Agent}i\"
+ wsgi:
+ daemon_process: gnocchi-api
+ processes: 2
+ threads: 10
+ user: gnocchi
+ group: gnocchi
+ display_name: '%{GROUP}'
+ script_alias: '/ /usr/bin/gnocchi-api'
+ application_group: '%{GLOBAL}'
+ authorization: 'On'
+ pkgs:
+ - apache2
+ modules:
+ - wsgi
diff --git a/tests/pillar/ssl.sls b/tests/pillar/ssl.sls
new file mode 100644
index 0000000..7f2be44
--- /dev/null
+++ b/tests/pillar/ssl.sls
@@ -0,0 +1,105 @@
+gnocchi:
+ common:
+ version: 4.0
+ database:
+ engine: mysql
+ host: 127.0.0.1
+ name: gnocchi
+ password: workshop
+ user: gnocchi
+ storage:
+ aggregation_workers: 2
+ driver: ceph
+ ceph_pool: gnocchi
+ ceph_username: gnocchi
+ ceph_secret: workshop
+ ceph_keyring: /etc/ceph/ceph.gnocchi.keyring
+ ceph_timeout: 20
+ ceph_conf: /etc/ceph/ceph.conf
+ redis_url: redis://127.0.0.2/test
+ file_basepath: /var/lib/gnocchi
+ incoming:
+ driver: redis
+ redis_url: redis://127.0.0.2/test_incoming
+ ceph_pool: gnocchi_incoming
+ ceph_username: gnocchi
+ ceph_secret: workshop
+ ceph_keyring: /etc/ceph/ceph.gnocchi.keyring
+ ceph_timeout: 30
+ ceph_conf: /etc/ceph/ceph.conf
+ file_basepath: /var/lib/gnocchi_incoming
+ coordination_backend:
+ url: redis://127.0.0.1/test
+ server:
+ enabled: true
+ debug: true
+ archive_policy:
+ default_aggregation_methods:
+ - mean
+ - max
+ identity:
+ engine: keystone
+ region: RegionOne
+ protocol: http
+ host: 127.0.0.1
+ port: 35357
+ private_port: 5000
+ user: gnocchi
+ password: workshop
+ tenant: service
+ cache:
+ engine: memcached
+ members:
+ - host: 127.0.0.1
+ port: 11211
+ metricd:
+ workers: 5
+ statsd:
+ resource_id: 07f26121-5777-48ba-8a0b-d70468133dd9
+ enabled: true
+ bind:
+ address: 127.0.0.1
+ port: 8125
+apache:
+ server:
+ enabled: true
+ default_mpm: event
+ mpm:
+ prefork:
+ enabled: true
+ servers:
+ start: 5
+ spare:
+ min: 2
+ max: 10
+ max_requests: 0
+ max_clients: 20
+ limit: 20
+ site:
+ gnocchi:
+ enabled: false
+ available: true
+ type: wsgi
+ name: gnocchi
+ host:
+ name: gnocchi.ci.local
+ address: 127.0.0.1
+ port: 8041
+ log:
+ custom:
+ format: >-
+ %v:%p %{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %D %O \"%{Referer}i\" \"%{User-Agent}i\"
+ wsgi:
+ daemon_process: gnocchi-api
+ processes: ${_param:gnocchi_api_workers}
+ threads: 10
+ user: gnocchi
+ group: gnocchi
+ display_name: '%{GROUP}'
+ script_alias: '/ /usr/bin/gnocchi-api'
+ application_group: '%{GLOBAL}'
+ authorization: 'On'
+ pkgs:
+ - apache2
+ modules:
+ - wsgi
\ No newline at end of file
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
new file mode 100755
index 0000000..742688b
--- /dev/null
+++ b/tests/run_tests.sh
@@ -0,0 +1,260 @@
+#!/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} --log-file=/dev/null"
+
+if [[ "x${SALT_VERSION}" != "x" ]]; then
+ PIP_SALT_VERSION="==${SALT_VERSION}"
+fi
+
+
+## Functions
+log_info() {
+ echo -e "[INFO] $*"
+}
+
+log_err() {
+ echo -e "[ERROR] $*" >&2
+}
+
+setup_virtualenv() {
+ log_info "Setting up Python virtualenv"
+ 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
+}
+
+setup_salt() {
+ [ ! -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
+
+ 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}/..
+
+pillar_roots:
+ base:
+ - ${SALT_PILLAR_DIR}
+ - ${PILLARDIR}
+EOF
+}
+
+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 $dep_root ] && { log_info "Dependency $dep_name already fetched"; return 0; }
+
+ log_info "Fetching dependency $dep_name"
+ [ ! -d ${DEPSDIR} ] && mkdir -p ${DEPSDIR}
+ git clone $dep_source ${DEPSDIR}/$(basename $dep_source .git)
+ ln -s ${dep_root}/${dep_name} ${SALT_FILE_DIR}/${dep_name}
+
+ 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
+import sys,yaml
+for dep in yaml.load(open('${METADATA}', 'ro'))['dependencies']:
+ print '%s:%s' % (dep["name"], dep["source"])
+EOF
+}
+
+clean() {
+ log_info "Cleaning up ${BUILDDIR}"
+ [ -d ${BUILDDIR} ] && rm -rf ${BUILDDIR} || exit 0
+}
+
+salt_run() {
+ [ -e ${VENV_DIR}/bin/activate ] && source ${VENV_DIR}/bin/activate
+ salt-call ${SALT_OPTS} $*
+}
+
+prepare() {
+ [ -d ${BUILDDIR} ] && mkdir -p ${BUILDDIR}
+
+ [[ ! -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
+}
+
+_atexit() {
+ RETVAL=$?
+ trap true INT TERM EXIT
+
+ if [ $RETVAL -ne 0 ]; then
+ log_err "Execution failed"
+ else
+ log_info "Execution successful"
+ fi
+ return $RETVAL
+}
+
+## Main
+trap _atexit INT TERM EXIT
+
+case $1 in
+ clean)
+ clean
+ ;;
+ prepare)
+ prepare
+ ;;
+ lint)
+ lint
+ ;;
+ run)
+ run
+ ;;
+ real-run)
+ real_run
+ ;;
+ model-validate)
+ prepare
+ run_model_validate
+ ;;
+ *)
+ prepare
+# lint
+ run
+# run_model_validate
+ ;;
+esac