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 import os
from ceilometerclient import client as ceilometer_client
from cinderclient import client as cinder_client from cinderclient import client as cinder_client
from gnocchiclient import client as gnocchi_client
from heat.common.i18n import _ from heat.common.i18n import _
from heatclient import client as heat_client from heatclient import client as heat_client
from keystoneauth1 import exceptions as kc_exceptions from keystoneauth1 import exceptions as kc_exceptions
@ -65,7 +65,7 @@ class ClientManager(object):
CINDERCLIENT_VERSION = '2' CINDERCLIENT_VERSION = '2'
HEATCLIENT_VERSION = '1' HEATCLIENT_VERSION = '1'
NOVA_API_VERSION = '2.1' NOVA_API_VERSION = '2.1'
CEILOMETER_VERSION = '2' GNOCCHI_VERSION = '1'
def __init__(self, conf, admin_credentials=False): def __init__(self, conf, admin_credentials=False):
self.conf = conf self.conf = conf
@ -87,7 +87,7 @@ class ClientManager(object):
self.network_client = self._get_network_client() self.network_client = self._get_network_client()
self.volume_client = self._get_volume_client() self.volume_client = self._get_volume_client()
self.object_client = self._get_object_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): def _username(self):
if self.admin_credentials: if self.admin_credentials:
@ -187,18 +187,13 @@ class ClientManager(object):
} }
return swift_client.Connection(**args) return swift_client.Connection(**args)
def _get_metering_client(self): def _get_metric_client(self):
try:
endpoint = self.identity_client.get_endpoint_url('metering', adapter_options = {'interface': 'public',
self.conf.region) 'region_name': self.conf.region}
except kc_exceptions.EndpointNotFound: args = {
return None 'session': self.identity_client.session,
else: 'adapter_options': adapter_options
args = { }
'session': self.identity_client.session, return gnocchi_client.Client(version=self.GNOCCHI_VERSION,
'region_name': self.conf.region, **args)
'endpoint_type': 'publicURL',
'service_type': 'metering',
}
return ceilometer_client.Client(self.CEILOMETER_VERSION,
endpoint, **args)

View File

@ -109,7 +109,7 @@ class HeatIntegrationTest(testscenarios.WithScenarios,
self.network_client = self.manager.network_client self.network_client = self.manager.network_client
self.volume_client = self.manager.volume_client self.volume_client = self.manager.volume_client
self.object_client = self.manager.object_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 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 # Add scenario tests to skip
# VolumeBackupRestoreIntegrationTest skipped until failure rate can be reduced ref bug #1382300 # 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 # 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 if [ "$DISABLE_CONVERGENCE" == "true" ]; then
iniset $conf_file heat_plugin convergence_engine_enabled false iniset $conf_file heat_plugin convergence_engine_enabled false

View File

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

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import datetime
from heat.common import timeutils
from oslo_log import log as logging from oslo_log import log as logging
from heat_integrationtests.common import test from heat_integrationtests.common import test
@ -36,22 +38,27 @@ class AodhAlarmTest(scenario_base.ScenarioTestsBase):
def test_alarm(self): def test_alarm(self):
"""Confirm we can create an alarm and trigger it.""" """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 # create the stack
stack_identifier = self.stack_create(template=self.template) 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) # confirm we get a scaleup.
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.
# Note: there is little point waiting more than 60s+time to scale up. # Note: there is little point waiting more than 60s+time to scale up.
self.assertTrue(test.call_until_true( self.assertTrue(test.call_until_true(
120, 2, self.check_instance_count, stack_identifier, 2)) 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-cinderclient>=3.2.0 # Apache-2.0
python-designateclient>=2.7.0 # Apache-2.0 python-designateclient>=2.7.0 # Apache-2.0
python-glanceclient>=2.8.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-heatclient>=1.10.0 # Apache-2.0
python-keystoneclient>=3.8.0 # Apache-2.0 python-keystoneclient>=3.8.0 # Apache-2.0
python-magnumclient>=2.0.0 # Apache-2.0 python-magnumclient>=2.0.0 # Apache-2.0