URL:
https://github.com/freeipa/freeipa/pull/5706
Author: Tiboris
Title: #5706: Do not change hostname if it is not neccessary
Action: opened
PR body:
"""
TLDR:
While testing using containers hostname can not be changed/set up on runtime only when
creating container.
Setting hostname in container is not possible using podman:
```
[root@perun ltevenv]# podman exec -ti master sh -c "hostnamectl set-hostname
master.tesrelm.test"
Could not set property: Access denied
[root@perun ltevenv]# podman exec -ti master sh -c "hostname
master.tesrelm.test"
hostname: you must be root to change the host name
[root@perun ltevenv]# podman exec -ti master sh -c "hostname"
master.testrelm.test
[root@perun ltevenv]#
```
while running tests:
```
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ipatests.pytest_ipa.integration.host.Host master.testrelm.test (master)>
argv = ['hostname', 'master.testrelm.test'], set_env = True, stdin_text =
None
log_stdout = True, raiseonerr = True, cwd = None, bg = False, encoding = 'utf-8'
ok_returncode = 0
def run_command(self, argv, set_env=True, stdin_text=None,
log_stdout=True, raiseonerr=True,
cwd=None, bg=False, encoding='utf-8', ok_returncode=0):
"""Wrapper around run_command to log stderr on raiseonerr=True
:param ok_returncode: return code considered to be correct,
you can pass an integer or sequence of integers
"""
result = super().run_command(
argv, set_env=set_env, stdin_text=stdin_text,
log_stdout=log_stdout, raiseonerr=False, cwd=cwd, bg=bg,
encoding=encoding
)
# in FIPS mode SSH may print noise to stderr, remove the string
# "FIPS mode initialized" + optional newline.
result.stderr_bytes = FIPS_NOISE_RE.sub(b'', result.stderr_bytes)
try:
result_ok = result.returncode in ok_returncode
except TypeError:
result_ok = result.returncode == ok_returncode
if not result_ok and raiseonerr:
result.log.error('stderr: %s', result.stderr_text)
raise subprocess.CalledProcessError(
result.returncode, argv,
result.stdout_text, result.stderr_text
)
E subprocess.CalledProcessError: Command '['hostname',
'master.testrelm.test']' returned non-zero exit status 1.
```
Signed-off-by: Tibor Dudlák <tdudlak(a)redhat.com>
"""
To pull the PR as Git branch:
git remote add ghfreeipa
https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/5706/head:pr5706
git checkout pr5706