Add proper skip mechanism for Stacklight component

Change-Id: Id732f8b121e518e0ea7716c4072fb95b5223b3e5
Related-PROD: PROD-22000
diff --git a/cvp_checks/fixtures/base.py b/cvp_checks/fixtures/base.py
index 2407a63..f64c256 100644
--- a/cvp_checks/fixtures/base.py
+++ b/cvp_checks/fixtures/base.py
@@ -14,6 +14,39 @@
     return request.param
 
 
+@pytest.fixture(scope='session')
+def check_prometheus(local_salt_client):
+    salt_output = local_salt_client.cmd(
+        'prometheus:server',
+        'test.ping',
+        expr_form='pillar')
+    if not salt_output:
+        pytest.skip("Prometheus service or prometheus:server pillar \
+          are not found on this environment.")
+
+
+@pytest.fixture(scope='session')
+def check_kibana(local_salt_client):
+    salt_output = local_salt_client.cmd(
+        'kibana:server',
+        'test.ping',
+        expr_form='pillar')
+    if not salt_output:
+        pytest.skip("Kibana service or kibana:server pillar \
+          are not found on this environment.")
+
+
+@pytest.fixture(scope='session')
+def check_grafana(local_salt_client):
+    salt_output = local_salt_client.cmd(
+        'grafana:client',
+        'test.ping',
+        expr_form='pillar')
+    if not salt_output:
+        pytest.skip("Grafana service or grafana:client pillar \
+          are not found on this environment.")
+
+
 def pytest_namespace():
     return {'contrail': None}
 
diff --git a/cvp_checks/tests/test_stacklight.py b/cvp_checks/tests/test_stacklight.py
index 80917f1..81127d4 100644
--- a/cvp_checks/tests/test_stacklight.py
+++ b/cvp_checks/tests/test_stacklight.py
@@ -5,6 +5,7 @@
 from cvp_checks import utils
 
 
+@pytest.mark.usefixtures('check_kibana')
 def test_elasticsearch_cluster(local_salt_client):
     salt_output = local_salt_client.cmd(
         'kibana:server',
@@ -12,10 +13,6 @@
         ['_param:haproxy_elasticsearch_bind_host'],
         expr_form='pillar')
 
-    if not salt_output:
-        pytest.skip("Kibana service or kibana:server pillar \
-        are not found on this environment.")
-
     proxies = {"http": None, "https": None}
     for node in salt_output.keys():
         IP = salt_output[node]
@@ -41,6 +38,7 @@
             json.dumps(resp, indent=4))
 
 
+@pytest.mark.usefixtures('check_kibana')
 def test_elasticsearch_node_count(local_salt_client):
     now = datetime.datetime.now()
     today = now.strftime("%Y.%m.%d")
@@ -51,10 +49,6 @@
         ['_param:haproxy_elasticsearch_bind_host'],
         expr_form='pillar')
 
-    if not salt_output:
-        pytest.skip("Kibana service or kibana:server pillar \
-        are not found on this environment.")
-
     IP = salt_output.values()[0]
     proxies = {"http": None, "https": None}
     resp = json.loads(requests.post('http://{0}:9200/log-{1}/_search?pretty'.
@@ -83,16 +77,17 @@
 
 
 def test_stacklight_services_replicas(local_salt_client):
+    # TODO
+    # change to docker:swarm:role:master ?
     salt_output = local_salt_client.cmd(
-        'docker:client:stack:monitoring',
+        'I@docker:client:stack:monitoring and I@prometheus:server',
         'cmd.run',
         ['docker service ls'],
-        expr_form='pillar')
+        expr_form='compound')
 
     if not salt_output:
-        pytest.skip("Docker replicas or \
-        docker:client:stack:monitoring pillar \
-        are not found on this environment.")
+        pytest.skip("docker:client:stack:monitoring or \
+        prometheus:server pillars are not found on this environment.")
 
     wrong_items = []
     for line in salt_output[salt_output.keys()[0]].split('\n'):
@@ -104,6 +99,7 @@
               {}'''.format(json.dumps(wrong_items, indent=4))
 
 
+@pytest.mark.usefixtures('check_prometheus')
 def test_prometheus_alert_count(local_salt_client):
     IP = utils.get_monitoring_ip('cluster_public_host')
     # keystone:server can return 3 nodes instead of 1
@@ -116,10 +112,6 @@
          'grep -v "0 active"'.format(IP)],
         expr_form='pillar')
 
-    if not nodes_info:
-        pytest.skip("Prometheus server url or keystone:server \
-        pillar are not found on this environment.")
-
     result = nodes_info[nodes_info.keys()[0]].replace('</td>', '').replace(
         '<td><i class="icon-chevron-down"></i> <b>', '').replace('</b>', '')
     assert result == '', 'AlertManager page has some alerts! {}'.format(
@@ -128,14 +120,14 @@
 
 def test_stacklight_containers_status(local_salt_client):
     salt_output = local_salt_client.cmd(
-        'docker:swarm:role:master',
+        'I@docker:swarm:role:master and I@prometheus:server',
         'cmd.run',
         ['docker service ps $(docker stack services -q monitoring)'],
-        expr_form='pillar')
+        expr_form='compound')
 
     if not salt_output:
-        pytest.skip("Docker or docker:swarm:role:master \
-        pillar are not found on this environment.")
+        pytest.skip("docker:swarm:role:master or prometheus:server \
+        pillars are not found on this environment.")
 
     result = {}
     # for old reclass models, docker:swarm:role:master can return
diff --git a/cvp_checks/tests/test_ui_addresses.py b/cvp_checks/tests/test_ui_addresses.py
index 69c0f6a..ee02232 100644
--- a/cvp_checks/tests/test_ui_addresses.py
+++ b/cvp_checks/tests/test_ui_addresses.py
@@ -21,6 +21,7 @@
         IP[0])
 
 
+@pytest.mark.usefixtures('check_kibana')
 def test_ui_kibana(local_salt_client):
     IP = utils.get_monitoring_ip('stacklight_log_address')
     result = local_salt_client.cmd(
@@ -33,6 +34,7 @@
         'Kibana login page is not reachable on {} from ctl nodes'.format(IP)
 
 
+@pytest.mark.usefixtures('check_prometheus')
 def test_ui_prometheus(local_salt_client):
     IP = utils.get_monitoring_ip('stacklight_monitor_address')
     result = local_salt_client.cmd(
@@ -45,6 +47,7 @@
         'Prometheus page is not reachable on {} from ctl nodes'.format(IP)
 
 
+@pytest.mark.usefixtures('check_prometheus')
 def test_ui_alert_manager(local_salt_client):
     IP = utils.get_monitoring_ip('stacklight_monitor_address')
     result = local_salt_client.cmd(
@@ -56,6 +59,7 @@
         'AlertManager page is not reachable on {} from ctl nodes'.format(IP)
 
 
+@pytest.mark.usefixtures('check_grafana')
 def test_ui_grafana(local_salt_client):
     IP = utils.get_monitoring_ip('cluster_public_host')
     result = local_salt_client.cmd(
diff --git a/cvp_checks/utils/__init__.py b/cvp_checks/utils/__init__.py
index 91501a8..132bfea 100644
--- a/cvp_checks/utils/__init__.py
+++ b/cvp_checks/utils/__init__.py
@@ -73,7 +73,7 @@
 def get_monitoring_ip(param_name):
     local_salt_client = init_salt_client()
     salt_output = local_salt_client.cmd(
-        'docker:client:stack:monitoring',
+        'salt:master',
         'pillar.get',
         ['_param:{}'.format(param_name)],
         expr_form='pillar')