Fix AodhAlarmTest to use gnocchi

This changes the test to use AodhGnocchiAggregationByMetricsAlarm
and add measures using gnocchi api.

Change-Id: I0b2fe154b93d9882b703e95a0b09f139697ceb9a
Closes-Bug: #1727637
This commit is contained in:
rabi 2017-10-26 14:52:52 +05:30
parent d2916d04e0
commit d69f031138
5 changed files with 45 additions and 42 deletions

View File

@ -109,7 +109,7 @@ class HeatIntegrationTest(testscenarios.WithScenarios,
self.network_client = self.manager.network_client
self.volume_client = self.manager.volume_client
self.object_client = self.manager.object_client
self.metering_client = self.manager.metering_client
self.metric_client = self.manager.metric_client
self.client = self.orchestration_client

View File

@ -12,8 +12,8 @@
import os
from ceilometerclient import client as ceilometer_client
from cinderclient import client as cinder_client
from gnocchiclient import client as gnocchi_client
from heatclient import client as heat_client
from keystoneauth1 import exceptions as kc_exceptions
from keystoneauth1.identity.generic import password
@ -64,7 +64,7 @@ class ClientManager(object):
CINDERCLIENT_VERSION = '2'
HEATCLIENT_VERSION = '1'
NOVA_API_VERSION = '2.1'
CEILOMETER_VERSION = '2'
GNOCCHI_VERSION = '1'
def __init__(self, conf, admin_credentials=False):
self.conf = conf
@ -82,7 +82,7 @@ class ClientManager(object):
self.network_client = self._get_network_client()
self.volume_client = self._get_volume_client()
self.object_client = self._get_object_client()
self.metering_client = self._get_metering_client()
self.metric_client = self._get_metric_client()
def _username(self):
if self.admin_credentials:
@ -182,18 +182,13 @@ class ClientManager(object):
}
return swift_client.Connection(**args)
def _get_metering_client(self):
try:
endpoint = self.identity_client.get_endpoint_url('metering',
self.conf.region)
except kc_exceptions.EndpointNotFound:
return None
else:
args = {
'session': self.identity_client.session,
'region_name': self.conf.region,
'endpoint_type': 'publicURL',
'service_type': 'metering',
}
return ceilometer_client.Client(self.CEILOMETER_VERSION,
endpoint, **args)
def _get_metric_client(self):
adapter_options = {'interface': 'public',
'region_name': self.conf.region}
args = {
'session': self.identity_client.session,
'adapter_options': adapter_options
}
return gnocchi_client.Client(version=self.GNOCCHI_VERSION,
**args)

View File

@ -1,4 +1,7 @@
heat_template_version: 2013-05-23
parameters:
metric_id:
type: string
resources:
asg:
type: OS::Heat::AutoScalingGroup
@ -15,22 +18,20 @@ resources:
cooldown: 0
scaling_adjustment: 1
alarm:
type: OS::Aodh::Alarm
type: OS::Aodh::GnocchiAggregationByMetricsAlarm
properties:
description: Scale-up if the average CPU > 50% for 1 minute
meter_name: test_meter
statistic: count
metrics:
- {get_param: metric_id}
comparison_operator: ge
threshold: 1
period: 60
evaluation_periods: 1
granularity: 60
aggregation_method: mean
threshold: 10
alarm_actions:
- str_replace:
template: trust+url
params:
url: {get_attr: [scaleup_policy, signal_url]}
matching_metadata:
metadata.metering.stack_id: {get_param: "OS::stack_id"}
outputs:
asg_size:
value: {get_attr: [asg, current_size]}

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
from heat.common import timeutils
from oslo_log import log as logging
from heat_tempest_plugin.common import test
@ -36,22 +38,27 @@ class AodhAlarmTest(scenario_base.ScenarioTestsBase):
def test_alarm(self):
"""Confirm we can create an alarm and trigger it."""
# create metric
metric = self.metric_client.metric.create({
'name': 'my_metric',
'archive_policy_name': 'high',
})
# 1. create the stack
stack_identifier = self.stack_create(template=self.template)
# create the stack
parameters = {'metric_id': metric['id']}
stack_identifier = self.stack_create(template=self.template,
parameters=parameters)
measures = [{'timestamp': timeutils.isotime(datetime.datetime.now()),
'value': 100}, {'timestamp': timeutils.isotime(
datetime.datetime.now() + datetime.timedelta(
minutes=1)), 'value': 100}]
# send measures(should cause the alarm to fire)
self.metric_client.metric.add_measures(metric['id'], measures)
# 2. send ceilometer a metric (should cause the alarm to fire)
sample = {}
sample['counter_type'] = 'gauge'
sample['counter_name'] = 'test_meter'
sample['counter_volume'] = 1
sample['counter_unit'] = 'count'
sample['resource_metadata'] = {'metering.stack_id':
stack_identifier.split('/')[-1]}
sample['resource_id'] = 'shouldnt_matter'
self.metering_client.samples.create(**sample)
# 3. confirm we get a scaleup.
# confirm we get a scaleup.
# Note: there is little point waiting more than 60s+time to scale up.
self.assertTrue(test.call_until_true(
120, 2, self.check_instance_count, stack_identifier, 2))
# cleanup metric
self.metric_client.metric.delete(metric['id'])

View File

@ -6,8 +6,8 @@ keystoneauth1>=3.2.0 # Apache-2.0
oslo.config>=4.6.0 # Apache-2.0
oslo.log>=3.30.0 # Apache-2.0
paramiko>=2.0.0 # LGPLv2.1+
python-ceilometerclient>=2.5.0 # Apache-2.0
python-cinderclient>=3.2.0 # Apache-2.0
gnocchiclient>=3.3.1 # Apache-2.0
python-heatclient>=1.10.0 # Apache-2.0
python-neutronclient>=6.3.0 # Apache-2.0
python-novaclient>=9.1.0 # Apache-2.0