Debmirror initial commit
Change-Id: I5c3b9f9ec0e8e882f4d1c4616a5b86598c04cf4b
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..333c426
--- /dev/null
+++ b/.kitchen.yml
@@ -0,0 +1,46 @@
+---
+driver:
+ name: docker
+ hostname: debmirror.ci.local
+ #socket: tcp://127.0.0.1:2376
+ use_sudo: false
+
+
+
+provisioner:
+ name: salt_solo
+ salt_install: bootstrap
+ salt_bootstrap_url: https://bootstrap.saltstack.com
+ salt_version: latest
+ require_chef: false
+ formula: debmirror
+ log_level: info
+ state_top:
+ base:
+ "*":
+ - debmirror
+ pillars:
+ top.sls:
+ base:
+ "*":
+ - debmirror
+ grains:
+ noservices: True
+
+
+platforms:
+ - name: ubuntu-16.04
+
+
+verifier:
+ name: inspec
+ sudo: true
+
+
+suites:
+ - name: default
+ # provisioner:
+ # pillars-from-files:
+ # debmirror.sls: tests/pillar/default.sls
+
+# vim: ft=yaml sw=2 ts=2 sts=2 tw=125
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
new file mode 100644
index 0000000..44df726
--- /dev/null
+++ b/CHANGELOG.rst
@@ -0,0 +1,6 @@
+debmirror formula
+=====================================
+
+2018.1 (2018-01-24)
+
+- 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..2f5d1e4
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,13 @@
+Copyright (c) 2018 Salt Stack Formulas
+
+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.md b/README.md
deleted file mode 100644
index 1a61918..0000000
--- a/README.md
+++ /dev/null
@@ -1,2 +0,0 @@
-# salt-formula-debmirror
-DEB mirroring with with debmirror tool
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..f33d150
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,86 @@
+
+==================================
+debmirror Formula
+==================================
+
+Service debmirror description
+
+
+Sample Pillars
+==============
+
+Example for one debmirror mirror, ubuntu.
+
+.. code-block:: yaml
+ parameters:
+ debmirror:
+ client:
+ enabled: true
+ mirrors:
+ target01:
+ force: False
+ lock_target: True
+ extra_flags: [ '--verbose', '--progress', '--nosource', '--no-check-gpg', '--rsync-extra=none' ]
+ method: "rsync" # string
+ arch: [ 'amd64' ]
+ mirror_host: "mirror.mirantis.com" # rsync
+ mirror_root: ':mirror/nightly/ubuntu/'
+ target_dir: "/var/www/mirror/ubuntu/"
+ log_file: "/var/www/mirror/target01_log.log"
+ dist: [ xenial ] #, xenial-security, xenial-updates ]
+ section: [ main ] #, multiverse, restricted, universe ]
+ exclude_deb_section: [ 'games', gnome, Xfce, sound, electronics, graphics, hamradio , doc, localization, kde, video ]
+ filter:
+ 00: "--exclude=/"
+ 01: "--exclude='/android*'"
+ 02: "--exclude='/firefox*'"
+ 03: "--exclude='/chromium-browser*'"
+ 04: "--exclude='/ceph*'"
+ 05: "--exclude='/*-wallpapers*'"
+ 06: "--exclude='/language-pack-(?!en)'"
+ 07: "--include='/main(.*)manpages'"
+ 08: "--include='/main(.*)python-(.*)doc'"
+ 09: "--include='/main(.*)python-(.*)network'"
+
+More Information
+================
+
+* https://github.com/salt-formulas/salt-formula-debmirror
+* Check debmirror/schemas/client.yaml for parameters description
+
+
+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-debmirror/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
+=========
+
+* links
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/_states/debmirror.py b/_states/debmirror.py
new file mode 100644
index 0000000..2e5533f
--- /dev/null
+++ b/_states/debmirror.py
@@ -0,0 +1,149 @@
+#!/usr/bin/env python
+"""
+Management of debmirror
+=======================
+
+Create debian mirrors, using debmirror
+--------------------------------------
+
+.. code-block:: yaml
+ debmirror_test1_present:
+ debmirror.mirror_present:
+ - name: test1
+
+"""
+import logging
+import os
+from functools import wraps
+from salt.exceptions import CommandExecutionError, SaltInvocationError
+log = logging.getLogger(__name__)
+
+def __virtual__():
+ '''
+ Only load this module if debmirror is installed with deps.
+ '''
+ return 'debmirror'
+
+def _test_call(method):
+ (resource, functionality) = method.func_name.split('_')
+ if functionality == 'present':
+ functionality = 'updated'
+ else:
+ functionality = 'removed'
+
+ @wraps(method)
+ def check_for_testing(name, *args, **kwargs):
+ if __opts__.get('test', None):
+ return _no_change(name, resource, test=functionality)
+ return method(name, *args, **kwargs)
+ return check_for_testing
+
+def _created(name, resource, resource_definition={}):
+ changes_dict = {'name': name,
+ 'changes': resource_definition,
+ 'result': True,
+ 'comment': '{0} {1} created'.format(resource, name)}
+ return changes_dict
+
+def _failed(name, resource, resource_definition={}):
+ changes_dict = {'name': name,
+ 'changes': resource_definition,
+ 'result': False,
+ 'comment': '{0} {1} failed to create'.format(resource, name)}
+ return changes_dict
+
+def _no_change(name, resource, test=False):
+ changes_dict = {'name': name,
+ 'changes': {},
+ 'result': True}
+ if test:
+ changes_dict['comment'] = \
+ '{0} {1} will be {2}'.format(resource, name, test)
+ else:
+ changes_dict['comment'] = \
+ '{0} {1} is in correct state'.format(resource, name)
+ return changes_dict
+
+def _check_state(name, tgt):
+ lock_file = _get_target_path(name,tgt)['lock_file']
+ if os.path.isfile(lock_file) and not tgt.get('force', False) :
+ return _no_change(name, '{} exist=>repo locked.'.format(lock_file))
+ return False
+
+def _get_target_path(name,tgt):
+ if not tgt.get('target_dir',False):
+ raise SaltInvocationError('Argument "target_dir" is mandatory! ')
+ return {'target_dir': tgt.get('target_dir'),
+ 'lock_file': tgt.get('lock_file', os.path.join(tgt.get('target_dir'), '.lockmirror')),
+ 'log_file': tgt.get('log_file', '/var/log/debmirror_'.join(name)) }
+
+def _get_cmdline(name,tgt):
+ cmdline = " debmirror "
+ if tgt.get('extra_flags'):
+ cmdline += ' '.join(tgt['extra_flags'])
+ if tgt.get('dist'):
+ cmdline += ' --dist=' + ",".join(tgt['dist'])
+ if tgt.get('section'):
+ cmdline += ' --section=' + ",".join(tgt['section'])
+ if tgt.get('method'):
+ cmdline += ' --method=' + tgt.get('method')
+ if tgt.get('mirror_host'):
+ cmdline += ' --host="{}"'.format(tgt.get('mirror_host'))
+ if tgt.get('mirror_root'):
+ cmdline += ' --root="{}"'.format(tgt.get('mirror_root'))
+ if tgt.get('arch', 'amd64'):
+ cmdline += ' --arch=' + ','.join(tgt.get('arch'))
+ if tgt.get('filter'):
+ for key, value in enumerate(sorted(tgt['filter'])):
+ cmdline += " " + tgt['filter'][value]
+ if tgt.get('target_dir',False):
+ cmdline += ' ' + _get_target_path(name,tgt)['target_dir']
+ return cmdline
+
+def _update_mirror(name,tgt):
+ # Remove old lock file, is was.
+ lock_file = _get_target_path(name,tgt)['lock_file']
+ if os.path.isfile(lock_file):
+ log.debug("Removing lockfile:{} for mirror{}".format(lock_file,name))
+ __states__['file.absent'](lock_file)
+ cmdline = _get_cmdline(name,tgt)
+ # init file logger
+ l_dir = os.path.dirname(tgt['log_file'])
+ if not os.path.isdir(l_dir):
+ __salt__['file.makedirs'](l_dir)
+ fh = logging.FileHandler("{0}".format(_get_target_path(name,tgt)['log_file']))
+ fh.setLevel(logging.DEBUG)
+ fh_format = logging.Formatter('%(asctime)s - %(lineno)d - %(levelname)-8s - %(message)s')
+ fh.setFormatter(fh_format)
+ log2file = logging.getLogger("debmirror")
+ log2file.addHandler(fh)
+ result = __salt__['cmd.run_all'](cmdline, redirect_stderr=True)
+ log2file.debug(result['stdout'])
+ # destroy file logger
+ for i in list(log2file.handlers):
+ log2file.removeHandler(i)
+ i.flush()
+ i.close()
+ if result['retcode'] != 0:
+ #raise CommandExecutionError(result['stderr'])
+ return _failed(name, "debmirror failed.Reason {0}".format(result['stderr']))
+ if tgt.get('lock_target',None):
+ __states__['file.touch'](lock_file)
+ return _created(name, "Mirror {0} created.".format(name) )
+
+@_test_call
+def mirror_present(name, **kwargs):
+ '''
+
+ :param name: mirror key name
+ '''
+ try:
+ tgt = __salt__['config.get']('debmirror')['client']['mirrors'][name]
+ except KeyError:
+ comment ='Mirror "{0}" not exist in configurathion,skipping..'.format(name)
+ return _no_change(name, comment)
+
+ current_state = _check_state(name,tgt)
+ if not current_state:
+ return _update_mirror(name,tgt)
+ return current_state
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..7eaa4a6
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,5 @@
+salt-formula-debmirror (2018.1) xenial; urgency=medium
+
+ * Initial release
+
+ -- Alexey Zvyagitnsev azvyagintsev@mirantis.com Wed, 24 Jan 2018 12:22:32 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..5bd916f
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,15 @@
+Source: salt-formula-debmirror
+Maintainer: Alexey Zvyagitnsev <azvyagintsev@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/salt-formula-debmirror
+Vcs-Browser: https://github.com/salt-formulas/salt-formula-debmirror
+Vcs-Git: https://github.com/salt-formulas/salt-formula-debmirror.git
+
+Package: salt-formula-debmirror
+Architecture: all
+Depends: ${misc:Depends}
+Description: debmirror salt formula
+ Install and configure debmirror.
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..c56cbcc
--- /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-debmirror
+Upstream-Contact: salt-formulas@freelists.org
+Source: https://github.com/salt-formulas/salt-formula-debmirror
+
+Files: *
+Copyright: 2018 Salt Stack Formulas
+License: Apache-2.0
+ Copyright (C) 2018 Salt Stack Formulas
+ .
+ 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/debmirror/client/init.sls b/debmirror/client/init.sls
new file mode 100644
index 0000000..fc56794
--- /dev/null
+++ b/debmirror/client/init.sls
@@ -0,0 +1,18 @@
+{%- from "debmirror/map.jinja" import client with context %}
+{%- if client.enabled %}
+
+debmirror_client_packages:
+ pkg.installed:
+ - names: {{ client.pkgs }}
+
+{%- for mirror_name, opts in client.get("mirrors",{}).iteritems() %}
+
+debmirror_{{ mirror_name }}_present:
+ debmirror.mirror_present:
+ - name: {{ mirror_name }}
+ - require:
+ - debmirror_client_packages
+
+{%- endfor %}
+{% endif %}
+
diff --git a/debmirror/init.sls b/debmirror/init.sls
new file mode 100644
index 0000000..91f6a1e
--- /dev/null
+++ b/debmirror/init.sls
@@ -0,0 +1,6 @@
+{%- if pillar.debmirror is defined %}
+include:
+{%- if pillar.debmirror.client is defined %}
+- debmirror.client
+{%- endif %}
+{%- endif %}
diff --git a/debmirror/map.jinja b/debmirror/map.jinja
new file mode 100644
index 0000000..0e7eae9
--- /dev/null
+++ b/debmirror/map.jinja
@@ -0,0 +1,12 @@
+
+{%- load_yaml as base_defaults %}
+
+Debian:
+ pkgs:
+ - debmirror
+ - apt-transport-https
+ - rsync
+
+{%- endload %}
+
+{%- set client = salt['grains.filter_by'](base_defaults, merge=salt['pillar.get']('debmirror:client')) %}
diff --git a/debmirror/meta/sphinx.yml b/debmirror/meta/sphinx.yml
new file mode 100644
index 0000000..4ef5734
--- /dev/null
+++ b/debmirror/meta/sphinx.yml
@@ -0,0 +1,8 @@
+{%- from "debmirror/map.jinja" import client with context %}
+# Fill in documentation details
+doc:
+ name: debmirror
+ description: Simple formula,which allows to run parametrized debmirror
+ role:
+ client:
+ name: client
diff --git a/debmirror/schemas/client.yaml b/debmirror/schemas/client.yaml
new file mode 100644
index 0000000..da54b1d
--- /dev/null
+++ b/debmirror/schemas/client.yaml
@@ -0,0 +1,85 @@
+title: "debmirror runner"
+description: |-
+ Simple formula,which allows to run parametrized debmirror
+type: object
+additionalProperties: true
+
+required:
+ - enabled
+
+properties:
+ enabled:
+ description: |-
+ Enables debmirror processing.
+ type: boolean
+ mirrors:
+ description: |-
+ Set of mirror to sync
+ type: object
+ additionalProperties: false
+ minProperties: 1
+ type: object
+ patternProperties:
+ '^[a-z][-a-z0-9_]*$':
+ type: object
+ $ref: "#/definitions/debmirror:mirror"
+
+definitions:
+ debmirror:mirror:
+ type: object
+ additionalProperties: false
+ properties:
+ extra_flags:
+ type: string
+ example: '--verbose --progress --nosource --no-check-gpg --rsync-extra=none'
+ method:
+ type: string
+ eval: [ "rsync", "http" , "https"]
+ arch:
+ type: array
+ items:
+ type: string
+ enum: [ 'amd64', 'i386' ]
+ mirror_host:
+ type: string
+ example: "mirror.mirantis.com"
+ mirror_root:
+ type: string
+ example: ':mirror/nightly/ubuntu/'
+ target_dir:
+ type: string
+ example: "/var/www/mirror/ubuntu/"
+ log_file:
+ type: string
+ example: "/var/www/mirror/target01_log.log"
+ dist:
+ type: array
+ items:
+ type: string
+ example: [ xenial , xenial-security, xenial-updates ]
+ section:
+ type: array
+ items:
+ type: string
+ example: [ main multiverse, restricted, universe ]
+ exclude_deb_section:
+ type: array
+ items:
+ type: string
+ example: [ games, gnome, Xfce, sound, electronics, graphics, hamradio , doc, localization, kde, video ]
+ filter:
+ type: object
+ items:
+ type: array
+ example:
+ 00: "--exclude=/"
+ 01: "--exclude='/android*'"
+ 02: "--exclude='/firefox*'"
+ 03: "--exclude='/chromium-browser*'"
+ lock_target:
+ type: boolean
+ description: "Create lockfile, to prevent future repo updates"
+ force:
+ type: boolean
+ description: "Ignore lockfile"
+
diff --git a/doc/source/conf.py b/doc/source/conf.py
new file mode 100644
index 0000000..7c5e306
--- /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-debmirror'
+copyright = u'2016, Salt Stack Formulas'
+
+# 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/metadata.yml b/metadata.yml
new file mode 100644
index 0000000..006e08c
--- /dev/null
+++ b/metadata.yml
@@ -0,0 +1,3 @@
+name: "debmirror"
+version: "2018.1"
+source: "https://github.com/salt-formulas/salt-formula-debmirror"
diff --git a/metadata/service/client/single.yml b/metadata/service/client/single.yml
new file mode 100644
index 0000000..49ce190
--- /dev/null
+++ b/metadata/service/client/single.yml
@@ -0,0 +1,8 @@
+applications:
+- debmirror
+classes:
+- service.debmirror.support
+parameters:
+ debmirror:
+ client:
+ enabled: false
diff --git a/metadata/service/support.yml b/metadata/service/support.yml
new file mode 100644
index 0000000..30bcc7b
--- /dev/null
+++ b/metadata/service/support.yml
@@ -0,0 +1,11 @@
+parameters:
+ debmirror:
+ _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/tests/pillar/client.sls b/tests/pillar/client.sls
new file mode 100644
index 0000000..2dcc74f
--- /dev/null
+++ b/tests/pillar/client.sls
@@ -0,0 +1,19 @@
+debmirror:
+ client:
+ enabled: true
+ mirrors:
+ target01:
+ extra_flags: '--verbose --progress --nosource --no-check-gpg --rsync-extra=none'
+ method: "rsync" # string
+ arch: [ 'amd64' ]
+ mirror_host: "archive.ubuntu.com" # rsync
+ mirror_root: ':ubuntu/' # rsync
+ target_dir: "/tmp/mirror/ubuntu/"
+ log_file: "/tmp/target01_log.log"
+ dist: [ xenial ] #, xenial-security, xenial-updates ]
+ section: [ main ] #, multiverse, restricted, universe ]
+ exclude_deb_section: [ 'games', gnome, Xfce, sound, electronics, graphics, hamradio , doc, localization, kde, video ]
+ filter:
+ 00: "--exclude='/*'" # exclude all for test
+ lock_target: True
+ force: True
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
new file mode 100755
index 0000000..9d23c56
--- /dev/null
+++ b/tests/run_tests.sh
@@ -0,0 +1,275 @@
+#!/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"
+ dependency_check virtualenv
+ virtualenv $VENV_DIR
+ source ${VENV_DIR}/bin/activate
+ python -m pip install salt${PIP_SALT_VERSION}
+ python -m pip install jsonschema
+ if [[ -f ${CURDIR}/pip_requirements.txt ]]; then
+ python -m 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"
+
+ dependency_check git
+ [ -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
+ python $(which 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
+ python -m pip install reno
+ reno lint ${CURDIR}/../
+}
+
+lint() {
+# lint_releasenotes
+ log_info "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(){
+ if [ -d ${SCHEMARDIR} ]; then
+ # model validator require py modules
+ fetch_dependency "salt:https://github.com/salt-formulas/salt-formula-salt"
+ link_modules
+ # Rendered Example:
+ # python $(which 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 -m ${DEPSDIR}/salt-formula-salt --id=${minion_id} modelschema.model_validate ${FORMULA_NAME} ${state_name} || { log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1 ; }
+ done
+ else
+ log_info "${SCHEMARDIR} not found!";
+ fi
+}
+
+dependency_check() {
+ local DEPENDENCY_COMMANDS=$*
+
+ for DEPENDENCY_COMMAND in $DEPENDENCY_COMMANDS; do
+ which $DEPENDENCY_COMMAND > /dev/null || { log_err "Command \"$DEPENDENCY_COMMAND\" can not be found in default path."; 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
+
diff --git a/tests/test-requirements.txt b/tests/test-requirements.txt
new file mode 100644
index 0000000..a0f561a
--- /dev/null
+++ b/tests/test-requirements.txt
@@ -0,0 +1,2 @@
+jsonschema
+reno