Browse Source

Merge "Add log level config to podman_container module"

changes/48/730348/1
Zuul 1 month ago
committed by Gerrit Code Review
parent
commit
c30393b2cb
1 changed files with 42 additions and 4 deletions
  1. +42
    -4
      tripleo_ansible/ansible_plugins/modules/podman_container.py

+ 42
- 4
tripleo_ansible/ansible_plugins/modules/podman_container.py View File

@@ -416,6 +416,18 @@ options:
- k8s-file
- journald
- json-file
log_level:
description:
- Logging level for Podman. Log messages above specified level
("debug"|"info"|"warn"|"error"|"fatal"|"panic") (default "error")
type: str
choices:
- debug
- info
- warn
- error
- fatal
- panic
log_opt:
description:
- Logging driver specific options. Used to set the path to the container
@@ -1115,6 +1127,9 @@ class PodmanModuleParams:
def addparam_log_opt(self, c):
return c + ['--log-opt', self.params['log_opt']]

def addparam_log_level(self, c):
return c + ['--log-level', self.params['log_level']]

def addparam_memory(self, c):
return c + ['--memory', self.params['memory']]

@@ -1282,6 +1297,7 @@ class PodmanDefaults:
"ipc": "",
"kernelmemory": "0",
"log_driver": "k8s-file",
"log_level": "error",
"memory": "0",
"memory_swap": "0",
"memory_reservation": "0",
@@ -1573,6 +1589,15 @@ class PodmanContainerDiff:
after = self.params['log_driver']
return self._diff_update_and_compare('log_driver', before, after)

def diffparam_log_level(self):
excom = self.info['exitcommand']
if '--log-level' in excom:
before = excom[excom.index('--log-level') + 1]
else:
before = self.params['log_level']
after = self.params['log_level']
return self._diff_update_and_compare('log_level', before, after)

# Parameter has limited idempotency, unable to guess the default log_path
def diffparam_log_opt(self):
before = self.info['logpath']
@@ -1819,6 +1844,13 @@ class PodmanContainer:
action {str} -- action to perform - start, create, stop, run,
delete
"""

def clean_stderr(err):
# Inspect STDERR for logs to avoid modules failures in case of
# increased log level verbosity
return "\n".join(
[line for line in err.splitlines() if 'level=' not in line]).strip()

b_command = PodmanModuleParams(action,
self.module.params,
self.version,
@@ -1826,17 +1858,23 @@ class PodmanContainer:
).construct_command_from_params()
full_cmd = " ".join([self.module.params['executable']]
+ [to_native(i) for i in b_command])
self.module.log("PODMAN-CONTAINER-DEBUG: %s" % full_cmd)
self.actions.append(full_cmd)
if not self.module.check_mode:
if self.module.check_mode:
self.module.log("PODMAN-CONTAINER-DEBUG (check_mode): %s" % full_cmd)
else:
rc, out, err = self.module.run_command(
[self.module.params['executable'], b'container'] + b_command,
expand_user_and_vars=False)
self.module.log("PODMAN-CONTAINER-DEBUG: %s" % full_cmd)
if self.module.params['debug']:
self.module.log("PODMAN-CONTAINER-DEBUG STDOUT: %s" % out)
self.module.log("PODMAN-CONTAINER-DEBUG STDERR: %s" % err)
self.module.log("PODMAN-CONTAINER-DEBUG RC: %s" % rc)
self.stdout = out
self.stderr = err
if rc != 0:
if rc != 0 or clean_stderr(err) != '':
self.module.fail_json(
msg="Can't %s container %s" % (action, self.name),
msg="Failed %s container %s" % (action, self.name),
stdout=out, stderr=err)

def run(self):


Loading…
Cancel
Save