# This file is part of Cockpit. # # Copyright (C) 2013 Red Hat, Inc. # # Cockpit is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Cockpit is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with Cockpit; If not, see . import contextlib import errno import fcntl import libvirt import libvirt_qemu import os import string import socket import subprocess import tempfile import sys import time from .exceptions import Failure, RepeatableFailure from .machine import Machine from .constants import TEST_DIR, BOTS_DIR from .directories import get_temp_dir MEMORY_MB = 1024 # The Atomic variants can't build their own packages, so we build in # their non-Atomic siblings. For example, fedora-atomic is built # in fedora-29 def get_build_image(image): (test_os, unused) = os.path.splitext(os.path.basename(image)) if test_os == "fedora-atomic": image = "fedora-29" elif test_os == "rhel-atomic": image = "rhel-7-7" elif test_os == "continuous-atomic": image = "centos-7" return image # some tests have suffixes that run the same image in different modes; map a # test context image to an actual physical image name def get_test_image(image): return image.replace("-distropkg", "") # based on http://stackoverflow.com/a/17753573 # we use this to quieten down calls @contextlib.contextmanager def stdchannel_redirected(stdchannel, dest_filename): """ A context manager to temporarily redirect stdout or stderr e.g.: with stdchannel_redirected(sys.stderr, os.devnull): noisy_function() """ try: stdchannel.flush() oldstdchannel = os.dup(stdchannel.fileno()) dest_file = open(dest_filename, 'w') os.dup2(dest_file.fileno(), stdchannel.fileno()) yield finally: if oldstdchannel is not None: os.dup2(oldstdchannel, stdchannel.fileno()) if dest_file is not None: dest_file.close() TEST_CONSOLE_XML=""" """ TEST_GRAPHICS_XML="""