Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12239792
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
18 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/_tests/modules/test_forest.py b/_tests/modules/test_forest.py
old mode 100644
new mode 100755
index ac5be0f..d4e3faa
--- a/_tests/modules/test_forest.py
+++ b/_tests/modules/test_forest.py
@@ -1,50 +1,52 @@
+#!/usr/bin/env python3
+
from importlib.machinery import SourceFileLoader
import unittest
salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
forest = SourceFileLoader("forest", "../_modules/forest.py").load_module()
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def setUp(self):
self.initialize_mocks()
self.instance = forest
self.mock_pillar("data/forests.yaml")
self.mock_grains()
self.grains["id"] = "egladil"
def test_exists(self):
self.assertTrue(forest.exists("lothlorien"))
self.assertFalse(forest.exists("notexisting"))
def test_get(self):
self.assertEqual("lothlorien", forest.get())
def test_get_when_key_not_exists(self):
self.grains["id"] = "notexisting"
self.assertRaises(KeyError, forest.get)
def test_list_groups(self):
self.assertEqual(["caras_galadhon", "ubiquity"], sorted(forest.list_groups()))
def test_list_groups_when_there_are_none_for_the_foreest(self):
self.grains["id"] = "entwash"
self.assertEqual(["ubiquity"], forest.list_groups())
def test_get_groups(self):
self.assertEqual(
["caras_galadhon", "ubiquity"], sorted(forest.get_groups().keys())
)
def test_list_users(self):
self.assertEqual(["amdir", "amroth"], sorted(forest.list_users()))
def test_get_users(self):
self.assertEqual(["amdir", "amroth"], sorted(forest.get_users().keys()))
if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_jails.py b/_tests/modules/test_jails.py
old mode 100644
new mode 100755
index 3f6f7cb..f9b011e
--- a/_tests/modules/test_jails.py
+++ b/_tests/modules/test_jails.py
@@ -1,39 +1,41 @@
+#!/usr/bin/env python3
+
from importlib.machinery import SourceFileLoader
import unittest
salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
jails = SourceFileLoader("jails", "../_modules/jails.py").load_module()
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def setUp(self):
self.initialize_mocks()
self.instance = jails
self.mock_pillar("data/jails.yaml")
self.mock_grains()
self.grains["id"] = "host"
def test_get_default_group(self):
self.assertEqual("host", jails._get_default_group())
def test_get_all_jails(self):
self.assertEqual(["anotherhost", "host"], sorted(jails._get_all_jails().keys()))
def test_list(self):
self.assertEqual(["guest1", "guest2"], sorted(jails.list()))
def test_list_for_a_group(self):
self.assertEqual(["guest3"], sorted(jails.list("anotherhost")))
def test_flatlist(self):
self.assertEqual("guest1 guest2", jails.flatlist())
def test_flatlist_for_a_group(self):
self.assertEqual("guest3", jails.flatlist("anotherhost"))
if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_nano.py b/_tests/modules/test_nano.py
old mode 100644
new mode 100755
index 040b5fc..447d3b0
--- a/_tests/modules/test_nano.py
+++ b/_tests/modules/test_nano.py
@@ -1,51 +1,53 @@
+#!/usr/bin/env python3
+
from importlib.machinery import SourceFileLoader
import unittest
salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
nano = SourceFileLoader("nano", "../_modules/nano.py").load_module()
DATA_DIR = "data/nanorc_dir"
EXPECTED_INCLUDES = [
"include data/nanorc_dir/bar.nanorc",
"include data/nanorc_dir/foo.nanorc",
]
EXTRA_SETTINGS = ["set foo bar"]
EXPECTED_FULL_CONFIG = [""] * 2 + EXPECTED_INCLUDES + EXTRA_SETTINGS
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def test_get_rc_contents(self):
actual_includes = nano._get_rc_content(DATA_DIR)
self.assertEqual(EXPECTED_INCLUDES, sorted(actual_includes.strip().split("\n")))
def test_get_rc_contents_full(self):
actual_includes = nano._get_rc_content(DATA_DIR, extra_settings=EXTRA_SETTINGS)
self.assertEqual(
EXPECTED_FULL_CONFIG, sorted(actual_includes.strip().split("\n"))
)
def test_get_rc_includes(self):
self.assertEqual(EXPECTED_INCLUDES, sorted(nano._get_rc_includes(DATA_DIR)))
def check_rc_up_to_date_when_it_is(self):
self.assertTrue(
nano.check_rc_up_to_date(name="data/nanorc_ok", nanorc_dir=DATA_DIR)
)
def check_rc_up_to_date_when_it_is_not(self):
self.assertFalse(
nano.check_rc_up_to_date(name="data/nanorc_not_ok", nanorc_dir=DATA_DIR)
)
def check_rc_up_to_date_when_it_is_does_not_exist(self):
self.assertFalse(
nano.check_rc_up_to_date(name="/not/existing", nanorc_dir=DATA_DIR)
)
if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_network.py b/_tests/modules/test_network.py
old mode 100644
new mode 100755
index 88786d1..b39ebd6
--- a/_tests/modules/test_network.py
+++ b/_tests/modules/test_network.py
@@ -1,52 +1,54 @@
+#!/usr/bin/env python3
+
from importlib.machinery import SourceFileLoader
from unittest_data_provider import data_provider
import unittest
salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
network = SourceFileLoader("network", "../_modules/network_utils.py").load_module()
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
cidr_prefixes = lambda: (
("255.255.255.255", 32),
("255.255.255.254", 31),
("255.255.255.252", 30),
("255.255.255.240", 28),
("255.255.255.224", 27),
("255.255.255.0", 24),
("255.252.0.0", 14),
)
valid_netmasks = lambda: (
("255.255.255.255",),
("255.255.255.254",),
("255.255.255.252",),
("255.255.255.240",),
)
invalid_netmasks = lambda: (
# In binary, it's not a suite of 1 then a suite of 0
("255.255.255.209",),
# By definition, netmask MUST be strictly greater than 0
("0.0.0.0",),
)
@data_provider(cidr_prefixes)
def test_netmask_to_cidr_prefix(self, netmask, expected_prefix):
actual_prefix = network.netmask_to_cidr_prefix(netmask)
self.assertTrue(actual_prefix == expected_prefix)
@data_provider(valid_netmasks)
def test_is_valid_netmask(self, netmask):
self.assertTrue(network.is_valid_netmask(netmask))
@data_provider(invalid_netmasks)
def test_is_valid_netmask_when_it_is_not(self, netmask):
self.assertFalse(network.is_valid_netmask(netmask))
if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_node.py b/_tests/modules/test_node.py
old mode 100644
new mode 100755
index 75d9adf..d2b01b9
--- a/_tests/modules/test_node.py
+++ b/_tests/modules/test_node.py
@@ -1,103 +1,109 @@
+#!/usr/bin/env python3
+
from importlib.machinery import SourceFileLoader
import unittest
salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
node = SourceFileLoader("node", "../_modules/node.py").load_module()
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def setUp(self):
self.initialize_mocks()
self.instance = node
self.mock_pillar("data/forests.yaml")
self.mock_grains()
self.grains["id"] = "egladil"
def test_get_wwwroot(self):
self.assertEqual("wwwroot/lothlorien.forest/egladil", node.get_wwwroot())
self.assertEqual("wwwroot/entwash.node/www", node.get_wwwroot("entwash"))
def test_has_web_content(self):
self.assertTrue(node.has_web_content(".ll/carasgaladhon"))
self.assertFalse(node.has_web_content(".arda/onodlo"))
self.assertTrue(node.has_web_content(".arda/onodlo", "entwash"))
self.assertFalse(node.has_web_content("notexisting"))
def test_filter_by_role(self):
node_key = self.grains["id"]
self.assertEqual(["Caras Galadhon"], node.filter_by_role("items_by_role"))
self.assertEqual(["Onodlo"], node.filter_by_role("items_by_role", "entwash"))
# No role
self.pillar["nodes"][node_key]["roles"] = []
self.assertEqual([], node.filter_by_role("items_by_role"))
# More than one role
self.pillar["nodes"][node_key]["roles"] = ["border", "treecity"]
self.assertEqual(
["Caras Galadhon", "Onodlo"], sorted(node.filter_by_role("items_by_role"))
)
def test_filter_by_role_with_star(self):
node_key = self.grains["id"]
self.assertEqual(
["Air", "Caras Galadhon"], node.filter_by_role("items_by_role_with_star")
)
self.assertEqual(
["Air", "Onodlo"], node.filter_by_role("items_by_role_with_star", "entwash")
)
# No role
self.pillar["nodes"][node_key]["roles"] = []
self.assertEqual(["Air"], node.filter_by_role("items_by_role_with_star"))
# More than one role
self.pillar["nodes"][node_key]["roles"] = ["border", "treecity"]
self.assertEqual(
["Air", "Caras Galadhon", "Onodlo"],
sorted(node.filter_by_role("items_by_role_with_star")),
)
def test_filter_by_name(self):
self.assertEqual(["Caras Galadhon"], node.filter_by_name("items_by_name"))
self.assertEqual(
["Caras Galadhon"], node.filter_by_name("items_by_name", "egladil")
)
self.grains["id"] = "entwash"
self.assertEqual([], node.filter_by_name("items_by_name"))
def test_filter_by_name_with_star(self):
self.assertEqual(
["Air", "Caras Galadhon"], node.filter_by_name("items_by_name_with_star")
)
self.assertEqual(
["Air", "Caras Galadhon"],
node.filter_by_name("items_by_name_with_star", "egladil"),
)
self.grains["id"] = "entwash"
self.assertEqual(["Air"], node.filter_by_name("items_by_name_with_star"))
def test_get_ipv6_list(self):
self.grains["ipv6"] = [
"::1",
"2001:470:1f13:ce7:ca5:cade:fab:1e",
"2001:470:1f12:ce7::2",
]
self.assertEqual(
"[::1] [2001:470:1f13:ce7:ca5:cade:fab:1e] [2001:470:1f12:ce7::2]",
node.get_ipv6_list(),
)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/_tests/modules/test_paas_docker.py b/_tests/modules/test_paas_docker.py
old mode 100644
new mode 100755
index 4ef6127..a0d6106
--- a/_tests/modules/test_paas_docker.py
+++ b/_tests/modules/test_paas_docker.py
@@ -1,53 +1,59 @@
+#!/usr/bin/env python3
+
from importlib.machinery import SourceFileLoader
import unittest
salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
docker = SourceFileLoader("docker", "../_modules/paas_docker.py").load_module()
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def setUp(self):
self.initialize_mocks()
self.instance = docker
self.mock_pillar("data/paas_docker.yaml")
self.mock_grains()
self.grains["id"] = "egladil"
def test_get_image(self):
container = {"image": "foo", "version": "42"}
self.assertEqual("foo:42", docker.get_image("not_foo", container))
def test_get_image_without_version(self):
container = {
"image": "foo",
}
self.assertEqual("foo", docker.get_image("not_foo", container))
def test_get_image_without_image(self):
container = {"version": "42"}
self.assertEqual("not_foo:42", docker.get_image("not_foo", container))
def test_get_image_without_anything(self):
self.assertEqual("not_foo", docker.get_image("not_foo", {}))
def test_get_image_with_numeric_version(self):
container = {"image": "foo", "version": 2.5}
self.assertEqual("foo:2.5", docker.get_image("not_foo", container))
def test_get_subnets(self):
expected = ["172.18.1.0/24", "172.18.2.0/24", "172.17.0.0/16"]
self.assertEqual(expected, docker.get_subnets())
def test_get_subnets_when_none_are_defined(self):
# Only the default Docker one
expected = ["172.17.0.0/16"]
self.grains["id"] = "voidserver"
self.assertEqual(expected, docker.get_subnets())
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/_tests/modules/test_rust.py b/_tests/modules/test_rust.py
old mode 100644
new mode 100755
index b9e95d5..17e5242
--- a/_tests/modules/test_rust.py
+++ b/_tests/modules/test_rust.py
@@ -1,13 +1,19 @@
+#!/usr/bin/env python3
+
from importlib.machinery import SourceFileLoader
import unittest
salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
rust = SourceFileLoader("rust", "../_modules/rust.py").load_module()
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def test_get_rustc_triplet(self):
triplet = rust.get_rustc_triplet()
self.assertTrue(len(triplet.split("-")) > 2)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/_tests/pillar/core/test_users.py b/_tests/pillar/core/test_users.py
old mode 100644
new mode 100755
index 1b75d08..c091847
--- a/_tests/pillar/core/test_users.py
+++ b/_tests/pillar/core/test_users.py
@@ -1,34 +1,40 @@
+#!/usr/bin/env python3
+
import unittest
import yaml
PILLAR_FILE = "../pillar/core/users.sls"
USER_PROPERTIES_MANDATORY = set(["fullname", "ssh_keys", "uid"])
USER_PROPERTIES_OPTIONAL = set(["class", "shell", "yubico_keys", "devserver_tasks"])
class Testinstance(unittest.TestCase):
def setUp(self):
with open(PILLAR_FILE, "r") as fd:
self.pillar = yaml.safe_load(fd)
# users must have an username, an UID and SSH keys
def test_users_properties(self):
is_valid = True
errors = []
for user, properties in self.pillar["shellusers"].items():
missing_properties = USER_PROPERTIES_MANDATORY - set(properties)
if missing_properties:
errors.append(f" Missing properties for {user}: {missing_properties}")
is_valid = False
invalid_properties = (
set(properties) - USER_PROPERTIES_MANDATORY - USER_PROPERTIES_OPTIONAL
)
if invalid_properties:
errors.append(f" Invalid properties for {user}: {invalid_properties}")
is_valid = False
self.assertTrue(is_valid, "\n" + "\n".join(errors))
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/_tests/pillar/paas/test_docker.py b/_tests/pillar/paas/test_docker.py
old mode 100644
new mode 100755
index 3350c3f..2f93625
--- a/_tests/pillar/paas/test_docker.py
+++ b/_tests/pillar/paas/test_docker.py
@@ -1,22 +1,28 @@
+#!/usr/bin/env python3
+
import unittest
import yaml
PILLAR_FILE = "../pillar/paas/docker.sls"
class Testinstance(unittest.TestCase):
def setUp(self):
with open(PILLAR_FILE, "r") as fd:
self.pillar = yaml.safe_load(fd)
# nginx needs a host/app_port pair to spawn a configuration
def test_host_is_paired_with_app_port_option(self):
for node, services in self.pillar["docker_containers"].items():
for service, containers in services.items():
for instance, container in containers.items():
if "host" not in container:
continue
entry = ":".join(["docker_containers", node, service, instance])
self.assertIn("app_port", container, entry + ": app_port missing")
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/_tests/scripts/python/test_clear_video_queue.py b/_tests/scripts/python/test_clear_video_queue.py
old mode 100644
new mode 100755
index a431944..863faa4
--- a/_tests/scripts/python/test_clear_video_queue.py
+++ b/_tests/scripts/python/test_clear_video_queue.py
@@ -1,15 +1,21 @@
+#!/usr/bin/env python3
+
from importlib.machinery import SourceFileLoader
import unittest
path = "roles/paas-docker/containers/files/mastodon/clear-video-queue.py"
script = SourceFileLoader("script", "../" + path).load_module()
class Testinstance(unittest.TestCase):
def test_extract_pids(self):
with open("data/T1492-ps-x-sample.txt", "r") as fd:
ps_data = [line.strip() for line in fd]
expected_pids = [11562, 11693, 11895]
self.assertEqual(expected_pids, script.extract_pids(ps_data))
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/_tests/scripts/python/test_edit_acme_dns_accounts.py b/_tests/scripts/python/test_edit_acme_dns_accounts.py
old mode 100644
new mode 100755
index 17284a1..ab351e9
--- a/_tests/scripts/python/test_edit_acme_dns_accounts.py
+++ b/_tests/scripts/python/test_edit_acme_dns_accounts.py
@@ -1,45 +1,47 @@
+#!/usr/bin/env python3
+
from importlib.machinery import SourceFileLoader
import os
import unittest
os.environ["ACME_ACCOUNTS"] = "/path/to/acmedns.json"
path = "roles/paas-docker/letsencrypt/files/edit-acme-dns-accounts.py"
script = SourceFileLoader("script", "../" + path).load_module()
class TestInstance(unittest.TestCase):
def setUp(self):
self.testAccounts = script.AcmeAccounts("/dev/null")
pass
def test_read_path_from_environment(self):
self.assertEqual("/path/to/acmedns.json", script.get_acme_accounts_path())
def test_accounts_are_empty_on_init(self):
self.assertEqual({}, self.testAccounts.accounts)
def test_add(self):
self.testAccounts.add("foo.tld", {})
self.assertEqual(1, len(self.testAccounts.accounts))
self.assertIn("foo.tld", self.testAccounts.accounts)
def test_remove_existing(self):
self.testAccounts.add("foo.tld", {})
self.assertTrue(self.testAccounts.remove("foo.tld"))
self.assertEqual(0, len(self.testAccounts.accounts))
def test_remove_non_existing(self):
self.assertFalse(self.testAccounts.remove("not-existing.tld"))
def test_merge(self):
accounts_to_merge = script.AcmeAccounts("/dev/null").add("bar.tld", {})
self.testAccounts.add("foo.tld", {}).merge_with(accounts_to_merge)
self.assertEqual(2, len(self.testAccounts.accounts))
if __name__ == "__main__":
unittest.main()
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Oct 12, 00:26 (13 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3064325
Default Alt Text
(18 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment