Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions podman/tests/integration/test_container_create.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import unittest
import re
import os
import pytest

import podman.tests.integration.base as base
from podman import PodmanClient
from podman.tests.utils import PODMAN_VERSION
from podman.tests.utils import PODMAN_VERSION, is_root

# @unittest.skipIf(os.geteuid() != 0, 'Skipping, not running as root')

Expand Down Expand Up @@ -279,7 +278,7 @@ def test_container_shm_size(self):
"""Test passing shared memory size"""
self._test_memory_limit('shm_size', 'ShmSize')

@pytest.mark.skipif(os.geteuid() != 0, reason='Skipping, not running as root')
@pytest.mark.skipif(not is_root(), reason='Skipping, rootless user')
@pytest.mark.skipif(
PODMAN_VERSION >= (5, 6, 0),
reason="Test against this feature in Podman 5.6.0 or greater https://github.com/containers/podman/pull/25942",
Expand Down Expand Up @@ -356,7 +355,7 @@ def test_container_mounts(self):

self.assertEqual(container.attrs.get('State', dict()).get('ExitCode', 256), 0)

@pytest.mark.skipif(os.geteuid() != 0, reason='Skipping, not running as root')
@pytest.mark.skipif(not is_root(), reason='Skipping, rootless user')
@pytest.mark.skipif(
PODMAN_VERSION < (5, 6, 0),
reason="Test against this feature before Podman 5.6.0 https://github.com/containers/podman/pull/25942",
Expand Down Expand Up @@ -397,6 +396,7 @@ def test_container_mounts_without_rw_as_default(self):
f"size={mount['size']},rprivate,nosuid,nodev,tmpcopyup",
)

@pytest.mark.skipif(not is_root(), reason='Skipping, rootless user')
def test_container_devices(self):
devices = ["/dev/null:/dev/foo", "/dev/zero:/dev/bar"]
container = self.client.containers.create(
Expand Down
10 changes: 10 additions & 0 deletions podman/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pathlib
import csv
import re
Expand Down Expand Up @@ -28,5 +29,14 @@ def podman_version() -> tuple[int, ...]:
return tuple(int(x) for x in version.split("."))


def is_root() -> bool:
"""Check if the current user is root.

Returns:
True if running as root (uid == 0), False otherwise.
"""
return os.geteuid() == 0


OS_RELEASE = freedesktop_os_release()
PODMAN_VERSION = podman_version()