Updated OpenContrail tests to support version 4

In OpenContrail 4 changed the way to collect status from Controller and
Analytic nodes.

Change-Id: I4c171671c0c9a2ec77fb6d11c1e3bb02ef035087
diff --git a/cvp_checks/fixtures/base.py b/cvp_checks/fixtures/base.py
index 96abad9..2407a63 100644
--- a/cvp_checks/fixtures/base.py
+++ b/cvp_checks/fixtures/base.py
@@ -12,3 +12,22 @@
 @pytest.fixture(scope='session', params=nodes.values(), ids=nodes.keys())
 def nodes_in_group(request):
     return request.param
+
+
+def pytest_namespace():
+    return {'contrail': None}
+
+
+@pytest.fixture(scope='module')
+def contrail(local_salt_client):
+    probe = local_salt_client.cmd(
+        'opencontrail:control',
+        'pillar.get',
+        'opencontrail:control:version',
+        expr_form='pillar')
+    if not probe:
+        pytest.skip("Contrail is not found on this environment")
+    versions = set(probe.values())
+    if len(versions) != 1:
+        pytest.fail('Contrail versions are not the same: {}'.format(probe))
+    pytest.contrail = str(versions.pop())[:1]
diff --git a/cvp_checks/tests/test_contrail.py b/cvp_checks/tests/test_contrail.py
index 22242f7..2d358e9 100644
--- a/cvp_checks/tests/test_contrail.py
+++ b/cvp_checks/tests/test_contrail.py
@@ -1,21 +1,21 @@
 import pytest
 import json
 
+pytestmark = pytest.mark.usefixtures("contrail")
+
+STATUS_FILTER = r'grep -Pv "(==|^$|Disk|unix|support|boot|\*\*|FOR NODE)"'
+STATUS_COMMAND = "contrail-status"
+
+def get_contrail_status(salt_client, pillar, command, processor):
+    return salt_client.cmd(
+        pillar, 'cmd.run',
+        ['{} | {}'.format(command, processor)],
+        expr_form='pillar'
+    )
 
 def test_contrail_compute_status(local_salt_client):
-    probe = local_salt_client.cmd(
-        'opencontrail:control', 'cmd.run',
-        ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support)\''],
-        expr_form='pillar'
-    )
-    if not probe:
-        pytest.skip("Contrail is not found on this environment")
-
-    cs = local_salt_client.cmd(
-        'nova:compute', 'cmd.run',
-        ['contrail-status | grep -Pv \'(==|^$)\''],
-        expr_form='pillar'
-    )
+    cs = get_contrail_status(local_salt_client, 'nova:compute',
+                             STATUS_COMMAND, STATUS_FILTER)
     broken_services = []
 
     for node in cs:
@@ -38,18 +38,17 @@
 
 
 def test_contrail_node_status(local_salt_client):
-    cs = local_salt_client.cmd(
-        'opencontrail:client:analytics_node', 'cmd.run',
-        ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support|boot)\''],
-        expr_form='pillar'
+    command = STATUS_COMMAND
+
+    # TODO: what will be in OpenContrail 5?
+    if pytest.contrail == '4':
+        command = "doctrail all " + command
+    cs = get_contrail_status(local_salt_client,
+                             'opencontrail:client:analytics_node',
+                             command, STATUS_FILTER)
+    cs.update(get_contrail_status(local_salt_client, 'opencontrail:control',
+                                  command, STATUS_FILTER)
     )
-    cs.update(local_salt_client.cmd(
-        'opencontrail:control', 'cmd.run',
-        ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support|boot)\''],
-        expr_form='pillar')
-    )
-    if not cs:
-        pytest.skip("Contrail is not found on this environment")
     broken_services = []
     for node in cs:
         for line in cs[node].split('\n'):
@@ -69,17 +68,9 @@
 
 
 def test_contrail_vrouter_count(local_salt_client):
-    probe = local_salt_client.cmd(
-        'opencontrail:control', 'cmd.run',
-        ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support)\''],
-        expr_form='pillar'
-    )
-    if not probe:
-        pytest.skip("Contrail is not found on this environment")
-    cs = local_salt_client.cmd(
-        'nova:compute', 'cmd.run', ['contrail-status | grep -Pv \'(==|^$)\''],
-        expr_form='pillar'
-    )
+    cs = get_contrail_status(local_salt_client, 'nova:compute',
+                             STATUS_COMMAND, STATUS_FILTER)
+
     # TODO: what if compute lacks these service unintentionally?
     if not cs:
         pytest.skip("Contrail services were not found on compute nodes")