From d1bb84fdf0c788044ff6b72d45c7dc033346aac6 Mon Sep 17 00:00:00 2001 From: Danny Smit Date: Thu, 16 Apr 2020 15:52:55 +0200 Subject: [PATCH 1/3] refactor(map.jinja): use `template-formula` structure & add `debian-10` --- tomcat/map.jinja | 50 ++++++++++++------- tomcat/{osmap.yaml => osfamilymap.yaml} | 4 -- tomcat/{codenamemap.yaml => osfingermap.yaml} | 13 ++++- 3 files changed, 43 insertions(+), 24 deletions(-) rename tomcat/{osmap.yaml => osfamilymap.yaml} (94%) rename tomcat/{codenamemap.yaml => osfingermap.yaml} (72%) diff --git a/tomcat/map.jinja b/tomcat/map.jinja index 987ca242..ba7902d6 100644 --- a/tomcat/map.jinja +++ b/tomcat/map.jinja @@ -1,25 +1,39 @@ # -*- coding: utf-8 -*- # vim: ft=jinja -{% import_yaml "tomcat/defaults.yaml" as defaults %} -{% import_yaml "tomcat/osmap.yaml" as osmap %} -{% import_yaml "tomcat/codenamemap.yaml" as codemap %} +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{#- Start imports as #} +{%- import_yaml tplroot ~ "/defaults.yaml" as default_settings %} +{%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap %} +{%- import_yaml tplroot ~ "/osfingermap.yaml" as osfingermap %} -{# get the settings for the os_family grain #} -{% set osfam = salt['grains.filter_by'](osmap) or {} %} -{# get the settings for the oscodename grain, os_family data will override - oscodename data #} -{% set oscode = salt['grains.filter_by'](codemap, - grain='oscodename', - merge=osfam) or {} %} +{#- Retrieve the config dict only once #} +{%- set _config = salt['config.get'](tplroot, default={}) %} -{# merge the os family/codename specific data over the defaults #} -{% do defaults.tomcat.update(oscode) %} +{%- set defaults = salt['grains.filter_by']( + default_settings, + default=tplroot, + merge=salt['grains.filter_by']( + osfamilymap, + grain='os_family', + merge=salt['grains.filter_by']( + osfingermap, + grain='osfinger', + merge=salt['grains.filter_by']( + _config, + default='lookup' + ) + ) + ) + ) +%} -{# merge the pillar:lookup dict into the defaults/os specific dict #} -{% set lookup = salt['pillar.get']('tomcat:lookup', - default=defaults.tomcat, - merge=True) %} +{%- set config = salt['grains.filter_by']( + {'defaults': defaults}, + default='defaults', + merge=_config + ) +%} -{# merge the actual tomcat pillar into the above combined dict #} -{% set tomcat = salt['pillar.get']('tomcat', default=lookup, merge=True) %} +{%- set tomcat = config %} diff --git a/tomcat/osmap.yaml b/tomcat/osfamilymap.yaml similarity index 94% rename from tomcat/osmap.yaml rename to tomcat/osfamilymap.yaml index bc5bcd98..e86ac6b4 100644 --- a/tomcat/osmap.yaml +++ b/tomcat/osfamilymap.yaml @@ -19,10 +19,6 @@ RedHat: native_pkg: tomcat-native manager_pkg: tomcat-admin-webapps main_config_template: salt://tomcat/files/tomcat-default-CentOS.template -CentOS: - native_pkg: tomcat-native - manager_pkg: tomcat-admin-webapps - main_config_template: salt://tomcat/files/tomcat-default-CentOS.template openSUSE: ver: 8 native_pkg: libtcnative-1-0 diff --git a/tomcat/codenamemap.yaml b/tomcat/osfingermap.yaml similarity index 72% rename from tomcat/codenamemap.yaml rename to tomcat/osfingermap.yaml index 9e4d1498..16188aa4 100644 --- a/tomcat/codenamemap.yaml +++ b/tomcat/osfingermap.yaml @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # vim: ft=yaml --- -trusty: +Ubuntu-14.04: ver: 7 pkg: tomcat7 manager_pkg: tomcat7-admin @@ -11,7 +11,7 @@ trusty: service: tomcat7 user: tomcat7 group: tomcat7 -wheezy: +Debian-7: pkg: tomcat7 manager_pkg: tomcat7-admin conf_dir: /etc/tomcat7 @@ -20,3 +20,12 @@ wheezy: service: tomcat7 user: tomcat7 group: tomcat7 +Debian-10: + ver: 9 + pkg: tomcat9 + manager_pkg: tomcat9-admin + conf_dir: /etc/tomcat9 + main_config: /etc/default/tomcat9 + service: tomcat9 + user: tomcat + group: tomcat From db49764ef1af145e9469f5dcd888a2b2779b04f3 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Tue, 21 Apr 2020 08:19:40 +0100 Subject: [PATCH 2/3] refactor: standardise structure from the `template-formula` --- tomcat/map.jinja | 22 +++++++++++----- tomcat/osarchmap.yaml | 35 ++++++++++++++++++++++++++ tomcat/osfamilymap.yaml | 27 +++++++++++++------- tomcat/osfingermap.yaml | 56 ++++++++++++++++++++++++++++++++--------- tomcat/osmap.yaml | 33 ++++++++++++++++++++++++ 5 files changed, 146 insertions(+), 27 deletions(-) create mode 100644 tomcat/osarchmap.yaml create mode 100644 tomcat/osmap.yaml diff --git a/tomcat/map.jinja b/tomcat/map.jinja index ba7902d6..d1fcea56 100644 --- a/tomcat/map.jinja +++ b/tomcat/map.jinja @@ -5,7 +5,9 @@ {%- set tplroot = tpldir.split('/')[0] %} {#- Start imports as #} {%- import_yaml tplroot ~ "/defaults.yaml" as default_settings %} +{%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap %} {%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap %} +{%- import_yaml tplroot ~ "/osmap.yaml" as osmap %} {%- import_yaml tplroot ~ "/osfingermap.yaml" as osfingermap %} {#- Retrieve the config dict only once #} @@ -15,14 +17,22 @@ default_settings, default=tplroot, merge=salt['grains.filter_by']( - osfamilymap, - grain='os_family', + osarchmap, + grain='osarch', merge=salt['grains.filter_by']( - osfingermap, - grain='osfinger', + osfamilymap, + grain='os_family', merge=salt['grains.filter_by']( - _config, - default='lookup' + osmap, + grain='os', + merge=salt['grains.filter_by']( + osfingermap, + grain='osfinger', + merge=salt['grains.filter_by']( + _config, + default='lookup' + ) + ) ) ) ) diff --git a/tomcat/osarchmap.yaml b/tomcat/osarchmap.yaml new file mode 100644 index 00000000..ab3bc1f4 --- /dev/null +++ b/tomcat/osarchmap.yaml @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +# +# Setup variables using grains['osarch'] based logic. +# You just need to add the key:values for an `osarch` that differ +# from `defaults.yaml`. +# Only add an `osarch` which is/will be supported by the formula. +# +# If you do not need to provide defaults via the `osarch` grain, +# you will need to provide at least an empty dict in this file, e.g. +# osarch: {} +--- +amd64: + arch: amd64 + +x86_64: + arch: amd64 + +386: + arch: 386 + +arm64: + arch: arm64 + +armv6l: + arch: armv6l + +armv7l: + arch: armv7l + +ppc64le: + arch: ppc64le + +s390x: + arch: s390x diff --git a/tomcat/osfamilymap.yaml b/tomcat/osfamilymap.yaml index e86ac6b4..bdec0c64 100644 --- a/tomcat/osfamilymap.yaml +++ b/tomcat/osfamilymap.yaml @@ -15,24 +15,20 @@ Debian: user: tomcat8 group: tomcat8 java_home: /usr/lib/jvm/default-java + RedHat: native_pkg: tomcat-native manager_pkg: tomcat-admin-webapps main_config_template: salt://tomcat/files/tomcat-default-CentOS.template -openSUSE: - ver: 8 - native_pkg: libtcnative-1-0 - manager_pkg: tomcat-admin-webapps - main_config_template: salt://tomcat/files/tomcat-default-CentOS.template + Suse: ver: 8 native_pkg: libtcnative-1-0 manager_pkg: tomcat-admin-webapps main_config_template: salt://tomcat/files/tomcat-default-CentOS.template -FreeBSD: - native_pkg: tomcat-native - ini_config: /etc/rc.conf - java_home: /usr + +Gentoo: {} + Arch: pkg: tomcat8 ver: 8 @@ -51,6 +47,19 @@ Arch: # Not used on Arch manager_pkg: '' +Alpine: {} + +FreeBSD: + native_pkg: tomcat-native + ini_config: /etc/rc.conf + java_home: /usr + +OpenBSD: {} + +Solaris: {} + +Windows: {} + {%- if grains.os == 'MacOS' %} {%- if salt['cmd.run']('/usr/libexec/java_home -F', output_loglevel="quiet") == 0 %} {%- set darwin_javahome = salt['cmd.run']('/usr/libexec/java_home') %} diff --git a/tomcat/osfingermap.yaml b/tomcat/osfingermap.yaml index 16188aa4..f1e70a66 100644 --- a/tomcat/osfingermap.yaml +++ b/tomcat/osfingermap.yaml @@ -1,8 +1,19 @@ # -*- coding: utf-8 -*- # vim: ft=yaml --- -Ubuntu-14.04: - ver: 7 +# os: Debian +Debian-10: + ver: 9 + pkg: tomcat9 + manager_pkg: tomcat9-admin + conf_dir: /etc/tomcat9 + main_config: /etc/default/tomcat9 + service: tomcat9 + user: tomcat + group: tomcat +Debian-9: {} +Debian-8: {} +Debian-7: pkg: tomcat7 manager_pkg: tomcat7-admin conf_dir: /etc/tomcat7 @@ -11,7 +22,12 @@ Ubuntu-14.04: service: tomcat7 user: tomcat7 group: tomcat7 -Debian-7: + +# os: Ubuntu +Ubuntu-18.04: {} +Ubuntu-16.04: {} +Ubuntu-14.04: + ver: 7 pkg: tomcat7 manager_pkg: tomcat7-admin conf_dir: /etc/tomcat7 @@ -20,12 +36,28 @@ Debian-7: service: tomcat7 user: tomcat7 group: tomcat7 -Debian-10: - ver: 9 - pkg: tomcat9 - manager_pkg: tomcat9-admin - conf_dir: /etc/tomcat9 - main_config: /etc/default/tomcat9 - service: tomcat9 - user: tomcat - group: tomcat + +# os: Fedora +Fedora-31: {} +Fedora-30: {} + +# os: CentOS +CentOS Linux-8: {} +CentOS Linux-7: {} +CentOS-6: {} + +# os: Amazon +Amazon Linux-2: {} +Amazon Linux AMI-2018: {} + +# os: SUSE +Leap-15: {} + +# os: FreeBSD +FreeBSD-12: {} + +# os: Windows +Windows-8.1: {} + +# os: Gentoo +Gentoo-2: {} diff --git a/tomcat/osmap.yaml b/tomcat/osmap.yaml new file mode 100644 index 00000000..de11a673 --- /dev/null +++ b/tomcat/osmap.yaml @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +# +# Setup variables using grains['os'] based logic. +# You just need to add the key:values for an `os` that differ +# from `defaults.yaml` + `osarch.yaml` + `os_family.yaml`. +# Only add an `os` which is/will be supported by the formula. +# +# If you do not need to provide defaults via the `os` grain, +# you will need to provide at least an empty dict in this file, e.g. +# osmap: {} +--- +# os_family: Debian +Ubuntu: {} +Raspbian: {} + +# os_family: RedHat +Fedora: {} +CentOS: {} +Amazon: {} + +# os_family: Suse +SUSE: {} +openSUSE: {} + +# os_family: Gentoo +Funtoo: {} + +# os_family: Arch +Manjaro: {} + +# os_family: Solaris +SmartOS: {} From 9b2bab530575f90ce9070bd4e64ecc026ac73d1c Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Mon, 20 Apr 2020 00:00:51 +0100 Subject: [PATCH 3/3] ci(travis+inspec): test `debian-10` as well * Semi-automated using https://github.com/myii/ssf-formula/pull/162 --- .travis.yml | 2 +- .yamllint | 2 +- .../tomcat_install/controls/packages_spec.rb | 7 +++- .../tomcat_install/controls/services_spec.rb | 7 +++- .../tomcat_install/controls/yaml_dump_spec.rb | 39 +++++++++++++++---- 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index e6890903..8d0c9aef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,7 +58,7 @@ jobs: ## Define the rest of the matrix based on Kitchen testing # Make sure the instances listed below match up with # the `platforms` defined in `kitchen.yml` - # - env: INSTANCE=tomcat-install-debian-10-master-py3 + - env: INSTANCE=tomcat-install-debian-10-master-py3 - env: INSTANCE=tomcat-install-ubuntu-1804-master-py3 # - env: INSTANCE=tomcat-extend-ubuntu-1804-master-py3 # - env: INSTANCE=tomcat-install-centos-8-master-py3 diff --git a/.yamllint b/.yamllint index 61c747d3..e80ebacd 100644 --- a/.yamllint +++ b/.yamllint @@ -12,7 +12,7 @@ ignore: | node_modules/ test/**/states/**/*.sls .kitchen/ - tomcat/osmap.yaml + tomcat/osfamilymap.yaml yaml-files: # Default settings diff --git a/test/integration/tomcat_install/controls/packages_spec.rb b/test/integration/tomcat_install/controls/packages_spec.rb index a5190b70..2a93d78e 100644 --- a/test/integration/tomcat_install/controls/packages_spec.rb +++ b/test/integration/tomcat_install/controls/packages_spec.rb @@ -7,7 +7,12 @@ packages = case platform[:family] when 'debian' - %w[tomcat8 haveged] + case platform[:release] + when /^10/ + %w[tomcat9 haveged] + else + %w[tomcat8 haveged] + end when 'redhat', 'fedora', 'suse' %w[tomcat] end diff --git a/test/integration/tomcat_install/controls/services_spec.rb b/test/integration/tomcat_install/controls/services_spec.rb index 088a70e6..32b814de 100644 --- a/test/integration/tomcat_install/controls/services_spec.rb +++ b/test/integration/tomcat_install/controls/services_spec.rb @@ -8,7 +8,12 @@ services = case platform[:family] when 'debian' - %w[tomcat8 haveged] + case platform[:release] + when /^10/ + %w[tomcat9 haveged] + else + %w[tomcat8 haveged] + end when 'redhat', 'fedora', 'suse' %w[tomcat] end diff --git a/test/integration/tomcat_install/controls/yaml_dump_spec.rb b/test/integration/tomcat_install/controls/yaml_dump_spec.rb index b27838a2..7723adda 100644 --- a/test/integration/tomcat_install/controls/yaml_dump_spec.rb +++ b/test/integration/tomcat_install/controls/yaml_dump_spec.rb @@ -7,7 +7,28 @@ yaml_dump += case platform[:family] when 'debian' + case platform[:release] + when /^10/ + conf_dir = '/etc/tomcat9' + group = 'tomcat' + main_config = '/etc/default/tomcat9' + manager_pkg = 'tomcat9-admin' + pkg = 'tomcat9' + service = 'tomcat9' + user = 'tomcat' + ver = 9 + else + conf_dir = '/etc/tomcat8' + group = 'tomcat8' + main_config = '/etc/default/tomcat8' + manager_pkg = 'tomcat8-admin' + pkg = 'tomcat8' + service = 'tomcat8' + user = 'tomcat8' + ver = 8 + end <<~YAML_DUMP.chomp + arch: amd64 authbind: 'no' catalina_base: /usr/share/tomcat catalina_home: /usr/share/tomcat @@ -15,7 +36,7 @@ catalina_tmpdir: /var/cache/tomcat/temp cluster: simple: true - conf_dir: /etc/tomcat8 + conf_dir: #{conf_dir} connectors: example_connector: port: 8443 @@ -72,7 +93,7 @@ global: simpleValue type: java.lang.Integer expires_when: 2 weeks - group: tomcat8 + group: #{group} haveged_enabled: true id: - example.com @@ -91,7 +112,7 @@ soft: 64000 logfile_compress: 1 logfile_days: 14 - main_config: /etc/default/tomcat8 + main_config: #{main_config} main_config_template: salt://tomcat/files/tomcat-default-Debian.template manager: roles: @@ -110,7 +131,7 @@ - manager-script - manager-jmx - manager-status - manager_pkg: tomcat8-admin + manager_pkg: #{manager_pkg} native_pkg: libtcnative-1 other_contexts: other-contexts: @@ -137,10 +158,10 @@ className: org.apache.catalina.webresources.DirResourceSet base: /var/lib/tomcat8/appconfig webAppMount: /WEB-INF/classes - pkg: tomcat8 + pkg: #{pkg} resources: {} security: 'no' - service: tomcat8 + service: #{service} service_enabled: true service_running: false sites: @@ -175,12 +196,13 @@ pattern: '%h %l %u %t "%m http://%v%U %H" %s %b "%{Referer}i" "%{User-Agent}i" %D' - className: org.apache.catalina.authenticator.SingleSignOn - user: tomcat8 - ver: 8 + user: #{user} + ver: #{ver} with_haveged: true YAML_DUMP when 'redhat', 'fedora' <<~YAML_DUMP.chomp + arch: amd64 authbind: 'no' catalina_base: /usr/share/tomcat catalina_home: /usr/share/tomcat @@ -354,6 +376,7 @@ YAML_DUMP when 'suse' <<~YAML_DUMP.chomp + arch: amd64 authbind: 'no' catalina_base: /usr/share/tomcat catalina_home: /usr/share/tomcat