Ejemplo n.º 1
0
    def test_fetch_tree_concurrent_timeout(self, monkeypatch, tmpdir):
        # Much shorter timeouts
        monkeypatch.setattr('fmf.utils.FETCH_LOCK_TIMEOUT', 1)
        monkeypatch.setattr('fmf.utils.NODE_LOCK_TIMEOUT', 2)

        real_fetch_repo = utils.fetch_repo

        def long_fetch_repo(*args, **kwargs):
            time.sleep(4)
            return real_fetch_repo(*args, **kwargs)

        # Patch fetch_repo with delay
        monkeypatch.setattr('fmf.utils.fetch_repo', long_fetch_repo)
        # Without remembering get_cache_directory value
        monkeypatch.setattr('fmf.utils._CACHE_DIRECTORY', str(tmpdir))

        # Background thread to fetch_tree() the same destination acquiring lock
        def target():
            utils.fetch_tree(GIT_REPO, '0.10')

        thread = threading.Thread(target=target)
        thread.start()

        # Small sleep to mitigate race
        time.sleep(1)

        # "Real" fetch shouldn't get the lock
        with pytest.raises(utils.GeneralError):
            utils.fetch_tree(GIT_REPO, '0.10')

        # Wait on parallel thread to finish
        thread.join()
Ejemplo n.º 2
0
    def node(reference):
        """
        Return Tree node referenced by the fmf identifier

        Keys supported in the reference:

        url .... git repository url (optional)
        ref .... branch, tag or commit (default branch if not provided)
        path ... metadata tree root ('.' by default)
        name ... tree node name ('/' by default)

        See the documentation for the full fmf id specification:
        https://fmf.readthedocs.io/en/latest/concept.html#identifiers
        Raises ReferenceError if referenced node does not exist.
        """

        # Fetch remote git repository
        if 'url' in reference:
            tree = utils.fetch_tree(reference.get('url'), reference.get('ref'),
                                    reference.get('path', '.').lstrip('/'))
        # Use local files
        else:
            root = reference.get('path', '.')
            if not root.startswith('/') and root != '.':
                raise utils.ReferenceError('Relative path "%s" specified.' %
                                           root)
            tree = Tree(root)
        found_node = tree.find(reference.get('name', '/'))
        if found_node is None:
            raise utils.ReferenceError(
                "No tree node found for '{0}' reference".format(reference))
        return found_node
Ejemplo n.º 3
0
 def target():
     utils.fetch_tree(GIT_REPO, '0.10')