1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
|
# Copyright 2015 GlobalLogic. All rights reserved.
#
# 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.
from tempest import config
from tempest.lib.common.utils import data_utils
from tempest.lib import decorators
from tempest.lib import exceptions as lib_exc
from telemetry_tempest_plugin.aodh.api import base
CONF = config.CONF
class TelemetryAlarmingNegativeGnocchiTest(base.BaseAlarmingTest):
"""Negative tests for show_alarm, update_alarm, show_alarm_history tests
** show non-existent alarm
** show the deleted alarm
** delete deleted alarm
** update deleted alarm
"""
@classmethod
def skip_checks(cls):
"""This section is used to evaluate config early
Skip all test methods based on these checks
"""
super(TelemetryAlarmingNegativeGnocchiTest, cls).skip_checks()
if 'gnocchi' not in CONF.telemetry_services.metric_backends:
msg = ("%s: Skipping Gnocchi specific tests withouth Gnocchi" %
cls.__name__)
raise cls.skipException(msg)
@decorators.attr(type=['negative'])
@decorators.idempotent_id('ef45000d-0a72-4781-866d-4cb7bf2582ae')
def test_get_update_show_history_delete_deleted_alarm(self):
# get, update and delete the deleted alarm
alarm_name = data_utils.rand_name('telemetry_alarm')
rule = {'metrics': ["c0d457b6-957e-41de-a384-d5eb0957de3b"],
'aggregation_method': 'mean',
'comparison_operator': 'eq',
'threshold': 100.0,
'granularity': 90}
body = self.alarming_client.create_alarm(
name=alarm_name,
type='gnocchi_aggregation_by_metrics_threshold',
gnocchi_aggregation_by_metrics_threshold_rule=rule)
alarm_id = body['alarm_id']
self.alarming_client.delete_alarm(alarm_id)
# get the deleted alarm
self.assertRaises(lib_exc.NotFound, self.alarming_client.show_alarm,
alarm_id)
# update the deleted alarm
updated_alarm_name = data_utils.rand_name('telemetry_alarm_updated')
updated_rule = {'metrics': ["c0d457b6-957e-41de-a384-d5eb0957de3b"],
'comparison_operator': 'eq',
'aggregation_method': 'mean',
'threshold': 70,
'granularity': 50}
self.assertRaises(
lib_exc.NotFound, self.alarming_client.update_alarm,
alarm_id,
gnocchi_aggregation_by_metrics_threshold_rule=updated_rule,
name=updated_alarm_name,
type='gnocchi_aggregation_by_metrics_threshold')
# delete the deleted alarm
self.assertRaises(lib_exc.NotFound, self.alarming_client.delete_alarm,
alarm_id)
@decorators.attr(type=['negative'])
@decorators.idempotent_id('3bd874d7-dcbf-410e-ab08-829969282d92')
def test_create_invalid_alarm_constraint_start(self):
# create bad time constraint
alarm_name = data_utils.rand_name('telemetry_alarm')
tc_name = data_utils.rand_name('time_constraint')
rule = {'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'mean',
'comparison_operator': 'eq',
'threshold': 300.0}
tc = [{'name': tc_name,
'start': '11:00am',
'duration': 10}]
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=alarm_name,
type='gnocchi_aggregation_by_metrics_threshold',
time_constraints=tc,
gnocchi_aggregation_by_metrics_threshold_rule=rule)
@decorators.skip_because(bug="2045115")
@decorators.attr(type=['negative'])
@decorators.idempotent_id('384dec5a-af5b-4a9e-8dc1-9d056fca71d6')
def test_create_null_alarm_constraint(self):
# create bad time constraint
alarm_name = data_utils.rand_name('telemetry_alarm')
rule = {'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'mean',
'comparison_operator': 'eq',
'threshold': 300.0}
tc = None
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=alarm_name,
type='gnocchi_aggregation_by_metrics_threshold',
time_constraints=tc,
gnocchi_aggregation_by_metrics_threshold_rule=rule)
@decorators.attr(type=['negative'])
@decorators.idempotent_id('f358ee93-798e-4641-8fdc-13dc2f7a71c5')
def test_create_duplicate_alarm_constraint_name(self):
# create bad time constraint
alarm_name = data_utils.rand_name('telemetry_alarm')
tc_name = data_utils.rand_name('time_constraint')
rule = {'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'mean',
'comparison_operator': 'eq',
'threshold': 300.0}
tc = [{'name': tc_name,
'start': '* 11 * * *',
'duration': 10},
{'name': tc_name,
'start': '* * * * *',
'duration': 20}]
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=alarm_name,
type='gnocchi_aggregation_by_metrics_threshold',
time_constraints=tc,
gnocchi_aggregation_by_metrics_threshold_rule=rule)
@decorators.attr(type=['negative'])
@decorators.idempotent_id('e1d5d605-61a0-415b-bcaf-dc3a15717344')
def test_create_invalid_alarm_constraint_timezone(self):
# create bad time constraint
alarm_name = data_utils.rand_name('telemetry_alarm')
tc_name = data_utils.rand_name('time_constraint')
rule = {'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'mean',
'comparison_operator': 'eq',
'threshold': 300.0}
tc = [{'name': tc_name,
'start': '* 11 * * *',
'duration': 10,
'timezone': 'aaaa'}]
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=alarm_name,
type='gnocchi_aggregation_by_metrics_threshold',
time_constraints=tc,
gnocchi_aggregation_by_metrics_threshold_rule=rule)
@decorators.attr(type=['negative'])
@decorators.idempotent_id('7d3ee20c-8a0f-4a43-8a1a-2168da9905da')
def test_create_invalid_alarm_constraint_duration(self):
# create bad time constraint
alarm_name = data_utils.rand_name('telemetry_alarm')
tc_name = data_utils.rand_name('time_constraint')
rule = {'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'mean',
'comparison_operator': 'eq',
'threshold': 300.0}
tc = [{'name': tc_name,
'start': '* 11 * * *',
'duration': -10}]
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=alarm_name,
type='gnocchi_aggregation_by_metrics_threshold',
time_constraints=tc,
gnocchi_aggregation_by_metrics_threshold_rule=rule)
@decorators.attr(type=['negative'])
@decorators.idempotent_id('21ab2919-8680-44d8-be90-57aac5b22474')
def test_create_invalid_alarm_rule_granularity(self):
# create bad time constraint
alarm_name = data_utils.rand_name('telemetry_alarm')
tc_name = data_utils.rand_name('time_constraint')
rule = {'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'mean',
'comparison_operator': 'eq',
'threshold': 300.0,
'granularity': -1}
tc = [{'name': tc_name,
'start': '* 11 * * *',
'duration': 10}]
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=alarm_name,
type='gnocchi_aggregation_by_metrics_threshold',
time_constraints=tc,
gnocchi_aggregation_by_metrics_threshold_rule=rule)
@decorators.attr(type=['negative'])
@decorators.idempotent_id('b942eeb3-7fc2-4ba4-ad8f-674f3ac7fb96')
def test_create_invalid_alarm_none_rule(self):
# create bad time constraint
alarm_name = data_utils.rand_name('telemetry_alarm')
tc_name = data_utils.rand_name('time_constraint')
rule = None
tc = [{'name': tc_name,
'start': '* 11 * * *',
'duration': -10}]
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=alarm_name,
type='gnocchi_aggregation_by_metrics_threshold',
time_constraints=tc,
gnocchi_aggregation_by_metrics_threshold_rule=rule)
@decorators.attr(type=['negative'])
@decorators.idempotent_id('a805f2f3-ea3e-4574-b616-3dbe86cb95f8')
def test_create_invalid_alarm_input_state(self):
# create bad time constraint
alarm_name = data_utils.rand_name('telemetry_alarm')
rule = {'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'mean',
'comparison_operator': 'eq',
'threshold': 300.0}
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=alarm_name,
state='bad_state',
type='gnocchi_aggregation_by_metrics_threshold',
gnocchi_aggregation_by_metrics_threshold_rule=rule)
@decorators.attr(type=['negative'])
@decorators.idempotent_id('ea90ef4a-135d-48f2-b984-c156a89f627c')
def test_create_invalid_alarm_input_severity(self):
# create bad time constraint
alarm_name = data_utils.rand_name('telemetry_alarm')
rule = {'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'mean',
'comparison_operator': 'eq',
'threshold': 300.0}
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=alarm_name,
state='ok',
severity='bad_value',
type='gnocchi_aggregation_by_metrics_threshold',
gnocchi_aggregation_by_metrics_threshold_rule=rule)
@decorators.attr(type=['negative'])
@decorators.idempotent_id('3af990af-f134-4b87-9234-a25280afc176')
def test_create_invalid_alarm_input_enabled_string(self):
# create bad time constraint
alarm_name = data_utils.rand_name('telemetry_alarm')
rule = {'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'mean',
'comparison_operator': 'eq',
'threshold': 300.0}
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=alarm_name,
state='ok',
enabled='bad_value',
type='gnocchi_aggregation_by_metrics_threshold',
gnocchi_aggregation_by_metrics_threshold_rule=rule)
@decorators.skip_because(bug="2045118")
@decorators.attr(type=['negative'])
@decorators.idempotent_id('db999b7e-3bc8-4be3-90f3-9d0034f61e8a')
def test_create_invalid_alarm_input_enabled_int(self):
# create bad time constraint
alarm_name = data_utils.rand_name('telemetry_alarm')
rule = {'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'mean',
'comparison_operator': 'eq',
'threshold': 300.0}
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=alarm_name,
state='ok',
enabled=0,
type='gnocchi_aggregation_by_metrics_threshold',
gnocchi_aggregation_by_metrics_threshold_rule=rule)
@decorators.attr(type=['negative'])
@decorators.idempotent_id('0c64f10f-8529-46a5-9172-f0a64789632f')
def test_create_invalid_alarm_statistic(self):
# create bad time constraint
alarm_name = data_utils.rand_name('telemetry_alarm')
rule = {'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'magic',
'comparison_operator': 'gt',
'threshold': 2.0}
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=alarm_name,
type='gnocchi_aggregation_by_metrics_threshold',
gnocchi_aggregation_by_metrics_threshold_rule=rule)
@decorators.attr(type=['negative'])
@decorators.idempotent_id('0c421fe7-69e9-4a7c-9df0-547f7bc4c91a')
def test_create_invalid_alarm_com_op(self):
# create bad time constraint
alarm_name = data_utils.rand_name('telemetry_alarm')
rule = {'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'comparison_operator': 'bd_co',
'threshold': 20.0}
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=alarm_name,
type='gnocchi_aggregation_by_metrics_threshold',
gnocchi_aggregation_by_metrics_threshold_rule=rule)
@decorators.attr(type=['negative'])
@decorators.idempotent_id('5bbccedd-dd80-462c-a6da-d796d7667b5e')
def test_create_alarm_wsme_workaround(self):
# create bad time constraint
alarm_name = data_utils.rand_name('telemetry_alarm')
rule_key = 'gnocchi_aggregation_by_metrics_threshold_rule'
rules = {
'type': {
'name': alarm_name,
rule_key: {
'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'mean',
'threshold': 2.0,
}
},
'name': {
'type': 'gnocchi_aggregation_by_metrics_threshold',
rule_key: {
'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'mean',
'threshold': 2.0,
}
},
'threshold_rule/metrics': {
'name': alarm_name,
'type': 'gnocchi_aggregation_by_metrics_threshold',
rule_key: {
'aggregation_method': 'mean',
'threshold': 2.0,
}
},
'threshold_rule/threshold': {
'name': alarm_name,
'type': 'gnocchi_aggregation_by_metrics_threshold',
rule_key: {
'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'mean',
}
},
}
for field, adef in rules.items():
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=getattr(adef, 'name', None),
type=getattr(adef, 'type', None),
gnocchi_aggregation_by_metrics_threshold_rule=adef[rule_key]
)
def _do_create_alarm_invalid_action(self, ok_actions=None,
alarm_actions=None,
insufficient_data_actions=None,
error_message=None):
ok_actions = ok_actions or []
alarm_actions = alarm_actions or []
insufficient_data_actions = insufficient_data_actions or []
rule_key = 'gnocchi_aggregation_by_metrics_threshold_rule'
alarm_name = data_utils.rand_name('telemetry_alarm')
adef = {
'enabled': False,
'state': 'ok',
'type': 'gnocchi_aggregation_by_metrics_threshold',
'ok_actions': ok_actions,
'alarm_actions': alarm_actions,
'insufficient_data_actions': insufficient_data_actions,
'repeat_actions': True,
rule_key: {
'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'comparison_operator': 'le',
'aggregation_method': 'count',
'threshold': 50,
'evaluation_periods': '3',
'granularity': '180',
}
}
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.create_alarm,
name=alarm_name,
type=adef['type'],
enabled=adef['enabled'],
state=adef['state'],
ok_actions=adef['ok_actions'],
alarm_actions=adef['alarm_actions'],
insufficient_data_actions=adef['insufficient_data_actions'],
repeat_actions=adef['repeat_actions'],
gnocchi_aggregation_by_metrics_threshold_rule=adef[rule_key])
@decorators.attr(type=['negative'])
@decorators.idempotent_id('95e505c3-51e0-4ac8-8e75-6dfb5828fcd2')
def test_create_invalid_alarm_ok_actions(self):
self._do_create_alarm_invalid_action(
ok_actions=['spam://something/ok'],
error_message='Unsupported action spam://something/ok')
@decorators.skip_because(bug="2045116")
@decorators.attr(type=['negative'])
@decorators.idempotent_id('4b2b7be0-9d13-4e36-ad28-d11c5aa06411')
def test_create_invalid_alarm_too_many_actions(self):
self._do_create_alarm_invalid_action(
ok_actions=['http://no.where', 'http://no.where2'],
error_message="alarm_actions count exceeds maximum value 1")
@decorators.attr(type=['negative'])
@decorators.idempotent_id('2332b637-8193-448c-8b37-e0b6a6fded34')
def test_post_invalid_alarm_alarm_actions(self):
self._do_create_alarm_invalid_action(
alarm_actions=['spam://something/alarm'],
error_message='Unsupported action spam://something/alarm')
@decorators.attr(type=['negative'])
@decorators.idempotent_id('78029ec7-cb70-4f89-a1b6-df235d6688b6')
def test_post_invalid_alarm_insufficient_data_actions(self):
self._do_create_alarm_invalid_action(
insufficient_data_actions=['spam://something/insufficient'],
error_message='Unsupported action spam://something/insufficient')
@decorators.attr(type='negative')
@decorators.idempotent_id('32bbc39e-7423-4309-acf9-39ff584764fc')
def test_create_update_with_faults_delete_alarm(self):
# create dual actions
alarm_name = data_utils.rand_name('telemetry_alarm')
rule = {'metrics': ['41869681-5776-46d6-91ed-cccc43b6e4e3',
'a1fb80f4-c242-4f57-87c6-68f47521059e'],
'aggregation_method': 'mean',
'comparison_operator': 'eq',
'threshold': 300.0}
body = self.alarming_client.create_alarm(
name=alarm_name,
alarm_actions=['http://no.where'],
type='gnocchi_aggregation_by_metrics_threshold',
gnocchi_aggregation_by_metrics_threshold_rule=rule
)
alarm_id = body['alarm_id']
alarms = self.alarming_client.list_alarms(['name', 'eq', alarm_name])
self.assertEqual(1, len(alarms))
# update the alarm with wrong fields.
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.update_alarm,
alarm_id=alarm_id,
this_can_not_be_correct='ha')
# update the alarm with invalid action
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.update_alarm,
alarm_id=alarm_id,
ok_actions='spam://something/ok')
# update the alarm with invalid state
self.assertRaises(
lib_exc.BadRequest,
self.alarming_client.alarm_set_state,
alarm_id=alarm_id,
state='not valid')
# Delete alarm and verify if deleted
self.alarming_client.delete_alarm(alarm_id)
self.assertRaises(lib_exc.NotFound,
self.alarming_client.show_alarm, alarm_id)
|