Skip to content

Commit

Permalink
Rev060 (#61)
Browse files Browse the repository at this point in the history
* fix chat typo

Signed-off-by: Kevin Carter <kecarter@redhat.com>

* fix issue #57

Kevin is old, in py3 we don't need to inherit from Object...

Signed-off-by: Kevin Carter <kecarter@redhat.com>

* fix issue #56

Signed-off-by: Kevin Carter <kecarter@redhat.com>

* fix issue #55

Signed-off-by: Kevin Carter <kecarter@redhat.com>
  • Loading branch information
cloudnull authored May 23, 2021
1 parent d5550f2 commit 7e70a1f
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 111 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ diagrams, installation, usage, and more can all be

### Have Questions?

Join us on [`libra chat`](https://libera.chat/guides/connect) at
Join us on [`libera.chat`](https://libera.chat/guides/connect) at
**#directord**. The community is just getting started: folks are here to help,
answer questions, and support one another.

Expand Down
8 changes: 3 additions & 5 deletions components/container_config_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def client(self, conn, cache, job):
for mc in matched_configs:
name = os.path.splitext(os.path.basename(mc))[0]
config = json.loads(self._slurp(mc))
self.log.debug("Config found for {}: {}".format(name, config))
self.log.debug("Config found for %s: %s", name, config)
config_dict.update({name: config})

# Merge the config dict with given overrides
Expand All @@ -131,9 +131,7 @@ def client(self, conn, cache, job):
tag="component",
)
else:
self.log.debug(
"{} does not exists, skipping step".format(config_path)
)
self.log.debug("%s does not exists, skipping step", config_path)
configs = dict()

return configs, None, True
Expand All @@ -148,5 +146,5 @@ def _slurp(self, path):
f = open(path, "r")
return f.read()
else:
self.log.warn("{} was not found.".format(path))
self.log.warn("%s was not found.", path)
return ""
20 changes: 9 additions & 11 deletions directord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def send_data(socket_path, data):
chunk = s.recv(1024)
if not chunk:
break
else:
fragments.append(chunk)

fragments.append(chunk)
return b"".join(fragments)


Expand Down Expand Up @@ -118,7 +118,7 @@ def component_import(component, job_id=None):
return True, transfer, component_obj.Component()


class Processor(object):
class Processor:
"""Processing class, provides queing and threading utilities.
This is a base class.
Expand Down Expand Up @@ -170,9 +170,7 @@ def read_in_chunks(self, file_object, chunk_size=10240):
data = file_object.read(chunk_size)
if not data:
break
self.log.debug(
"Transimitting a {size} Chunk ".format(size=len(data))
)
self.log.debug("Transimitting a %s Chunk ", len(data))
yield data

@contextlib.contextmanager
Expand All @@ -194,9 +192,9 @@ def timeout(self, time, job_id, reraise=False):
yield
except TimeoutError:
self.log.warning(
"Timeout encountered after {} seconds running {}.".format(
time, job_id
)
"Timeout encountered after %s seconds running %s.",
time,
job_id,
)
if reraise:
raise TimeoutError
Expand All @@ -210,7 +208,7 @@ def raise_timeout(self, *args, **kwargs):
raise TimeoutError


class UNIXSocketConnect(object):
class UNIXSocketConnect:
"""Context manager for connecting to a UNIX socket."""

def __init__(self, sock_path):
Expand Down Expand Up @@ -238,7 +236,7 @@ def __exit__(self, *args, **kwargs):
self.sock.close()


class DirectordConnect(object):
class DirectordConnect:
"""Library context manager providing easy access into Directord."""

def __init__(self, debug=False, socket_path="/var/run/directord.sock"):
Expand Down
27 changes: 13 additions & 14 deletions directord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ def run_heartbeat(self, sentinel=False):
if time.time() > heartbeat_at and heartbeat_misses > 5:
self.log.error("Heartbeat failure, can't reach server")
self.log.warning(
"Reconnecting in {}s...".format(
self.heartbeat_failure_interval
)
"Reconnecting in [ %s ]...",
self.heartbeat_failure_interval,
)

time.sleep(self.heartbeat_failure_interval)
Expand Down Expand Up @@ -247,12 +246,12 @@ def _job_executor(
if cached and component.cacheable:
# TODO(cloudnull): Figure out how to skip cache when file
# transfering.
self.log.info("Cache hit on {}, task skipped.".format(job_sha1))
self.log.info("Cache hit on %s, task skipped.", job_sha1)
conn.info = b"job skipped"
conn.job_state = self.job_end
return None, None, None
else:
return component.client(**component_kwargs)

return component.client(**component_kwargs)

def run_job(self, sentinel=False):
"""Job entry point.
Expand Down Expand Up @@ -330,7 +329,7 @@ def run_job(self, sentinel=False):
job = json.loads(data.decode())
job_id = job.get("task", utils.get_uuid())
job_sha1 = job.get("task_sha1sum", utils.object_sha1(job))
self.log.info("Job received {}".format(job_id))
self.log.info("Job received %s", job_id)
self.socket_multipart_send(
zsocket=self.bind_job,
msg_id=job_id.encode(),
Expand All @@ -356,9 +355,9 @@ def run_job(self, sentinel=False):
) as c:
if cache.get(job_parent_id) is False:
self.log.error(
"Parent failure {} skipping {}".format(
job_parent_id, job_id
)
"Parent failure %s skipping %s",
job_parent_id,
job_id,
)
status = (
"Job [ {} ] was not allowed to run because"
Expand All @@ -372,8 +371,8 @@ def run_job(self, sentinel=False):

if sentinel:
break
else:
continue

continue

with self.timeout(
time=job.get("timeout", 600), job_id=job_id
Expand Down Expand Up @@ -410,7 +409,7 @@ def run_job(self, sentinel=False):

if outcome is False:
state = c.job_state = self.job_failed
self.log.error("Job failed {}".format(job_id))
self.log.error("Job failed %s", job_id)
if job_parent_id:
base_component.set_cache(
cache=cache,
Expand All @@ -420,7 +419,7 @@ def run_job(self, sentinel=False):
)
elif outcome is True:
state = c.job_state = self.job_end
self.log.info("Job complete {}".format(job_id))
self.log.info("Job complete %s", job_id)
if job_parent_id:
base_component.set_cache(
cache=cache,
Expand Down
10 changes: 5 additions & 5 deletions directord/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from directord import utils


class ComponentBase(object):
class ComponentBase:
"""Component base class."""

def __init__(self, desc=None):
Expand Down Expand Up @@ -103,8 +103,8 @@ def run_command(
output, error = process.communicate()
if process.returncode not in return_codes:
return output, error, False
else:
return output, error, True

return output, error, True

def options_converter(self, documentation):
"""Convert an options YAML to Arguments.
Expand Down Expand Up @@ -298,8 +298,8 @@ def blueprinter(self, content, values):
return
else:
return rendered_content
else:
return content

return content

def parser_error(self):
"""Return parser help information."""
Expand Down
28 changes: 14 additions & 14 deletions directord/components/builtin_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,23 @@ def client(self, cache, conn, job):
data = json.dumps(data)
if status:
return data, None, status
else:
return None, data, status
else:
return (
None,
(
"The action [ {action} ] failed to return"
" a function".format(action=job["pod_action"])
),
False,
)

return None, data, status

return (
None,
(
"The action [ {action} ] failed to return"
" a function".format(action=job["pod_action"])
),
False,
)
except Exception as e:
self.log.critical(str(e))
return None, traceback.format_exc(), False


class PodmanConnect(object):
class PodmanConnect:
"""Connect to the podman unix socket."""

def __init__(self, socket="/var/run/podman/podman.sock"):
Expand Down Expand Up @@ -351,8 +351,8 @@ def play(self, pod_file, tls_verify=True):
params={"tlsVerify": tls_verify, "start": True},
)
return resp.ok, self._decode(resp.content)
else:
return False, "Pod YAML did not exist"

return False, "Pod YAML did not exist"

def exec_run(self, name, command, env, privileged=False):
"""Create an exec container and run it.
Expand Down
1 change: 1 addition & 0 deletions directord/components/builtin_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ def client(self, conn, cache, job):
query = json.dumps(args.get(job["query"]))
else:
query = None

return query, None, True
10 changes: 5 additions & 5 deletions directord/datastore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def prune(self):
self.pop(key)
except (KeyError, TypeError):
pass
else:
return len(self)

return len(self)

def set(self, key, value):
"""Set key and value if key doesn't already exist.
Expand All @@ -56,9 +56,9 @@ def set(self, key, value):

if key in self:
return self[key]
else:
super().__setitem__(key, value)
return self[key]

super().__setitem__(key, value)
return self[key]

def __repr__(self):
return f"{type(self).__name__}({super().__repr__()})"
11 changes: 5 additions & 6 deletions directord/datastore/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import redis


class BaseDocument(object):
class BaseDocument:
"""Create a document store object."""

def __init__(self, url, database=0):
Expand Down Expand Up @@ -120,9 +120,8 @@ def prune(self):
self.datastore.delete(item)
except (KeyError, TypeError):
pass
else:

return len(self.datastore.keys("*"))
return len(self.datastore.keys("*"))

def get(self, key):
"""Return the value of a given key.
Expand All @@ -147,6 +146,6 @@ def set(self, key, value):
item = self.__getitem__(key)
if item:
return item
else:
self.__setitem__(key, value)
return value

self.__setitem__(key, value)
return value
6 changes: 3 additions & 3 deletions directord/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def getLogger(name, debug_logging=False):
)


class LogSetup(object):
class LogSetup:
"""Logging Class."""

def __init__(self, max_size=500, max_backup=5, debug_logging=False):
Expand Down Expand Up @@ -159,5 +159,5 @@ def return_logfile(filename, log_dir="/var/log"):
return os.path.join(log_dir, filename)
elif log_dir_stat.st_gid == user:
return os.path.join(log_dir, filename)
else:
return os.path.join(home, filename)

return os.path.join(home, filename)
2 changes: 1 addition & 1 deletion directord/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def _args(exec_args=None):
return args, parser


class SystemdInstall(object):
class SystemdInstall:
"""Simple system service unit creation class."""

def __init__(self):
Expand Down
13 changes: 7 additions & 6 deletions directord/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from directord import utils


class Mixin(object):
class Mixin:
"""Mixin class."""

def __init__(self, args):
Expand Down Expand Up @@ -368,8 +368,8 @@ def _computed_totals(item, value_heading, value):

seen_computed_key.append(key)
tabulated_data.append(arranged_data)
else:
return tabulated_data, found_headings, computed_values

return tabulated_data, found_headings, computed_values

@staticmethod
def bootstrap_catalog_entry(entry):
Expand Down Expand Up @@ -413,8 +413,8 @@ def bootstrap_localfile_padding(localfile):
else:
base_path = os.path.join(sys.prefix, "share/directord/tools")
return os.path.join(base_path, localfile)
else:
return localfile

return localfile

def bootstrap_flatten_jobs(self, jobs, return_jobs=None):
"""Return a flattened list of jobs.
Expand All @@ -439,6 +439,7 @@ def bootstrap_flatten_jobs(self, jobs, return_jobs=None):
)
else:
return_jobs.append(job)

return return_jobs

def bootstrap_run(self, job_def, catalog):
Expand All @@ -463,7 +464,7 @@ def bootstrap_run(self, job_def, catalog):
self.log.info("Running bootstrap for %s", job_def["host"])
for job in self.bootstrap_flatten_jobs(jobs=job_def["jobs"]):
key, value = next(iter(job.items()))
self.log.debug("Executing: {} {}".format(key, value))
self.log.debug("Executing: %s %s", key, value)
with utils.ParamikoConnect(
host=job_def["host"],
username=job_def["username"],
Expand Down
Loading

0 comments on commit 7e70a1f

Please sign in to comment.