From 2e26b6f6068050ad57a40cec5561a58b5201033d Mon Sep 17 00:00:00 2001 From: Nicole Scherfenberg Date: Fri, 5 Aug 2016 20:22:51 +0200 Subject: [PATCH] fixes formula to comply to its spec The reworks in merge #110 broke this formulas kitchen based specs. This MR changes a few minor things, mostly pillar.example and other inconsistent documentations. Also, the use of db_user for `postgres_tablespace.present` and `postgres_database.present` now fits the states options, as db_password etc can be specified as well. --- pillar.example | 12 ++----- postgres/defaults.yaml | 1 - postgres/init.sls | 36 ++++++++++++++----- .../default/serverspec/postgres_spec.rb | 6 ++-- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/pillar.example b/pillar.example index 33435c7..788d610 100644 --- a/pillar.example +++ b/pillar.example @@ -1,12 +1,5 @@ postgres: pg_hba.conf: salt://postgres/pg_hba.conf - prepare_cluster: - user: root - command: service postgresql initdb - test: test -f /path/to/some/file - env: - LC_ALL: en_US.UTF-8 - use_upstream_repo: False pkg: 'postgresql-9.3' @@ -50,12 +43,13 @@ postgres: - ['host', 'db2', 'remoteUser', '123.123.0.0/24'] tablespaces: - my_space: /srv/my_tablespace + my_space: + directory: /srv/my_tablespace + owner: localUser databases: db1: owner: 'localUser' - user: 'localUser' template: 'template0' lc_ctype: 'en_US.UTF-8' lc_collate: 'en_US.UTF-8' diff --git a/postgres/defaults.yaml b/postgres/defaults.yaml index d35e17b..7eefda3 100644 --- a/postgres/defaults.yaml +++ b/postgres/defaults.yaml @@ -3,7 +3,6 @@ postgres: pkg_dev: postgresql-devel pkg_libpq_dev: postgresql-libs pkg_client: postgresql-client - pkgs_extra: python: python-psycopg2 service: postgresql conf_dir: /var/lib/pgsql/data diff --git a/postgres/init.sls b/postgres/init.sls index 1fc290f..03388eb 100644 --- a/postgres/init.sls +++ b/postgres/init.sls @@ -48,9 +48,11 @@ postgresql-running: - cmd: postgresql-cluster-prepared {% if postgres.pkgs_extra %} -postgresql-extra-pkgs-installed: +{% for pkg in postgres.pkgs_extra %} +postgresql-extra-pkgs-installed_{{ pkg }}: pkg.installed: - - pkgs: {{ postgres.pkgs_extra }} + - name: {{ pkg }} +{% endfor %} {% endif %} {% if postgres.postgresconf %} @@ -132,8 +134,17 @@ postgresql-tablespace-{{ name }}: - name: {{ name }} - directory: {{ tblspace.directory }} - user: {{ tblspace.get('runas', postgres.user) }} -{% if tblspace.get('user') %} - - db_user: {{ tblspace.user }} +{% if tblspace.get('db_user') %} + - db_user: {{ tblspace.db_user }} +{% endif %} +{% if tblspace.get('db_password') %} + - db_password: {{ tblspace.db_password }} +{% endif %} +{% if tblspace.get('db_host') %} + - db_host: {{ tblspace.db_host }} +{% endif %} +{% if tblspace.get('db_port') %} + - db_port: {{ tblspace.db_port }} {% endif %} {% if tblspace.get('owner') %} - owner: {{ tblspace.owner }} @@ -172,8 +183,17 @@ postgresql-db-{{ name }}: - owner: {{ db.owner }} {% endif %} - user: {{ db.get('runas', postgres.user) }} - {% if db.get('user') %} - - db_user: {{ db.user }} + {% if db.get('db_user') %} + - db_user: {{ db.db_user }} + {% endif %} + {% if db.get('db_password') %} + - db_password: {{ db.db_password }} + {% endif %} + {% if db.get('db_host') %} + - db_host: {{ db.db_host }} + {% endif %} + {% if db.get('db_port') %} + - db_port: {{ db.db_port }} {% endif %} - require: - service: postgresql-running @@ -184,7 +204,7 @@ postgresql-db-{{ name }}: - postgres_user: postgresql-user-{{ db.owner }} {% endif %} {% if db.get('tablespace') %} - - postgres_tablespace: postgresql-tablespace-{{ name }} + - postgres_tablespace: postgresql-tablespace-{{ db.get('tablespace') }} {% endif %} {# NOTE: postgres_schema doesn't have a 'runas' equiv. at all #} @@ -252,7 +272,7 @@ postgresql-ext-{{ ext_name }}-for-db-{{ name }}: - postgres_user: postgresql-user-{{ ext.user }} {% endif %} {% if ext.get('schema') %} - - postgres_schema: postgresql-schema-{{ ext.schema }} + - postgres_schema: postgresql-schema-{{ ext.schema }}-for-db-{{ name }} {% endif %} {% endif %} {% endfor %} diff --git a/test/integration/default/serverspec/postgres_spec.rb b/test/integration/default/serverspec/postgres_spec.rb index 68c4096..f709f58 100644 --- a/test/integration/default/serverspec/postgres_spec.rb +++ b/test/integration/default/serverspec/postgres_spec.rb @@ -1,5 +1,7 @@ require 'serverspec' +set :backend, :exec + describe service('postgresql') do it { should be_enabled } it { should be_running } @@ -16,6 +18,6 @@ describe file('/srv/my_tablespace') do it { should be_grouped_into 'postgres' } end -describe command('su - postgres -c "psql -qtc \"\l+ db2\""') do - its(:stdout) { should match(/db2.*localUser.*UTF8.*C.UTF-8.*C.UTF-8.*my_space/) } +describe command(%q{su - postgres -c 'psql -qtc "\l+ db2"'}) do + its(:stdout) { should match(/db2.*localUser.*UTF8.*en_US\.UTF-8.*en_US\.UTF-8.*my_space/) } end