From a09308ed52f1eb3931e0184a52a0da0634e6602e Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Wed, 2 Oct 2019 19:59:17 +0100 Subject: [PATCH 1/2] feat(semantic-release): implement for this formula * Automated using https://github.com/myii/ssf-formula/pull/55 * Close #1 --- .github/ISSUE_TEMPLATE/bug_report.md | 54 +++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 42 ++++++++++ .travis.yml | 31 +++++--- .yamllint | 14 ++++ docs/TOFS_pattern.rst | 72 +++++++++++++++++ kitchen.yml | 94 ++++++++++++++++------- test/integration/default/inspec.yml | 3 + 7 files changed, 272 insertions(+), 38 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..04af2ae --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,54 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '[BUG] ' +labels: 'bug' +assignees: '' + +--- + + + +#### Describe the bug + + + + +#### Setup + + + + +#### Steps to reproduce the bug + + + + + + +#### Expected behaviour + + + + +#### Versions report + + + + +#### Additional context + + + + +--- + +#### Optional: How can this template be improved? + + + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..ae0b773 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,42 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '[FEATURE] ' +labels: 'enhancement' +assignees: '' + +--- + + + +#### Is your feature request related to a problem? + + + + +#### Describe the solution you'd like + + + + +#### Describe alternatives you've considered + + + + +#### Additional context + + + + +--- + +#### Optional: How can this template be improved? + + + diff --git a/.travis.yml b/.travis.yml index 28b05fb..d911edb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,16 @@ # -*- coding: utf-8 -*- # vim: ft=yaml --- +dist: bionic stages: - test - - commitlint + - lint - name: release if: branch = master AND type != pull_request sudo: required cache: bundler language: ruby -dist: xenial services: - docker @@ -25,40 +25,49 @@ env: # - INSTANCE: default-fedora-30-develop-py3 # - INSTANCE: default-opensuse-leap-15-develop-py3 # - INSTANCE: default-amazonlinux-2-develop-py2 + # - INSTANCE: default-arch-base-latest-develop-py2 # - INSTANCE: default-debian-9-2019-2-py3 - INSTANCE: default-ubuntu-1804-2019-2-py3 - # - INSTANCE: default-centos-7-2019-2-py3 - # - INSTANCE: default-fedora-30-2019-2-py3 + - INSTANCE: default-centos-7-2019-2-py3 + - INSTANCE: default-fedora-30-2019-2-py3 # - INSTANCE: default-opensuse-leap-15-2019-2-py3 - - INSTANCE: default-amazonlinux-2-2019-2-py2 + # - INSTANCE: default-amazonlinux-2-2019-2-py2 + # - INSTANCE: default-arch-base-latest-2019-2-py2 # - INSTANCE: default-debian-9-2018-3-py2 # - INSTANCE: default-ubuntu-1604-2018-3-py2 # - INSTANCE: default-centos-7-2018-3-py2 - - INSTANCE: default-fedora-29-2018-3-py2 + # - INSTANCE: default-fedora-29-2018-3-py2 - INSTANCE: default-opensuse-leap-15-2018-3-py2 # - INSTANCE: default-amazonlinux-2-2018-3-py2 + # - INSTANCE: default-arch-base-latest-2018-3-py2 # - INSTANCE: default-debian-8-2017-7-py2 - # - INSTANCE: default-ubuntu-1604-2017-7-py2 - - INSTANCE: centos6-centos-6-2017-7-py2 + - INSTANCE: default-ubuntu-1604-2017-7-py2 + # - INSTANCE: default-centos-6-2017-7-py2 # - INSTANCE: default-fedora-29-2017-7-py2 # - INSTANCE: default-opensuse-leap-15-2017-7-py2 # - INSTANCE: default-amazonlinux-2-2017-7-py2 + # - INSTANCE: default-arch-base-latest-2017-7-py2 script: - bin/kitchen verify ${INSTANCE} jobs: include: - # Define the commitlint stage - - stage: commitlint + # Define the `lint` stage (runs `yamllint` and `commitlint`) + - stage: lint language: node_js node_js: lts/* before_install: skip script: + # Install and run `yamllint` + # Need at least `v1.17.0` for the `yaml-files` setting + - pip install --user yamllint>=1.17.0 + - yamllint -s . + # Install and run `commitlint` - npm install @commitlint/config-conventional -D - npm install @commitlint/travis-cli -D - commitlint-travis - # Define the release stage that runs semantic-release + # Define the release stage that runs `semantic-release` - stage: release language: node_js node_js: lts/* diff --git a/.yamllint b/.yamllint index 3a90f57..a8509bc 100644 --- a/.yamllint +++ b/.yamllint @@ -6,10 +6,24 @@ extends: default # Files to ignore completely # 1. All YAML files under directory `node_modules/`, introduced during the Travis run +# 2. Any SLS files under directory `test/`, which are actually state files ignore: | node_modules/ + test/**/states/**/*.sls + +yaml-files: + # Default settings + - '*.yaml' + - '*.yml' + - .yamllint + # SaltStack Formulas additional settings + - '*.example' + - test/**/*.sls rules: + empty-values: + forbid-in-block-mappings: true + forbid-in-flow-mappings: true line-length: # Increase from default of `80` # Based on https://github.com/PyCQA/flake8-bugbear#opinionated-warnings (`B950`) diff --git a/docs/TOFS_pattern.rst b/docs/TOFS_pattern.rst index 20233c8..4fea5dd 100644 --- a/docs/TOFS_pattern.rst +++ b/docs/TOFS_pattern.rst @@ -444,3 +444,75 @@ Resulting in: Note: This does *not* override the default value. Rather, the value from the pillar/config is prepended to the default. +Using sub-directories for ``components`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +If your formula is composed of several components, you may prefer to provides files under sub-directories, like in the `systemd-formula `_. + +.. code-block:: + + /srv/saltstack/systemd-formula/ + systemd/ + init.sls + libtofs.jinja + map.jinja + networkd/ + init.sls + files/ + default/ + network/ + 99-default.link + resolved/ + init.sls + files/ + default/ + resolved.conf + timesyncd/ + init.sls + files/ + Arch/ + resolved.conf + Debian/ + resolved.conf + default/ + resolved.conf + Ubuntu/ + resolved.conf + +For example, the following ``formula.component.config`` SLS: + +.. code-block:: sls + + {%- from "formula/libtofs.jinja" import files_switch with context %} + + formula configuration file: + file.managed: + - name: /etc/formula.conf + - user: root + - group: root + - mode: 644 + - template: jinja + - source: {{ files_switch(['formula.conf'], + lookup='formula', + use_subpath=True + ) + }} + +will be rendered on a ``Debian`` minion named ``salt-formula.ci.local`` as: + +.. code-block:: sls + + formula configuration file: + file.managed: + - name: /etc/formula.conf + - user: root + - group: root + - mode: 644 + - template: jinja + - source: + - salt://formula/component/files/salt-formula.ci.local/formula.conf + - salt://formula/component/files/Debian/formula.conf + - salt://formula/component/files/default/formula.conf + - salt://formula/files/salt-formula.ci.local/formula.conf + - salt://formula/files/Debian/formula.conf + - salt://formula/files/default/formula.conf diff --git a/kitchen.yml b/kitchen.yml index 9b7d65e..2aaffa2 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -38,17 +38,32 @@ platforms: - sh bootstrap-salt.sh -XdPbfrq -x python3 git develop - name: opensuse-leap-15-develop-py3 driver: - image: netmanagers/salt-develop-py3:opensuse-leap-15 + image: opensuse/leap:15 provision_command: - - curl -o bootstrap-salt.sh -L https://bootstrap.saltstack.com - - sh bootstrap-salt.sh -XdPbfrq -x python3 git develop + # yamllint disable-line rule:line-length + - zypper install -y glibc-locale net-tools net-tools-deprecated python-xml python3-pip + - systemctl enable sshd.service run_command: /usr/lib/systemd/systemd + provisioner: + salt_bootstrap_options: -XdPfrq -x python3 git develop + salt_install: bootstrap + # Workaround to avoid intermittent failures on `opensuse-leap-15`: + # => SCP did not finish successfully (255): (Net::SCP::Error) + transport: + max_ssh_sessions: 1 - name: amazonlinux-2-develop-py2 driver: image: netmanagers/salt-develop-py2:amazonlinux-2 provision_command: - curl -o bootstrap-salt.sh -L https://bootstrap.saltstack.com - sh bootstrap-salt.sh -XdPbfrq -x python2 git develop + - name: arch-base-latest-develop-py2 + driver: + image: netmanagers/salt-develop-py2:arch-base-latest + provision_command: + - curl -o bootstrap-salt.sh -L https://bootstrap.saltstack.com + - sh bootstrap-salt.sh -XdPbfrq -x python2 git develop + run_command: /usr/lib/systemd/systemd ## SALT `2019.2` - name: debian-9-2019-2-py3 @@ -65,11 +80,26 @@ platforms: image: netmanagers/salt-2019.2-py3:fedora-30 - name: opensuse-leap-15-2019-2-py3 driver: - image: netmanagers/salt-2019.2-py3:opensuse-leap-15 + image: opensuse/leap:15 + provision_command: + # yamllint disable-line rule:line-length + - zypper install -y glibc-locale net-tools net-tools-deprecated python-xml python3-pip + - systemctl enable sshd.service run_command: /usr/lib/systemd/systemd + provisioner: + salt_bootstrap_options: -XdPfrq -x python3 git 2019.2 + salt_install: bootstrap + # Workaround to avoid intermittent failures on `opensuse-leap-15`: + # => SCP did not finish successfully (255): (Net::SCP::Error) + transport: + max_ssh_sessions: 1 - name: amazonlinux-2-2019-2-py2 driver: image: netmanagers/salt-2019.2-py2:amazonlinux-2 + - name: arch-base-latest-2019-2-py2 + driver: + image: netmanagers/salt-2019.2-py2:arch-base-latest + run_command: /usr/lib/systemd/systemd ## SALT `2018.3` - name: debian-9-2018-3-py2 @@ -86,11 +116,26 @@ platforms: image: netmanagers/salt-2018.3-py2:fedora-29 - name: opensuse-leap-15-2018-3-py2 driver: - image: netmanagers/salt-2018.3-py2:opensuse-leap-15 + image: opensuse/leap:15 + provision_command: + # yamllint disable-line rule:line-length + - zypper install -y glibc-locale net-tools net-tools-deprecated python-xml python2-pip + - systemctl enable sshd.service run_command: /usr/lib/systemd/systemd + provisioner: + salt_bootstrap_options: -XdPfrq -x python2 git 2018.3 + salt_install: bootstrap + # Workaround to avoid intermittent failures on `opensuse-leap-15`: + # => SCP did not finish successfully (255): (Net::SCP::Error) + transport: + max_ssh_sessions: 1 - name: amazonlinux-2-2018-3-py2 driver: image: netmanagers/salt-2018.3-py2:amazonlinux-2 + - name: arch-base-latest-2018-3-py2 + driver: + image: netmanagers/salt-2018.3-py2:arch-base-latest + run_command: /usr/lib/systemd/systemd ## SALT `2017.7` - name: debian-8-2017-7-py2 @@ -108,15 +153,30 @@ platforms: image: netmanagers/salt-2017.7-py2:fedora-29 - name: opensuse-leap-15-2017-7-py2 driver: - image: netmanagers/salt-2017.7-py2:opensuse-leap-15 + image: opensuse/leap:15 + provision_command: + # yamllint disable-line rule:line-length + - zypper install -y glibc-locale net-tools net-tools-deprecated python-xml python2-pip + - systemctl enable sshd.service run_command: /usr/lib/systemd/systemd + provisioner: + salt_bootstrap_options: -XdPfrq -x python2 git 2017.7 + salt_install: bootstrap + # Workaround to avoid intermittent failures on `opensuse-leap-15`: + # => SCP did not finish successfully (255): (Net::SCP::Error) + transport: + max_ssh_sessions: 1 - name: amazonlinux-2-2017-7-py2 driver: image: netmanagers/salt-2017.7-py2:amazonlinux-2 + - name: arch-base-latest-2017-7-py2 + driver: + image: netmanagers/salt-2017.7-py2:arch-base-latest + run_command: /usr/lib/systemd/systemd provisioner: name: salt_solo - log_level: info + log_level: debug salt_install: none require_chef: false formula: telegraf @@ -134,26 +194,6 @@ verifier: suites: - name: default - excludes: - - centos-6-2017-7-py2 - provisioner: - state_top: - base: - '*': - - telegraf - pillars: - top.sls: - base: - '*': - - telegraf - pillars_from_files: - telegraf.sls: test/salt/pillar/telegraf.sls - verifier: - inspec_tests: - - path: test/integration/default - - name: centos6 - includes: - - centos-6-2017-7-py2 provisioner: state_top: base: diff --git a/test/integration/default/inspec.yml b/test/integration/default/inspec.yml index 885552a..1088689 100644 --- a/test/integration/default/inspec.yml +++ b/test/integration/default/inspec.yml @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml --- name: default title: telegraf formula @@ -13,3 +15,4 @@ supports: - platform-name: suse - platform-name: freebsd - platform-name: amazon + - platform-name: arch From 9e2fe52b258ae2bfcc748a4b92fe64fbddcdf3eb Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Wed, 2 Oct 2019 21:51:41 +0100 Subject: [PATCH 2/2] fix(`toml_pkg`): fix `yamllint` errors ```bash telegraf-formula$ yamllint -s . ./telegraf/osfamilymap.yaml 35:89 error line too long (102 > 88 characters) (line-length) ./telegraf/osfingermap.yaml 14:2 error syntax error: found character '%' that cannot start any token 75:89 error line too long (117 > 88 characters) (line-length) ``` --- telegraf/defaults.yaml | 1 + telegraf/map.jinja | 15 +++++++++++ telegraf/osfamilymap.yaml | 1 + telegraf/osfingermap.yaml | 57 +-------------------------------------- 4 files changed, 18 insertions(+), 56 deletions(-) diff --git a/telegraf/defaults.yaml b/telegraf/defaults.yaml index a91c78a..cae25f1 100644 --- a/telegraf/defaults.yaml +++ b/telegraf/defaults.yaml @@ -5,6 +5,7 @@ telegraf: config: /etc/telegraf/telegraf.conf system_user: root system_group: root + toml_pkg: python-pytoml pkg: name: telegraf service: diff --git a/telegraf/map.jinja b/telegraf/map.jinja index 1edb1b8..3dc1409 100644 --- a/telegraf/map.jinja +++ b/telegraf/map.jinja @@ -47,3 +47,18 @@ %} {%- set telegraf = config %} + +{#- Post-processing for specific non-YAML customisations #} +{%- if grains.pythonversion[0] == 2 %} +{%- if grains.os in ['Fedora'] %} +{%- do telegraf.update({'toml_pkg': 'python2-toml'}) %} +{%- elif grains.os in ['openSUSE', 'SUSE'] %} +{%- do telegraf.update({'toml_pkg': 'python2-pytoml'}) %} +{%- endif %} +{%- elif grains.pythonversion[0] == 3 %} +{%- if grains.os in ['CentOS'] %} +{%- do telegraf.update({'toml_pkg': 'python36-pytoml'}) %} +{%- else %} +{%- do telegraf.update({'toml_pkg': 'python3-pytoml'}) %} +{%- endif %} +{%- endif %} diff --git a/telegraf/osfamilymap.yaml b/telegraf/osfamilymap.yaml index 7aec070..1ec659e 100644 --- a/telegraf/osfamilymap.yaml +++ b/telegraf/osfamilymap.yaml @@ -32,4 +32,5 @@ Suse: name: go enabled: 1 gpgautoimport: true + # yamllint disable-line rule:line-length baseurl: https://download.opensuse.org/repositories/devel:/languages:/go/openSUSE_Leap_$releasever diff --git a/telegraf/osfingermap.yaml b/telegraf/osfingermap.yaml index e7d6490..a1b8eda 100644 --- a/telegraf/osfingermap.yaml +++ b/telegraf/osfingermap.yaml @@ -10,66 +10,11 @@ # you will need to provide at least an empty dict in this file, e.g. # osfingermap: {} --- -Debian-10: -{% if grains['pythonversion'][0] == 3 %} - toml_pkg: python3-pytoml -{% else %} - toml_pkg: python-pytoml -{% endif %} - -Debian-9: -{% if grains['pythonversion'][0] == 3 %} - toml_pkg: python3-pytoml -{% else %} - toml_pkg: python-pytoml -{% endif %} - -Debian-8: - toml_pkg: python-pytoml - -Ubuntu-18.04: - toml_pkg: python3-pytoml - -Ubuntu-16.04: - toml_pkg: python-pytoml - -CentOS Linux-7: -{% if grains['pythonversion'][0] == 3 %} - toml_pkg: python36-pytoml -{% else %} - toml_pkg: python-pytoml -{% endif %} - -Fedora-29: -{% if grains['pythonversion'][0] == 3 %} - toml_pkg: python3-pytoml -{% else %} - toml_pkg: python2-toml -{% endif %} - -Fedora-28: -{% if grains['pythonversion'][0] == 3 %} - toml_pkg: python3-pytoml -{% else %} - toml_pkg: python2-pytoml -{% endif %} - -Leap-15: -{% if grains['pythonversion'][0] == 3 %} - toml_pkg: python3-pytoml -{% else %} - toml_pkg: python2-pytoml -{% endif %} - Leap-42: -{% if grains['pythonversion'][0] == 3 %} - toml_pkg: python3-pytoml -{% else %} - toml_pkg: python-pytoml -{% endif %} repo_python: humanname: Python backports name: python-backports enabled: 1 gpgautoimport: true + # yamllint disable-line rule:line-length baseurl: https://download.opensuse.org/repositories/devel:/languages:/python:/backports/openSUSE_Leap_$releasever