Exemplo n.º 1
0
    def test_execute(self, mock_putils_exec, mock_exec_root):
        priv_rootwrap.execute('echo', 'foo', run_as_root=False)
        self.assertFalse(mock_exec_root.called)

        priv_rootwrap.execute('echo', 'foo', run_as_root=True,
                              root_helper='baz', check_exit_code=0)
        mock_exec_root.assert_called_once_with(
            'echo', 'foo', check_exit_code=0)
Exemplo n.º 2
0
    def test_execute(self, mock_putils_exec, mock_exec_root):
        priv_rootwrap.execute('echo', 'foo', run_as_root=False)
        self.assertFalse(mock_exec_root.called)

        priv_rootwrap.execute('echo', 'foo', run_as_root=True,
                              root_helper='baz', check_exit_code=0)
        mock_exec_root.assert_called_once_with(
            'echo', 'foo', check_exit_code=0)
Exemplo n.º 3
0
    def is_multipath_running(enforce_multipath, root_helper):
        try:
            priv_rootwrap.execute('multipathd', 'show', 'status',
                                  run_as_root=True,
                                  root_helper=root_helper)
        except putils.ProcessExecutionError as err:
            LOG.error(_LE('multipathd is not running: exit code %(err)s'),
                      {'err': err.exit_code})
            if enforce_multipath:
                raise
            return False

        return True
Exemplo n.º 4
0
    def get_all_volume_groups(root_helper, vg_name=None):
        """Static method to get all VGs on a system.

        :param root_helper: root_helper to use for execute
        :param vg_name: optional, gathers info for only the specified VG
        :returns: List of Dictionaries with VG info

        """
        cmd = LVM.LVM_CMD_PREFIX + [
            'vgs', '--noheadings', '--unit=g', '-o',
            'name,size,free,lv_count,uuid', '--separator', ':', '--nosuffix'
        ]
        if vg_name is not None:
            cmd.append(vg_name)

        (out, _err) = priv_rootwrap.execute(*cmd,
                                            root_helper=root_helper,
                                            run_as_root=True)
        vg_list = []
        if out is not None:
            vgs = out.split()
            for vg in vgs:
                fields = vg.split(':')
                vg_list.append({
                    'name': fields[0],
                    'size': float(fields[1]),
                    'available': float(fields[2]),
                    'lv_count': int(fields[3]),
                    'uuid': fields[4]
                })

        return vg_list
Exemplo n.º 5
0
    def get_all_physical_volumes(root_helper, vg_name=None):
        """Static method to get all PVs on a system.

        :param root_helper: root_helper to use for execute
        :param vg_name: optional, gathers info for only the specified VG
        :returns: List of Dictionaries with PV info

        """
        field_sep = '|'
        cmd = LVM.LVM_CMD_PREFIX + [
            'pvs', '--noheadings', '--unit=g', '-o', 'vg_name,name,size,free',
            '--separator', field_sep, '--nosuffix'
        ]
        (out, _err) = priv_rootwrap.execute(*cmd,
                                            root_helper=root_helper,
                                            run_as_root=True)

        pvs = out.split()
        if vg_name is not None:
            pvs = [pv for pv in pvs if vg_name == pv.split(field_sep)[0]]

        pv_list = []
        for pv in pvs:
            fields = pv.split(field_sep)
            pv_list.append({
                'vg': fields[0],
                'name': fields[1],
                'size': float(fields[2]),
                'available': float(fields[3])
            })
        return pv_list
Exemplo n.º 6
0
Arquivo: lvm.py Projeto: e0ne/os-brick
    def get_all_volume_groups(root_helper, vg_name=None):
        """Static method to get all VGs on a system.

        :param root_helper: root_helper to use for execute
        :param vg_name: optional, gathers info for only the specified VG
        :returns: List of Dictionaries with VG info

        """
        cmd = LVM.LVM_CMD_PREFIX + ['vgs', '--noheadings',
                                    '--unit=g', '-o',
                                    'name,size,free,lv_count,uuid',
                                    '--separator', ':',
                                    '--nosuffix']
        if vg_name is not None:
            cmd.append(vg_name)

        (out, _err) = priv_rootwrap.execute(*cmd,
                                            root_helper=root_helper,
                                            run_as_root=True)
        vg_list = []
        if out is not None:
            vgs = out.split()
            for vg in vgs:
                fields = vg.split(':')
                vg_list.append({'name': fields[0],
                                'size': float(fields[1]),
                                'available': float(fields[2]),
                                'lv_count': int(fields[3]),
                                'uuid': fields[4]})

        return vg_list
Exemplo n.º 7
0
Arquivo: lvm.py Projeto: e0ne/os-brick
    def get_all_physical_volumes(root_helper, vg_name=None):
        """Static method to get all PVs on a system.

        :param root_helper: root_helper to use for execute
        :param vg_name: optional, gathers info for only the specified VG
        :returns: List of Dictionaries with PV info

        """
        field_sep = '|'
        cmd = LVM.LVM_CMD_PREFIX + ['pvs', '--noheadings',
                                    '--unit=g',
                                    '-o', 'vg_name,name,size,free',
                                    '--separator', field_sep,
                                    '--nosuffix']
        (out, _err) = priv_rootwrap.execute(*cmd,
                                            root_helper=root_helper,
                                            run_as_root=True)

        pvs = out.split()
        if vg_name is not None:
            pvs = [pv for pv in pvs if vg_name == pv.split(field_sep)[0]]

        pv_list = []
        for pv in pvs:
            fields = pv.split(field_sep)
            pv_list.append({'vg': fields[0],
                            'name': fields[1],
                            'size': float(fields[2]),
                            'available': float(fields[3])})
        return pv_list
Exemplo n.º 8
0
 def test_execute_as_root(self, exec_mock):
     res = priv_rootwrap.execute(mock.sentinel.cmds, run_as_root=True,
                                 root_helper=mock.sentinel.root_helper,
                                 keyword_arg=mock.sentinel.kwarg)
     self.assertEqual(exec_mock.return_value, res)
     exec_mock.assert_called_once_with(mock.sentinel.cmds, shell=False,
                                       run_as_root=False,
                                       keyword_arg=mock.sentinel.kwarg)
Exemplo n.º 9
0
 def test_execute_as_root(self, exec_mock):
     res = priv_rootwrap.execute(mock.sentinel.cmds, run_as_root=True,
                                 root_helper=mock.sentinel.root_helper,
                                 keyword_arg=mock.sentinel.kwarg)
     self.assertEqual(exec_mock.return_value, res)
     exec_mock.assert_called_once_with(mock.sentinel.cmds, shell=False,
                                       run_as_root=False,
                                       keyword_arg=mock.sentinel.kwarg)
Exemplo n.º 10
0
    def get_lv_info(root_helper, vg_name=None, lv_name=None):
        """Retrieve info about LVs (all, in a VG, or a single LV).

        :param root_helper: root_helper to use for execute
        :param vg_name: optional, gathers info for only the specified VG
        :param lv_name: optional, gathers info for only the specified LV
        :returns: List of Dictionaries with LV info

        """

        cmd = LVM.LVM_CMD_PREFIX + [
            'lvs', '--noheadings', '--unit=g', '-o', 'vg_name,name,size',
            '--nosuffix'
        ]
        if lv_name is not None and vg_name is not None:
            cmd.append("%s/%s" % (vg_name, lv_name))
        elif vg_name is not None:
            cmd.append(vg_name)

        try:
            (out, _err) = priv_rootwrap.execute(*cmd,
                                                root_helper=root_helper,
                                                run_as_root=True)
        except putils.ProcessExecutionError as err:
            with excutils.save_and_reraise_exception(reraise=True) as ctx:
                if "not found" in err.stderr or "Failed to find" in err.stderr:
                    ctx.reraise = False
                    LOG.info(
                        "Logical Volume not found when querying "
                        "LVM info. (vg_name=%(vg)s, lv_name=%(lv)s", {
                            'vg': vg_name,
                            'lv': lv_name
                        })
                    out = None

        lv_list = []
        if out is not None:
            volumes = out.split()
            iterator = moves.zip(*[iter(volumes)] * 3)  # pylint: disable=E1101
            for vg, name, size in iterator:
                lv_list.append({"vg": vg, "name": name, "size": size})

        return lv_list
Exemplo n.º 11
0
Arquivo: lvm.py Projeto: e0ne/os-brick
    def get_lv_info(root_helper, vg_name=None, lv_name=None):
        """Retrieve info about LVs (all, in a VG, or a single LV).

        :param root_helper: root_helper to use for execute
        :param vg_name: optional, gathers info for only the specified VG
        :param lv_name: optional, gathers info for only the specified LV
        :returns: List of Dictionaries with LV info

        """

        cmd = LVM.LVM_CMD_PREFIX + ['lvs', '--noheadings', '--unit=g',
                                    '-o', 'vg_name,name,size', '--nosuffix']
        if lv_name is not None and vg_name is not None:
            cmd.append("%s/%s" % (vg_name, lv_name))
        elif vg_name is not None:
            cmd.append(vg_name)

        try:
            (out, _err) = priv_rootwrap.execute(*cmd,
                                                root_helper=root_helper,
                                                run_as_root=True)
        except putils.ProcessExecutionError as err:
            with excutils.save_and_reraise_exception(reraise=True) as ctx:
                if "not found" in err.stderr or "Failed to find" in err.stderr:
                    ctx.reraise = False
                    LOG.info(_LI("Logical Volume not found when querying "
                                 "LVM info. (vg_name=%(vg)s, lv_name=%(lv)s"),
                             {'vg': vg_name, 'lv': lv_name})
                    out = None

        lv_list = []
        if out is not None:
            volumes = out.split()
            iterator = moves.zip(*[iter(volumes)] * 3)  # pylint: disable=E1101
            for vg, name, size in iterator:
                lv_list.append({"vg": vg, "name": name, "size": size})

        return lv_list
Exemplo n.º 12
0
    def get_lvm_version(root_helper):
        """Static method to get LVM version from system.

        :param root_helper: root_helper to use for execute
        :returns: version 3-tuple

        """

        cmd = LVM.LVM_CMD_PREFIX + ['vgs', '--version']
        (out, _err) = priv_rootwrap.execute(*cmd,
                                            root_helper=root_helper,
                                            run_as_root=True)
        lines = out.split('\n')

        for line in lines:
            if 'LVM version' in line:
                version_list = line.split()
                # NOTE(gfidente): version is formatted as follows:
                # major.minor.patchlevel(library API version)[-customisation]
                version = version_list[2]
                version_filter = r"(\d+)\.(\d+)\.(\d+).*"
                r = re.search(version_filter, version)
                version_tuple = tuple(map(int, r.group(1, 2, 3)))
                return version_tuple
Exemplo n.º 13
0
Arquivo: lvm.py Projeto: e0ne/os-brick
    def get_lvm_version(root_helper):
        """Static method to get LVM version from system.

        :param root_helper: root_helper to use for execute
        :returns: version 3-tuple

        """

        cmd = LVM.LVM_CMD_PREFIX + ['vgs', '--version']
        (out, _err) = priv_rootwrap.execute(*cmd,
                                            root_helper=root_helper,
                                            run_as_root=True)
        lines = out.split('\n')

        for line in lines:
            if 'LVM version' in line:
                version_list = line.split()
                # NOTE(gfidente): version is formatted as follows:
                # major.minor.patchlevel(library API version)[-customisation]
                version = version_list[2]
                version_filter = r"(\d+)\.(\d+)\.(\d+).*"
                r = re.search(version_filter, version)
                version_tuple = tuple(map(int, r.group(1, 2, 3)))
                return version_tuple