Page MenuHomeDevCentral

D2552.diff
No OneTemporary

D2552.diff

diff --git a/.arclint b/.arclint
--- a/.arclint
+++ b/.arclint
@@ -23,6 +23,7 @@
"python": {
"type": "flake8",
"severity": {
+ "E203": "disabled",
"F821": "advice"
},
"include": [
diff --git a/.flake8 b/.flake8
new file mode 100644
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,3 @@
+[flake8]
+max-line-length = 88
+extend-ignore = E203
diff --git a/_modules/forest.py b/_modules/forest.py
--- a/_modules/forest.py
+++ b/_modules/forest.py
@@ -18,7 +18,7 @@
salt '*' forest.exists eglide
"""
- return forest in __pillar__.get('forests', [])
+ return forest in __pillar__.get("forests", [])
def get():
@@ -29,9 +29,9 @@
salt '*' forest.get
"""
- nodes = __pillar__.get('nodes')
- minion = __grains__['id']
- return nodes[minion]['forest']
+ nodes = __pillar__.get("nodes")
+ minion = __grains__["id"]
+ return nodes[minion]["forest"]
def list_groups(forest=None):
@@ -45,9 +45,9 @@
if forest is None:
forest = get()
- groups = __pillar__.get('shellgroups_ubiquity', [])
+ groups = __pillar__.get("shellgroups_ubiquity", [])
- groups_by_forest = __pillar__.get('shellgroups_by_forest', {})
+ groups_by_forest = __pillar__.get("shellgroups_by_forest", {})
if forest in groups_by_forest:
groups.extend(groups_by_forest[forest])
@@ -66,7 +66,7 @@
groups = {}
for groupname in list_groups(forest):
- groups[groupname] = __pillar__['shellgroups'][groupname]
+ groups[groupname] = __pillar__["shellgroups"][groupname]
return groups
@@ -83,7 +83,7 @@
for group in get_groups(forest).values():
if "members" in group:
- users.extend(group['members'])
+ users.extend(group["members"])
return list(set(users))
@@ -100,6 +100,6 @@
users = {}
for username in list_users(forest):
- users[username] = __pillar__['shellusers'][username]
+ users[username] = __pillar__["shellusers"][username]
return users
diff --git a/_modules/jails.py b/_modules/jails.py
--- a/_modules/jails.py
+++ b/_modules/jails.py
@@ -14,7 +14,7 @@
def _get_all_jails():
- return __pillar__.get('jails', {})
+ return __pillar__.get("jails", {})
def _get_default_group():
@@ -22,7 +22,7 @@
Gets the default group to use as key to
the pillar's jails dictionary.
"""
- return __grains__['id']
+ return __grains__["id"]
def list(group=None):
@@ -58,11 +58,11 @@
def _get_hardware_network_interfaces():
- return [interface for interface in __grains__['hwaddr_interfaces']]
+ return [interface for interface in __grains__["hwaddr_interfaces"]]
def _get_ipv6_network_interfaces():
- return [interface for interface in __grains__['ip6_interfaces']]
+ return [interface for interface in __grains__["ip6_interfaces"]]
def guess_ipv4_network_interface():
@@ -88,7 +88,7 @@
interfaces = _get_ipv6_network_interfaces()
for interface in interfaces:
- ips = __grains__['ip6_interfaces'][interface]
+ ips = __grains__["ip6_interfaces"][interface]
# We want an interface with IPv6
if len(ips) < 1:
@@ -130,9 +130,9 @@
jail = get(jailname, group)
config = [
- ["lo1", jail['lo']],
- [guess_ipv4_network_interface(), jail['ipv4']],
- [guess_ipv6_network_interface(), jail['ipv6']]
+ ["lo1", jail["lo"]],
+ [guess_ipv4_network_interface(), jail["ipv4"]],
+ [guess_ipv6_network_interface(), jail["ipv6"]],
]
return ",".join(["|".join(interface) for interface in config])
diff --git a/_modules/motd.py b/_modules/motd.py
--- a/_modules/motd.py
+++ b/_modules/motd.py
@@ -10,12 +10,12 @@
def get_path():
- os = __grains__['os_family']
+ os = __grains__["os_family"]
if os == "Debian":
return "/etc/motd.tail"
- if os == "FreeBSD" and __grains__['osmajorrelease'] >= 13:
+ if os == "FreeBSD" and __grains__["osmajorrelease"] >= 13:
return "/etc/motd.template"
return "/etc/motd"
diff --git a/_modules/nano.py b/_modules/nano.py
--- a/_modules/nano.py
+++ b/_modules/nano.py
@@ -14,8 +14,12 @@
def _get_rc_includes(nanorc_dir):
- process = subprocess.run(["find", nanorc_dir, "-type", "f"], check=True,
- stdout=subprocess.PIPE, universal_newlines=True)
+ process = subprocess.run(
+ ["find", nanorc_dir, "-type", "f"],
+ check=True,
+ stdout=subprocess.PIPE,
+ universal_newlines=True,
+ )
return ["include " + file for file in process.stdout.split()]
@@ -29,7 +33,9 @@
return content
-def check_rc_up_to_date(name="/etc/nanorc", nanorc_dir="/usr/share/nano", extra_settings=[]):
+def check_rc_up_to_date(
+ name="/etc/nanorc", nanorc_dir="/usr/share/nano", extra_settings=[]
+):
expected_content = _get_rc_content(nanorc_dir, extra_settings)
try:
@@ -43,7 +49,9 @@
return actual_content == expected_content
-def config_autogenerate(name="/etc/nanorc", nanorc_dir="/usr/share/nano", extra_settings=[]):
+def config_autogenerate(
+ name="/etc/nanorc", nanorc_dir="/usr/share/nano", extra_settings=[]
+):
nano_rc_content = _get_rc_content(nanorc_dir, extra_settings)
fd = open(name, "w")
diff --git a/_modules/node.py b/_modules/node.py
--- a/_modules/node.py
+++ b/_modules/node.py
@@ -14,7 +14,7 @@
def _get_all_nodes():
- return __pillar__.get('nodes', {})
+ return __pillar__.get("nodes", {})
def get_all_properties(nodename=None):
@@ -26,15 +26,13 @@
salt * node.get_all_properties
"""
if nodename is None:
- nodename = __grains__['id']
+ nodename = __grains__["id"]
all_nodes = _get_all_nodes()
if nodename not in all_nodes:
raise CommandExecutionError(
- SaltCloudConfigError(
- "Node {0} not declared in pillar.".format(nodename)
- )
+ SaltCloudConfigError("Node {0} not declared in pillar.".format(nodename))
)
return all_nodes[nodename]
@@ -51,25 +49,27 @@
return _get_property(key, nodename, None)
-def _explode_key(k): return k.split(':')
+def _explode_key(k):
+ return k.split(":")
-def _get_first_key(k): return _explode_key(k)[0]
+def _get_first_key(k):
+ return _explode_key(k)[0]
-def _strip_first_key(k): return ':'.join(_explode_key(k)[1:])
+def _strip_first_key(k):
+ return ":".join(_explode_key(k)[1:])
def _get_property(key, nodename, default_value, parent=None):
if parent is None:
parent = get_all_properties(nodename)
- if ':' in key:
+ if ":" in key:
first_key = _get_first_key(key)
if first_key in parent:
return _get_property(
- _strip_first_key(key), nodename,
- default_value, parent[first_key]
+ _strip_first_key(key), nodename, default_value, parent[first_key]
)
elif key in parent:
return parent[key]
@@ -114,7 +114,7 @@
salt * node.has_role devserver
"""
- return role in get_list('roles', nodename)
+ return role in get_list("roles", nodename)
def filter_by_role(pillar_key, nodename=None):
@@ -134,12 +134,12 @@
salt * node.filter_by_role web_content_sls
"""
- roles = get_list('roles', nodename)
+ roles = get_list("roles", nodename)
dictionary = __pillar__.get(pillar_key, {})
filtered_list = []
for role, items in dictionary.items():
- if role == '*' or role in roles:
+ if role == "*" or role in roles:
filtered_list.extend(items)
return filtered_list
@@ -163,20 +163,20 @@
salt * node.filter_by_name mars
"""
if nodename is None:
- nodename = __grains__['id']
+ nodename = __grains__["id"]
dictionary = __pillar__.get(pillar_key, {})
filtered_list = []
for name, items in dictionary.items():
- if name == '*' or name == nodename:
+ if name == "*" or name == nodename:
filtered_list.extend(items)
return filtered_list
def has_web_content(content, nodename=None):
- return content in filter_by_role('web_content_sls', nodename)
+ return content in filter_by_role("web_content_sls", nodename)
def get_wwwroot(nodename=None):
@@ -198,14 +198,11 @@
)
)
- if hostname.count('.') < 2:
+ if hostname.count(".") < 2:
return "wwwroot/{0}/www".format(hostname)
fqdn = hostname.split(".")
- return "wwwroot/{1}/{0}".format(
- ".".join(fqdn[0:-2]),
- ".".join(fqdn[-2:])
- )
+ return "wwwroot/{1}/{0}".format(".".join(fqdn[0:-2]), ".".join(fqdn[-2:]))
def get_ipv6_list():
diff --git a/_modules/opensearch.py b/_modules/opensearch.py
--- a/_modules/opensearch.py
+++ b/_modules/opensearch.py
@@ -21,15 +21,15 @@
salt * opensearch.get_config
"""
if nodename is None:
- nodename = __grains__['id']
+ nodename = __grains__["id"]
try:
- clusters = __pillar__['opensearch_clusters']
+ clusters = __pillar__["opensearch_clusters"]
except KeyError:
clusters = []
for _, cluster in clusters.items():
- if nodename in cluster['nodes']:
+ if nodename in cluster["nodes"]:
return _expand_cluster_config(nodename, cluster)
raise CommandExecutionError(
@@ -43,14 +43,16 @@
config = dict(config)
nodes = _convert_to_ip(config["nodes"])
- config.update({
- "nodes": nodes,
- "nodes_certificates": _get_nodes_info(config["nodes"]),
- "node_name": nodename,
- "network_host": _get_ip(nodename),
- "lead_nodes": nodes,
- "dashboards_nodes": nodes,
- })
+ config.update(
+ {
+ "nodes": nodes,
+ "nodes_certificates": _get_nodes_info(config["nodes"]),
+ "node_name": nodename,
+ "network_host": _get_ip(nodename),
+ "lead_nodes": nodes,
+ "dashboards_nodes": nodes,
+ }
+ )
return config
@@ -61,7 +63,7 @@
def _get_ip(nodename):
try:
- network = __pillar__['nodes'][nodename]['network']
+ network = __pillar__["nodes"][nodename]["network"]
except KeyError:
raise CommandExecutionError(
SaltCloudConfigError(
@@ -69,7 +71,7 @@
)
)
- for field in ['ipv4_address', 'ipv6_address']:
+ for field in ["ipv4_address", "ipv6_address"]:
if field in network:
return network[field]
@@ -81,26 +83,30 @@
def _get_node_info(nodename):
return {
"id": nodename,
- "fqdn": __pillar__['nodes'][nodename]['hostname'],
+ "fqdn": __pillar__["nodes"][nodename]["hostname"],
"ip": _get_ip(nodename),
}
def hash_password(clear_password):
- command = "/opt/opensearch/plugins/opensearch-security/tools/hash.sh -p '{0}'".format(clear_password)
+ command = (
+ "/opt/opensearch/plugins/opensearch-security/tools/hash.sh -p '{0}'".format(
+ clear_password
+ )
+ )
env = {
"JAVA_HOME": "/opt/opensearch/jdk",
}
- return __salt__['cmd.shell'](command, env=env)
+ return __salt__["cmd.shell"](command, env=env)
def list_certificates(nodename=None):
config = get_config(nodename=None)
- certificates = ['admin', 'root-ca']
+ certificates = ["admin", "root-ca"]
for node in config["nodes_certificates"]:
- certificates.extend([node['id'], node['id'] + '_http'])
+ certificates.extend([node["id"], node["id"] + "_http"])
return certificates
diff --git a/_modules/paas_docker.py b/_modules/paas_docker.py
--- a/_modules/paas_docker.py
+++ b/_modules/paas_docker.py
@@ -20,11 +20,11 @@
"""
image = default_image
- if 'image' in args:
- image = args['image']
+ if "image" in args:
+ image = args["image"]
- if 'version' in args:
- image += ":" + str(args['version'])
+ if "version" in args:
+ image += ":" + str(args["version"])
return image
@@ -38,7 +38,7 @@
salt * paas_docker.get_subnets
"""
try:
- networks = __pillar__['docker_networks'][__grains__['id']]
+ networks = __pillar__["docker_networks"][__grains__["id"]]
except KeyError:
networks = {}
diff --git a/_modules/rust.py b/_modules/rust.py
--- a/_modules/rust.py
+++ b/_modules/rust.py
@@ -16,8 +16,10 @@
"""
Only load if the Rust compiler is available
"""
- return path_which('rustc') is not None,\
- "The Rust execution module cannot be loaded: rustc not installed."
+ return (
+ path_which("rustc") is not None,
+ "The Rust execution module cannot be loaded: rustc not installed.",
+ )
def get_rustc_triplet():
@@ -30,4 +32,4 @@
"""
# Thanks to @semarie for that tip.
- return __salt__['cmd.shell']("rustc -vV | sed -ne 's/^host: //p'")
+ return __salt__["cmd.shell"]("rustc -vV | sed -ne 's/^host: //p'")
diff --git a/_modules/zr.py b/_modules/zr.py
--- a/_modules/zr.py
+++ b/_modules/zr.py
@@ -17,8 +17,10 @@
"""
Only load if zr exists on the system
"""
- return path_which('zr') is not None,\
- "The Zemke-Rhyne execution module cannot be loaded: zr not installed."
+ return (
+ path_which("zr") is not None,
+ "The Zemke-Rhyne execution module cannot be loaded: zr not installed.",
+ )
def _build_pillar_key(expression):
@@ -28,7 +30,7 @@
def _get_credential_id_from_pillar_key(expression):
"""Gets credentials id from a dot pillar path, e.g. nasqueron.foo.bar"""
key = _build_pillar_key(expression)
- return __salt__['pillar.get'](key)
+ return __salt__["pillar.get"](key)
def get_credential_id(expression):
@@ -37,8 +39,7 @@
number = int(expression)
if number < 1:
- raise ValueError(
- expression, "A strictly positive integer was expected.")
+ raise ValueError(expression, "A strictly positive integer was expected.")
return number
except ValueError:
@@ -67,7 +68,7 @@
credential_id = get_credential_id(credential_expression)
zr_command = "zr getcredentials {0}".format(credential_id)
- return __salt__['cmd.shell'](zr_command)
+ return __salt__["cmd.shell"](zr_command)
def get_username(credential_expression):
@@ -87,7 +88,7 @@
credential_id = get_credential_id(credential_expression)
zr_command = "zr getcredentials {0} username".format(credential_id)
- return __salt__['cmd.shell'](zr_command)
+ return __salt__["cmd.shell"](zr_command)
def get_token(credential_expression):
@@ -106,17 +107,26 @@
credential_id = get_credential_id(credential_expression)
zr_command = "zr getcredentials {0} token".format(credential_id)
- return __salt__['cmd.shell'](zr_command)
+ return __salt__["cmd.shell"](zr_command)
def get_sentry_dsn(args):
- sentry_server = _get_sentry_server(args['realm'])
-
- return "https://" + ":".join([
- get_username(args['credential']),
- get_password(args['credential']),
- ]) + "@" + sentry_server + "/" + str(args['project_id'])
+ sentry_server = _get_sentry_server(args["realm"])
+
+ return (
+ "https://"
+ + ":".join(
+ [
+ get_username(args["credential"]),
+ get_password(args["credential"]),
+ ]
+ )
+ + "@"
+ + sentry_server
+ + "/"
+ + str(args["project_id"])
+ )
def _get_sentry_server(realm):
- return __pillar__['sentry_realms'][realm]['host']
+ return __pillar__["sentry_realms"][realm]["host"]
diff --git a/_states/nano.py b/_states/nano.py
--- a/_states/nano.py
+++ b/_states/nano.py
@@ -10,28 +10,31 @@
# -------------------------------------------------------------
-def config_autogenerated(name="/etc/nanorc", nanorc_dir="/usr/share/nano", extra_settings=[]):
- ret = {'name': name,
- 'result': False,
- 'changes': {},
- 'comment': ''}
+def config_autogenerated(
+ name="/etc/nanorc", nanorc_dir="/usr/share/nano", extra_settings=[]
+):
+ ret = {"name": name, "result": False, "changes": {}, "comment": ""}
- if __salt__['nano.check_rc_up_to_date'](name=name, nanorc_dir=nanorc_dir, extra_settings=extra_settings):
- ret['result'] = True
- ret['comment'] = '{0} is already up to date'.format(name)
+ if __salt__["nano.check_rc_up_to_date"](
+ name=name, nanorc_dir=nanorc_dir, extra_settings=extra_settings
+ ):
+ ret["result"] = True
+ ret["comment"] = "{0} is already up to date".format(name)
return ret
- if __opts__['test']:
- ret['result'] = None
- ret['comment'] = 'State nano will write config file {0}'.format(name)
+ if __opts__["test"]:
+ ret["result"] = None
+ ret["comment"] = "State nano will write config file {0}".format(name)
return ret
try:
- __salt__['nano.config_autogenerate'](name=name, nanorc_dir=nanorc_dir, extra_settings=extra_settings)
+ __salt__["nano.config_autogenerate"](
+ name=name, nanorc_dir=nanorc_dir, extra_settings=extra_settings
+ )
except Exception as e:
- ret['comment'] = e
+ ret["comment"] = e
return ret
- ret['comment'] = "Configuration written"
- ret['result'] = True
+ ret["comment"] = "Configuration written"
+ ret["result"] = True
return ret
diff --git a/_tests/mocks/dunder.py b/_tests/mocks/dunder.py
--- a/_tests/mocks/dunder.py
+++ b/_tests/mocks/dunder.py
@@ -1,5 +1,4 @@
class dunder:
-
def __init__(self):
self.data = {}
diff --git a/_tests/modules/test_forest.py b/_tests/modules/test_forest.py
--- a/_tests/modules/test_forest.py
+++ b/_tests/modules/test_forest.py
@@ -2,52 +2,49 @@
import unittest
-salt_test_case = SourceFileLoader('salt_test_case', "salt_test_case.py").load_module()
-forest = SourceFileLoader('forest', "../_modules/forest.py").load_module()
+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_pillar("data/forests.yaml")
self.mock_grains()
- self.grains['id'] = 'egladil'
+ self.grains["id"] = "egladil"
def test_exists(self):
- self.assertTrue(forest.exists('lothlorien'))
- self.assertFalse(forest.exists('notexisting'))
+ 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.grains["id"] = "notexisting"
self.assertRaises(KeyError, forest.get)
def test_list_groups(self):
- self.assertEqual(['caras_galadhon', 'ubiquity'],
- sorted(forest.list_groups()))
+ 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())
+ 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()))
+ self.assertEqual(
+ ["caras_galadhon", "ubiquity"], sorted(forest.get_groups().keys())
+ )
def test_list_users(self):
- self.assertEqual(['amdir', 'amroth'],
- sorted(forest.list_users()))
+ self.assertEqual(["amdir", "amroth"], sorted(forest.list_users()))
def test_get_users(self):
- self.assertEqual(['amdir', 'amroth'],
- sorted(forest.get_users().keys()))
+ self.assertEqual(["amdir", "amroth"], sorted(forest.get_users().keys()))
-if __name__ == '__main__':
+if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_jails.py b/_tests/modules/test_jails.py
--- a/_tests/modules/test_jails.py
+++ b/_tests/modules/test_jails.py
@@ -2,42 +2,38 @@
import unittest
-salt_test_case = SourceFileLoader('salt_test_case', "salt_test_case.py").load_module()
-jails = SourceFileLoader('jails', "../_modules/jails.py").load_module()
+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_pillar("data/jails.yaml")
self.mock_grains()
- self.grains['id'] = 'host'
+ self.grains["id"] = "host"
def test_get_default_group(self):
- self.assertEqual('host', jails._get_default_group())
+ self.assertEqual("host", jails._get_default_group())
def test_get_all_jails(self):
- self.assertEqual(['anotherhost', 'host'],
- sorted(jails._get_all_jails().keys()))
+ self.assertEqual(["anotherhost", "host"], sorted(jails._get_all_jails().keys()))
def test_list(self):
- self.assertEqual(['guest1', 'guest2'],
- sorted(jails.list()))
+ self.assertEqual(["guest1", "guest2"], sorted(jails.list()))
def test_list_for_a_group(self):
- self.assertEqual(['guest3'],
- sorted(jails.list('anotherhost')))
+ 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'))
+ self.assertEqual("guest3", jails.flatlist("anotherhost"))
-if __name__ == '__main__':
+if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_nano.py b/_tests/modules/test_nano.py
--- a/_tests/modules/test_nano.py
+++ b/_tests/modules/test_nano.py
@@ -2,50 +2,50 @@
import unittest
-salt_test_case = SourceFileLoader(
- 'salt_test_case', "salt_test_case.py").load_module()
-nano = SourceFileLoader('nano', "../_modules/nano.py").load_module()
+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',
+ "include data/nanorc_dir/bar.nanorc",
+ "include data/nanorc_dir/foo.nanorc",
]
-EXTRA_SETTINGS = ['set foo bar']
+EXTRA_SETTINGS = ["set foo bar"]
-EXPECTED_FULL_CONFIG = [''] * 2 + EXPECTED_INCLUDES + EXTRA_SETTINGS
+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")))
+ 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")))
+ 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)))
+ 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))
+ 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))
+ 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))
+ self.assertFalse(
+ nano.check_rc_up_to_date(name="/not/existing", nanorc_dir=DATA_DIR)
+ )
-if __name__ == '__main__':
+if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_node.py b/_tests/modules/test_node.py
--- a/_tests/modules/test_node.py
+++ b/_tests/modules/test_node.py
@@ -2,126 +2,102 @@
import unittest
-salt_test_case = SourceFileLoader('salt_test_case', "salt_test_case.py").load_module()
-node = SourceFileLoader('node', "../_modules/node.py").load_module()
+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_pillar("data/forests.yaml")
self.mock_grains()
- self.grains['id'] = 'egladil'
+ 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'))
+ 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(".ll/carasgaladhon"))
+ self.assertFalse(node.has_web_content(".arda/onodlo"))
- self.assertTrue(node.has_web_content('.arda/onodlo', 'entwash'))
+ self.assertTrue(node.has_web_content(".arda/onodlo", "entwash"))
- self.assertFalse(node.has_web_content('notexisting'))
+ self.assertFalse(node.has_web_content("notexisting"))
def test_filter_by_role(self):
- node_key = self.grains['id']
+ node_key = self.grains["id"]
- self.assertEqual(['Caras Galadhon'],
- node.filter_by_role('items_by_role'))
+ self.assertEqual(["Caras Galadhon"], node.filter_by_role("items_by_role"))
- self.assertEqual(['Onodlo'],
- node.filter_by_role('items_by_role', 'entwash'))
+ 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'))
+ 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')))
+ 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']
+ node_key = self.grains["id"]
- self.assertEqual(['Air', 'Caras Galadhon'],
- node.filter_by_role('items_by_role_with_star'))
+ 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'
- ))
+ 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'))
+ 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.pillar["nodes"][node_key]["roles"] = ["border", "treecity"]
self.assertEqual(
- ['Air', 'Caras Galadhon', 'Onodlo'],
- sorted(node.filter_by_role('items_by_role_with_star'))
+ ["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"))
self.assertEqual(
- ['Caras Galadhon'],
- node.filter_by_name('items_by_name', 'egladil')
+ ["Caras Galadhon"], node.filter_by_name("items_by_name", "egladil")
)
- self.grains['id'] = 'entwash'
- self.assertEqual(
- [],
- node.filter_by_name('items_by_name')
- )
+ 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')
+ ["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')
+ ["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')
- )
+ 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.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()
+ "[::1] [2001:470:1f13:ce7:ca5:cade:fab:1e] [2001:470:1f12:ce7::2]",
+ node.get_ipv6_list(),
)
diff --git a/_tests/modules/test_paas_docker.py b/_tests/modules/test_paas_docker.py
--- a/_tests/modules/test_paas_docker.py
+++ b/_tests/modules/test_paas_docker.py
@@ -1,26 +1,22 @@
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()
+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_pillar("data/paas_docker.yaml")
self.mock_grains()
- self.grains['id'] = 'egladil'
+ self.grains["id"] = "egladil"
def test_get_image(self):
- container = {
- "image": "foo",
- "version": "42"
- }
+ container = {"image": "foo", "version": "42"}
self.assertEqual("foo:42", docker.get_image("not_foo", container))
@@ -32,9 +28,7 @@
self.assertEqual("foo", docker.get_image("not_foo", container))
def test_get_image_without_image(self):
- container = {
- "version": "42"
- }
+ container = {"version": "42"}
self.assertEqual("not_foo:42", docker.get_image("not_foo", container))
@@ -42,21 +36,18 @@
self.assertEqual("not_foo", docker.get_image("not_foo", {}))
def test_get_image_with_numeric_version(self):
- container = {
- "image": "foo",
- "version": 2.5
- }
+ 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']
+ 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']
+ expected = ["172.17.0.0/16"]
- self.grains['id'] = 'voidserver'
+ self.grains["id"] = "voidserver"
self.assertEqual(expected, docker.get_subnets())
diff --git a/_tests/modules/test_rust.py b/_tests/modules/test_rust.py
--- a/_tests/modules/test_rust.py
+++ b/_tests/modules/test_rust.py
@@ -2,12 +2,11 @@
import unittest
-salt_test_case = SourceFileLoader('salt_test_case', "salt_test_case.py").load_module()
-rust = SourceFileLoader('rust', "../_modules/rust.py").load_module()
+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()
diff --git a/_tests/pillar/core/test_users.py b/_tests/pillar/core/test_users.py
--- a/_tests/pillar/core/test_users.py
+++ b/_tests/pillar/core/test_users.py
@@ -2,21 +2,15 @@
import yaml
-PILLAR_FILE = '../pillar/core/users.sls'
+PILLAR_FILE = "../pillar/core/users.sls"
USER_PROPERTIES_MANDATORY = set(["fullname", "ssh_keys", "uid"])
-USER_PROPERTIES_OPTIONAL = set([
- "class",
- "shell",
- "yubico_keys",
- "devserver_tasks"
-])
+USER_PROPERTIES_OPTIONAL = set(["class", "shell", "yubico_keys", "devserver_tasks"])
class Testinstance(unittest.TestCase):
-
def setUp(self):
- with open(PILLAR_FILE, 'r') as fd:
+ with open(PILLAR_FILE, "r") as fd:
self.pillar = yaml.safe_load(fd)
# users must have an username, an UID and SSH keys
@@ -30,7 +24,9 @@
errors.append(f" Missing properties for {user}: {missing_properties}")
is_valid = False
- invalid_properties = set(properties) - USER_PROPERTIES_MANDATORY - USER_PROPERTIES_OPTIONAL
+ 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
diff --git a/_tests/pillar/paas/test_docker.py b/_tests/pillar/paas/test_docker.py
--- a/_tests/pillar/paas/test_docker.py
+++ b/_tests/pillar/paas/test_docker.py
@@ -2,24 +2,21 @@
import yaml
-PILLAR_FILE = '../pillar/paas/docker.sls'
+PILLAR_FILE = "../pillar/paas/docker.sls"
class Testinstance(unittest.TestCase):
-
def setUp(self):
- with open(PILLAR_FILE, 'r') as fd:
+ 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 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:
+ if "host" not in container:
continue
- entry = ':'.join(['docker_containers', node,
- service, instance])
- self.assertIn('app_port', container,
- entry + ": app_port missing")
+ entry = ":".join(["docker_containers", node, service, instance])
+ self.assertIn("app_port", container, entry + ": app_port missing")
diff --git a/_tests/salt_test_case.py b/_tests/salt_test_case.py
--- a/_tests/salt_test_case.py
+++ b/_tests/salt_test_case.py
@@ -3,7 +3,6 @@
class SaltTestCase:
-
def initialize_mocks(self):
source = SourceFileLoader("dunder", "mocks/dunder.py").load_module()
self.pillar = source.dunder()
@@ -11,7 +10,7 @@
@staticmethod
def import_data_from_yaml(filename):
- with open(filename, 'r') as fd:
+ with open(filename, "r") as fd:
return yaml.safe_load(fd.read())
def mock_pillar(self, filename=None, target=None):
diff --git a/_tests/scripts/python/test_clear_video_queue.py b/_tests/scripts/python/test_clear_video_queue.py
--- a/_tests/scripts/python/test_clear_video_queue.py
+++ b/_tests/scripts/python/test_clear_video_queue.py
@@ -3,11 +3,10 @@
path = "roles/paas-docker/containers/files/mastodon/clear-video-queue.py"
-script = SourceFileLoader('script', "../" + path).load_module()
+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]
diff --git a/_tests/scripts/python/test_edit_acme_dns_accounts.py b/_tests/scripts/python/test_edit_acme_dns_accounts.py
--- a/_tests/scripts/python/test_edit_acme_dns_accounts.py
+++ b/_tests/scripts/python/test_edit_acme_dns_accounts.py
@@ -6,7 +6,7 @@
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()
+script = SourceFileLoader("script", "../" + path).load_module()
class TestInstance(unittest.TestCase):
@@ -34,15 +34,12 @@
self.assertFalse(self.testAccounts.remove("not-existing.tld"))
def test_merge(self):
- accounts_to_merge = script.AcmeAccounts("/dev/null") \
- .add("bar.tld", {})
+ accounts_to_merge = script.AcmeAccounts("/dev/null").add("bar.tld", {})
- self.testAccounts \
- .add("foo.tld", {}) \
- .merge_with(accounts_to_merge)
+ self.testAccounts.add("foo.tld", {}).merge_with(accounts_to_merge)
self.assertEqual(2, len(self.testAccounts.accounts))
-if __name__ == '__main__':
+if __name__ == "__main__":
unittest.main()
diff --git a/roles/devserver/userland-software/files/shell.py b/roles/devserver/userland-software/files/shell.py
--- a/roles/devserver/userland-software/files/shell.py
+++ b/roles/devserver/userland-software/files/shell.py
@@ -34,18 +34,20 @@
def get_candidates_configuration_directories():
candidates = []
- if 'HOME' in os.environ:
- candidates.append(os.environ['HOME'])
+ if "HOME" in os.environ:
+ candidates.append(os.environ["HOME"])
- candidates.append('/usr/local/etc')
- candidates.append('/etc')
+ candidates.append("/usr/local/etc")
+ candidates.append("/etc")
return candidates
def get_candidates_configuration_files():
- return [directory + "/.shell.yml" for directory
- in get_candidates_configuration_directories()]
+ return [
+ directory + "/.shell.yml"
+ for directory in get_candidates_configuration_directories()
+ ]
def find_configuration_file():
@@ -60,7 +62,7 @@
def parse_configuration_file(filename):
- configuration_file = open(filename, 'r')
+ configuration_file = open(filename, "r")
configuration = yaml.safe_load(configuration_file)
configuration_file.close()
@@ -94,10 +96,10 @@
return ["ssh"]
def get_alias(self, alias_name):
- return self.get_config_section('aliases', alias_name)
+ return self.get_config_section("aliases", alias_name)
def get_handler(self, handler_name):
- return self.get_config_section('handlers', handler_name)
+ return self.get_config_section("handlers", handler_name)
def get_config_section(self, section, key):
if section in self.config:
@@ -105,27 +107,27 @@
return self.config[section][key]
def parse_alias(self, alias):
- if 'args' in alias:
- alias['args'].reverse()
- self.args.extendleft(alias['args'])
+ if "args" in alias:
+ alias["args"].reverse()
+ self.args.extendleft(alias["args"])
- if 'handler' in alias:
- handler = self.config['handlers'][alias['handler']]
+ if "handler" in alias:
+ handler = self.config["handlers"][alias["handler"]]
return self.parse_handler(handler)
- if 'command' in alias:
- return self.parse_command(alias['command'])
+ if "command" in alias:
+ return self.parse_command(alias["command"])
raise ValueError("Unable to parse alias")
def parse_handler(self, handler):
command = self.get_default_command()
- if 'interactive' in handler and handler['interactive']:
+ if "interactive" in handler and handler["interactive"]:
command.append("-t")
- command.append(handler['server'])
- command.extend(self.parse_command(handler['command']))
+ command.append(handler["server"])
+ command.extend(self.parse_command(handler["command"]))
command.extend(self.args)
return command
@@ -133,7 +135,7 @@
def parse_variable_fragment(self, variable):
# {{%s-|bash}} means %s-, with bash as default value if we don't
# have any more argument to substitute
- matches = re.search('(.*)\|(.*)', variable)
+ matches = re.search("(.*)\|(.*)", variable)
if matches:
if not self.args:
return [matches.group(2)]
@@ -142,18 +144,18 @@
return self.parse_variable_fragment(cleaned_fragment)
# Substitute with one argument
- if variable == '%s':
+ if variable == "%s":
return [self.args.popleft()]
# Substitute with all arguments
- if variable == '%s-':
+ if variable == "%s-":
return self.pop_all_args()
raise ValueError("Can't parse " + variable)
def parse_fragment(self, fragment):
# If the fragment is {{something}}, this is a variable to substitute.
- matches = re.search('{{(.*)}}', fragment)
+ matches = re.search("{{(.*)}}", fragment)
if matches:
return self.parse_variable_fragment(matches.group(1))
@@ -186,6 +188,7 @@
raise ValueError(target + ": No such target")
+
# -------------------------------------------------------------
# Runner code
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -196,7 +199,7 @@
def is_debug_mode_enabled():
- return 'DEBUG' in os.environ
+ return "DEBUG" in os.environ
def print_error(err):
@@ -239,5 +242,5 @@
subprocess.run(subprocess_args)
-if __name__ == '__main__':
+if __name__ == "__main__":
main()
diff --git a/roles/devserver/userland-software/files/url.py b/roles/devserver/userland-software/files/url.py
--- a/roles/devserver/userland-software/files/url.py
+++ b/roles/devserver/userland-software/files/url.py
@@ -41,11 +41,11 @@
def get_candidates_configuration_files():
candidates = []
- if 'HOME' in os.environ:
- candidates.append(os.environ['HOME'] + "/.urls.yml")
+ if "HOME" in os.environ:
+ candidates.append(os.environ["HOME"] + "/.urls.yml")
- candidates.append('/usr/local/etc/urls.yml')
- candidates.append('/etc/urls.yml')
+ candidates.append("/usr/local/etc/urls.yml")
+ candidates.append("/etc/urls.yml")
return candidates
@@ -62,12 +62,12 @@
def parse_configuration_file(filename):
- configuration_file = open(filename, 'r')
+ configuration_file = open(filename, "r")
configuration = yaml.safe_load(configuration_file)
configuration_file.close()
- if 'urls' not in configuration:
- configuration['urls'] = {}
+ if "urls" not in configuration:
+ configuration["urls"] = {}
return configuration
@@ -93,17 +93,14 @@
def extract_relative_user_url(base_directory, search_path):
- return extract_relative_url_in_fragments(base_directory,
- search_path, 1)
+ return extract_relative_url_in_fragments(base_directory, search_path, 1)
def extract_relative_wwwroot_url(base_directory, search_path):
- return extract_relative_url_in_fragments(base_directory,
- search_path, 2)
+ return extract_relative_url_in_fragments(base_directory, search_path, 2)
-def extract_relative_url_in_fragments(base_directory, search_path,
- fragments_count):
+def extract_relative_url_in_fragments(base_directory, search_path, fragments_count):
base_url = extract_relative_url(base_directory, search_path)
fragments = base_url.split("/", fragments_count)
@@ -121,18 +118,17 @@
def resolve_url(base_directory, args, search_path):
- if 'static' in args:
- return args['static'] + extract_relative_url(base_directory,
- search_path)
+ if "static" in args:
+ return args["static"] + extract_relative_url(base_directory, search_path)
- if 'userdir' in args:
- username, local_url = extract_relative_user_url(base_directory,
- search_path)
+ if "userdir" in args:
+ username, local_url = extract_relative_user_url(base_directory, search_path)
return "https://" + platform.node() + "/~" + username + "/" + local_url
- if 'wwwroot' in args:
- domain, sub, local_url = extract_relative_wwwroot_url(base_directory,
- search_path)
+ if "wwwroot" in args:
+ domain, sub, local_url = extract_relative_wwwroot_url(
+ base_directory, search_path
+ )
return "https://" + sub + "." + domain + "/" + local_url
return None
@@ -142,8 +138,7 @@
if os.path.isabs(search_path):
normalized_path = search_path
else:
- normalized_path = os.path.normpath(os.path.join(base_directory,
- search_path))
+ normalized_path = os.path.normpath(os.path.join(base_directory, search_path))
return os.path.realpath(normalized_path)
@@ -183,7 +178,7 @@
argc = len(sys.argv)
if argc == 1:
- return '.'
+ return "."
elif argc == 2:
return sys.argv[1]
else:
@@ -195,7 +190,7 @@
required_path = parse_path_argument()
config = get_configuration()
- url = find_url(config['urls'], os.getcwd(), required_path)
+ url = find_url(config["urls"], os.getcwd(), required_path)
if url is None:
print_error("No URL found.")
sys.exit(1)
@@ -203,5 +198,5 @@
print(url)
-if __name__ == '__main__':
+if __name__ == "__main__":
main()
diff --git a/roles/paas-docker/containers/files/hound/generate-config.py b/roles/paas-docker/containers/files/hound/generate-config.py
--- a/roles/paas-docker/containers/files/hound/generate-config.py
+++ b/roles/paas-docker/containers/files/hound/generate-config.py
@@ -21,7 +21,7 @@
"dbpath": "data",
"title": f"{account} code search".title(),
"health-check-uri": "/healthz",
- "repos": dict(repos)
+ "repos": dict(repos),
}
@@ -29,7 +29,7 @@
return repo[0], {
"url": f"https://www.github.com/{account}/{repo[0]}.git",
"vcs-config": {
- "ref": repo[1],
+ "ref": repo[1],
},
"ms-between-poll": POLL_TIME,
}
diff --git a/roles/paas-docker/containers/files/mastodon/clear-video-queue.py b/roles/paas-docker/containers/files/mastodon/clear-video-queue.py
--- a/roles/paas-docker/containers/files/mastodon/clear-video-queue.py
+++ b/roles/paas-docker/containers/files/mastodon/clear-video-queue.py
@@ -25,9 +25,7 @@
PS_COLUMN_TIME = 3
PS_COLUMN_COMMAND = 4
-SUSPECT_COMMANDS = [
- "ffmpeg"
-]
+SUSPECT_COMMANDS = ["ffmpeg"]
MAX_TIME = 30
@@ -67,9 +65,9 @@
def extract_pids(output):
extracted_pids = [extract_pid(line) for line in output]
- return [extracted_pid
- for extracted_pid in extracted_pids
- if extracted_pid is not None]
+ return [
+ extracted_pid for extracted_pid in extracted_pids if extracted_pid is not None
+ ]
def get_kill_command(pids_to_kill):
diff --git a/roles/paas-docker/letsencrypt/files/acme-dns-auth.py b/roles/paas-docker/letsencrypt/files/acme-dns-auth.py
--- a/roles/paas-docker/letsencrypt/files/acme-dns-auth.py
+++ b/roles/paas-docker/letsencrypt/files/acme-dns-auth.py
@@ -46,8 +46,9 @@
if allowfrom:
# Include allowed networks to the registration call
reg_data = {"allowfrom": allowfrom}
- res = requests.post(self.acmedns_url + "/register",
- data=json.dumps(reg_data))
+ res = requests.post(
+ self.acmedns_url + "/register", data=json.dumps(reg_data)
+ )
else:
res = requests.post(self.acmedns_url + "/register")
if res.status_code == 201:
@@ -55,30 +56,36 @@
return res.json()
else:
# Encountered an error
- msg = ("Encountered an error while trying to register a new "
- "acme-dns account. HTTP status {}, Response body: {}")
+ msg = (
+ "Encountered an error while trying to register a new "
+ "acme-dns account. HTTP status {}, Response body: {}"
+ )
print(msg.format(res.status_code, res.text))
sys.exit(1)
def update_txt_record(self, account, txt):
"""Updates the TXT challenge record to ACME-DNS subdomain."""
- update = {"subdomain": account['subdomain'], "txt": txt}
- headers = {"X-Api-User": account['username'],
- "X-Api-Key": account['password'],
- "Content-Type": "application/json"}
- res = requests.post(self.acmedns_url + "/update",
- headers=headers,
- data=json.dumps(update))
+ update = {"subdomain": account["subdomain"], "txt": txt}
+ headers = {
+ "X-Api-User": account["username"],
+ "X-Api-Key": account["password"],
+ "Content-Type": "application/json",
+ }
+ res = requests.post(
+ self.acmedns_url + "/update", headers=headers, data=json.dumps(update)
+ )
if res.status_code == 200:
# Successful update
return
else:
- msg = ("Encountered an error while trying to update TXT record in "
- "acme-dns. \n"
- "------- Request headers:\n{}\n"
- "------- Request body:\n{}\n"
- "------- Response HTTP status: {}\n"
- "------- Response body: {}")
+ msg = (
+ "Encountered an error while trying to update TXT record in "
+ "acme-dns. \n"
+ "------- Request headers:\n{}\n"
+ "------- Request body:\n{}\n"
+ "------- Response HTTP status: {}\n"
+ "------- Response body: {}"
+ )
s_headers = json.dumps(headers, indent=2, sort_keys=True)
s_update = json.dumps(update, indent=2, sort_keys=True)
s_body = json.dumps(res.json(), indent=2, sort_keys=True)
@@ -96,7 +103,7 @@
data = dict()
filedata = ""
try:
- with open(self.storagepath, 'r') as fh:
+ with open(self.storagepath, "r") as fh:
filedata = fh.read()
except IOError:
if os.path.isfile(self.storagepath):
@@ -116,8 +123,9 @@
"""Saves the storage content to disk"""
serialized = json.dumps(self._data)
try:
- with os.fdopen(os.open(self.storagepath, os.O_WRONLY | os.O_CREAT,
- 0o600), 'w') as fh:
+ with os.fdopen(
+ os.open(self.storagepath, os.O_WRONLY | os.O_CREAT, 0o600), "w"
+ ) as fh:
fh.truncate()
fh.write(serialized)
except IOError:
diff --git a/roles/paas-docker/letsencrypt/files/edit-acme-dns-accounts.py b/roles/paas-docker/letsencrypt/files/edit-acme-dns-accounts.py
--- a/roles/paas-docker/letsencrypt/files/edit-acme-dns-accounts.py
+++ b/roles/paas-docker/letsencrypt/files/edit-acme-dns-accounts.py
@@ -56,7 +56,7 @@
except KeyError:
return False
- def merge_with(self, other_accounts: 'AcmeAccounts'):
+ def merge_with(self, other_accounts: "AcmeAccounts"):
self.accounts.update(other_accounts.accounts)
return self
@@ -74,17 +74,16 @@
accounts_to_import = AcmeAccounts(file_to_import).read_from_file()
- AcmeAccounts(ACME_ACCOUNTS_PATH)\
- .read_from_file()\
- .merge_with(accounts_to_import)\
- .write_to_file()
+ AcmeAccounts(ACME_ACCOUNTS_PATH).read_from_file().merge_with(
+ accounts_to_import
+ ).write_to_file()
commands = {
"import": {
"required_argc": 3,
"command_usage": "import <file>",
- "callable": import_other_file
+ "callable": import_other_file,
},
}
diff --git a/roles/saltmaster/software/files/staging-commit-message.py b/roles/saltmaster/software/files/staging-commit-message.py
--- a/roles/saltmaster/software/files/staging-commit-message.py
+++ b/roles/saltmaster/software/files/staging-commit-message.py
@@ -17,8 +17,8 @@
import re
import subprocess
-class SubmoduleCommit:
+class SubmoduleCommit:
def __init__(self, repo_path, submodule_path):
self.repo_path = repo_path
self.submodule_path = submodule_path
@@ -30,19 +30,21 @@
old_hash = self.get_old_hash()
new_hash = self.get_new_hash()
- lines.append("Bump " + path.basename(self.submodule_path)
- + " to " + new_hash[:12])
+ lines.append(
+ "Bump " + path.basename(self.submodule_path) + " to " + new_hash[:12]
+ )
lines.append("")
lines.extend(self.get_commits_lines(old_hash, new_hash))
return "\n".join(lines)
def get_old_hash(self):
- output = subprocess.check_output(['git', 'ls-tree',
- '@', self.submodule_path],
- cwd=self.repo_path,
- encoding="utf-8")
- matches = re.search('.*commit ([a-f0-9]*).*', output.strip())
+ output = subprocess.check_output(
+ ["git", "ls-tree", "@", self.submodule_path],
+ cwd=self.repo_path,
+ encoding="utf-8",
+ )
+ matches = re.search(".*commit ([a-f0-9]*).*", output.strip())
return matches.group(1)
def get_new_hash(self):
@@ -68,27 +70,30 @@
return commits_lines
def has_submodule_been_updated(self):
- process = subprocess.run(['git', 'diff-files', '--quiet',
- self.submodule_path],
- cwd=self.repo_path)
+ process = subprocess.run(
+ ["git", "diff-files", "--quiet", self.submodule_path], cwd=self.repo_path
+ )
return process.returncode != 0
def run(repo_path):
repo = Repo(repo_path)
- submodules = [SubmoduleCommit(repo_path, submodule.name)
- for submodule in repo.submodules]
+ submodules = [
+ SubmoduleCommit(repo_path, submodule.name) for submodule in repo.submodules
+ ]
- commits = [submodule.craft_commit()
- for submodule in submodules
- if submodule.has_submodule_been_updated()]
+ commits = [
+ submodule.craft_commit()
+ for submodule in submodules
+ if submodule.has_submodule_been_updated()
+ ]
print("\n\n".join(commits))
def determine_current_repo():
- return Repo('.', search_parent_directories=True).working_tree_dir
+ return Repo(".", search_parent_directories=True).working_tree_dir
if __name__ == "__main__":
diff --git a/roles/viperserv/fantoir/files/extract_streets.py b/roles/viperserv/fantoir/files/extract_streets.py
--- a/roles/viperserv/fantoir/files/extract_streets.py
+++ b/roles/viperserv/fantoir/files/extract_streets.py
@@ -13,8 +13,7 @@
def extract_streets(filename_source, filename_out):
- with open(filename_out, 'w') as output,\
- open(filename_source, 'r') as input:
+ with open(filename_out, "w") as output, open(filename_source, "r") as input:
for line in input:
# Streets and other « voies » are the record where
# the 109th position (« type de voie ») is 1.
@@ -28,9 +27,10 @@
if __name__ == "__main__":
argc = len(sys.argv)
if argc != 3:
- print("Usage: {} <FANTOIR filename> <street filename>"
- .format(sys.argv[0]),
- file=sys.stderr)
+ print(
+ "Usage: {} <FANTOIR filename> <street filename>".format(sys.argv[0]),
+ file=sys.stderr,
+ )
sys.exit(1)
extract_streets(sys.argv[1], sys.argv[2])
diff --git a/roles/viperserv/wikidata-access-layer/files/user-config.py b/roles/viperserv/wikidata-access-layer/files/user-config.py
--- a/roles/viperserv/wikidata-access-layer/files/user-config.py
+++ b/roles/viperserv/wikidata-access-layer/files/user-config.py
@@ -13,8 +13,8 @@
# and will be lost if the state is redeployed.
# </auto-generated>
-mylang = 'wikidata'
-family = 'wikidata'
-usernames['wikidata']['wikidata'] = u'DæghrefnBot'
+mylang = "wikidata"
+family = "wikidata"
+usernames["wikidata"]["wikidata"] = "DæghrefnBot"
-console_encoding = 'utf-8'
+console_encoding = "utf-8"
diff --git a/roles/webserver-legacy/php-builder/source.sls b/roles/webserver-legacy/php-builder/source.sls
--- a/roles/webserver-legacy/php-builder/source.sls
+++ b/roles/webserver-legacy/php-builder/source.sls
@@ -14,14 +14,17 @@
def get_release_builds():
- return {name: build
- for (name, build) in __pillar__["php_custom_builds"].items()
- if build["mode"] == "release"}
+ return {
+ name: build
+ for (name, build) in __pillar__["php_custom_builds"].items()
+ if build["mode"] == "release"
+ }
def get_release_versions():
- versions = [(build['version'], build['hash'])
- for build in get_release_builds().values()]
+ versions = [
+ (build["version"], build["hash"]) for build in get_release_builds().values()
+ ]
return set(versions)
@@ -37,9 +40,11 @@
def get_build_directory(build):
return "/opt/php/_builds/" + build
+
def get_install_directory(build):
return "/opt/php/" + build
+
def get_extract_archive_command(archive, directory):
return "tar xjf " + archive + " --strip-components=1 -C " + directory
@@ -51,14 +56,16 @@
def get_configure(version, build):
if version.startswith("5.6"):
- cmd = "./configure --prefix=/opt/php/{target} --disable-cgi " \
- "--enable-fpm --with-fpm-user=app --with-fpm-group=app " \
- "--enable-mysqlnd --enable-bcmath --with-bz2 --enable-calendar " \
- "--with-curl --with-gd --with-jpeg-dir --enable-gd-native-ttf " \
- "--enable-mbstring --with-mcrypt --with-mysqli --with-pdo-mysql " \
- "--enable-pcntl --with-xsl --with-readline " \
- "--with-openssl=/opt/openssl-legacy " \
- "--with-zlib --enable-zip"
+ cmd = (
+ "./configure --prefix=/opt/php/{target} --disable-cgi "
+ "--enable-fpm --with-fpm-user=app --with-fpm-group=app "
+ "--enable-mysqlnd --enable-bcmath --with-bz2 --enable-calendar "
+ "--with-curl --with-gd --with-jpeg-dir --enable-gd-native-ttf "
+ "--enable-mbstring --with-mcrypt --with-mysqli --with-pdo-mysql "
+ "--enable-pcntl --with-xsl --with-readline "
+ "--with-openssl=/opt/openssl-legacy "
+ "--with-zlib --enable-zip"
+ )
return cmd.format(target=build)
@@ -73,45 +80,53 @@
def run():
config = {}
- builder_user = 'builder'
+ builder_user = "builder"
build_directories = get_build_directories()
- directories_to_create = ['/opt/php', '/opt/php/_archives', '/opt/php/_builds']
+ directories_to_create = ["/opt/php", "/opt/php/_archives", "/opt/php/_builds"]
# Task: create directories
directories_to_create.extend(build_directories)
for directory in directories_to_create:
- config[directory] = {'file.directory': [{'user': builder_user}]}
+ config[directory] = {"file.directory": [{"user": builder_user}]}
# Task: fetch archives
for version, archive_hash in get_release_versions():
archive = get_archive_path(version)
url = "http://fr2.php.net/get/php-" + version + ".tar.bz2/from/this/mirror"
- config[archive] = {'file.managed': [
- {'source': url},
- {'source_hash': archive_hash},
- {'user': builder_user},
- ]}
+ config[archive] = {
+ "file.managed": [
+ {"source": url},
+ {"source_hash": archive_hash},
+ {"user": builder_user},
+ ]
+ }
# Task: extract archives to build directories
for build_name, build in get_release_builds().items():
- archive = get_archive_path(build['version'])
+ archive = get_archive_path(build["version"])
directory = get_build_directory(build_name)
command = get_extract_archive_command(archive, directory)
- config["php_build_" + build_name + "_phase1_extract"] = {'cmd.run': [
- {'name': command},
- {'runas': builder_user},
- {'creates': directory + "/configure.in"},
- ]}
+ config["php_build_" + build_name + "_phase1_extract"] = {
+ "cmd.run": [
+ {"name": command},
+ {"runas": builder_user},
+ {"creates": directory + "/configure.in"},
+ ]
+ }
- if build['version'] < "7":
+ if build["version"] < "7":
# New versions of Onigurama requires a patch not merged in 5.6.38
# See https://bugs.php.net/bug.php?id=76113
- config["php_build_" + build_name + "_phase1_patch"] = {'file.patch': [
- {'name': directory + '/ext/mbstring/php_mbregex.c'},
- {'source': 'salt://roles/webserver-legacy/php-builder/files/fix-bug-76113.patch'},
- ]}
+ config["php_build_" + build_name + "_phase1_patch"] = {
+ "file.patch": [
+ {"name": directory + "/ext/mbstring/php_mbregex.c"},
+ {
+ "source": "salt://roles/webserver-legacy/php-builder/files/fix-bug-76113.patch"
+ },
+ ]
+ }
# Task: build PHP
# Task: install PHP
@@ -119,21 +134,27 @@
build_directory = get_build_directory(build_name)
install_directory = get_install_directory(build_name)
- config["php_build_" + build_name + "_phase2_compile"] = {'cmd.run': [
- {'names': [
- get_configure(build["version"], build_name),
- "make",
- "touch .built",
- ]},
- {'cwd': build_directory},
- {'runas': builder_user},
- {'creates': build_directory + "/.built"},
- ]}
-
- config["php_build_" + build_name + "_phase2_install"] = {'cmd.run': [
- {'name': "make install"},
- {'cwd': build_directory},
- {'creates': install_directory + "/bin/php"},
- ]}
+ config["php_build_" + build_name + "_phase2_compile"] = {
+ "cmd.run": [
+ {
+ "names": [
+ get_configure(build["version"], build_name),
+ "make",
+ "touch .built",
+ ]
+ },
+ {"cwd": build_directory},
+ {"runas": builder_user},
+ {"creates": build_directory + "/.built"},
+ ]
+ }
+
+ config["php_build_" + build_name + "_phase2_install"] = {
+ "cmd.run": [
+ {"name": "make install"},
+ {"cwd": build_directory},
+ {"creates": install_directory + "/bin/php"},
+ ]
+ }
return config
diff --git a/utils/dump-py-state.py b/utils/dump-py-state.py
--- a/utils/dump-py-state.py
+++ b/utils/dump-py-state.py
@@ -26,9 +26,11 @@
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")]
+ files = [
+ os.path.join(dir_path, file_name)
+ for file_name in file_names
+ if file_name.endswith(".sls")
+ ]
pillar_files.extend(files)
@@ -52,7 +54,7 @@
def system(args):
result = subprocess.run(args, stdout=subprocess.PIPE)
- return result.stdout.decode('utf-8').strip()
+ return result.stdout.decode("utf-8").strip()
# -------------------------------------------------------------
@@ -65,7 +67,7 @@
def assemble_source_code(filename):
- with open(filename, 'r') as fd:
+ with open(filename, "r") as fd:
source_code = fd.read()
return source_code + run_shim()
@@ -92,8 +94,6 @@
exit(ex.errno)
__pillar__ = load_pillar("pillar")
- __grains__ = {
- 'os': system(["uname", "-o"])
- }
+ __grains__ = {"os": system(["uname", "-o"])}
exec(source_code)
diff --git a/utils/generate-webcontent-index.py b/utils/generate-webcontent-index.py
--- a/utils/generate-webcontent-index.py
+++ b/utils/generate-webcontent-index.py
@@ -52,10 +52,10 @@
def get_sites(pillar_file):
- sites = get_pillar_entry(pillar_file, 'web_content_sls')
- return sorted([site for sublist in
- [sites[role] for role in sites]
- for site in sublist])
+ sites = get_pillar_entry(pillar_file, "web_content_sls")
+ return sorted(
+ [site for sublist in [sites[role] for role in sites] for site in sublist]
+ )
def print_header(file_to_update):
diff --git a/utils/migrate-ssh-keys.py b/utils/migrate-ssh-keys.py
--- a/utils/migrate-ssh-keys.py
+++ b/utils/migrate-ssh-keys.py
@@ -33,14 +33,14 @@
# Where is located the dictionary to update?
-state_file = 'pillar/core/users.sls'
-state_key = 'shellusers'
+state_file = "pillar/core/users.sls"
+state_key = "shellusers"
# Where are located the data fileS?
-data_path = 'roles/shellserver/users/files/ssh_keys/'
+data_path = "roles/shellserver/users/files/ssh_keys/"
# What property should get the data and be added if missing in the dict?
-state_data_property = 'ssh_keys'
+state_data_property = "ssh_keys"
# -------------------------------------------------------------
@@ -51,7 +51,6 @@
class SaltStyleDumper(yaml.Dumper):
-
def increase_indent(self, flow=False, indentless=False):
return super(SaltStyleDumper, self).increase_indent(flow, False)
@@ -94,16 +93,16 @@
if line.startswith("#"):
return False
- if line.strip() == '':
+ if line.strip() == "":
return False
return True
def dump_state(state):
- return yaml.dump({state_key: state},
- default_flow_style=False,
- Dumper=SaltStyleDumper, width=1000)
+ return yaml.dump(
+ {state_key: state}, default_flow_style=False, Dumper=SaltStyleDumper, width=1000
+ )
# -------------------------------------------------------------
diff --git a/utils/next-uid.py b/utils/next-uid.py
--- a/utils/next-uid.py
+++ b/utils/next-uid.py
@@ -10,8 +10,8 @@
import yaml
-USERS_DATASOURCE = 'pillar/core/users.sls'
-USERS_DATASOURCE_KEY = 'shellusers'
+USERS_DATASOURCE = "pillar/core/users.sls"
+USERS_DATASOURCE_KEY = "shellusers"
USERS_CUT = 5000
@@ -22,9 +22,11 @@
def get_uids(users, threshold):
- return [users[username]['uid']
- for username in users
- if users[username]['uid'] < threshold]
+ return [
+ users[username]["uid"]
+ for username in users
+ if users[username]["uid"] < threshold
+ ]
users = get_shellusers(USERS_DATASOURCE, USERS_DATASOURCE_KEY)

File Metadata

Mime Type
text/plain
Expires
Fri, Oct 4, 09:09 (21 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2174067
Default Alt Text
D2552.diff (69 KB)

Event Timeline