Merge "Add functional integration test coverage for Aodh"
diff --git a/.zuul.yaml b/.zuul.yaml
index f4f7774..fdeb80f 100644
--- a/.zuul.yaml
+++ b/.zuul.yaml
@@ -78,6 +78,7 @@
       - openstack/diskimage-builder
       - openstack/tempest
       - gnocchixyz/gnocchi
+      - infrawatch/sg-core
     vars: &base_vars
       configure_swap_size: 8192
       devstack_plugins:
@@ -85,15 +86,24 @@
         ceilometer: https://opendev.org/openstack/ceilometer
         aodh: https://opendev.org/openstack/aodh
         panko: https://opendev.org/openstack/panko
+        sg-core: https://github.com/infrawatch/sg-core
       devstack_services:
         tempest: true
       devstack_localrc:
         USE_PYTHON3: True
         TEMPEST_PLUGINS: '"/opt/stack/telemetry-tempest-plugin /opt/stack/heat-tempest-plugin"'
         GNOCCHI_ARCHIVE_POLICY_TEMPEST: "ceilometer-high-rate"
+        # NOTE(jwysogla): We can define both of the variables. In versions, where
+        # the ceilometer devstack plugin doesn't support the CEILOMETER_BACKENDS,
+        # it'll just ignore it and use the CEILOMETER_BACKEND. In versions, where
+        # CEILOMETER_BACKENDS is supported, the ceilometer devstack plugin will
+        # just try to merge the variables, so the final contents in this casse will
+        # be "gnocchi,sg-core"
         CEILOMETER_BACKEND: "gnocchi"
+        CEILOMETER_BACKENDS: "gnocchi,sg-core"
         CEILOMETER_PIPELINE_INTERVAL: 15
         CEILOMETER_ALARM_THRESHOLD: 6000000000
+        GLOBAL_VENV: False
       devstack_local_conf:
         test-config:
           $TEMPEST_CONFIG:
@@ -101,11 +111,11 @@
               disable_ssl_certificate_validation: True
       tempest_test_regex: telemetry_tempest_plugin
       tox_envlist: all
+      branches: ^(?!stable/(ocata|pike|queens|rocky|stein)).*$
 
 - job:
     name: telemetry-dsvm-integration
     parent: telemetry-tempest-base
-    branches: ^(?!stable/(ocata|pike|queens|rocky|stein|train)).*$
 
 - job:
     name: telemetry-dsvm-integration
@@ -135,7 +145,6 @@
 - job:
     name: telemetry-dsvm-integration-ipv6-only
     parent: devstack-tempest-ipv6
-    branches: ^(?!stable/(ocata|pike|queens|rocky|stein)).*$
     description: |
       Telemetry devstack tempest tests job for IPv6-only deployment
     required-projects: *base_required_projects
@@ -153,6 +162,7 @@
     parent: telemetry-dsvm-integration
     nodeset: openstack-single-node-bionic
     override-checkout: stable/train
+    voting: false
     vars:
       devstack_localrc:
         USE_PYTHON3: True
diff --git a/doc/source/test_additions.rst b/doc/source/test_additions.rst
new file mode 100644
index 0000000..8b1e103
--- /dev/null
+++ b/doc/source/test_additions.rst
@@ -0,0 +1,12 @@
+=======================
+Adding additional tests
+=======================
+
+:Modify .zuul.yaml:
+    Make required modifications to the devstack configuration in the .zuul.yaml. Mainly add any new required projects and env variables. If you require a non-openstack project, check that it's listed in the project-config under the openstack tenant: https://opendev.org/openstack/project-config/src/branch/master/zuul/main.yaml. Create a patch for the project-config to add that project if it isn't already there, otherwise it won't be available in check and gate jobs.
+
+:Add tests:
+    Add new tests. These can be either the scenario tests using gabbi: https://gabbi.readthedocs.io/en/latest/ or python code using tempest directly. See https://docs.openstack.org/tempest/latest/field_guide/index.html. If there is some configuration required to run the tests, take a look at the telemetry_tempest_plugin/conf.py.
+
+:Example:
+    An example of adding a simple test can be seen here: https://review.opendev.org/c/openstack/telemetry-tempest-plugin/+/898201
diff --git a/telemetry_tempest_plugin/aodh/api/base.py b/telemetry_tempest_plugin/aodh/api/base.py
index 816f204..7298170 100644
--- a/telemetry_tempest_plugin/aodh/api/base.py
+++ b/telemetry_tempest_plugin/aodh/api/base.py
@@ -31,6 +31,8 @@
         super(BaseAlarmingTest, cls).skip_checks()
         if not CONF.service_available.aodh:
             raise cls.skipException("Aodh support is required")
+        if not CONF.service_available.gnocchi:
+            raise cls.skipException("Gnocchi support is required")
 
     @classmethod
     def setup_clients(cls):
diff --git a/telemetry_tempest_plugin/config.py b/telemetry_tempest_plugin/config.py
index e12d3f9..be3f6d4 100644
--- a/telemetry_tempest_plugin/config.py
+++ b/telemetry_tempest_plugin/config.py
@@ -30,6 +30,10 @@
                   cfg.BoolOpt('gnocchi',
                               default=True,
                               help="Whether or not Gnocchi is expected to be"
+                                   "available"),
+                  cfg.BoolOpt('sg_core',
+                              default=True,
+                              help="Whether or not sg-core is expected to be"
                                    "available")]
 
 telemetry_group = cfg.OptGroup(name='telemetry',
@@ -70,6 +74,10 @@
                 default=False,
                 help="Disable SSL certificate validation when running "
                      "scenario tests"),
+    cfg.StrOpt('sg_core_service_url',
+               default="127.0.0.1:3000",
+               help="URL to sg-core prometheus endpoint"),
+
 ]
 
 event_opts = [
diff --git a/telemetry_tempest_plugin/scenario/telemetry_integration_prometheus_gabbits/ceilometer-sg-core-integration.yaml b/telemetry_tempest_plugin/scenario/telemetry_integration_prometheus_gabbits/ceilometer-sg-core-integration.yaml
new file mode 100644
index 0000000..f4cd0b1
--- /dev/null
+++ b/telemetry_tempest_plugin/scenario/telemetry_integration_prometheus_gabbits/ceilometer-sg-core-integration.yaml
@@ -0,0 +1,10 @@
+tests:
+  - name: Check for ceilometer metrics
+    desc: Check the sg-core prometheus endpoint for ceilometer metrics
+    GET: $ENVIRON['SG_CORE_SERVICE_URL']/metrics
+    poll:
+      count: 60
+      delay: 2
+    response_strings:
+      - "ceilometer_image_size"
+      - "sg_total_ceilometer_metric_decode_error_count{source=\"SG\"} 0"
diff --git a/telemetry_tempest_plugin/scenario/test_telemetry_integration.py b/telemetry_tempest_plugin/scenario/test_telemetry_integration.py
index 7db4fd5..3cd7301 100644
--- a/telemetry_tempest_plugin/scenario/test_telemetry_integration.py
+++ b/telemetry_tempest_plugin/scenario/test_telemetry_integration.py
@@ -94,6 +94,8 @@
             "HEAT_SERVICE_URL": self._get_endpoint(auth, "heat_plugin"),
             "NOVA_SERVICE_URL": self._get_endpoint(auth, "compute"),
             "GLANCE_SERVICE_URL": self._get_endpoint(auth, "image"),
+            "SG_CORE_SERVICE_URL":
+            str(config.CONF.telemetry.sg_core_service_url),
             "GLANCE_IMAGE_NAME": self.image_create(),
             "NOVA_FLAVOR_REF": config.CONF.compute.flavor_ref,
             "NEUTRON_NETWORK": networks[0].get('id'),
diff --git a/telemetry_tempest_plugin/scenario/test_telemetry_integration_prometheus.py b/telemetry_tempest_plugin/scenario/test_telemetry_integration_prometheus.py
new file mode 100644
index 0000000..c379470
--- /dev/null
+++ b/telemetry_tempest_plugin/scenario/test_telemetry_integration_prometheus.py
@@ -0,0 +1,44 @@
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+import os
+
+from tempest import config
+import tempest.test
+
+from telemetry_tempest_plugin.scenario import utils
+
+CONF = config.CONF
+
+TEST_DIR = os.path.join(os.path.dirname(__file__),
+                        'telemetry_integration_prometheus_gabbits')
+
+
+class PrometheusGabbiTest(tempest.test.BaseTestCase):
+    credentials = ['admin']
+
+    TIMEOUT_SCALING_FACTOR = 5
+
+    @classmethod
+    def skip_checks(cls):
+        super(PrometheusGabbiTest, cls).skip_checks()
+        if not CONF.service_available.sg_core:
+            raise cls.skipException("sg-core support is required")
+
+    def _prep_test(self, filename):
+        os.environ.update({
+            "SG_CORE_SERVICE_URL":
+            str(config.CONF.telemetry.sg_core_service_url),
+        })
+
+
+utils.generate_tests(PrometheusGabbiTest, TEST_DIR)