예제 #1
0
def test_atomic_write_create(tmpdir):
    path = str(tmpdir.join("file"))
    fileUtils.atomic_write(path, b"new")

    with open(path, "rb") as f:
        assert f.read() == b"new"
    assert stat.S_IMODE(os.stat(path).st_mode) == 0o644
예제 #2
0
def test_atomic_write_mode(tmpdir, mode):
    path = str(tmpdir.join("file"))

    # Create old file with default mode.
    fileUtils.atomic_write(path, b"old")

    fileUtils.atomic_write(path, b"new", mode=mode)

    with open(path, "rb") as f:
        assert f.read() == b"new"
    assert stat.S_IMODE(os.stat(path).st_mode) == mode
예제 #3
0
def test_atomic_write_replace(tmpdir, mode):
    path = str(tmpdir.join("file"))

    # Create old file with differnt mode.
    fileUtils.atomic_write(path, b"old")
    os.chmod(path, mode)

    fileUtils.atomic_write(path, b"new")

    with open(path, "rb") as f:
        assert f.read() == b"new"
    assert stat.S_IMODE(os.stat(path).st_mode) == 0o644
예제 #4
0
파일: lvm.py 프로젝트: dong-df/vdsm
def configure():
    """
    Disable and mask lvmetad daemon, and install vdsm managed lvmlocal.conf.
    """
    if not _lvm_conf_configured():
        backup = fileUtils.backup_file(_LVMLOCAL_CUR)
        if backup:
            _log("Previous lvmlocal.conf copied to %s", backup)

        # TODO: we should merge the contents of the exisiting file and vdsm
        # settings, in case the user has some useful setting in the
        # lvmlocal.conf.
        _log("Installing %s at %s", _LVMLOCAL_VDSM, _LVMLOCAL_CUR)
        with open(_LVMLOCAL_VDSM, "rb") as f:
            fileUtils.atomic_write(_LVMLOCAL_CUR, f.read(), relabel=True)
예제 #5
0
def configure():
    """
    Set up the multipath daemon configuration to the known and
    supported state. The original configuration, if any, is saved
    """
    backup = fileUtils.backup_file(_CONF_FILE)
    if backup:
        sys.stdout.write("Previous multipath.conf copied to %s\n" % backup)

    data = _CONF_DATA.encode('utf-8')
    fileUtils.atomic_write(_CONF_FILE, data, relabel=True)

    # We want to handle these cases:
    #
    # 1. multipathd is not running and the kernel module is not loaded. We
    #    don't have any online multipath devices, so there is nothing to
    #    reconfigure, but we want to make sure that multipathd is happy with
    #    new multipath configuration.
    #
    # 2. multipathd is not running but the kernel module is loaded. We may have
    #    online devices that need reconfiguration.
    #
    # 3. multipathd is running with older configuration not compatible with
    #    vdsm configuration.
    #
    # 4. multipathd is running with older vdsm configuration. Reloading is
    #    needed to update devices with new configuration.
    #
    # When we have online devices using incompatible configuration, they may
    # use "user friendly" names (/dev/mapper/mpath{N}) instead of consistent
    # names (/dev/mapper/{WWID}). Restarting multipathd with the new
    # configuration will rename the devices, however due to multipathd bug,
    # these devices may not pick all configuration changes. Reconfiguring
    # multipathd ensures that all configurations changes are applied.
    #
    # To simplify handing of all cases, we first start multipathd service. This
    # eliminates cases 1 and 2. Case 3 and 4 are handled by reconfiguring
    # multipathd.
    #
    # If any of those steps fails, we want to fail the configuration.

    service.service_start("multipathd")
    commands.run([_MULTIPATHD.cmd, "reconfigure"])
예제 #6
0
def test_atomic_write_relabel(tmpdir):
    path = str(tmpdir.join("file"))

    # Create old file with non-default label.
    fileUtils.atomic_write(path, b"old")
    selinux.setfilecon(path, "unconfined_u:object_r:etc_t:s0")

    fileUtils.atomic_write(path, b"new", relabel=True)

    with open(path, "rb") as f:
        assert f.read() == b"new"
    assert stat.S_IMODE(os.stat(path).st_mode) == 0o644

    # The label depends on the enviroment and selinux policy:
    # - Locally we get: "unconfined_u:object_r:user_tmp_t:s0"
    # - In mock we get: "unconfined_u:object_r:mock_var_lib_t:s0"
    # So lets check what selinux.restorecon(path, force=True) is creating.
    control = str(tmpdir.ensure("control"))
    selinux.restorecon(control, force=True)

    assert selinux.getfilecon(path)[1] == selinux.getfilecon(control)[1]
예제 #7
0
def configure():
    """
    Disable and mask lvmetad daemon, and install vdsm managed lvmlocal.conf.
    """
    if not _lvm_conf_configured():
        backup = fileUtils.backup_file(_LVMLOCAL_CUR)
        if backup:
            _log("Previous lvmlocal.conf copied to %s", backup)

        # TODO: we should merge the contents of the exisiting file and vdsm
        # settings, in case the user has some useful setting in the
        # lvmlocal.conf.
        _log("Installing %s at %s", _LVMLOCAL_VDSM, _LVMLOCAL_CUR)
        with open(_LVMLOCAL_VDSM, "rb") as f:
            fileUtils.atomic_write(_LVMLOCAL_CUR, f.read(), relabel=True)

    # TODO: remove disabling lvmetad once we don't support Fedora 30. On
    # Fedora 31 and RHEL8 lvmetad is not supported anymore.
    if not _lvmetad_configured():
        _systemctl("mask", _LVMETAD_SERVICE, _LVMETAD_SOCKET)
        _systemctl("disable", _LVMETAD_SERVICE, _LVMETAD_SOCKET)
        _systemctl("stop", _LVMETAD_SERVICE, _LVMETAD_SOCKET)