Пример #1
0
    def scan_directory(self, path):
        osd_metadata = {'cluster_name': conf.cluster}
        path_mounts = system.get_mounts(paths=True)
        for _file in os.listdir(path):
            file_path = os.path.join(path, _file)
            if os.path.islink(file_path):
                osd_metadata[_file] = self.scan_device(file_path)
            if os.path.isdir(file_path):
                continue
            # the check for binary needs to go before the file, to avoid
            # capturing data from binary files but still be able to capture
            # contents from actual files later
            if system.is_binary(file_path):
                continue
            if os.path.isfile(file_path):
                content = self.get_contents(file_path)
                try:
                    osd_metadata[_file] = int(content)
                except ValueError:
                    osd_metadata[_file] = content

        device = path_mounts.get(path)
        # it is possible to have more than one device, pick the first one, and
        # warn that it is possible that more than one device is 'data'
        if not device:
            terminal.error('Unable to detect device mounted for path: %s' %
                           path)
            raise RuntimeError('Cannot activate OSD')
        osd_metadata['data'] = self.scan_device(
            device[0] if len(device) else None)

        return osd_metadata
Пример #2
0
    def scan_directory(self, path):
        osd_metadata = {'cluster_name': conf.cluster}
        directory_files = os.listdir(path)
        if 'keyring' not in directory_files:
            raise RuntimeError(
                'OSD files not found, required "keyring" file is not present at: %s'
                % path)
        for file_ in os.listdir(path):
            file_path = os.path.join(path, file_)
            file_json_key = file_
            if file_.endswith('_dmcrypt'):
                file_json_key = file_.rstrip('_dmcrypt')
                logger.info(('reading file {}, stripping _dmcrypt',
                             'suffix').format(file_))
            if os.path.islink(file_path):
                if os.path.exists(file_path):
                    osd_metadata[file_json_key] = self.scan_device(file_path)
                else:
                    msg = 'broken symlink found %s -> %s' % (
                        file_path, os.path.realpath(file_path))
                    terminal.warning(msg)
                    logger.warning(msg)

            if os.path.isdir(file_path):
                continue

            # the check for binary needs to go before the file, to avoid
            # capturing data from binary files but still be able to capture
            # contents from actual files later
            try:
                if system.is_binary(file_path):
                    logger.info('skipping binary file: %s' % file_path)
                    continue
            except IOError:
                logger.exception('skipping due to IOError on file: %s' %
                                 file_path)
                continue
            if os.path.isfile(file_path):
                content = self.get_contents(file_path)
                if 'keyring' in file_path:
                    content = parse_keyring(content)
                try:
                    osd_metadata[file_json_key] = int(content)
                except ValueError:
                    osd_metadata[file_json_key] = content

        # we must scan the paths again because this might be a temporary mount
        path_mounts = system.get_mounts(paths=True)
        device = path_mounts.get(path)

        # it is possible to have more than one device, pick the first one, and
        # warn that it is possible that more than one device is 'data'
        if not device:
            terminal.error('Unable to detect device mounted for path: %s' %
                           path)
            raise RuntimeError('Cannot activate OSD')
        osd_metadata['data'] = self.scan_device(
            device[0] if len(device) else None)

        return osd_metadata
Пример #3
0
    def scan_directory(self, path):
        osd_metadata = {'cluster_name': conf.cluster}
        path_mounts = system.get_mounts(paths=True)
        for _file in os.listdir(path):
            file_path = os.path.join(path, _file)
            if os.path.islink(file_path):
                osd_metadata[_file] = self.scan_device(file_path)
            if os.path.isdir(file_path):
                continue
            # the check for binary needs to go before the file, to avoid
            # capturing data from binary files but still be able to capture
            # contents from actual files later
            if system.is_binary(file_path):
                continue
            if os.path.isfile(file_path):
                content = self.get_contents(file_path)
                try:
                    osd_metadata[_file] = int(content)
                except ValueError:
                    osd_metadata[_file] = content

        device = path_mounts.get(path)
        # it is possible to have more than one device, pick the first one, and
        # warn that it is possible that more than one device is 'data'
        if not device:
            terminal.error('Unable to detect device mounted for path: %s' % path)
            raise RuntimeError('Cannot activate OSD')
        osd_metadata['data'] = self.scan_device(device[0] if len(device) else None)

        return osd_metadata
Пример #4
0
    def scan_directory(self, path):
        osd_metadata = {'cluster_name': conf.cluster}
        directory_files = os.listdir(path)
        if 'keyring' not in directory_files:
            raise RuntimeError(
                'OSD files not found, required "keyring" file is not present at: %s' % path
            )
        for _file in os.listdir(path):
            file_path = os.path.join(path, _file)
            if os.path.islink(file_path):
                if os.path.exists(file_path):
                    osd_metadata[_file] = self.scan_device(file_path)
                else:
                    msg = 'broken symlink found %s -> %s' % (file_path, os.path.realpath(file_path))
                    terminal.warning(msg)
                    logger.warning(msg)

            if os.path.isdir(file_path):
                continue

            # the check for binary needs to go before the file, to avoid
            # capturing data from binary files but still be able to capture
            # contents from actual files later
            try:
                if system.is_binary(file_path):
                    logger.info('skipping binary file: %s' % file_path)
                    continue
            except IOError:
                logger.exception('skipping due to IOError on file: %s' % file_path)
                continue
            if os.path.isfile(file_path):
                content = self.get_contents(file_path)
                if 'keyring' in file_path:
                    content = parse_keyring(content)
                try:
                    osd_metadata[_file] = int(content)
                except ValueError:
                    osd_metadata[_file] = content

        # we must scan the paths again because this might be a temporary mount
        path_mounts = system.get_mounts(paths=True)
        device = path_mounts.get(path)

        # it is possible to have more than one device, pick the first one, and
        # warn that it is possible that more than one device is 'data'
        if not device:
            terminal.error('Unable to detect device mounted for path: %s' % path)
            raise RuntimeError('Cannot activate OSD')
        osd_metadata['data'] = self.scan_device(device[0] if len(device) else None)

        return osd_metadata
Пример #5
0
 def test_is_not_binary(self, fake_filesystem):
     binary_path = fake_filesystem.create_file('/tmp/fake-file',
                                               contents='asd\n\nlkjh0')
     assert system.is_binary(binary_path.path) is False
Пример #6
0
 def test_is_not_binary(self, tmpfile):
     binary_path = tmpfile(contents='asd\n\nlkjh0')
     assert system.is_binary(binary_path) is False
Пример #7
0
 def test_is_not_binary(self, tmpfile):
     binary_path = tmpfile(contents='asd\n\nlkjh0')
     assert system.is_binary(binary_path) is False