Allow to use environment variable to override some metric values

Change-Id: Ifd1d04ce813028f115c19bc983e7dd1e63c6f8a5
diff --git a/playbooks/legacy/telemetry-dsvm-integration-tempest-plugin/post_test_hook.sh b/playbooks/legacy/telemetry-dsvm-integration-tempest-plugin/post_test_hook.sh
index 624d62e..1507bd3 100755
--- a/playbooks/legacy/telemetry-dsvm-integration-tempest-plugin/post_test_hook.sh
+++ b/playbooks/legacy/telemetry-dsvm-integration-tempest-plugin/post_test_hook.sh
@@ -55,6 +55,8 @@
         gnocchi resource show -t instance $instance_id
         echo "* Gnocchi measures for instance ${instance_id}:"
         gnocchi measures show -r $instance_id cpu_util
+        gnocchi metric show -r $instance_id cpu
+        gnocchi --debug measures show -r $instance_id --aggregation rate:mean cpu
     done
 
     gnocchi status
diff --git a/playbooks/legacy/telemetry-dsvm-integration-tempest-plugin/run.yaml b/playbooks/legacy/telemetry-dsvm-integration-tempest-plugin/run.yaml
index 07a50d8..8453716 100644
--- a/playbooks/legacy/telemetry-dsvm-integration-tempest-plugin/run.yaml
+++ b/playbooks/legacy/telemetry-dsvm-integration-tempest-plugin/run.yaml
@@ -43,6 +43,7 @@
           export DEVSTACK_LOCAL_CONFIG+=$'\n'"INSTALL_TEMPEST='False'"
           export DEVSTACK_LOCAL_CONFIG+=$'\n'"CEILOMETER_BACKEND=gnocchi"
           export DEVSTACK_LOCAL_CONFIG+=$'\n'"GNOCCHI_ARCHIVE_POLICY=high"
+          export DEVSTACK_LOCAL_CONFIG+=$'\n'"GNOCCHI_ARCHIVE_POLICY_TEMPEST=ceilometer-high"
           export DEVSTACK_LOCAL_CONFIG+=$'\n'"CEILOMETER_PIPELINE_INTERVAL=15"
           function post_test_hook {
               cd /opt/stack/new/telemetry-tempest-plugin/playbooks/legacy/telemetry-dsvm-integration-tempest-plugin/
diff --git a/telemetry_tempest_plugin/config.py b/telemetry_tempest_plugin/config.py
index d5d9245..7ca6e6f 100644
--- a/telemetry_tempest_plugin/config.py
+++ b/telemetry_tempest_plugin/config.py
@@ -60,8 +60,16 @@
     cfg.IntOpt('alarm_granularity',
                default=300,
                help="Granularity to use for aodh alarms. This must match the "
-                    "configured Gnocchi archive policy")
-
+                    "configured Gnocchi archive policy"),
+    cfg.StrOpt('alarm_metric_name',
+               default="cpu_util",
+               help="Name of the metric to create an alarm on."),
+    cfg.StrOpt('alarm_aggregation_method',
+               default="mean",
+               help="Aggregation method to use for alarm."),
+    cfg.IntOpt('alarm_threshold',
+               default=10,
+               help="Threshold to cross for the alarm to trigger."),
 ]
 
 event_opts = [
diff --git a/telemetry_tempest_plugin/scenario/telemetry_integration_gabbits/create_stack.json b/telemetry_tempest_plugin/scenario/telemetry_integration_gabbits/create_stack.json
index 57a6366..126f0c5 100644
--- a/telemetry_tempest_plugin/scenario/telemetry_integration_gabbits/create_stack.json
+++ b/telemetry_tempest_plugin/scenario/telemetry_integration_gabbits/create_stack.json
@@ -42,11 +42,11 @@
                 "type": "OS::Ceilometer::GnocchiAggregationByResourcesAlarm",
                 "properties": {
                     "description": "Scale-up if the mean CPU > 10% on 1 minute",
-                    "metric": "cpu_util",
-                    "aggregation_method": "mean",
+                    "metric": "$ENVIRON["CEILOMETER_METRIC_NAME"]",
+                    "aggregation_method": "$ENVIRON["GNOCCHI_AGGREGATION_METHOD"]",
                     "granularity": $ENVIRON["AODH_GRANULARITY"],
                     "evaluation_periods": 1,
-                    "threshold": 10,
+                    "threshold": $ENVIRON["AODH_THRESHOLD"],
                     "comparison_operator": "gt",
                     "alarm_actions": [
                         {
diff --git a/telemetry_tempest_plugin/scenario/telemetry_integration_gabbits/update_stack.json b/telemetry_tempest_plugin/scenario/telemetry_integration_gabbits/update_stack.json
index 54f8e29..a107f4b 100644
--- a/telemetry_tempest_plugin/scenario/telemetry_integration_gabbits/update_stack.json
+++ b/telemetry_tempest_plugin/scenario/telemetry_integration_gabbits/update_stack.json
@@ -41,11 +41,11 @@
                 "type": "OS::Ceilometer::GnocchiAggregationByResourcesAlarm",
                 "properties": {
                     "description": "Scale-down if the mean CPU > 10% on 1 minute",
-                    "metric": "cpu_util",
-                    "aggregation_method": "mean",
+                    "metric": "$ENVIRON["CEILOMETER_METRIC_NAME"]",
+                    "aggregation_method": "$ENVIRON["GNOCCHI_AGGREGATION_METHOD"]",
                     "granularity": $ENVIRON["AODH_GRANULARITY"],
                     "evaluation_periods": 1,
-                    "threshold": 10,
+                    "threshold": $ENVIRON["AODH_THRESHOLD"],
                     "comparison_operator": "gt",
                     "alarm_actions": [
                         {
diff --git a/telemetry_tempest_plugin/scenario/test_telemetry_integration.py b/telemetry_tempest_plugin/scenario/test_telemetry_integration.py
index 22155dd..f6634f5 100644
--- a/telemetry_tempest_plugin/scenario/test_telemetry_integration.py
+++ b/telemetry_tempest_plugin/scenario/test_telemetry_integration.py
@@ -82,6 +82,11 @@
         os.environ.update({
             "ADMIN_TOKEN": admin_auth[0],
             "USER_TOKEN": auth[0],
+            "CEILOMETER_METRIC_NAME":
+            config.CONF.telemetry.alarm_metric_name,
+            "GNOCCHI_AGGREGATION_METHOD":
+            config.CONF.telemetry.alarm_aggregation_method,
+            "AODH_THRESHOLD": str(config.CONF.telemetry.alarm_threshold),
             "AODH_GRANULARITY": str(config.CONF.telemetry.alarm_granularity),
             "AODH_SERVICE_URL": self._get_endpoint(auth, "alarming_plugin"),
             "GNOCCHI_SERVICE_URL": self._get_endpoint(auth, "metric"),