Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F56941026
test_postgresql.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
test_postgresql.py
View Options
#!/usr/bin/env python3
# -------------------------------------------------------------
# Tests for dbserver pillar, PostgreSQL flavour
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: Checks for PostgreSQL pillar coherence
# License: BSD-2-Clause
# -------------------------------------------------------------
import
unittest
from
unittest_data_provider
import
data_provider
from
helpers
import
load_pillars
from
pillar.schema_helpers
import
PILLAR_ROOT
,
assert_matches_schema
,
find_sls_files
# -------------------------------------------------------------
# Connection keys
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MANDATORY_CONNECTION_KEYS
=
[
"db"
,
"user"
,
"ips"
,
]
OPTIONAL_CONNECTION_KEYS
=
[
"method"
,
]
ALL_CONNECTION_KEYS
=
MANDATORY_CONNECTION_KEYS
+
OPTIONAL_CONNECTION_KEYS
# -------------------------------------------------------------
# Tests
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pillars
=
load_pillars
(
"../pillar/dbserver/"
)
PILLAR_PATH
=
PILLAR_ROOT
/
"dbserver"
SCHEMA
=
"dbserver.schema.json"
class
Testinstance
(
unittest
.
TestCase
):
@staticmethod
def
provide_pillar_files
():
for
pillar_file_path
in
find_sls_files
(
PILLAR_PATH
):
yield
(
pillar_file_path
,)
@staticmethod
def
provide_pillars
():
for
file_path
,
pillar
in
pillars
.
items
():
if
"dbserver_postgresql"
not
in
pillar
:
continue
yield
file_path
,
pillar
[
"dbserver_postgresql"
]
@data_provider
(
provide_pillars
)
def
test_connections
(
self
,
pillar_file_path
,
pillar
):
for
connection
in
pillar
[
"connections"
]:
for
key
in
MANDATORY_CONNECTION_KEYS
:
self
.
assertIn
(
key
,
connection
,
f
"Mandatory key missing in {pillar_file_path}"
)
for
key
in
connection
:
self
.
assertIn
(
key
,
ALL_CONNECTION_KEYS
,
f
"Unknown connection parameter in {pillar_file_path}"
,
)
self
.
assertIn
(
"/"
,
connection
[
"ips"
],
f
"Connection IP range should be in CIDR notation in {pillar_file_path}."
,
)
@data_provider
(
provide_pillar_files
)
def
test_pillar_matches_schema
(
self
,
pillar_file_path
):
assert_matches_schema
(
self
,
pillar_file_path
,
SCHEMA
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Fri, Nov 13, 06:32 (4 d, 17 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4209330
Default Alt Text
test_postgresql.py (2 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment