Page MenuHomeDevCentral

D3027.id7728.diff
No OneTemporary

D3027.id7728.diff

diff --git a/_tests/Makefile b/_tests/Makefile
--- a/_tests/Makefile
+++ b/_tests/Makefile
@@ -7,3 +7,10 @@
test-bats:
bats scripts/bats/test_edit_acme_dns_accounts.sh
+
+# -------------------------------------------------------------
+# Configuration test specific to the primary server
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+test-config:
+ cd config/salt-primary && make
diff --git a/_tests/config/salt-primary/Makefile b/_tests/config/salt-primary/Makefile
new file mode 100644
--- /dev/null
+++ b/_tests/config/salt-primary/Makefile
@@ -0,0 +1,17 @@
+# -------------------------------------------------------------
+# Salt :: tests :: config for Salt primary server
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: BSD-2-Clause
+# -------------------------------------------------------------
+
+all: netbox rabbitmq vault
+
+netbox:
+ ./netbox.py
+
+rabbitmq:
+ ./rabbitmq.py
+
+vault:
+ ./vault.py
diff --git a/_tests/config/salt-primary/netbox.py b/_tests/config/salt-primary/netbox.py
new file mode 100755
--- /dev/null
+++ b/_tests/config/salt-primary/netbox.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python3
+
+# -------------------------------------------------------------
+# Salt :: tests :: config :: NetBox
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Description: Connect to NetBox API
+# License: BSD-2-Clause
+# -------------------------------------------------------------
+
+
+import yaml
+import requests
+import sys
+
+
+def get_config_path():
+ # As long as we deploy primary servers on FreeBSD,
+ # this path is stable.
+ return "/usr/local/etc/salt/master.d/netbox.conf"
+
+
+def load_config():
+ with open(get_config_path()) as fd:
+ return yaml.safe_load(fd)
+
+
+def connect_to_netbox():
+ config = load_config()
+ try:
+ config = config["ext_pillar"][0]["netbox"]
+ except KeyError:
+ print(
+ "Invalid configuration format. See https://docs.saltproject.io/en/latest/ref/pillar/all/salt.pillar.netbox.html for the expected format.",
+ file=sys.stderr,
+ )
+ return False
+
+ url = config["api_url"] + "dcim/devices/"
+ headers = {"Authorization": f"Token {config['api_token']}"}
+ r = requests.get(url, headers=headers)
+ if r.status_code != 200:
+ return False
+
+ try:
+ if url not in r.json()["results"][0]["url"]:
+ print(
+ "Test request to list devices. Device URL was expected to match API URL.",
+ file=sys.stderr,
+ )
+ return False
+ except KeyError:
+ print("Request format not recognized. API response changed?", file=sys.stderr)
+ return False
+
+ return True
+
+
+# -------------------------------------------------------------
+# Application entry point
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def run_tests():
+ return connect_to_netbox()
+
+
+if __name__ == "__main__":
+ is_success = run_tests()
+ sys.exit(0 if is_success else 1)
diff --git a/_tests/config/salt-primary/rabbitmq.py b/_tests/config/salt-primary/rabbitmq.py
new file mode 100755
--- /dev/null
+++ b/_tests/config/salt-primary/rabbitmq.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+
+# -------------------------------------------------------------
+# Salt :: tests :: config :: RabbitMQ
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Description: Connect to RabbitMQ
+# License: BSD-2-Clause
+# -------------------------------------------------------------
+
+
+import sys
+
+import yaml
+import requests
+from requests.auth import HTTPBasicAuth
+
+
+def get_config_path():
+ # As long as we deploy primary servers on FreeBSD,
+ # this path is stable.
+ return "/usr/local/etc/salt/master.d/rabbitmq.conf"
+
+
+def load_config():
+ with open(get_config_path()) as fd:
+ return yaml.safe_load(fd)
+
+
+def connect_to_rabbitmq(args):
+ url = args["url"] + "/overview"
+
+ if args["auth"] == "basic":
+ auth = HTTPBasicAuth(args["user"], args["password"])
+ else:
+ raise RuntimeError(
+ f"RabbitMQ HTTP API authentication scheme not supported: {args['auth']}"
+ )
+
+ r = requests.get(url, auth=auth)
+ if r.status_code != 200:
+ return False
+
+ return True
+
+
+# -------------------------------------------------------------
+# Application entry point
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def run_tests():
+ overall_result = True
+ clusters = load_config()["rabbitmq"]
+ for cluster, args in clusters.items():
+ result = "✔️"
+ if not connect_to_rabbitmq(args):
+ result = "❌"
+ overall_result = False
+ print(f"{cluster}\t{result}")
+
+ return overall_result
+
+
+if __name__ == "__main__":
+ is_success = run_tests()
+ sys.exit(0 if is_success else 1)
diff --git a/_tests/config/salt-primary/vault.py b/_tests/config/salt-primary/vault.py
new file mode 100755
--- /dev/null
+++ b/_tests/config/salt-primary/vault.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+
+# -------------------------------------------------------------
+# Salt :: tests :: config :: Vault
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Description: Connect to Vault
+# License: BSD-2-Clause
+# -------------------------------------------------------------
+
+
+import yaml
+import json
+import requests
+import sys
+
+
+def get_config_path():
+ # As long as we deploy primary servers on FreeBSD,
+ # this path is stable.
+ return "/usr/local/etc/salt/master.d/vault.conf"
+
+
+def load_config():
+ with open(get_config_path()) as fd:
+ return yaml.safe_load(fd)
+
+
+def connect_to_vault():
+ config = load_config()
+
+ authdata = json.dumps(config["vault"]["auth"])
+ url = config["vault"]["url"] + "/v1/auth/approle/login"
+ r = requests.post(url, verify=config["vault"]["verify"], data=authdata)
+ if r.status_code != 200:
+ return False
+
+ auth = r.json()["auth"]
+ print("Can connect to Vault:")
+ for k in ["metadata", "policies", "token_policies", "token_type"]:
+ print(f"\t{k}: {auth[k]}")
+ return True
+
+
+# -------------------------------------------------------------
+# Application entry point
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def run_tests():
+ return connect_to_vault()
+
+
+if __name__ == "__main__":
+ is_success = run_tests()
+ sys.exit(0 if is_success else 1)

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 1, 03:51 (17 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2274027
Default Alt Text
D3027.id7728.diff (6 KB)

Event Timeline