diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..ca02fdf --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,86 @@ +--- +driver: + name: docker + hostname: maas.ci.local + #socket: tcp://127.0.0.1:2376 + use_sudo: false + + + +provisioner: + name: salt_solo + salt_install: bootstrap + salt_bootstrap_url: https://bootstrap.saltstack.com + salt_version: latest + require_chef: false + formula: maas + log_level: info + state_top: + base: + "*": + - rsyslog + - postgresql + - maas + pillars: + top.sls: + base: + "*": + - rsyslog + - postgresql + - linux + - maas + + pillars-from-files: + postgresql.sls: tests/pillar/postgresql.sls + rsyslog.sls: tests/pillar/rsyslog.sls + linux.sls: tests/pillar/linux.sls + + grains: + noservices: False + kitchen-test: True + + dependencies: + - name: postgresql + repo: git + source: https://github.com/salt-formulas/salt-formula-postgresql + - name: rsyslog + repo: git + source: https://github.com/salt-formulas/salt-formula-rsyslog + + +platforms: + - name: <%=ENV['PLATFORM'] || 'saltstack-ubuntu-xenial-salt-stable' %> + driver_config: + image: <%=ENV['PLATFORM'] || 'epcim/salt-formulas:saltstack-ubuntu-xenial-salt-stable'%> + platform: ubuntu + + +verifier: + name: inspec + sudo: true + + +suites: + + + - name: maas_cluster + provisioner: + pillars-from-files: + maas.sls: tests/pillar/maas_cluster.sls + + #- name: disk_layout + #provisioner: + #pillars-from-files: + #maas.sls: tests/pillar/disk_layout.sls + + #- name: maas_mirror + #provisioner: + #pillars-from-files: + #maas.sls: tests/pillar/maas_mirror.sls + + #- name: maas_region + #provisioner: + #pillars-from-files: + #maas.sls: tests/pillar/maas_region.sls + +# vim: ft=yaml sw=2 ts=2 sts=2 tw=125 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..abc6b38 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,46 @@ +sudo: required +services: + - docker + +addons: + apt: + packages: + - apt-transport-https + +install: + - pip install PyYAML + - pip install virtualenv + - | + test -e Gemfile || cat < 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-2017.7 + - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 +# - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-bionic-salt-2017.7 + +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 diff --git a/Makefile b/Makefile index d166862..f9b4f47 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,7 @@ all: @echo "make release-major - Generate new major release" @echo "make release-minor - Generate new minor release" @echo "make changelog - Show changes since last release" + @echo "make test-model-validate - Run salt jsonschema validation" install: # Formula @@ -41,6 +42,7 @@ install: cp -a $(FORMULANAME) $(DESTDIR)/$(SALTENVDIR)/ [ ! -d _modules ] || cp -a _modules $(DESTDIR)/$(SALTENVDIR)/ [ ! -d _states ] || cp -a _states $(DESTDIR)/$(SALTENVDIR)/ || true + [ ! -d _engines ] || cp -a _engines $(DESTDIR)/$(SALTENVDIR)/ || true [ ! -d _grains ] || cp -a _grains $(DESTDIR)/$(SALTENVDIR)/ || true # Metadata [ -d $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME) ] || mkdir -p $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME) @@ -52,6 +54,10 @@ lint: test: [ ! -d tests ] || (cd tests; ./run_tests.sh) +test-model-validate: + # TODO make it actually fail + [ ! -d $(FORMULANAME)/schemas/ ] || (cd tests; ./run_tests.sh model-validate) + release-major: check-changes @echo "Current version is $(VERSION), new version is $(NEW_MAJOR_VERSION)" @[ $(VERSION_MAJOR) != $(NEW_MAJOR_VERSION) ] || (echo "Major version $(NEW_MAJOR_VERSION) already released, nothing to do. Do you want release-minor?" && exit 1) diff --git a/README.rst b/README.rst index e466959..351b097 100644 --- a/README.rst +++ b/README.rst @@ -16,6 +16,27 @@ Single maas service server: enabled: true +Configure node interfaces. + +Interfaces are identified by provided `name` or by `mac` if `name` is not provided or not found. +When configured name is not found interface name will be renamed. + +.. code-block:: yaml + + maas: + region: + machines: + machine1: + pxe_interface_mac: "11:22:33:44:55:66" + interfaces: + nic01: + name: eth0 + mac: "11:22:33:44:55:66" + mode: "static" + ip: "2.2.3.19" + subnet: "subnet1" + gateway: "2.2.3.2" + Single MAAS region service [single UI/API] .. code-block:: yaml @@ -471,6 +492,14 @@ MAAS region service with backup data source: cfg01.local host: 192.168.0.11 +Test pillars +============== + +Mind the postgresql and rsyslog `.sls`. Database and syslog service are required for MAAS to properly install and work. + +* https://github.com/salt-formulas/salt-formula-rsyslog/tree/master/tests/pillar + + Module function's example: ========================== diff --git a/_modules/maas.py b/_modules/maas.py index 426aff5..1c80c5f 100644 --- a/_modules/maas.py +++ b/_modules/maas.py @@ -509,6 +509,18 @@ def _get_nic_id_by_mac(self, machine, req_mac=None): 'node:{}'.format(req_mac, machine['fqdn'])) return data + def _get_nic_id_by_name(self, machine, req_name=None): + data = {} + for nic in machine['interface_set']: + data[nic['name']] = nic['id'] + if req_name: + if req_name in data.keys(): + return data[req_name] + else: + raise Exception('NIC with name:{} not found at ' + 'node:{}'.format(req_name, machine['fqdn'])) + return data + def _disconnect_all_nic(self, machine): """ Maas will fail, in case same config's will be to apply @@ -538,7 +550,18 @@ def _process_interface(self, nic_data, machine): external "process" method. Those broke old-MaasObject logic, though make functions more simple in case iterable tasks. """ - nic_id = self._get_nic_id_by_mac(machine, nic_data['mac']) + + if nic_data.has_key('name'): + try: + nic_id = self._get_nic_id_by_mac(machine, nic_data['name']) + except Exception as e: + LOG.warn("Failed to find interface: {} on node: {}. Will try now by its MAC: {}".format( + nic_data['name'], machine['fqdn'], nic_data['mac_address'])) + nic_id = False + + if not nic_id: + # assume MAC is always provided + nic_id = self._get_nic_id_by_mac(machine, nic_data['mac']) # Process op=link_subnet link_data = {} diff --git a/maas/cluster.sls b/maas/cluster.sls index 9fe61bf..59284db 100644 --- a/maas/cluster.sls +++ b/maas/cluster.sls @@ -62,5 +62,8 @@ maas_cluster_services: - file: /etc/maas/rackd.conf - watch: - file: /etc/maas/rackd.conf + {%- if grains.get('kitchen-test') %} + - onlyif: /bin/false + {%- endif %} {%- endif %} diff --git a/maas/files/regiond.conf b/maas/files/regiond.conf index 8c9e8df..83b06e8 100644 --- a/maas/files/regiond.conf +++ b/maas/files/regiond.conf @@ -1,7 +1,15 @@ {%- from "maas/map.jinja" import region with context %} +{%- if region.database.host is defined %} database_host: {{ region.database.host }} +{%- endif %} +{%- if region.database.name is defined %} database_name: {{ region.database.name }} +{%- endif %} +{%- if region.database.password is defined %} database_pass: {{ region.database.password }} +{%- endif %} +{%- if region.database.username is defined %} database_user: {{ region.database.username }} +{%- endif %} maas_url: http://{{ region.bind.host }}/MAAS diff --git a/maas/region.sls b/maas/region.sls index e9711ea..81e0d49 100644 --- a/maas/region.sls +++ b/maas/region.sls @@ -109,8 +109,9 @@ maas_apache_headers: - require: - pkg: maas_region_packages -/root/.pgpass: +Configure /root/.pgpass for MAAS: file.managed: + - name: /root/.pgpass - source: salt://maas/files/pgpass - template: jinja - user: root @@ -125,11 +126,14 @@ maas_region_services: - cmd: maas_region_syncdb - watch: - file: /etc/maas/regiond.conf + {%- if grains.get('kitchen-test') %} + - onlyif: /bin/false + {%- endif %} maas_region_syncdb: cmd.run: - names: - - maas-region syncdb + - maas-region syncdb --noinput - require: - file: /etc/maas/regiond.conf @@ -139,16 +143,27 @@ maas_set_admin_password: - creates: /var/lib/maas/.setup_admin - require: - service: maas_region_services + {%- if grains.get('kitchen-test') %} + - onlyif: /bin/false + {%- endif %} maas_login_admin: cmd.run: - name: "maas-region apikey --username {{ region.admin.username }} > /var/lib/maas/.maas_credentials" + - require: + - cmd: maas_set_admin_password + {%- if grains.get('kitchen-test') %} + - onlyif: /bin/false + {%- endif %} maas_config: module.run: - name: maas.process_maas_config - require: - cmd: maas_login_admin + {%- if grains.get('kitchen-test') %} + - onlyif: /bin/false + {%- endif %} {%- if region.get('boot_sources', False) %} maas_boot_sources: @@ -243,6 +258,9 @@ maas_domain: - name: maas.process_domain - require: - module: maas_config + {%- if grains.get('kitchen-test') %} + - onlyif: /bin/false + {%- endif %} {%- if region.fabrics is defined %} {%- for fabric_name, fabric in region.fabrics.iteritems() %} diff --git a/metadata.yml b/metadata.yml index dacbd6f..72d1aea 100644 --- a/metadata.yml +++ b/metadata.yml @@ -1,3 +1,8 @@ name: "maas" version: "0.1" source: "https://github.com/salt-formulas/salt-formula-maas" +dependencies: +- name: postgresql + source: "https://github.com/salt-formulas/salt-formula-postgresql" +- name: rsyslog + source: "https://github.com/salt-formulas/salt-formula-rsyslog" diff --git a/tests/pillar/linux.sls b/tests/pillar/linux.sls new file mode 100644 index 0000000..a150747 --- /dev/null +++ b/tests/pillar/linux.sls @@ -0,0 +1,3 @@ +linux: + system: + domain: ci.local diff --git a/tests/pillar/maas_cluster.sls b/tests/pillar/maas_cluster.sls index af63517..263fcc9 100644 --- a/tests/pillar/maas_cluster.sls +++ b/tests/pillar/maas_cluster.sls @@ -1,11 +1,46 @@ maas: cluster: enabled: true + role: master region: + port: 80 host: localhost - role: slave + saltstack_repo_key: | + -----BEGIN PGP PUBLIC KEY BLOCK----- + Version: GnuPG v2 + + mQENBFOpvpgBCADkP656H41i8fpplEEB8IeLhugyC2rTEwwSclb8tQNYtUiGdna9 + m38kb0OS2DDrEdtdQb2hWCnswxaAkUunb2qq18vd3dBvlnI+C4/xu5ksZZkRj+fW + tArNR18V+2jkwcG26m8AxIrT+m4M6/bgnSfHTBtT5adNfVcTHqiT1JtCbQcXmwVw + WbqS6v/LhcsBE//SHne4uBCK/GHxZHhQ5jz5h+3vWeV4gvxS3Xu6v1IlIpLDwUts + kT1DumfynYnnZmWTGc6SYyIFXTPJLtnoWDb9OBdWgZxXfHEcBsKGha+bXO+m2tHA + gNneN9i5f8oNxo5njrL8jkCckOpNpng18BKXABEBAAG0MlNhbHRTdGFjayBQYWNr + YWdpbmcgVGVhbSA8cGFja2FnaW5nQHNhbHRzdGFjay5jb20+iQE4BBMBAgAiBQJT + qb6YAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRAOCKFJ3le/vhkqB/0Q + WzELZf4d87WApzolLG+zpsJKtt/ueXL1W1KA7JILhXB1uyvVORt8uA9FjmE083o1 + yE66wCya7V8hjNn2lkLXboOUd1UTErlRg1GYbIt++VPscTxHxwpjDGxDB1/fiX2o + nK5SEpuj4IeIPJVE/uLNAwZyfX8DArLVJ5h8lknwiHlQLGlnOu9ulEAejwAKt9CU + 4oYTszYM4xrbtjB/fR+mPnYh2fBoQO4d/NQiejIEyd9IEEMd/03AJQBuMux62tjA + /NwvQ9eqNgLw9NisFNHRWtP4jhAOsshv1WW+zPzu3ozoO+lLHixUIz7fqRk38q8Q + 9oNR31KvrkSNrFbA3D89uQENBFOpvpgBCADJ79iH10AfAfpTBEQwa6vzUI3Eltqb + 9aZ0xbZV8V/8pnuU7rqM7Z+nJgldibFk4gFG2bHCG1C5aEH/FmcOMvTKDhJSFQUx + uhgxttMArXm2c22OSy1hpsnVG68G32Nag/QFEJ++3hNnbyGZpHnPiYgej3FrerQJ + zv456wIsxRDMvJ1NZQB3twoCqwapC6FJE2hukSdWB5yCYpWlZJXBKzlYz/gwD/Fr + GL578WrLhKw3UvnJmlpqQaDKwmV2s7MsoZogC6wkHE92kGPG2GmoRD3ALjmCvN1E + PsIsQGnwpcXsRpYVCoW7e2nW4wUf7IkFZ94yOCmUq6WreWI4NggRcFC5ABEBAAGJ + AR8EGAECAAkFAlOpvpgCGwwACgkQDgihSd5Xv74/NggA08kEdBkiWWwJZUZEy7cK + WWcgjnRuOHd4rPeT+vQbOWGu6x4bxuVf9aTiYkf7ZjVF2lPn97EXOEGFWPZeZbH4 + vdRFH9jMtP+rrLt6+3c9j0M8SIJYwBL1+CNpEC/BuHj/Ra/cmnG5ZNhYebm76h5f + T9iPW9fFww36FzFka4VPlvA4oB7ebBtquFg3sdQNU/MmTVV4jPFWXxh4oRDDR+8N + 1bcPnbB11b5ary99F/mqr7RgQ+YFF0uKRE3SKa7a+6cIuHEZ7Za+zhPaQlzAOZlx + fuBmScum8uQTrEF5+Um5zkwC7EXTdH1co/+/V/fpOtxIg4XO4kcugZefVm5ERfVS + MA== + =dtMN + -----END PGP PUBLIC KEY BLOCK----- + saltstack_repo_trusty: "http://repo.saltstack.com/apt/ubuntu/14.04/amd64/2016.3/ trusty main" + saltstack_repo_xenial: "http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/ xenial main" region: - theme: theme + theme: mirantis bind: host: localhost port: 80 @@ -16,8 +51,8 @@ maas: database: engine: postgresql host: localhost - name: maasdb - password: password - username: maas + #name: maasdb + #password: password + #username: maas enabled: true salt_master_ip: 127.0.0.1 diff --git a/tests/pillar/postgresql.sls b/tests/pillar/postgresql.sls new file mode 100644 index 0000000..cc2d3ed --- /dev/null +++ b/tests/pillar/postgresql.sls @@ -0,0 +1,20 @@ +postgresql: + server: + enabled: true + clients: + - 127.0.0.1 + bind: + address: 127.0.0.1 + port: 5432 + protocol: tcp + #database: + #maasdb: + #enabled: true + #encoding: 'UTF8' + #locale: 'en_US' + #users: + #- name: maas + #password: password + #host: localhost + #createdb: true + #rights: all privileges diff --git a/tests/pillar/rsyslog.sls b/tests/pillar/rsyslog.sls new file mode 100644 index 0000000..32c26c1 --- /dev/null +++ b/tests/pillar/rsyslog.sls @@ -0,0 +1,13 @@ +rsyslog: + #server: + #enabled: true + client: + enabled: true + #output: + #file: + #/var/log/syslog: + #filter: "*.*;auth,authpriv.none" + #owner: syslog + #group: adm + #createmode: 0640 + #umask: 0022 diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 9761585..a348912 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash +### +# Script requirments: +#apt-get install -y python-yaml virtualenv git + set -e [ -n "$DEBUG" ] && set -x @@ -14,32 +18,40 @@ 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" +IGNORE_MODELVALIDATE_MASK=${IGNORE_MODELVALIDATE_MASK:-"novalidate"} + if [ "x${SALT_VERSION}" != "x" ]; then PIP_SALT_VERSION="==${SALT_VERSION}" fi ## Functions log_info() { - echo "[INFO] $*" + echo -e "[INFO] $*" } log_err() { - echo "[ERROR] $*" >&2 + 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} + if [[ -f ${CURDIR}/test-requirements.txt ]]; then + python -m pip install -r ${CURDIR}/test-requirements.txt + fi } setup_mock_bin() { @@ -65,6 +77,7 @@ 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 @@ -76,6 +89,7 @@ setup_salt() { 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 @@ -83,7 +97,6 @@ file_roots: base: - ${SALT_FILE_DIR} - ${CURDIR}/.. - - /usr/share/salt-formulas/env pillar_roots: base: @@ -93,13 +106,14 @@ 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 /usr/share/salt-formulas/env/${dep_name} ] && log_info "Dependency $dep_name already present in system-wide salt env" && return 0 - [ -d $dep_root ] && log_info "Dependency $dep_name already fetched" && return 0 + 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} @@ -109,6 +123,19 @@ fetch_dependency() { 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 @@ -129,13 +156,30 @@ salt_run() { } prepare() { - [ -d ${BUILDDIR} ] && mkdir -p ${BUILDDIR} + if [[ -f ${BUILDDIR}/.prepare_done ]]; then + log_info "${BUILDDIR}/.prepare_done exist, not rebuilding BUILDDIR" + return + fi + [[ -d ${BUILDDIR} ]] && mkdir -p ${BUILDDIR} - which salt-call || setup_virtualenv + [[ ! -f "${VENV_DIR}/bin/activate" ]] && setup_virtualenv setup_mock_bin setup_pillar setup_salt install_dependencies + link_modules + touch ${BUILDDIR}/.prepare_done +} + +lint_releasenotes() { + [[ ! -f "${VENV_DIR}/bin/activate" ]] && setup_virtualenv + source ${VENV_DIR}/bin/activate + reno lint ${CURDIR}/../ +} + +lint() { +# lint_releasenotes + log_err "TODO: lint_releasenotes" } run() { @@ -152,7 +196,7 @@ run() { 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) + || { log_err "Failed to render meta ${meta} using pillar ${FORMULA_NAME}.${state_name}"; exit 1; } cat ${SALT_CACHE_DIR}/${meta_name} done done @@ -161,8 +205,43 @@ run() { 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) + salt_run --id=${state_name} state.sls ${FORMULA_NAME} || { log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1; } + done +} + +run_model_validate(){ + # Run modelschema.model_validate validation. + # TEST iterateble, run for `each formula ROLE against each ROLE_PILLARNAME` + # Pillars should be named in conviend ROLE_XXX.sls or ROLE.sls + # Example: + # client.sls client_auth.sls server.sls server_auth.sls + if [ -d ${SCHEMARDIR} ]; then + # model validator require py modules + fetch_dependency "salt:https://github.com/salt-formulas/salt-formula-salt" + link_modules + salt_run saltutil.clear_cache; salt_run saltutil.refresh_pillar; salt_run saltutil.sync_all; + for role in ${SCHEMARDIR}/*.yaml; do + role_name=$(basename "${role%*.yaml}") + for pillar in $(ls pillar/${role_name}*.sls | grep -v ${IGNORE_MODELVALIDATE_MASK} ); do + pillar_name=$(basename "${pillar%*.sls}") + local _message="FORMULA:${FORMULA_NAME} ROLE:${role_name} against PILLAR:${pillar_name}" + log_info "model_validate ${_message}" + # Rendered Example: + # python $(which salt-call) --local -c /test1/maas/tests/build/salt --id=maas_cluster modelschema.model_validate maas cluster + salt_run -m ${DEPSDIR}/salt-formula-salt --id=${pillar_name} modelschema.model_validate ${FORMULA_NAME} ${role_name} || { log_err "Execution of model_validate ${_message} failed"; exit 1 ; } + done 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() { @@ -187,14 +266,23 @@ case $1 in prepare) prepare ;; + lint) + lint + ;; run) run ;; real-run) real_run ;; + model-validate) + prepare + run_model_validate + ;; *) prepare +# lint run + run_model_validate ;; esac