Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F13127353
D3878.id10034.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D3878.id10034.diff
View Options
diff --git a/_tests/Makefile b/_tests/Makefile
--- a/_tests/Makefile
+++ b/_tests/Makefile
@@ -9,7 +9,7 @@
PYTHONPATH="${CURRENT_DIR}:${MODULES_DIR}" python -m unittest discover modules
test-pillar:
- python -m unittest discover pillar
+ PYTHONPATH="${CURRENT_DIR}" python -m unittest discover pillar
test-python-scripts:
PYTHONPATH="${CURRENT_DIR}" python -m unittest discover scripts/python
diff --git a/_tests/helpers.py b/_tests/helpers.py
--- a/_tests/helpers.py
+++ b/_tests/helpers.py
@@ -3,12 +3,17 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# License: 0BSD for import_from_path
+# BSD-2-Clause for load_pillar*
# Reference: http://docs.python.org/3/library/importlib.html
# -------------------------------------------------------------
import importlib.util
+import os
import sys
+from typing import Dict, List
+
+import yaml
# -------------------------------------------------------------
@@ -28,3 +33,34 @@
spec.loader.exec_module(module)
return module
+
+
+# -------------------------------------------------------------
+# Pillar helpers
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def load_pillar_files(pillar_directory: str) -> List:
+ pillar_files = []
+
+ for dir_path, dir_names, file_names in os.walk(pillar_directory):
+ files = [
+ os.path.join(dir_path, file_name)
+ for file_name in file_names
+ if file_name.endswith(".sls")
+ ]
+
+ pillar_files.extend(files)
+
+ return pillar_files
+
+
+def load_pillar(file_path: str) -> Dict:
+ with open(file_path) as fd:
+ return yaml.safe_load(fd)
+
+
+def load_pillars(directory_path) -> Dict:
+ pillar_files = load_pillar_files(directory_path)
+
+ return {file_path: load_pillar(file_path) for file_path in pillar_files}
diff --git a/_tests/pillar/dbserver/__init__.py b/_tests/pillar/dbserver/__init__.py
new file mode 100644
diff --git a/_tests/pillar/dbserver/test_postgresql.py b/_tests/pillar/dbserver/test_postgresql.py
new file mode 100644
--- /dev/null
+++ b/_tests/pillar/dbserver/test_postgresql.py
@@ -0,0 +1,72 @@
+#!/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
+
+
+# -------------------------------------------------------------
+# 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/")
+
+
+class Testinstance(unittest.TestCase):
+ @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}.",
+ )
diff --git a/_tests/roles/python/dns/run_test_dns_zones.sh b/_tests/roles/python/dns/run_test_dns_zones.sh
--- a/_tests/roles/python/dns/run_test_dns_zones.sh
+++ b/_tests/roles/python/dns/run_test_dns_zones.sh
@@ -24,4 +24,7 @@
# Run test
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+PYTHONPATH="$(pwd)"
+export PYTHONPATH
+
python roles/python/dns/test_dns_zones.py
diff --git a/_tests/roles/python/dns/test_dns_zones.py b/_tests/roles/python/dns/test_dns_zones.py
--- a/_tests/roles/python/dns/test_dns_zones.py
+++ b/_tests/roles/python/dns/test_dns_zones.py
@@ -13,46 +13,13 @@
import subprocess
import sys
import tempfile
-from typing import Dict, List
+from typing import Dict
from jinja2 import Environment, FileSystemLoader
import unittest
from unittest_data_provider import data_provider
-import yaml
-
-# -------------------------------------------------------------
-# Pillars helpers
-# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
-PILLARS_DIRECTORY = "../pillar/dns/"
-
-
-def load_pillar_files(pillar_directory: str) -> List:
- pillar_files = []
-
- for dir_path, dir_names, file_names in os.walk(pillar_directory):
- files = [
- os.path.join(dir_path, file_name)
- for file_name in file_names
- if file_name.endswith(".sls")
- ]
-
- pillar_files.extend(files)
-
- return pillar_files
-
-
-def load_pillar(file_path: str) -> Dict:
- with open(file_path) as fd:
- return yaml.safe_load(fd)
-
-
-def load_pillars() -> Dict:
- pillar_files = load_pillar_files(PILLARS_DIRECTORY)
-
- return {file_path: load_pillar(file_path) for file_path in pillar_files}
+from helpers import load_pillars
# -------------------------------------------------------------
@@ -126,7 +93,7 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-pillars = load_pillars()
+pillars = load_pillars("../pillar/dns/")
class Testinstance(unittest.TestCase):
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 20, 11:00 (18 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3186323
Default Alt Text
D3878.id10034.diff (6 KB)
Attached To
Mode
D3878: Test if PostgreSQL connections for pg_hba.conf use CIDR notation
Attached
Detach File
Event Timeline
Log In to Comment