From 9d243a6d231d16aea377c9f99dad6a8ef2eaba35 Mon Sep 17 00:00:00 2001 From: Francisco de Paz Galan Date: Thu, 16 Feb 2023 11:37:25 +0100 Subject: [PATCH] [bitnami/*] Refactor Goss' common tests (#24127) * [bitnami/*] Refactor Goss' common tests Signed-off-by: FraPazGal * Trigger VIB for MariaDB Signed-off-by: FraPazGal * Fix path typo Signed-off-by: FraPazGal * Trigger VIB for WordPress Signed-off-by: FraPazGal * Trigger VIB for Apache Signed-off-by: FraPazGal * Remove VIB triggers Signed-off-by: FraPazGal * Add missing MariaDB tests and launch VIB pipeline Signed-off-by: FraPazGal * Remove VIB trigger Signed-off-by: FraPazGal --------- Signed-off-by: FraPazGal --- .vib/apache/goss/apache.yaml | 32 +++++++------- .vib/apache/goss/goss.yaml | 8 ++-- .vib/apache/goss/vars.yaml | 22 +++++----- ...ents-binaries.yaml => check-binaries.yaml} | 6 +-- .../check-components-directories.yaml | 11 ----- .../templates/check-components-files.yaml | 11 ----- .../check-directories-permissions.yaml | 17 ------- .../goss/templates/check-directories.yaml | 23 ++++++++++ .vib/common/goss/templates/check-files.yaml | 23 ++++++++++ .vib/mariadb/goss/goss.yaml | 6 +-- .../mariadb/goss/{templates => }/mariadb.yaml | 0 .vib/mariadb/goss/vars.yaml | 13 +++--- .vib/wordpress/goss/goss.yaml | 8 ++-- .vib/wordpress/goss/vars.yaml | 24 +++++----- .vib/wordpress/goss/wordpress.yaml | 44 +++++++++---------- 15 files changed, 127 insertions(+), 121 deletions(-) rename .vib/common/goss/templates/{check-components-binaries.yaml => check-binaries.yaml} (53%) delete mode 100644 .vib/common/goss/templates/check-components-directories.yaml delete mode 100644 .vib/common/goss/templates/check-components-files.yaml delete mode 100644 .vib/common/goss/templates/check-directories-permissions.yaml create mode 100644 .vib/common/goss/templates/check-directories.yaml create mode 100644 .vib/common/goss/templates/check-files.yaml rename .vib/mariadb/goss/{templates => }/mariadb.yaml (100%) diff --git a/.vib/apache/goss/apache.yaml b/.vib/apache/goss/apache.yaml index 853a110b0b36..a0d2d5f042a5 100644 --- a/.vib/apache/goss/apache.yaml +++ b/.vib/apache/goss/apache.yaml @@ -1,3 +1,19 @@ +command: + # There are no syntax error in the configuration + check-configuration: + exec: apachectl -t + exit-status: 0 + # Check explicitly enabled and disabled modules + check-loaded-modules: + exec: apachectl -M + exit-status: 0 + stdout: + {{ range $module := .Vars.modules.loaded }} + - "{{ $module }}_module" + {{ end }} + {{ range $module := .Vars.modules.disabled }} + - "!{{ $module }}_module" + {{ end }} file: # Main Apache config file includes other config files {{ .Vars.root_dir }}/apache/conf/httpd.conf: @@ -31,19 +47,3 @@ file: exists: true filetype: file {{ end }} -command: - # There are no syntax error in the configuration - check-configuration: - exec: apachectl -t - exit-status: 0 - # Check explicitly enabled and disabled modules - check-loaded-modules: - exec: apachectl -M - exit-status: 0 - stdout: - {{ range $module := .Vars.modules.loaded }} - - "{{ $module }}_module" - {{ end }} - {{ range $module := .Vars.modules.disabled }} - - "!{{ $module }}_module" - {{ end }} diff --git a/.vib/apache/goss/goss.yaml b/.vib/apache/goss/goss.yaml index 7497d0914bfb..c26a8cfe05ee 100644 --- a/.vib/apache/goss/goss.yaml +++ b/.vib/apache/goss/goss.yaml @@ -3,10 +3,10 @@ gossfile: ../../apache/goss/apache.yaml: {} # Load scripts from .vib/common/goss/templates ../../common/goss/templates/check-app-version.yaml: {} + ../../common/goss/templates/check-binaries.yaml: {} ../../common/goss/templates/check-broken-symlinks.yaml: {} ../../common/goss/templates/check-ca-certs.yaml: {} - ../../common/goss/templates/check-components-binaries.yaml: {} - ../../common/goss/templates/check-components-files.yaml: {} - ../../common/goss/templates/check-directories-permissions.yaml: {} + ../../common/goss/templates/check-directories.yaml: {} + ../../common/goss/templates/check-files.yaml: {} ../../common/goss/templates/check-linked-libraries.yaml: {} - ../../common/goss/templates/check-sed-in-place.yaml: {} \ No newline at end of file + ../../common/goss/templates/check-sed-in-place.yaml: {} diff --git a/.vib/apache/goss/vars.yaml b/.vib/apache/goss/vars.yaml index 36d70f7b61a4..500c40281e42 100644 --- a/.vib/apache/goss/vars.yaml +++ b/.vib/apache/goss/vars.yaml @@ -1,14 +1,14 @@ -components: - binaries: - - httpd - - gosu - - render-template - files: - - /opt/bitnami/apache/conf/modsecurity.conf - - /opt/bitnami/apache/conf/unicode.mapping -filesystem: +binaries: + - httpd + - gosu + - render-template +files: + - paths: + - /opt/bitnami/apache/conf/modsecurity.conf + - /opt/bitnami/apache/conf/unicode.mapping +directories: - mode: "0775" - directories: + paths: - /opt/bitnami/apache/var/run - /opt/bitnami/apache/conf - /opt/bitnami/apache/logs @@ -46,4 +46,4 @@ modules: root_dir: /opt/bitnami version: bin_name: apachectl - flag: -v \ No newline at end of file + flag: -v diff --git a/.vib/common/goss/templates/check-components-binaries.yaml b/.vib/common/goss/templates/check-binaries.yaml similarity index 53% rename from .vib/common/goss/templates/check-components-binaries.yaml rename to .vib/common/goss/templates/check-binaries.yaml index 2aba2424206d..b1b9ddaafad1 100644 --- a/.vib/common/goss/templates/check-components-binaries.yaml +++ b/.vib/common/goss/templates/check-binaries.yaml @@ -1,10 +1,10 @@ ######################## -# Checks components binaries are added to the $PATH +# Checks binaries are added to the $PATH # Needed vars: -# - .Vars.components.binaries (Array) +# - .Vars.binaries (Array) ######################## command: - {{ range $binary := .Vars.components.binaries }} + {{ range $binary := .Vars.binaries }} check-{{ $binary }}-binary: exec: which {{ $binary }} exit-status: 0 diff --git a/.vib/common/goss/templates/check-components-directories.yaml b/.vib/common/goss/templates/check-components-directories.yaml deleted file mode 100644 index f28ee37aae9f..000000000000 --- a/.vib/common/goss/templates/check-components-directories.yaml +++ /dev/null @@ -1,11 +0,0 @@ -######################## -# Checks components directories exist -# Needed vars: -# - .Vars.components.directories (Array) -######################## -file: - {{ range $directory := .Vars.components.directories }} - {{ $directory }}: - exists: true - filetype: directory - {{ end }} diff --git a/.vib/common/goss/templates/check-components-files.yaml b/.vib/common/goss/templates/check-components-files.yaml deleted file mode 100644 index 67645885d3d2..000000000000 --- a/.vib/common/goss/templates/check-components-files.yaml +++ /dev/null @@ -1,11 +0,0 @@ -######################## -# Checks components files exist -# Needed vars: -# - .Vars.components.files (Array) -######################## -file: - {{ range $file := .Vars.components.files }} - {{ $file }}: - exists: true - filetype: file - {{ end }} diff --git a/.vib/common/goss/templates/check-directories-permissions.yaml b/.vib/common/goss/templates/check-directories-permissions.yaml deleted file mode 100644 index e0cad8d67b46..000000000000 --- a/.vib/common/goss/templates/check-directories-permissions.yaml +++ /dev/null @@ -1,17 +0,0 @@ -######################## -# Checks directories permissions, usually changed in the postunpack stage -# Needed vars: -# - .Vars.filesystem (Array) -# - .Vars.filesystem.directories (Array) -# - .Vars.filesystem.mode (String) -######################## -file: - {{ range .Vars.filesystem }} - {{ $mode := .mode }} - {{ range $directory := .directories }} - {{ $directory }}: - exists: true - filetype: directory - mode: "{{ $mode }}" - {{ end }} - {{ end }} diff --git a/.vib/common/goss/templates/check-directories.yaml b/.vib/common/goss/templates/check-directories.yaml new file mode 100644 index 000000000000..2301a24ea260 --- /dev/null +++ b/.vib/common/goss/templates/check-directories.yaml @@ -0,0 +1,23 @@ +######################## +# Checks directories exist, +# optionally checking their permissions +# Needed vars: +# - .Vars.directories (Array) +# - .Vars.directories.paths (Array) +# - .Vars.directories.mode (Optional - String) +######################## +file: + {{ range .Vars.directories }} + {{ $mode := "" }} + {{ if (gt (len .) 1) }} + {{ $mode = .mode }} + {{ end }} + {{ range $directory := .paths }} + {{ $directory }}: + exists: true + filetype: directory + {{ if $mode }} + mode: "{{ $mode }}" + {{ end }} + {{ end }} + {{ end }} diff --git a/.vib/common/goss/templates/check-files.yaml b/.vib/common/goss/templates/check-files.yaml new file mode 100644 index 000000000000..eed7ab63e5a5 --- /dev/null +++ b/.vib/common/goss/templates/check-files.yaml @@ -0,0 +1,23 @@ +######################## +# Checks files exist, +# optionally checking their permissions +# Needed vars: +# - .Vars.files (Array) +# - .Vars.files.paths (Array) +# - .Vars.directories.mode (Optional - String) +######################## +file: + {{ range .Vars.files }} + {{ $mode := "" }} + {{ if (gt (len .) 1) }} + {{ $mode = .mode }} + {{ end }} + {{ range $file := .paths }} + {{ $file }}: + exists: true + filetype: file + {{ if $mode }} + mode: "{{ $mode }}" + {{ end }} + {{ end }} + {{ end }} diff --git a/.vib/mariadb/goss/goss.yaml b/.vib/mariadb/goss/goss.yaml index 6301ce9cdcef..ea39ad96f0e8 100644 --- a/.vib/mariadb/goss/goss.yaml +++ b/.vib/mariadb/goss/goss.yaml @@ -1,11 +1,11 @@ gossfile: # Goss tests exclusive to the current container - ../../mariadb/goss/templates/mariadb.yaml: {} + ../../mariadb/goss/mariadb.yaml: {} # Load scripts from .vib/common/goss/templates ../../common/goss/templates/check-app-version.yaml: {} + ../../common/goss/templates/check-binaries.yaml: {} ../../common/goss/templates/check-broken-symlinks.yaml: {} ../../common/goss/templates/check-ca-certs.yaml: {} - ../../common/goss/templates/check-components-binaries.yaml: {} - ../../common/goss/templates/check-directories-permissions.yaml: {} + ../../common/goss/templates/check-directories.yaml: {} ../../common/goss/templates/check-linked-libraries.yaml: {} ../../common/goss/templates/check-sed-in-place.yaml: {} diff --git a/.vib/mariadb/goss/templates/mariadb.yaml b/.vib/mariadb/goss/mariadb.yaml similarity index 100% rename from .vib/mariadb/goss/templates/mariadb.yaml rename to .vib/mariadb/goss/mariadb.yaml diff --git a/.vib/mariadb/goss/vars.yaml b/.vib/mariadb/goss/vars.yaml index f6c61fc119ba..e269b441bd28 100644 --- a/.vib/mariadb/goss/vars.yaml +++ b/.vib/mariadb/goss/vars.yaml @@ -1,11 +1,10 @@ -components: - binaries: - - gosu - - ini-file - - mysql -filesystem: +binaries: + - gosu + - ini-file + - mysql +directories: - mode: "0775" - directories: + paths: - /bitnami/mariadb - /bitnami/mariadb/data - /opt/bitnami/mariadb/conf diff --git a/.vib/wordpress/goss/goss.yaml b/.vib/wordpress/goss/goss.yaml index 0fb0b285fd8b..98082c34dcfd 100644 --- a/.vib/wordpress/goss/goss.yaml +++ b/.vib/wordpress/goss/goss.yaml @@ -2,10 +2,10 @@ gossfile: # Goss tests exclusive to the current container ../../wordpress/goss/wordpress.yaml: {} # Load scripts from .vib/common/goss/templates + ../../common/goss/templates/check-binaries.yaml: {} ../../common/goss/templates/check-broken-symlinks.yaml: {} ../../common/goss/templates/check-ca-certs.yaml: {} - ../../common/goss/templates/check-components-binaries.yaml: {} - ../../common/goss/templates/check-components-files.yaml: {} - ../../common/goss/templates/check-directories-permissions.yaml: {} + ../../common/goss/templates/check-directories.yaml: {} + ../../common/goss/templates/check-files.yaml: {} ../../common/goss/templates/check-linked-libraries.yaml: {} - ../../common/goss/templates/check-sed-in-place.yaml: {} \ No newline at end of file + ../../common/goss/templates/check-sed-in-place.yaml: {} diff --git a/.vib/wordpress/goss/vars.yaml b/.vib/wordpress/goss/vars.yaml index f8a5411c0b1d..9d46273cb9f3 100644 --- a/.vib/wordpress/goss/vars.yaml +++ b/.vib/wordpress/goss/vars.yaml @@ -1,17 +1,17 @@ -components: - binaries: - - apachectl - - gosu - - mariadb - - php - - render-template - - wp - files: +binaries: + - apachectl + - gosu + - mariadb + - php + - render-template + - wp +files: + - paths: - /opt/bitnami/apache/modules/libphp.so - /opt/bitnami/wordpress/wp-config.php -filesystem: +directories: - mode: "0775" - directories: + paths: - /bitnami/wordpress - /opt/bitnami/wordpress - /opt/bitnami/wordpress/tmp @@ -41,4 +41,4 @@ phpmodules: - zip # Specific from postunpack logic - memcached -root_dir: /opt/bitnami \ No newline at end of file +root_dir: /opt/bitnami diff --git a/.vib/wordpress/goss/wordpress.yaml b/.vib/wordpress/goss/wordpress.yaml index 0970fdf38651..c0bc2c70128c 100644 --- a/.vib/wordpress/goss/wordpress.yaml +++ b/.vib/wordpress/goss/wordpress.yaml @@ -1,3 +1,24 @@ +command: + check-app-version: + exec: cat {{ .Vars.root_dir }}/wordpress/wp-includes/version.php | grep "wp_version" + exit-status: 0 + stdout: + - {{ .Env.APP_VERSION }} + # WP-CLI points to correct binaries and config file + check-wp-cli-conf: + exec: wp --info + exit-status: 0 + stdout: + - "{{ .Vars.root_dir }}/php/bin/php" + - "{{ .Vars.root_dir }}/mysql/bin/mysql" + - "{{ .Vars.root_dir }}/wp-cli/conf/wp-cli.yml" + check-enabled-modules: + exec: php -m + exit-status: 0 + stdout: + {{ range $module := .Vars.phpmodules }} + - "{{ $module }}" + {{ end }} file: # HTTP vhost should have been properly rendered {{ .Vars.root_dir }}/apache/conf/vhosts/wordpress-vhost.conf: @@ -20,30 +41,9 @@ file: filetype: file contains: - /path.*{{ .Vars.root_dir }}/wordpress/ -command: - check-app-version: - exec: cat {{ .Vars.root_dir }}/wordpress/wp-includes/version.php | grep "wp_version" - exit-status: 0 - stdout: - - {{ .Env.APP_VERSION }} - # WP-CLI points to correct binaries and config file - check-wp-cli-conf: - exec: wp --info - exit-status: 0 - stdout: - - "{{ .Vars.root_dir }}/php/bin/php" - - "{{ .Vars.root_dir }}/mysql/bin/mysql" - - "{{ .Vars.root_dir }}/wp-cli/conf/wp-cli.yml" - check-enabled-modules: - exec: php -m - exit-status: 0 - stdout: - {{ range $module := .Vars.phpmodules }} - - "{{ $module }}" - {{ end }} group: daemon: exists: true user: daemon: - exists: true \ No newline at end of file + exists: true