# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Refer to the README and COPYING files for full details of the license # from __future__ import absolute_import import logging from vdsm.common.cmdutils import CommandPath from . import cmdutils from . import commands _UDEVADM = CommandPath("udevadm", "/sbin/udevadm", "/usr/sbin/udevadm") def settle(timeout, exit_if_exists=None): """ Watches the udev event queue, and wait until all current events are handled. Arguments: timeout Maximum number of seconds to wait for the event queue to become empty. A value of 0 will check if the queue is empty and always return immediately. exit_if_exists Stop waiting if file exists. """
import six from netaddr.core import AddrFormatError from netaddr import IPAddress from netaddr import IPNetwork from vdsm.common.cmdutils import CommandPath from vdsm.common.compat import subprocess from vdsm.common.config import config from vdsm.network import cmd from vdsm.network import ethtool from vdsm.network.link import dpdk from vdsm.network.netlink import libnl from vdsm.network.netlink import link _IP_BINARY = CommandPath('ip', '/sbin/ip') NET_SYSFS = '/sys/class/net' DUMMY_BRIDGE = ';vdsmdummy;' _ROUTE_FLAGS = frozenset(( # copied from iproute2's rtnl_rtntype_n2a() 'unicast', 'local', 'broadcast', 'anycast', 'multicast', 'blackhole', 'unreachable', 'prohibit', 'throw', 'nat',
from v2v_testlib import VM_SPECS, MockVirDomain from v2v_testlib import MockVirConnect, _mac_from_uuid, BLOCK_DEV_PATH from vdsm import v2v from vdsm import libvirtconnection from vdsm.commands import execCmd from vdsm.common import response from vdsm.common.cmdutils import CommandPath from vdsm.common.password import ProtectedPassword from vdsm.utils import terminating from testlib import VdsmTestCase as TestCaseBase, recorded from monkeypatch import MonkeyPatch, MonkeyPatchScope import vmfakelib as fake FAKE_VIRT_V2V = CommandPath('fake-virt-v2v', os.path.abspath('fake-virt-v2v')) FAKE_SSH_ADD = CommandPath('fake-ssh-add', os.path.abspath('fake-ssh-add')) FAKE_SSH_AGENT = CommandPath('fake-ssh-agent', os.path.abspath('fake-ssh-agent')) def legacylistAllDomains(): raise fake.Error(libvirt.VIR_ERR_NO_SUPPORT, 'Method not supported') def legacylistAllDomainsWrongRaise(): raise fake.Error(libvirt.VIR_ERR_NO_DOMAIN, 'Domain not exists') def lookupByNameFailure(name): raise fake.Error(libvirt.VIR_ERR_NO_DOMAIN, 'Domain not exists')
# # This program 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Refer to the README and COPYING files for full details of the license # from __future__ import absolute_import from vdsm import cmdutils from vdsm import commands from vdsm.common.cmdutils import CommandPath _blkdiscard = CommandPath("blkdiscard", "/sbin/blkdiscard") def blkdiscard(device): cmd = [_blkdiscard.cmd] cmd.append(device) rc, out, err = commands.execCmd(cmd) if rc != 0: raise cmdutils.Error(cmd, rc, out, err)
def _ovs_vsctl_cmd(): return CommandPath('ovs-vsctl', '/usr/sbin/ovs-vsctl', '/usr/bin/ovs-vsctl').cmd
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Refer to the README and COPYING files for full details of the license # from __future__ import absolute_import from vdsm.common.cache import memoized from vdsm.common.cmdutils import CommandPath from vdsm.network import cmd from .nmdbus import NMDbus, NMDbusIfcfgRH1 from .nmdbus.active import NMDbusActiveConnections from .nmdbus.device import NMDbusDevice from .nmdbus.settings import NMDbusSettings SYSTEMCTL = CommandPath('systemctl', '/bin/systemctl', '/usr/bin/systemctl') NM_SERVICE = 'NetworkManager' @memoized def is_running(): rc, out, err = cmd.exec_sync([SYSTEMCTL.cmd, 'status', NM_SERVICE]) return rc == 0 def init(): NMDbus.init() class Device(object): def __init__(self, device_name):
# # Refer to the README and COPYING files for full details of the license # from __future__ import absolute_import from __future__ import division from contextlib import contextmanager import logging from nose.plugins.skip import SkipTest from vdsm.common.cmdutils import CommandPath from vdsm.network import cmd _FIREWALLD_BINARY = CommandPath('firewall-cmd', '/bin/firewall-cmd') _IPTABLES_BINARY = CommandPath('iptables', '/sbin/iptables') _SERVICE_BINARY = CommandPath('service', '/sbin/service') class FirewallError(Exception): pass @contextmanager def allow_dhcp(iface): """Temporarily allow DHCP traffic in firewall.""" _allow_dhcp(iface) try: yield finally:
netns_exec) from vdsm.network.link import iface as linkiface, bond as linkbond from vdsm.network.link.iface import random_iface_name from vdsm.network.lldpad import lldptool from vdsm.network.netinfo import routes from vdsm.network.netlink import monitor from vdsm.common.cache import memoized from vdsm.common.cmdutils import CommandPath from vdsm.common.proc import pgrep from . import dhcp from . import firewall EXT_IP = "/sbin/ip" EXT_TC = "/sbin/tc" _IPERF3_BINARY = CommandPath('iperf3', '/usr/bin/iperf3') _SYSTEMCTL = CommandPath('systemctl', '/bin/systemctl', '/usr/bin/systemctl') class ExecError(RuntimeError): def __init__(self, msg, out, err): super(ExecError, self).__init__(msg) self.out = out self.err = err def check_call(cmds): rc, out, err = cmd.exec_sync(cmds) if rc != 0: raise ExecError( 'Command %s returned non-zero exit status %s.' % (cmds, rc), out,
# from __future__ import absolute_import from __future__ import division from errno import ENOENT, ESRCH import logging import os from signal import SIGKILL, SIGTERM from subprocess import PIPE, Popen from time import sleep, time from vdsm.common.cmdutils import CommandPath from vdsm.network import cmd _DNSMASQ_BINARY = CommandPath('dnsmasq', '/usr/sbin/dnsmasq') _DHCLIENT_BINARY = CommandPath('dhclient', '/usr/sbin/dhclient', '/sbin/dhclient') _START_CHECK_TIMEOUT = 0.5 _DHCLIENT_TIMEOUT = 10 _WAIT_FOR_STOP_TIMEOUT = 2 _DHCLIENT_LEASE = '/var/lib/dhclient/dhclient{0}--{1}.lease' _DHCLIENT_LEASE_LEGACY = '/var/lib/dhclient/dhclient{0}-{1}.leases' class DhcpError(Exception): pass class Dnsmasq(): def __init__(self):
# You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Refer to the README and COPYING files for full details of the license # import logging import os from vdsm.common import commands from vdsm.common import supervdsm from vdsm.common.cmdutils import CommandPath from vdsm.storage import constants as sc SANLOCK = CommandPath('sanlock', '/usr/sbin/sanlock') _LEASES_FIELDS = [ ("offset", int), ("lockspace", str), ("resource", str), ("timestamp", int), ("own", int), ("gen", int), ("lver", int) ] _LOCKSPACE_FIELDS = [ ("offset", int), ("lockspace", str), ("resource", str),
_ip_network = netaddr.IPNetwork(IP_NETWORK_AND_CIDR) IP_MASK = str(_ip_network.netmask) IP_GATEWAY = str(_ip_network.broadcast - 1) DHCP_RANGE_FROM = '192.0.2.10' DHCP_RANGE_TO = '192.0.2.100' DHCPv6_RANGE_FROM = 'fdb3:84e5:4ff4:55e3::a' DHCPv6_RANGE_TO = 'fdb3:84e5:4ff4:55e3::64' CUSTOM_PROPS = {'linux': 'rules', 'vdsm': 'as well'} IPv6_ADDRESS = 'fdb3:84e5:4ff4:55e3::1' IPv6_CIDR = '64' IPv6_ADDRESS_AND_CIDR = IPv6_ADDRESS + '/' + IPv6_CIDR IPv6_ADDRESS_IN_NETWORK = 'fdb3:84e5:4ff4:55e3:0:ffff:ffff:0' IPv6_GATEWAY = 'fdb3:84e5:4ff4:55e3::ff' _ARPPING_COMMAND = CommandPath('arping', '/usr/sbin/arping') dummyPool = set() DUMMY_POOL_SIZE = 5 NOCHK = {'connectivityCheck': False} @ValidateRunningAsRoot @RequireDummyMod def setupModule(): vds = getProxy() running_config, kernel_config = _get_running_and_kernel_config(vds.config) if ((running_config['networks'] != kernel_config['networks']) or (running_config['bonds'] != kernel_config['bonds'])):
# along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Refer to the README and COPYING files for full details of the license # from __future__ import absolute_import from __future__ import division import logging from subprocess import PIPE, Popen from time import sleep from vdsm.common.cmdutils import CommandPath _DNSMASQ_BINARY = CommandPath('dnsmasq', '/usr/sbin/dnsmasq') _START_CHECK_TIMEOUT = 0.5 class DhcpError(Exception): pass class Dnsmasq(object): def __init__(self): self._popen = None def start( self, interface, dhcp_range_from=None,
from __future__ import absolute_import from collections import defaultdict, namedtuple import xml.etree.cElementTree as ET from vdsm import cmdutils from vdsm import commands from vdsm import libvirtconnection from vdsm.common import cache from vdsm.common.cmdutils import CommandPath NumaTopology = namedtuple('NumaTopology', 'topology, distances, cpu_topology') CpuTopology = namedtuple('CpuTopology', 'sockets, cores, threads, online_cpus') _SYSCTL = CommandPath("sysctl", "/sbin/sysctl", "/usr/sbin/sysctl") AUTONUMA_STATUS_DISABLE = 0 AUTONUMA_STATUS_ENABLE = 1 AUTONUMA_STATUS_UNKNOWN = 2 def topology(capabilities=None): ''' Get what we call 'numa topology' of the host from libvirt. This topology contains mapping numa cell -> (cpu ids, total memory). Example: {'0': {'cpus': [0, 1, 2, 3, 4, 10, 11, 12, 13, 14], 'totalMemory': '32657'}, '1': {'cpus': [5, 6, 7, 8, 9, 15, 16, 17, 18, 19],
# from __future__ import absolute_import import os from collections import namedtuple from vdsm.common.cmdutils import CommandPath from vdsm.storage.misc import execCmd ScanOutput = namedtuple( 'ScanOutput', ['partitionName', 'partitionStartBytes', 'partitionAlignment', 'alignmentScanResult', 'alignmentScanExplanation']) _virtAlignmentScan = CommandPath("virt-alignment-scan", "/usr/bin/virt-alignment-scan", # Fedora, EL6 ) class VirtAlignError(Exception): pass def runScanArgs(*args): cmd = [_virtAlignmentScan.cmd] cmd.extend(args) # TODO: remove the environment when the issue in # virt-alignment-scan/libvirt is resolved # http://bugzilla.redhat.com/1151838 env = os.environ.copy() env['LIBGUESTFS_BACKEND'] = 'direct'
import os import glob import pwd import selinux from vdsm.common.cmdutils import CommandPath from vdsm.common.commands import execCmd from .. import constants from ..config import config from . import expose, ExtraArgsError SELINUX_VIRT_IMAGE_LABEL = "system_u:object_r:virt_image_t:s0" TRANSIENT_DISKS_REPO = config.get('vars', 'transient_disks_repository') _fuser = CommandPath( "fuser", "/sbin/fuser", # Fedora, EL6 ) @expose("setup-transient-repository") def setup_transient_repository(*args): """ setup-transient-repository Prepare the transient disks repository """ if len(args) > 1: raise ExtraArgsError() _, _, vdsm_uid, vdsm_gid, _, _, _ = pwd.getpwnam(constants.VDSM_USER) try:
import functools import re import sys from collections import defaultdict from vdsm.common.cmdutils import CommandPath from vdsm.common.commands import execCmd as _execCmd from . import expose, UsageError, ExtraArgsError def execCmd(argv, raw=True, *args, **kwargs): return _execCmd(argv, raw=raw, *args, **kwargs) _SYSTEMCTL = CommandPath("systemctl", "/bin/systemctl", "/usr/bin/systemctl", ) _INITCTL = CommandPath("initctl", "/sbin/initctl", ) _SERVICE = CommandPath("service", "/sbin/service", "/usr/sbin/service", ) _CHKCONFIG = CommandPath("chkconfig", "/sbin/chkconfig", )
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Refer to the README and COPYING files for full details of the license # from __future__ import absolute_import from vdsm.common import cmdutils from vdsm.common import commands from vdsm.common.cmdutils import CommandPath _VIRTSYSPREP = CommandPath("virt-sysprep", "/usr/bin/virt-sysprep") def sysprep(vol_paths): """ Run virt-sysprep on the list of volumes :param vol_paths: list of volume paths """ cmd = [_VIRTSYSPREP.cmd] for vol_path in vol_paths: cmd.extend(('-a', vol_path)) rc, out, err = commands.execCmd(cmd) if rc != 0:
# along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Refer to the README and COPYING files for full details of the license # from __future__ import absolute_import from __future__ import division from contextlib import contextmanager import logging from vdsm.common.cmdutils import CommandPath from vdsm.network import cmd _FIREWALLD_BINARY = CommandPath('firewall-cmd', '/bin/firewall-cmd') _IPTABLES_BINARY = CommandPath('iptables', '/sbin/iptables') _SYSTEMCTL_BINARY = CommandPath('systemctl', '/bin/systemctl') class FirewallError(Exception): pass @contextmanager def allow_dhcp(iface): """Temporarily allow DHCP traffic in firewall.""" _allow_dhcp(iface) try: yield finally:
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Refer to the README and COPYING files for full details of the license # from __future__ import absolute_import from contextlib import contextmanager from vdsm.common.cmdutils import CommandPath from vdsm.network import cmd from vdsm.network.link import iface as linkiface from vdsm.network.link.iface import random_iface_name TEST_LINK_TYPE = 'bond' SYSTEMCTL = CommandPath('systemctl', '/bin/systemctl', '/usr/bin/systemctl') NM_SERVICE = 'NetworkManager' NMCLI_BINARY = CommandPath('nmcli', '/usr/bin/nmcli') IP_BINARY = CommandPath('ip', '/sbin/ip') class NMService(object): def __init__(self): rc, out, err = cmd.exec_sync([SYSTEMCTL.cmd, 'status', NM_SERVICE]) self.nm_init_state_is_up = (rc == 0) def setup(self): if not self.nm_init_state_is_up: cmd.exec_sync([SYSTEMCTL.cmd, 'start', NM_SERVICE])
# Refer to the README and COPYING files for full details of the license # from __future__ import absolute_import from __future__ import print_function from collections import namedtuple import sys import hooking import traceback from vdsm.common.cmdutils import CommandPath from vdsm.network.link.bond import Bond ETHTOOL_BINARY = CommandPath( 'ethtool', '/usr/sbin/ethtool', # F19+ '/sbin/ethtool', # EL6, ubuntu and Debian '/usr/bin/ethtool', # Arch ) ALL_SLAVES = '*' # wildcard to make the hook resolve the nics to modify Subcommand = namedtuple('Subcommand', ('name', 'device', 'flags')) class EthtoolError(Exception): pass def _test_cmd_with_nics(nics, ethtool_opts): net_attrs = { 'bonding': 'james',
# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Refer to the README and COPYING files for full details of the license # from __future__ import absolute_import from vdsm.common import commands from vdsm.common.cmdutils import CommandPath # Fedora, EL6 _VIRTSPARSIFY = CommandPath( "virt-sparsify", "/usr/bin/virt-sparsify", ) def sparsify(src_vol, tmp_vol, dst_vol, src_format=None, dst_format=None): """ Sparsify the 'src_vol' volume (src_format) to 'dst_vol' volume (dst_format) using libguestfs virt-sparsify src_vol: path of base volume tmp_vol: path of temporary volume created with src_vol as backing volume dst_vol: path of destination volume src_format: format of base volume ('raw' or `qcow2') src_format: format of destination volume ('raw' or `qcow2') """ cmd = [_VIRTSPARSIFY.cmd, '--tmp', 'prebuilt:' + tmp_vol]
import errno import os import selinux import shutil import sys import time from vdsm.tool import confmeta from vdsm.common import cmdutils from vdsm.common import commands from vdsm.common.cmdutils import CommandPath from . import YES, NO _SYSTEMCTL = CommandPath("systemctl", "/bin/systemctl", "/usr/bin/systemctl") # TODO: use constants.py _LVMLOCAL_CUR = "/etc/lvm/lvmlocal.conf" _LVMLOCAL_VDSM = "/usr/share/vdsm/lvmlocal.conf" _LVMETAD_SERVICE = "lvm2-lvmetad.service" _LVMETAD_SOCKET = "lvm2-lvmetad.socket" # Configuratior interface name = "lvm" services = [] def configure(): """ Disable and mask lvmetad daemon, and install vdsm managed lvmlocal.conf.
import os import signal import subprocess from vdsm.network import cmd from vdsm.network import errors as ne from vdsm.network.link import iface as linkiface from vdsm.common import concurrent from vdsm.common.cache import memoized from vdsm.common.cmdutils import CommandPath from vdsm.common.fileutils import rm_file from vdsm.common.proc import pgrep from . import address DHCLIENT_BINARY = CommandPath('dhclient', '/sbin/dhclient') DHCLIENT_CGROUP = 'vdsm-dhclient' LEASE_DIR = '/var/lib/dhclient' LEASE_FILE = os.path.join(LEASE_DIR, 'dhclient{0}--{1}.lease') DHCP4 = 'dhcpv4' DHCP6 = 'dhcpv6' class DhcpClient(object): PID_FILE = '/var/run/dhclient%s-%s.pid' def __init__(self, iface, family=4, default_route=False, duid_source=None, cgroup=DHCLIENT_CGROUP): self.iface = iface self.family = family
from testlib import VdsmTestCase as TestCaseBase from testlib import permutations, expandPermutations from testlib import temporaryPath import verify from vdsm.common import cpuarch from vdsm.common.cmdutils import CommandPath from vdsm.virt import vmstatus from vdsm.storage.misc import execCmd from utils import getProxy, SUCCESS _mkinitrd = CommandPath( "mkinitrd", "/usr/bin/mkinitrd", # Fedora "/sbin/mkinitrd") # RHEL 6.x, Centos 6.x _kernelVer = os.uname()[2] _kernelPath = "/boot/vmlinuz-" + _kernelVer _initramfsPath = None _initramfsPaths = [ "/boot/initramfs-%s.img" % _kernelVer, # Fedora, RHEL "/boot/initrd.img-" + _kernelVer, # Ubuntu ] _tmpinitramfs = False VM_MINIMAL_UPTIME = 30 _GRAPHICS_FOR_ARCH = {cpuarch.PPC64LE: 'vnc', cpuarch.X86_64: 'qxl'}
VM_ID_KEY = 'vmId' PROVIDER_TYPE_KEY = 'provider_type' OPENSTACK_NET_PROVIDER_TYPE = 'OPENSTACK_NETWORK' VNIC_ID_KEY = 'vnic_id' PLUGIN_TYPE_KEY = 'plugin_type' SECURITY_GROUPS_KEY = 'security_groups' PT_BRIDGE = 'LINUX_BRIDGE' PT_OVS = 'OPEN_VSWITCH' # Default integration bridge name to use for OVS INTEGRATION_BRIDGE = 'br-int' # The maximum device name length in Linux DEV_MAX_LENGTH = 14 EXT_BRCTL = CommandPath('brctl', '/sbin/brctl', '/usr/sbin/brctl').cmd EXT_IP = CommandPath('ip', '/sbin/ip').cmd ovs_vsctl = CommandPath('ovs-vsctl', '/usr/sbin/ovs-vsctl', '/usr/bin/ovs-vsctl') MARK_FOR_UNPAUSE_FILE = 'marked_for_unpause' MARK_FOR_UNPAUSE_PATH = os.path.join( constants.P_VDSM_RUN, '%s', MARK_FOR_UNPAUSE_FILE, ) # Make pyflakes happy DUMMY_BRIDGE def executeOrExit(command):
import os from vdsm import jobs from vdsm import virtsysprep from vdsm.common import response from vdsm.common.cmdutils import CommandPath from vdsm.virt.jobs import seal from testlib import make_uuid from testlib import namedTemporaryDir from testlib import recorded from testlib import VdsmTestCase from testlib import wait_for_job from monkeypatch import MonkeyPatch FAKE_VIRTSYSPREP = CommandPath('fake-virt-sysprep', os.path.abspath('fake-virt-sysprep')) TEARDOWN_ERROR_IMAGE_ID = make_uuid() def _vol_path(base, domainId, poolId, imageId, ext='.img'): return os.path.join(base, '-'.join((poolId, domainId, imageId)) + ext) class FakeIRS(object): def __init__(self, image_path_base): self._image_path_base = image_path_base @recorded def prepareImage(self, domainId, poolId,
VM_ID_KEY = 'vmId' PROVIDER_TYPE_KEY = 'provider_type' OPENSTACK_NET_PROVIDER_TYPE = 'OPENSTACK_NETWORK' VNIC_ID_KEY = 'vnic_id' PLUGIN_TYPE_KEY = 'plugin_type' PT_BRIDGE = 'LINUX_BRIDGE' PT_OVS = 'OPEN_VSWITCH' PT_OPENSTACK_OVN = 'OPENSTACK_OVN' # Default integration bridge name to use for OVS INTEGRATION_BRIDGE = 'br-int' # The maximum device name length in Linux DEV_MAX_LENGTH = 14 ovs_vsctl = CommandPath('ovs-vsctl', '/usr/sbin/ovs-vsctl', '/usr/bin/ovs-vsctl') MARK_FOR_UNPAUSE_FILE = 'marked_for_unpause' MARK_FOR_UNPAUSE_PATH = os.path.join( constants.P_VDSM_RUN, '%s', MARK_FOR_UNPAUSE_FILE, ) # Make pyflakes happy DUMMY_BRIDGE def executeOrExit(command): retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: raise RuntimeError("Failed to execute %s, due to: %s" % (command, err))