File: base.py

package info (click to toggle)
python-podman 5.4.0.1-2~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 1,140 kB
  • sloc: python: 7,532; makefile: 82; sh: 75
file content (68 lines) | stat: -rw-r--r-- 2,327 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#   Copyright 2020 Red Hat, Inc.
#
#   Licensed under the Apache License, Version 2.0 (the "License"); you may
#   not use this file except in compliance with the License. You may obtain
#   a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#   WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#   License for the specific language governing permissions and limitations
#   under the License.
#
"""Base integration test code"""

import logging
import os
import shutil
import uuid

import fixtures

from podman.tests.integration import utils


HAVE_FUSE = os.path.exists('/dev/fuse')


class IntegrationTest(fixtures.TestWithFixtures):
    """Base Integration test case.

    Notes:
        - Logging for the Podman service configured here for later capture, this configuration is
          inherited by other libraries like unittest and requests.
        - Logging output will start with stdout from the Podman service events, followed by
          results and logging captured by the unittest module test runner.
    """

    podman: str = None

    @classmethod
    def setUpClass(cls) -> None:
        super(fixtures.TestWithFixtures, cls).setUpClass()

        command = os.environ.get("PODMAN_BINARY", "podman")
        if shutil.which(command) is None:
            raise AssertionError(f"'{command}' not found.")
        IntegrationTest.podman = command

        # This log_level is for our python code
        log_level = os.environ.get("PODMAN_LOG_LEVEL", "INFO")
        log_level = logging.getLevelName(log_level)
        logging.basicConfig(level=log_level)

    def setUp(self):
        super().setUp()

        self.log_level = os.environ.get("PODMAN_LOG_LEVEL", "INFO")

        self.test_dir = self.useFixture(fixtures.TempDir()).path
        self.socket_file = os.path.join(self.test_dir, uuid.uuid4().hex)
        self.socket_uri = f'unix://{self.socket_file}'
        self.service_launcher = utils.PodmanLauncher(
            self.socket_uri, podman_path=IntegrationTest.podman, log_level=self.log_level
        )
        self.service_launcher.start()
        self.addCleanup(self.service_launcher.stop)