mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Force version type to string in deb_postgres module (#58299)
* ensure version isn't an int because of yaml parsing Fix #50899 * Add test for working float version Add some test to make sure float/int value of version will work * Add changelog * Drop six usage and Py2 support
This commit is contained in:
parent
2961006491
commit
72c5382b10
3 changed files with 32 additions and 22 deletions
5
changelog/50899.fixed
Normal file
5
changelog/50899.fixed
Normal file
|
@ -0,0 +1,5 @@
|
|||
permit the use of int/float type for the version in:
|
||||
- the state postgres_cluster.present
|
||||
- the state postgres_cluster.absent
|
||||
- the module postgres.cluster_create
|
||||
- the module postgres.cluster_remove
|
|
@ -1,18 +1,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Module to provide Postgres compatibility to salt for debian family specific tools.
|
||||
|
||||
"""
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import logging
|
||||
import pipes
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils.path
|
||||
from salt.ext import six
|
||||
|
||||
# Import 3rd-party libs
|
||||
|
||||
|
@ -66,14 +63,14 @@ def cluster_create(
|
|||
|
||||
cmd = [salt.utils.path.which("pg_createcluster")]
|
||||
if port:
|
||||
cmd += ["--port", six.text_type(port)]
|
||||
cmd += ["--port", str(port)]
|
||||
if locale:
|
||||
cmd += ["--locale", locale]
|
||||
if encoding:
|
||||
cmd += ["--encoding", encoding]
|
||||
if datadir:
|
||||
cmd += ["--datadir", datadir]
|
||||
cmd += [version, name]
|
||||
cmd += [str(version), name]
|
||||
# initdb-specific options are passed after '--'
|
||||
if allow_group_access or data_checksums or wal_segsize:
|
||||
cmd += ["--"]
|
||||
|
@ -125,7 +122,7 @@ def cluster_exists(version, name="main"):
|
|||
|
||||
salt '*' postgres.cluster_exists '9.3' 'main'
|
||||
"""
|
||||
return "{0}/{1}".format(version, name) in cluster_list()
|
||||
return "{}/{}".format(version, name) in cluster_list()
|
||||
|
||||
|
||||
def cluster_remove(version, name="main", stop=False):
|
||||
|
@ -147,16 +144,14 @@ def cluster_remove(version, name="main", stop=False):
|
|||
cmd = [salt.utils.path.which("pg_dropcluster")]
|
||||
if stop:
|
||||
cmd += ["--stop"]
|
||||
cmd += [version, name]
|
||||
cmd += [str(version), name]
|
||||
cmdstr = " ".join([pipes.quote(c) for c in cmd])
|
||||
ret = __salt__["cmd.run_all"](cmdstr, python_shell=False)
|
||||
# FIXME - return Boolean ?
|
||||
if ret.get("retcode", 0) != 0:
|
||||
log.error("Error removing a Postgresql cluster %s/%s", version, name)
|
||||
else:
|
||||
ret["changes"] = ("Successfully removed" " cluster {0}/{1}").format(
|
||||
version, name
|
||||
)
|
||||
ret["changes"] = ("Successfully removed" " cluster {}/{}").format(version, name)
|
||||
return ret
|
||||
|
||||
|
||||
|
@ -167,7 +162,7 @@ def _parse_pg_lscluster(output):
|
|||
cluster_dict = {}
|
||||
for line in output.splitlines():
|
||||
version, name, port, status, user, datadir, log = line.split()
|
||||
cluster_dict["{0}/{1}".format(version, name)] = {
|
||||
cluster_dict["{}/{}".format(version, name)] = {
|
||||
"port": int(port),
|
||||
"status": status,
|
||||
"user": user,
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import salt.modules.deb_postgres as deb_postgres
|
||||
|
||||
|
@ -82,14 +79,22 @@ class PostgresClusterTestCase(TestCase, LoaderModuleMockMixin):
|
|||
)
|
||||
self.assertEqual(cmdstr, self.cmd_run_all_mock.call_args[0][0])
|
||||
|
||||
# XXX version should be a string but from cmdline you get a float
|
||||
# def test_cluster_create_with_float(self):
|
||||
# self.assertRaises(AssertionError, deb_postgres.cluster_create,
|
||||
# (9.3,'main',),
|
||||
# dict(port='5432',
|
||||
# locale='fr_FR',
|
||||
# encoding='UTF-8',
|
||||
# datadir='/opt/postgresql'))
|
||||
def test_cluster_create_with_float(self):
|
||||
deb_postgres.cluster_create(
|
||||
9.3,
|
||||
"main",
|
||||
port="5432",
|
||||
locale="fr_FR",
|
||||
encoding="UTF-8",
|
||||
datadir="/opt/postgresql",
|
||||
)
|
||||
cmdstr = (
|
||||
"/usr/bin/pg_createcluster "
|
||||
"--port 5432 --locale fr_FR --encoding UTF-8 "
|
||||
"--datadir /opt/postgresql "
|
||||
"9.3 main"
|
||||
)
|
||||
self.assertEqual(cmdstr, self.cmd_run_all_mock.call_args[0][0])
|
||||
|
||||
|
||||
class PostgresLsClusterTestCase(TestCase, LoaderModuleMockMixin):
|
||||
|
@ -184,3 +189,8 @@ class PostgresDeleteClusterTestCase(TestCase, LoaderModuleMockMixin):
|
|||
"/usr/bin/pg_dropcluster --stop 9.3 main",
|
||||
self.cmd_run_all_mock.call_args[0][0],
|
||||
)
|
||||
deb_postgres.cluster_remove(9.3, "main", stop=True)
|
||||
self.assertEqual(
|
||||
"/usr/bin/pg_dropcluster --stop 9.3 main",
|
||||
self.cmd_run_all_mock.call_args[0][0],
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue