Exemplo n.º 1
0
from v2v_testlib import VM_SPECS, MockVirDomain
from v2v_testlib import MockVirConnect, _mac_from_uuid, BLOCK_DEV_PATH
from vdsm import v2v
from vdsm.common import libvirtconnection
from vdsm.common import response
from vdsm.common.cmdutils import CommandPath, exec_cmd
from vdsm.common.commands import terminating
from vdsm.common.password import ProtectedPassword

from testlib import VdsmTestCase as TestCaseBase, recorded
from monkeypatch import MonkeyPatch, MonkeyPatchScope

import vmfakecon 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')
Exemplo n.º 2
0
from collections import defaultdict, namedtuple
import xml.etree.ElementTree as ET

from vdsm import taskset
from vdsm.common import cache
from vdsm.common import commands
from vdsm.common import libvirtconnection
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'},
Exemplo n.º 3
0
# Refer to the README and COPYING files for full details of the license
#
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):
Exemplo n.º 4
0
)
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),
Exemplo n.º 5
0
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:
Exemplo n.º 6
0
#
# When the request fails, the kernel *silently* falls-back to
# inefficient manually writing zeros, and changes both the LV and the
# underlying multipath device write_same_max_bytes to 0. Future
# BLKZEROOUT requests on any LV on this multipath device will use the
# inefficient manual zero fallback.
#
# qemu-img is using 2 MiB by defualt for BLKZEROOUT during qemu-img
# convert, so we can safely use the same value.
#
# Note: on newer kernels (>4.12), the kernel is not using WRITE_SAME for
# zeroing. We will need to test again this value when we require newer
# kernels.
SAFE_WRITE_SAME_SIZE = 2 * 1024**2

_blkdiscard = CommandPath("blkdiscard", "/sbin/blkdiscard")


def discard(device):
    """
    Discards a block device.

    Arguments:
        device (str): The path to the block device to discard.

    Raises:
        cmdutils.Error if an error has occurred in blkdiscard.
    """
    cmd = [_blkdiscard.cmd]
    cmd.append(device)
Exemplo n.º 7
0
Arquivo: lvm.py Projeto: akashihi/vdsm
import errno
import os
import selinux
import shutil
import sys
import time

from vdsm import cmdutils
from vdsm import commands
from vdsm.tool import confmeta
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.
Exemplo n.º 8
0
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'}

Exemplo n.º 9
0
#
# 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_inplace(vol_path):
    """
    Sparsify the volume in place
    (without copying from an input disk to an output disk)

    :param vol_path: path to the volume
    """
    cmd = [_VIRTSPARSIFY.cmd, '--machine-readable', '--in-place', vol_path]

    commands.run(cmd)
Exemplo n.º 10
0
# Refer to the README and COPYING files for full details of the license
#

from __future__ import absolute_import
from __future__ import division

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):
Exemplo n.º 11
0
# 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),
                     ("timestamp", int), ("own", int), ("gen", int)]

log = logging.getLogger("storage.sanlock_direct")


def dump_leases(path,
                offset=0,
                size=None,
                block_size=sc.BLOCK_SIZE_512,
Exemplo n.º 12
0
import six

from netaddr.core import AddrFormatError
from netaddr import IPAddress
from netaddr import IPNetwork

from vdsm.common.cmdutils import CommandPath
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',
Exemplo n.º 13
0
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))
Exemplo n.º 14
0
# 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.cmdutils import CommandPath
from . import cmdutils
from . import commands

_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:
Exemplo n.º 15
0
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

EXT_BRCTL = CommandPath('brctl', '/sbin/brctl', '/usr/sbin/brctl').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):
Exemplo n.º 16
0
_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'])):
Exemplo n.º 17
0
import io
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 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,
Exemplo n.º 18
0
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(
Exemplo n.º 19
0
def _ovs_vsctl_cmd():
    return CommandPath('ovs-vsctl', '/usr/sbin/ovs-vsctl',
                       '/usr/bin/ovs-vsctl').cmd
Exemplo n.º 20
0
import logging
import os
import signal

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,
Exemplo n.º 21
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')
_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:
Exemplo n.º 22
0
# Refer to the README and COPYING files for full details of the license
#
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'