Merge "Fix AodhAlarmTest to use gnocchi"

This commit is contained in:
Zuul 2017-11-14 08:20:53 +00:00 committed by Gerrit Code Review
commit 48f75a2341
6 changed files with 46 additions and 42 deletions

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 heat.common.i18n import _
from heatclient import client as heat_client
from keystoneauth1 import exceptions as kc_exceptions
@ -65,7 +65,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
@ -87,7 +87,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:
@ -187,18 +187,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

@ -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

@ -63,7 +63,7 @@ iniset $conf_file heat_plugin skip_functional_test_list 'ReloadOnSighupTest, Not
# Add scenario tests to skip
# VolumeBackupRestoreIntegrationTest skipped until failure rate can be reduced ref bug #1382300
# test_server_signal_userdata_format_software_config is skipped untill bug #1651768 is resolved
iniset $conf_file heat_plugin skip_scenario_test_list 'SoftwareConfigIntegrationTest, VolumeBackupRestoreIntegrationTest, AodhAlarmTest'
iniset $conf_file heat_plugin skip_scenario_test_list 'SoftwareConfigIntegrationTest, VolumeBackupRestoreIntegrationTest'
if [ "$DISABLE_CONVERGENCE" == "true" ]; then
iniset $conf_file heat_plugin convergence_engine_enabled false

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_integrationtests.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

@ -36,6 +36,7 @@ python-ceilometerclient>=2.5.0 # Apache-2.0
python-cinderclient>=3.2.0 # Apache-2.0
python-designateclient>=2.7.0 # Apache-2.0
python-glanceclient>=2.8.0 # Apache-2.0
gnocchiclient>=3.3.1 # Apache-2.0
python-heatclient>=1.10.0 # Apache-2.0
python-keystoneclient>=3.8.0 # Apache-2.0
python-magnumclient>=2.0.0 # Apache-2.0