1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-02-04 07:11:49 +00:00

Fix signal diff for truncated and RT signal names (#326)

* Fix signal diff for truncated and RT signal names

This refactors the signal mapping logic to closely resemble the logic in
podman.

Podman tolerates images with truncated STOPSIGNAL names e.g RTMIN+3
is used in the freeipa-container Dockerfiles.

Also avoids hardcoding real-time signals as they vary per
platform or glibc implementation (see man 7 signal).

* Cleanup lint

* More lint cleanup
This commit is contained in:
Oliver Walsh 2021-10-19 15:18:22 +01:00 committed by GitHub
parent e90eb325ae
commit a0377fbd24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 42 deletions

View file

@ -7,6 +7,7 @@ __metaclass__ = type
import json
import os
import shutil
import signal
def run_podman_command(module, executable='podman', args=None, expected_rc=0, ignore_errors=False):
@ -96,3 +97,63 @@ def remove_file_or_dir(path):
shutil.rmtree(path)
else:
raise ValueError("file %s is not a file or dir." % path)
# Generated from https://github.com/containers/podman/blob/main/pkg/signal/signal_linux.go
# and https://github.com/containers/podman/blob/main/pkg/signal/signal_linux_mipsx.go
_signal_map = {
"ABRT": 6,
"ALRM": 14,
"BUS": 7,
"CHLD": 17,
"CLD": 17,
"CONT": 18,
"EMT": 7,
"FPE": 8,
"HUP": 1,
"ILL": 4,
"INT": 2,
"IO": 29,
"IOT": 6,
"KILL": 9,
"PIPE": 13,
"POLL": 29,
"PROF": 27,
"PWR": 30,
"QUIT": 3,
"RTMAX": int(signal.SIGRTMAX),
"RTMIN": int(signal.SIGRTMIN),
"SEGV": 11,
"STKFLT": 16,
"STOP": 19,
"SYS": 31,
"TERM": 15,
"TRAP": 5,
"TSTP": 20,
"TTIN": 21,
"TTOU": 22,
"URG": 23,
"USR1": 10,
"USR2": 12,
"VTALRM": 26,
"WINCH": 28,
"XCPU": 24,
"XFSZ": 25
}
for i in range(1, _signal_map['RTMAX'] - _signal_map['RTMIN'] + 1):
_signal_map['RTMIN+{0}'.format(i)] = _signal_map['RTMIN'] + i
_signal_map['RTMAX-{0}'.format(i)] = _signal_map['RTMAX'] - i
def normalize_signal(signal_name_or_number):
signal_name_or_number = str(signal_name_or_number)
if signal_name_or_number.isdigit():
return signal_name_or_number
else:
signal_name = signal_name_or_number.upper()
if signal_name.startswith('SIG'):
signal_name = signal_name[3:]
if signal_name not in _signal_map:
raise RuntimeError("Unknown signal '{0}'".format(signal_name_or_number))
return str(_signal_map[signal_name])

View file

@ -6,6 +6,7 @@ from distutils.version import LooseVersion # noqa: F402
from ansible.module_utils._text import to_bytes, to_native # noqa: F402
from ansible_collections.containers.podman.plugins.module_utils.podman.common import lower_keys
from ansible_collections.containers.podman.plugins.module_utils.podman.common import generate_systemd
from ansible_collections.containers.podman.plugins.module_utils.podman.common import normalize_signal
__metaclass__ = type
@ -1152,47 +1153,8 @@ class PodmanContainerDiff:
return self._diff_update_and_compare('security_opt', before, after)
def diffparam_stop_signal(self):
signals = {
"sighup": "1",
"sigint": "2",
"sigquit": "3",
"sigill": "4",
"sigtrap": "5",
"sigabrt": "6",
"sigiot": "6",
"sigbus": "7",
"sigfpe": "8",
"sigkill": "9",
"sigusr1": "10",
"sigsegv": "11",
"sigusr2": "12",
"sigpipe": "13",
"sigalrm": "14",
"sigterm": "15",
"sigstkflt": "16",
"sigchld": "17",
"sigcont": "18",
"sigstop": "19",
"sigtstp": "20",
"sigttin": "21",
"sigttou": "22",
"sigurg": "23",
"sigxcpu": "24",
"sigxfsz": "25",
"sigvtalrm": "26",
"sigprof": "27",
"sigwinch": "28",
"sigio": "29",
"sigpwr": "30",
"sigsys": "31",
"sigrtmin+3": "37"
}
before = str(self.info['config']['stopsignal'])
if not before.isdigit():
before = signals[before.lower()]
after = str(self.params['stop_signal'])
if not after.isdigit():
after = signals[after.lower()]
before = normalize_signal(self.info['config']['stopsignal'])
after = normalize_signal(self.params['stop_signal'])
return self._diff_update_and_compare('stop_signal', before, after)
def diffparam_timezone(self):

View file

@ -21,7 +21,7 @@ EXPOSE 80
EXPOSE 8080/tcp
VOLUME ["/data", "/data2"]
USER user
STOPSIGNAL SIGKILL
STOPSIGNAL KILL
# problem with OS w/o systemd
# HEALTHCHECK --interval=5m --timeout=3s \