cfme.utils.events_db module

Library for event testing.

class cfme.utils.events_db.DbEventListener(appliance)[source]

Bases: threading.Thread

accepts “expected” events, listens to db events and compares showed up events with expected events. Runs callback function if expected events have it.

__call__(*args, **kwargs)[source]

it is called by register_event fixture. bad idea, to replace register_event by object later

check_expected_events()[source]
get_next_portion()[source]
got_events

returns dict with expected events and all the events matched to expected ones

listen_to(*evts, **kwargs)[source]

accepts one or many events callback function will be called when event arrived in event_streams. callback will receive expected event and got event as params.

Parameters:
  • evts – list of events which EventListener should listen to
  • callback – callback function that will be called if event is received
  • first_event – EventListener waits for only first event of such type. it ignores such event in future if first matching event is found.

By default EventListener collects and receives all matching events.

new_event(*attrs, **kwattrs)[source]

this method just simplifies “expected” event creation. .. rubric:: Usage:

listener = appliance.event_listener()
evt = listener.new_event(target_type='VmOrTemplate',
                        target_name='my_lovely_vm',
                        event_type='vm_create')
listener.listen_to(evt)
process_events()[source]

processes all new db events and compares them with expected events. processed events are ignored next time

reset_events()[source]
reset_matches()[source]
run()[source]
set_last_record(evt=None)[source]
start()[source]
started
stop()[source]
class cfme.utils.events_db.Event(event_tool, *args)[source]

Bases: object

represents either db event received by CFME and stored in event_streams or an expected event

add_attrs(*attrs)[source]

event consists of attributes like event_type, etc. this method allows to add an attribute to event

build_from_raw_event(evt)[source]

helper method which takes raw event from event_streams and prepares event object

matches(evt)[source]

compares current event with passed event.

class cfme.utils.events_db.EventAttr(attr_type=None, cmp_func=None, **attrs)[source]

Bases: object

contains one event attribute and the method for comparing it.

match(attr)[source]

compares current attribute with passed attribute

class cfme.utils.events_db.EventTool(appliance)[source]

Bases: object

EventTool serves as a wrapper to getting the events from the database. :var OBJECT_TABLE: Mapping of object types to tables and column names.

OBJECT_TABLE = {'Host': ('hosts', 'name', 'id'), 'Service': ('services', 'name', 'id'), 'VmOrTemplate': ('vms', 'name', 'id')}
all_event_types

Returns a list of all possible events that can be used. :returns: A list of str.

ensure_event_happens(*args, **kwds)[source]

Context manager usable for one-off checking of the events.

See also: query_miq_events()

Parameters:
  • target_type – What kind of object is the target of the event (MiqServer, VmOrTemplate)
  • target_id – What is the ID of the object (or name, see process_id()).
  • event_type – Type of the event. Ideally one of the all_event_types() but other kinds of events exist too.
event_streams

event_streams table.

event_streams_attributes

event_streams columns and python’s column types

miq_event_definitions

miq_event_definitions table.

process_id(target_type, target_name)[source]

Resolves id, let it be a string or an id. In case the target_type is defined in the OBJECT_TABLE, you can pass a string with object’s name, otherwise a numeric id to the table is required. :param target_type: What kind of object is the target of the event (MiqServer, VmOrTemplate...) :param target_name: An id or a name of the object.

Returns:int with id of the object in the database.
query(*args, **kwargs)[source]

Wrapper for the SQLAlchemy query method.

query_miq_events(target_type=None, target_id=None, event_type=None, since=None, until=None, from_id=None)[source]

Checks whether an event occured.

Parameters:
  • target_type – What kind of object is the target of the event (MiqServer, VmOrTemplate)
  • target_id – What is the ID of the object (or name, see process_id()).
  • event_type – Type of the event. Ideally one of the all_event_types() but other kinds of events exist too.
  • since – Since when you want to check it. UTC
  • until – Until what time you want to check it.