mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-23 15:40:01 -06:00
1aff24e891
Since a4a9a6f7c6
systemd improves the detection of Docker and Podman containers based
on the presence of files-markers.
```console
[slev@test systemd]$ git describe --contains --tags a4a9a6f7c6e9cd9e219c56d08434a04bc2f395ff
v248-rc1~155^2~1
```
Note: on Azure unit tests are run as non-privileged user in non-systemd
inited container.
This worked on F32 because:
```console
[root@6d2aad38f62c /]# rpm -q systemd
systemd-245.9-1.fc32.x86_64
```
So, actual comparison in test was `assert None == None`.
But F34 has:
```console
[root@1ff1325f5a61 /]# rpm -q systemd
systemd-248-2.fc34.x86_64
```
So, the test's expectations should be updated.
Unfortunately, this is incompatible with older versions of systemd
(< v248).
See https://github.com/systemd/systemd/pull/17902 for details.
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
#
|
|
# Copyright (C) 2017 FreeIPA Contributors see COPYING for license
|
|
#
|
|
from __future__ import absolute_import
|
|
|
|
import os
|
|
|
|
from ipaplatform.tasks import tasks
|
|
|
|
|
|
def test_ipa_version():
|
|
v3 = tasks.parse_ipa_version('3.0')
|
|
assert v3.version == u'3.0'
|
|
if hasattr(v3, '_rpmvercmp'):
|
|
assert v3._rpmvercmp_func is None
|
|
v3._rpmvercmp(b'1', b'2')
|
|
assert v3._rpmvercmp_func is not None
|
|
|
|
v4 = tasks.parse_ipa_version('4.0')
|
|
assert v4.version == u'4.0'
|
|
if hasattr(v4, '_rpmvercmp'):
|
|
assert v4._rpmvercmp_func is not None
|
|
|
|
# pylint: disable=comparison-with-itself
|
|
assert v3 < v4
|
|
assert v3 <= v4
|
|
assert v3 <= v3
|
|
assert v3 != v4
|
|
assert v3 == v3
|
|
assert not v3 == v4
|
|
assert v4 > v3
|
|
assert v4 >= v3
|
|
|
|
|
|
def test_detect_container():
|
|
container = None
|
|
# naive detection, may fail for OpenVZ and other container runtimes
|
|
if os.path.isfile('/run/systemd/container'):
|
|
with open('/run/systemd/container') as f:
|
|
container = f.read().strip()
|
|
elif os.geteuid() == 0:
|
|
with open('/proc/1/environ') as f:
|
|
environ = f.read()
|
|
for item in environ.split('\x00'):
|
|
if not item:
|
|
continue
|
|
k, v = item.split('=', 1)
|
|
if k == 'container':
|
|
container = v
|
|
elif os.path.isfile("/run/.containerenv"):
|
|
container = "podman"
|
|
elif os.path.isfile("/.dockerenv"):
|
|
container = "docker"
|
|
|
|
detected = tasks.detect_container()
|
|
assert detected == container
|