Add grab version func

Change-Id: I942db548d9df5273da7bb2155fadd06f09b45384
diff --git a/tcp_tests/fixtures/underlay_fixtures.py b/tcp_tests/fixtures/underlay_fixtures.py
index e1420b5..a1476e3 100644
--- a/tcp_tests/fixtures/underlay_fixtures.py
+++ b/tcp_tests/fixtures/underlay_fixtures.py
@@ -196,3 +196,26 @@
         underlay = underlay_ssh_manager.UnderlaySSHManager(config)
 
     return underlay
+
+
+@pytest.fixture(scope='function', autouse=True)
+def grab_versions(request, underlay):
+    """Fixture for grab package versions at the end of test
+
+    Marks:
+        grab_versions(name=None) - make snapshot if test is passed. If
+        name argument provided, it will be used for creating data,
+        otherwise, test function name will be used
+
+    """
+    grab_version = request.keywords.get('grab_versions', None)
+
+    def test_fin():
+        default_name = getattr(request.node.function, '_name',
+                               request.node.function.__name__)
+        if hasattr(request.node, 'rep_call') and request.node.rep_call.passed \
+                and grab_version:
+            artifact_name = utils.extract_name_from_mark(grab_version) or \
+                "{}".format(default_name)
+            underlay.get_logs(artifact_name)
+    request.addfinalizer(test_fin)