Example #1
0
    def test_tree_concurrent_timeout(self, monkeypatch):
        # Much shorter timeout
        monkeypatch.setattr('fmf.utils.NODE_LOCK_TIMEOUT', 2)

        def long_fetch(*args, **kwargs):
            # Longer than timeout
            time.sleep(7)
            return EXAMPLES

        # Patch fetch to sleep and later return tmpdir path
        monkeypatch.setattr('fmf.utils.fetch_repo', long_fetch)

        # Background thread to get node() acquiring lock
        def target():
            Tree.node({
                'url': 'localhost',
                'name': '/',
            })

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

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

        # "Real" fetch shouldn't get the lock
        with pytest.raises(utils.GeneralError):
            Tree.node({
                'url': 'localhost',
                'name': '/',
            })

        # Wait on parallel thread to finish
        thread.join()
Example #2
0
    def test_tree_node_remote(self):
        reference = {
            'url': FMF_REPO,
            'ref': '0.10',
            'path': 'examples/deep',
            'name': '/one/two/three',
        }

        # Values of test in 0.10 tag
        expected_data = {
            'hardware': {
                'memory': {
                    'size': 8
                },
                'network': {
                    'model': 'e1000'
                }
            },
            'key': 'value'
        }

        # Full identifier
        node = Tree.node(reference)
        assert (node.get() == expected_data)

        # Default ref
        reference.pop('ref')
        node = Tree.node(reference)
        assert (node.get() == expected_data)

        # Raise exception for invalid tree nodes
        with pytest.raises(utils.ReferenceError):
            reference['name'] = 'not_existing_name_'
            node = Tree.node(reference)
Example #3
0
 def test_tree_commit(self, tmpdir):
     # Tag
     node = Tree.node(dict(url=FMF_REPO, ref='0.12'))
     assert node.commit == '6570aa5f10729991625d74036473a71f384d745b'
     # Hash
     node = Tree.node(dict(url=FMF_REPO, ref='fa05dd9'))
     assert 'fa05dd9' in node.commit
     assert 'fa05dd9' in node.commit  # return already detected value
     # Data
     node = Tree(dict(x=1))
     assert node.commit is False
     # No git repository
     tree = Tree(Tree.init(str(tmpdir)))
     assert tree.commit is False
Example #4
0
 def test_tree_node_local(self):
     reference = {
         'path': EXAMPLES + 'wget',
         'name': '/protocols/https',
     }
     node = Tree.node(reference)
     assert node.get('time') == '1 min'
Example #5
0
 def target():
     Tree.node({
         'url': 'localhost',
         'name': '/',
     })
Example #6
0
 def get_node(ref):
     try:
         node = Tree.node(dict(url=FMF_REPO, ref=ref))
         q.put(True)
     except Exception as error:
         q.put(error)
Example #7
0
 def test_tree_node_relative_path(self):
     with pytest.raises(utils.ReferenceError):
         Tree.node(dict(path='some/relative/path'))