~ubuntu-branches/ubuntu/vivid/ceilometer/vivid

« back to all changes in this revision

Viewing changes to bin/ceilometer-test-event.py

  • Committer: Package Import Robot
  • Author(s): James Page, Corey Bryant, James Page
  • Date: 2015-02-19 14:59:07 UTC
  • mfrom: (1.2.3)
  • Revision ID: package-import@ubuntu.com-20150219145907-9jojybdsl64zcn14
Tags: 2015.1~b2-0ubuntu1
[ Corey Bryant ]
* New upstream release.
  - d/control: Align requirements with upstream.
  - d/p/skip-test.patch: Rebased.

[ James Page ]
* d/rules,d/p/skip-gabbi.patch: Skip tests that rely on python-gabbi until
  packaging and MIR is complete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
#
3
 
# Copyright 2013 Rackspace Hosting.
4
 
#
5
 
# Author: Monsyne Dragon <mdragon@rackspace.com>
6
 
#
7
 
# Licensed under the Apache License, Version 2.0 (the "License"); you may
8
 
# not use this file except in compliance with the License. You may obtain
9
 
# a copy of the License at
10
 
#
11
 
#      http://www.apache.org/licenses/LICENSE-2.0
12
 
#
13
 
# Unless required by applicable law or agreed to in writing, software
14
 
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
 
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
 
# License for the specific language governing permissions and limitations
17
 
# under the License.
18
 
 
19
 
"""Command line tool help you debug your event definitions.
20
 
 
21
 
Feed it a list of test notifications in json format, and it will show
22
 
you what events will be generated.
23
 
"""
24
 
 
25
 
import json
26
 
import sys
27
 
 
28
 
from oslo.config import cfg
29
 
from stevedore import extension
30
 
 
31
 
from ceilometer.event import converter
32
 
from ceilometer import service
33
 
 
34
 
 
35
 
cfg.CONF.register_cli_opts([
36
 
    cfg.StrOpt('input-file',
37
 
               short='i',
38
 
               help='File to read test notifications from.'
39
 
               ' (Containing a json list of notifications.)'
40
 
               ' defaults to stdin.'),
41
 
    cfg.StrOpt('output-file',
42
 
               short='o',
43
 
               help='File to write results to. Defaults to stdout.'),
44
 
])
45
 
 
46
 
TYPES = {1: 'text',
47
 
         2: 'int',
48
 
         3: 'float',
49
 
         4: 'datetime'}
50
 
 
51
 
 
52
 
service.prepare_service()
53
 
 
54
 
config_file = converter.get_config_file()
55
 
output_file = cfg.CONF.output_file
56
 
input_file = cfg.CONF.input_file
57
 
 
58
 
if output_file is None:
59
 
    out = sys.stdout
60
 
else:
61
 
    out = open(output_file, 'w')
62
 
 
63
 
if input_file is None:
64
 
    notifications = json.load(sys.stdin)
65
 
else:
66
 
    with open(input_file, 'r') as f:
67
 
        notifications = json.load(f)
68
 
 
69
 
out.write("Definitions file: %s\n" % config_file)
70
 
out.write("Notifications tested: %s\n" % len(notifications))
71
 
 
72
 
event_converter = converter.setup_events(
73
 
    extension.ExtensionManager(
74
 
        namespace='ceilometer.event.trait_plugin'))
75
 
 
76
 
for notification in notifications:
77
 
    event = event_converter.to_event(notification)
78
 
    if event is None:
79
 
        out.write("Dropped notification: %s\n" %
80
 
                  notification['message_id'])
81
 
        continue
82
 
    out.write("Event: %s at %s\n" % (event.event_name, event.generated))
83
 
    for trait in event.traits:
84
 
        dtype = TYPES[trait.dtype]
85
 
        out.write("    Trait: name: %s, type: %s, value: %s\n" % (
86
 
            trait.name, dtype, trait.value))