Skip to content

Commit

Permalink
Enhance remove S/W support
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmcloughlin committed Jul 24, 2018
1 parent 332fe7b commit 9d2f69a
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 39 deletions.
31 changes: 28 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Creates such DB objects as: users, tablespaces, databases, schemas and extension
See ``pillar.example`` file for details.

``postgres.python``
-------------------
----------------------

Installs the PostgreSQL adapter for Python on Linux.

Expand Down Expand Up @@ -83,11 +83,36 @@ The state relies on the ``postgres:use_upstream_repo`` Pillar value which could
The ``postgres:version`` Pillar controls which version of the PostgreSQL packages should be
installed from the upstream Linux repository. Defaults to ``9.5``.


Removal states
===============

``postgres.dropped``
--------------------

Meta state to remove Postgres software. By default the release specified, or installed by, the formula is targeted only. To target multiple releases, set pillar ``postgres.removal.multiple_releases: True``.

``postgres.server.remove``
------------------------

Remove server, lib, and contrib packages. The ``postgres.server.remove`` will retain data by default (no data loss) - set pillar ``postgres.remove.data: True`` to remove data and configuration directories also.

``postgres.client.remove``
------------------------

Remove client package.

``postgres.dev.remove``
----------------------

Remove development and python packages.


Testing
=======
The postgres state was tested on MacOS (El Capitan 10.11.6)
The ``postgres`` state was tested on MacOS (El Capitan 10.11.6), and ``remove`` states on Ubuntu, Centos, and Fedora.

Testing is done with the ``kitchen-salt``.
Linux testing is done with the ``kitchen-salt``.

``kitchen converge``
--------------------
Expand Down
5 changes: 5 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,9 @@ postgres:
maintenance_db: db1
#postgis: {}

remove:
data: True
multiple_releases: True
releases: ['9.6', '10',]

# vim: ft=yaml ts=2 sts=2 sw=2 et
47 changes: 47 additions & 0 deletions postgres/client/remove.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{%- from "postgres/map.jinja" import postgres with context -%}
#remove release installed by formula
postgresql-client-removed:
pkg.removed:
- pkgs:
{% if postgres.pkg_client %}
- {{ postgres.pkg_client }}
{% endif %}
{%- if postgres.remove.multiple_releases %}
#search for and cleandown multiple releases
{% for release in postgres.remove.releases %}
{% if 'bin_dir' in postgres %}
{%- for bin in postgres.client_bins %}
{% set path = '/usr/pgsql-' + release|string + '/bin/' + bin %}
postgresql{{ release }}-client-{{ bin }}-alternative-remove:
alternatives.remove:
- name: {{ bin }}
- path: {{ path }}
{% if grains.os in ('Fedora', 'CentOS',) %}
{# bypass bug #}
- onlyif: alternatives --display {{ bin }}
{% else %}
- onlyif: test -f {{ path }}
{% endif %}
- require_in:
- pkg: postgresql{{ release }}-client-pkgs-removed
{%- endfor %}
{%- endif %}
postgresql{{ release }}-client-pkgs-removed:
pkg.purged:
- pkgs:
- postgresql
- postgresql-{{ release }}
- postgresql-{{ release|replace('.', '') }}
- postgresql{{ release }}-common
- postgresql{{ release }}-jdbc
- postgresql{{ release }}
- postgresql{{ release|replace('.', '') }}
{% endfor %}
{%- endif %}
5 changes: 5 additions & 0 deletions postgres/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,8 @@ postgres:
linux:
#Alternatives system are disabled by a 'altpriority=0' pillar.
altpriority: 0

remove:
data: False
multiple_releases: False
releases: ['9.2', '9.3', '9.4', '9.5', '9.6', '10',]
4 changes: 4 additions & 0 deletions postgres/dev.sls
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ postgresql-{{ bin }}-altinstall:
- link: {{ salt['file.join']('/usr/bin', bin) }}
- path: {{ path }}
- priority: {{ postgres.linux.altpriority }}
{% if grains.os in ('Fedora', 'CentOS',) %} {# bypass bug #}
- onlyif: alternatives --display {{ bin }}
{% else %}
- onlyif: test -f {{ path }}
{% endif %}
{%- endfor %}
{%- endif %}
Expand Down
55 changes: 55 additions & 0 deletions postgres/dev/remove.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{%- from "postgres/map.jinja" import postgres with context -%}
# remove release installed by formula
postgresql-devel-removed:
pkg.removed:
- pkgs:
{% if postgres.pkg_dev %}
- {{ postgres.pkg_dev }}
{% endif %}
{% if postgres.pkg_libpq_dev %}
- {{ postgres.pkg_libpq_dev }}
{% endif %}
{% if postgres.pkg_python %}
- {{ postgres.pkg_python }}
{% endif %}
{%- if postgres.remove.multiple_releases %}
#search for and cleandown multiple releases
{% for release in postgres.remove.releases %}
{% if 'bin_dir' in postgres %}
{%- for bin in postgres.dev_bins %}
{% set path = '/usr/pgsql-' + release|string + '/bin/' + bin %}
postgresql{{ release }}-devel-{{ bin }}-alternative-remove:
alternatives.remove:
- name: {{ bin }}
- path: {{ path }}
{% if grains.os in ('Fedora', 'CentOS',) %}
{# bypass bug #}
- onlyif: alternatives --display {{ bin }}
{% else %}
- onlyif: test -f {{ path }}
{% endif %}
- require_in:
- pkg: postgresql{{ release }}-devel-pkgs-removed
{%- endfor %}
{%- endif %}
postgresql{{ release }}-devel-pkgs-removed:
pkg.purged:
- pkgs:
- postgresql-dev
- postgresql-dev-{{ release|replace('.', '') }}
- postgresql-server-dev
- postgresql-server-dev-{{ release|replace('.', '') }}
- postgresql{{ release }}-jdbc
- postgresql{{ release|replace('.', '') }}-jdbc
- postgresql-{{ release }}
- postgresql-{{ release|replace('.', '') }}
- {{ postgres.pkg_python or "postgresql-python" }}
{% endfor %}
{%- endif %}
35 changes: 4 additions & 31 deletions postgres/dropped.sls
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
{% from tpldir + "/map.jinja" import postgres with context %}

postgresql-dead:
service.dead:
- name: {{ postgres.service }}
postgresql-removed:
pkg.removed:
- pkgs:
{% if postgres.pkg %}
- {{ postgres.pkg }}
{% endif %}
{% if postgres.pkg_client %}
- {{ postgres.pkg_client }}
{% endif %}
{% if postgres.pkg_dev %}
- {{ postgres.pkg_dev }}
{% endif %}
{% if postgres.pkg_libpq_dev %}
- {{ postgres.pkg_libpq_dev }}
{% endif %}
{% if postgres.pkgs_extra %}
{% for pkg in postgres.pkgs_extra %}
- {{ pkg }}
{% endfor %}
{% endif %}
postgres-dir-absent:
file.absent:
- names:
- {{ postgres.conf_dir }}
- {{ postgres.data_dir }}
include:
- postgres.server.remove
- postgres.client.remove
- postgres.dev.remove
2 changes: 2 additions & 0 deletions postgres/osmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
Fedora:
pkg_repo:
baseurl: 'https://download.postgresql.org/pub/repos/yum/{{ repo.version }}/fedora/fedora-$releasever-$basearch'
remove:
releases: ['9.4', '9.5', '9.6', '10',]

# vim: ft=sls
8 changes: 3 additions & 5 deletions postgres/server/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ postgresql-server:
- group: wheel
- require_in:
- service: postgresql-running
{%- else %}
# Alternatives system. Make server binaries available in $PATH
{%- if 'bin_dir' in postgres and postgres.linux.altpriority %}
{%- elif 'bin_dir' in postgres and postgres.linux.altpriority %}
{%- for bin in postgres.server_bins %}
{%- set path = salt['file.join'](postgres.bin_dir, bin) %}
Expand All @@ -56,9 +56,7 @@ postgresql-{{ bin }}-altinstall:
- cmd: postgresql-cluster-prepared
{%- endfor %}
{%- endif %}
{%- endif %}
{%- endif %}
postgresql-cluster-prepared:
file.directory:
Expand Down
89 changes: 89 additions & 0 deletions postgres/server/remove.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{%- from "postgres/map.jinja" import postgres with context %}
postgresql-dead:
service.dead:
- name: {{ postgres.service }}
- enable: False
postgresql-repo-removed:
pkgrepo.absent:
- name: {{ postgres.pkg_repo.name }}
{%- if 'pkg_repo_keyid' in postgres %}
- keyid: {{ postgres.pkg_repo_keyid }}
{%- endif %}
#remove release installed by formula
postgresql-server-removed:
pkg.removed:
- pkgs:
{% if postgres.pkg %}
- {{ postgres.pkg }}
{% endif %}
{% if postgres.pkgs_extra %}
{% for pkg in postgres.pkgs_extra %}
- {{ pkg }}
{% endfor %}
{% endif %}
{%- if postgres.remove.multiple_releases %}
#search for and cleandown multiple releases
{% for release in postgres.remove.releases %}
postgresql{{ release }}-server-pkgs-removed:
pkg.purged:
- pkgs:
- {{ postgres.pkg if postgres.pkg else "postgresql" }}
- postgresql-server
- postgresql-libs
- postgresql-contrib
- postgresql-server-{{ release }}
- postgresql-libs-{{ release }}
- postgresql-contrib-{{ release }}
- postgresql{{ release }}-contrib
- postgresql{{ release }}-server
- postgresql{{ release }}-libs
- postgresql{{ release }}-contrib
- postgresql{{ release|replace('.', '') }}-contrib
- postgresql{{ release|replace('.', '') }}-server
- postgresql{{ release|replace('.', '') }}-libs
- postgresql{{ release|replace('.', '') }}-contrib
{% if 'bin_dir' in postgres %}
{% for bin in postgres.server_bins %}
{% set path = '/usr/pgsql-' + release|string + '/bin/' + bin %}
postgresql{{ release }}-server-{{ bin }}-alternative-remove:
alternatives.remove:
- name: {{ bin }}
- path: {{ path }}
{% if grains.os in ('Fedora', 'CentOS',) %}
{# bypass bug #}
- onlyif: alternatives --display {{ bin }}
{% else %}
- onlyif: test -f {{ path }}
{% endif %}
{% endfor %}
{% endif %}
{%- if postgres.remove.data %}
#allow data loss? default is no
postgresql{{ release }}-dataconf-removed:
file.absent:
- names:
- {{ postgres.conf_dir }}
- {{ postgres.data_dir }}
- /var/lib/postgresql
- /var/lib/pgsql
{% for name, tblspace in postgres.tablespaces|dictsort() %}
postgresql{{ release }}-tablespace-dir-{{ name }}-removed:
file.absent:
- name: {{ tblspace.directory }}
- require:
- file: postgresql{{ release }}-dataconf-removed
{% endfor %}
{% endif %}
{% endfor %}
{%- endif %}

0 comments on commit 9d2f69a

Please sign in to comment.