rename internal vitrage properties

1. vitrage_sync_mode to vitrage_action_type
2. vitrage_sync_type to vitrage_entity_type

Change-Id: Icd60d8f6f6c5658449028bcec9688f61b8da7c62
This commit is contained in:
Alexey Weyl 2016-11-27 10:23:19 +02:00
parent de1a397423
commit aac14c51a2
61 changed files with 219 additions and 214 deletions

View File

@ -71,9 +71,9 @@ and must implement the following methods:
+----------------------+------------------------------------+--------------------------------+--------------------------------+
| Name | Input | Output | Comments |
+======================+====================================+================================+================================+
| get_all | sync mode | entities | for snapshot mechanism |
| get_all | action type | entities | for snapshot mechanism |
+----------------------+------------------------------------+--------------------------------+--------------------------------+
| get_changes | sync mode | entities | for update pulling mechanism |
| get_changes | action type | entities | for update pulling mechanism |
+----------------------+------------------------------------+--------------------------------+--------------------------------+
| get_event_types | | event types | for update pushing mechanism |
+----------------------+------------------------------------+--------------------------------+--------------------------------+

View File

@ -64,7 +64,7 @@ class EdgeLabel(object):
if not label.startswith(('_', 'labels'))]
class SyncMode(object):
class ActionType(object):
SNAPSHOT = 'snapshot'
INIT_SNAPSHOT = 'init_snapshot'
UPDATE = 'update'
@ -88,8 +88,8 @@ class EntityCategory(object):
class DatasourceProperties(object):
SYNC_TYPE = 'vitrage_sync_type'
SYNC_MODE = 'vitrage_sync_mode'
ENTITY_TYPE = 'vitrage_entity_type'
ACTION_TYPE = 'vitrage_action_type'
SAMPLE_DATE = 'vitrage_sample_date'
EVENT_TYPE = 'vitrage_event_type'

View File

@ -26,8 +26,8 @@ class AlarmDriverBase(DriverBase):
super(DriverBase, self).__init__()
self.cache = dict()
def _sync_type(self):
"""Return the type of the plugin """
def _entity_type(self):
"""Return the type of the datasource """
pass
def _alarm_key(self, alarm):
@ -71,15 +71,15 @@ class AlarmDriverBase(DriverBase):
"""
pass
def get_all(self, sync_mode):
def get_all(self, action_type):
return self.make_pickleable(self._get_all_alarms(),
self._sync_type(),
sync_mode)
self._entity_type(),
action_type)
def get_changes(self, sync_mode):
def get_changes(self, action_type):
return self.make_pickleable(self._get_changed_alarms(),
self._sync_type(),
sync_mode)
self._entity_type(),
action_type)
def _get_all_alarms(self):
alarms = self._get_alarms()

View File

@ -14,10 +14,10 @@
from oslo_log import log as logging
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import EntityCategory
from vitrage.common.constants import EventAction
from vitrage.common.constants import SyncMode
from vitrage.common.exception import VitrageTransformerError
from vitrage.datasources.alarm_properties import AlarmProperties as AlarmProps
from vitrage.datasources import transformer_base as tbase
@ -44,15 +44,16 @@ class AlarmTransformerBase(tbase.TransformerBase):
entity_event[DSProps.EVENT_TYPE] == EventAction.DELETE_ENTITY:
return entity_event[DSProps.EVENT_TYPE]
sync_mode = entity_event[DSProps.SYNC_MODE]
if sync_mode in (SyncMode.UPDATE, SyncMode.SNAPSHOT):
action_type = entity_event[DSProps.ACTION_TYPE]
if action_type in (ActionType.UPDATE, ActionType.SNAPSHOT):
return EventAction.DELETE_ENTITY if self._ok_status(entity_event) \
else EventAction.UPDATE_ENTITY
if SyncMode.INIT_SNAPSHOT == sync_mode:
if ActionType.INIT_SNAPSHOT == action_type:
return EventAction.CREATE_ENTITY
raise VitrageTransformerError('Invalid sync mode: (%s)' % sync_mode)
raise VitrageTransformerError('Invalid action type: (%s)'
% action_type)
def _key_values(self, *args):
return (EntityCategory.ALARM,) + args

View File

@ -35,7 +35,7 @@ class AodhDriver(AlarmDriverBase):
self._client = os_clients.ceilometer_client(self.conf)
return self._client
def _sync_type(self):
def _entity_type(self):
return AODH_DATASOURCE
def _alarm_key(self, alarm):

View File

@ -68,7 +68,7 @@ class AodhTransformer(AlarmTransformerBase):
self._create_entity_key(entity_event),
entity_id=entity_event[AodhProps.ALARM_ID],
entity_category=EntityCategory.ALARM,
entity_type=entity_event[DSProps.SYNC_TYPE],
entity_type=entity_event[DSProps.ENTITY_TYPE],
entity_state=self._get_alarm_state(entity_event),
sample_timestamp=sample_timestamp,
update_timestamp=update_timestamp,
@ -122,9 +122,9 @@ class AodhTransformer(AlarmTransformerBase):
if _is_vitrage_alarm(entity_event):
return entity_event.get(AodhProps.VITRAGE_ID)
sync_type = entity_event[DSProps.SYNC_TYPE]
entity_type = entity_event[DSProps.ENTITY_TYPE]
alarm_id = entity_event[AodhProps.ALARM_ID]
return tbase.build_key(self._key_values(sync_type, alarm_id))
return tbase.build_key(self._key_values(entity_type, alarm_id))
@staticmethod
def _timestamp(entity_event):

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import SyncMode
from vitrage.datasources.cinder.volume import CINDER_VOLUME_DATASOURCE
from vitrage.datasources.driver_base import DriverBase
from vitrage import os_clients
@ -36,12 +36,12 @@ class CinderVolumeDriver(DriverBase):
def extract_events(volumes):
return [volume.__dict__ for volume in volumes]
def get_all(self, sync_mode):
def get_all(self, action_type):
return self.make_pickleable(
self.extract_events(self.client.volumes.list(
search_opts={'all_tenants': 1})),
CINDER_VOLUME_DATASOURCE,
sync_mode,
action_type,
'manager')
@staticmethod
@ -50,7 +50,7 @@ class CinderVolumeDriver(DriverBase):
return CinderVolumeDriver.make_pickleable([event],
CINDER_VOLUME_DATASOURCE,
SyncMode.UPDATE)[0]
ActionType.UPDATE)[0]
@staticmethod
def get_event_types():

View File

@ -17,9 +17,9 @@ import six
from oslo_log import log
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import EventAction
from vitrage.common.constants import SyncMode
from vitrage.common import datetime_utils
LOG = log.getLogger(__name__)
@ -32,54 +32,54 @@ class DriverBase(object):
pass
@abc.abstractmethod
def get_all(self, sync_mode):
def get_all(self, action_type):
pass
def callback_on_fault(self, exception):
LOG.exception('Exception: {0}'.format(exception))
@staticmethod
def _get_end_message(sync_type):
def _get_end_message(entity_type):
end_message = {
DSProps.SYNC_TYPE: sync_type,
DSProps.SYNC_MODE: SyncMode.INIT_SNAPSHOT,
DSProps.ENTITY_TYPE: entity_type,
DSProps.ACTION_TYPE: ActionType.INIT_SNAPSHOT,
DSProps.EVENT_TYPE: EventAction.END_MESSAGE
}
return end_message
def get_changes(self, sync_mode):
def get_changes(self, action_type):
pass
@classmethod
def make_pickleable(cls, entities, sync_type, sync_mode, *args):
def make_pickleable(cls, entities, entity_type, action_type, *args):
pickleable_entities = []
for entity in entities:
for field in args:
entity.pop(field, None)
cls._add_sync_type(entity, sync_type)
cls._add_sync_mode(entity, sync_mode)
cls._add_entity_type(entity, entity_type)
cls._add_action_type(entity, action_type)
cls._add_sampling_time(entity)
pickleable_entities.append(entity)
if sync_mode == SyncMode.INIT_SNAPSHOT:
pickleable_entities.append(cls._get_end_message(sync_type))
if action_type == ActionType.INIT_SNAPSHOT:
pickleable_entities.append(cls._get_end_message(entity_type))
return pickleable_entities
@staticmethod
def _add_sync_type(entity, sync_type):
if DSProps.SYNC_TYPE not in entity:
entity[DSProps.SYNC_TYPE] = sync_type
def _add_entity_type(entity, entity_type):
if DSProps.ENTITY_TYPE not in entity:
entity[DSProps.ENTITY_TYPE] = entity_type
@staticmethod
def _add_sampling_time(entity):
entity[DSProps.SAMPLE_DATE] = str(datetime_utils.utcnow())
@staticmethod
def _add_sync_mode(entity, sync_mode):
entity[DSProps.SYNC_MODE] = sync_mode
def _add_action_type(entity, action_type):
entity[DSProps.ACTION_TYPE] = action_type
@staticmethod
@abc.abstractmethod

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import SyncMode
from vitrage.datasources.cinder.volume import CINDER_VOLUME_DATASOURCE
from vitrage.datasources.driver_base import DriverBase
from vitrage.datasources.heat.stack import HEAT_STACK_DATASOURCE
@ -75,7 +75,7 @@ class HeatStackDriver(DriverBase):
return HeatStackDriver.make_pickleable([event],
HEAT_STACK_DATASOURCE,
SyncMode.UPDATE)[0]
ActionType.UPDATE)[0]
def _filter_resource_types(self):
types = self.conf.datasources.types
@ -102,11 +102,11 @@ class HeatStackDriver(DriverBase):
HeatStackDriver.RESOURCE_TYPE_CONVERSION]
return stack
def get_all(self, sync_mode):
def get_all(self, action_type):
stacks = HeatStackDriver.client().stacks.list(global_tenant=True)
stacks_list = self._make_stacks_list(stacks)
stacks_with_resources = self._append_stacks_resources(stacks_list)
return self.make_pickleable(stacks_with_resources,
HEAT_STACK_DATASOURCE,
sync_mode,
action_type,
'manager')

View File

@ -25,6 +25,7 @@ from vitrage.datasources.nagios.parser import NagiosParser
from vitrage.datasources.nagios.properties import NagiosProperties\
as NagiosProps
from vitrage.datasources.nagios.properties import NagiosTestStatus
# noinspection PyProtectedMember
from vitrage.i18n import _LE
# noinspection PyProtectedMember
@ -41,7 +42,7 @@ class NagiosDriver(AlarmDriverBase):
self.conf = conf
self.config = NagiosConfig(conf)
def _sync_type(self):
def _entity_type(self):
return NAGIOS_DATASOURCE
def _alarm_key(self, alarm):
@ -83,7 +84,7 @@ class NagiosDriver(AlarmDriverBase):
for alarm in alarms:
# based on nagios configuration file, convert nagios host name
# to vitrage resource type and name
alarm[DSProps.SYNC_TYPE] = NagiosProps.NAGIOS
alarm[DSProps.ENTITY_TYPE] = NagiosProps.NAGIOS
nagios_host = alarm[NagiosProps.RESOURCE_NAME]
vitrage_resource = self.config.get_vitrage_resource(nagios_host)

View File

@ -63,7 +63,7 @@ class NagiosTransformer(AlarmTransformerBase):
return graph_utils.create_vertex(
self._create_entity_key(entity_event),
entity_category=EntityCategory.ALARM,
entity_type=entity_event[DSProps.SYNC_TYPE],
entity_type=entity_event[DSProps.ENTITY_TYPE],
entity_state=self._get_alarm_state(entity_event),
sample_timestamp=sample_timestamp,
update_timestamp=update_timestamp,
@ -124,10 +124,10 @@ class NagiosTransformer(AlarmTransformerBase):
def _create_entity_key(self, entity_event):
sync_type = entity_event[DSProps.SYNC_TYPE]
entity_type = entity_event[DSProps.ENTITY_TYPE]
alarm_name = entity_event[NagiosProperties.SERVICE]
resource_name = entity_event[NagiosProperties.RESOURCE_NAME]
return tbase.build_key(self._key_values(sync_type,
return tbase.build_key(self._key_values(entity_type,
resource_name,
alarm_name))

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import SyncMode
from vitrage.datasources.neutron.base import NeutronBase
from vitrage.datasources.neutron.network import NEUTRON_NETWORK_DATASOURCE
@ -33,10 +33,10 @@ class NetworkDriver(NeutronBase):
return NetworkDriver.make_pickleable([event],
NEUTRON_NETWORK_DATASOURCE,
SyncMode.UPDATE)[0]
ActionType.UPDATE)[0]
def get_all(self, sync_mode):
def get_all(self, action_type):
return self.make_pickleable(
self.client.list_networks()['networks'],
NEUTRON_NETWORK_DATASOURCE,
sync_mode)
action_type)

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import SyncMode
from vitrage.datasources.neutron.base import NeutronBase
from vitrage.datasources.neutron.port import NEUTRON_PORT_DATASOURCE
@ -32,10 +32,10 @@ class PortDriver(NeutronBase):
event[DSProps.EVENT_TYPE] = event_type
return PortDriver.make_pickleable([event], NEUTRON_PORT_DATASOURCE,
SyncMode.UPDATE)[0]
ActionType.UPDATE)[0]
def get_all(self, sync_mode):
def get_all(self, action_type):
return self.make_pickleable(
self.client.list_ports()['ports'],
NEUTRON_PORT_DATASOURCE,
sync_mode)
action_type)

View File

@ -27,9 +27,9 @@ class HostDriver(NovaDriverBase):
compute_hosts.append(host_dict)
return compute_hosts
def get_all(self, sync_mode):
def get_all(self, action_type):
return self.make_pickleable(
self.filter_none_compute_hosts(self.client.hosts.list()),
NOVA_HOST_DATASOURCE,
sync_mode,
action_type,
'manager')

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import SyncMode
from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE
from vitrage.datasources.nova.nova_driver_base import NovaDriverBase
@ -24,12 +24,12 @@ class InstanceDriver(NovaDriverBase):
def extract_events(instances):
return [instance.__dict__ for instance in instances]
def get_all(self, sync_mode):
def get_all(self, action_type):
return self.make_pickleable(
self.extract_events(self.client.servers.list(
search_opts={'all_tenants': 1})),
NOVA_INSTANCE_DATASOURCE,
sync_mode,
action_type,
'manager',
'OS-EXT-SRV-ATTR:user_data',
'_info')
@ -40,7 +40,7 @@ class InstanceDriver(NovaDriverBase):
return InstanceDriver.make_pickleable([event],
NOVA_INSTANCE_DATASOURCE,
SyncMode.UPDATE)[0]
ActionType.UPDATE)[0]
@staticmethod
def get_event_types():

View File

@ -67,7 +67,7 @@ class InstanceTransformer(ResourceTransformerBase):
sample_timestamp = entity_event[DSProps.SAMPLE_DATE]
# TODO(Alexey): need to check here that only the UPDATE sync_mode will
# TODO(Alexey): need to check that only the UPDATE action_type will
# update the UPDATE_TIMESTAMP property
update_timestamp = self._format_update_timestamp(
extract_field_value(entity_event, DSProps.SAMPLE_DATE),

View File

@ -10,8 +10,8 @@
# 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 vitrage.datasources.nova.nova_driver_base import NovaDriverBase
from vitrage.datasources.nova.zone import NOVA_ZONE_DATASOURCE
@ -27,9 +27,9 @@ class ZoneDriver(NovaDriverBase):
zones_res.append(zone_dict)
return zones_res
def get_all(self, sync_mode):
def get_all(self, action_type):
return self.make_pickleable(self.filter_internal_zone(
self.client.availability_zones.list()),
NOVA_ZONE_DATASOURCE,
sync_mode,
action_type,
'manager')

View File

@ -14,7 +14,7 @@
from oslo_log import log
from oslo_service import service as os_service
from vitrage.common.constants import SyncMode
from vitrage.common.constants import ActionType
from vitrage.datasources.rescheduler import ReScheduler
LOG = log.getLogger(__name__)
@ -48,7 +48,8 @@ class SnapshotsService(DatasourceService):
for ds_driver in self.registered_datasources.values():
snap_scheduler.schedule(
func=self.entities_to_queue(ds_driver, SyncMode.INIT_SNAPSHOT),
func=self.entities_to_queue(ds_driver,
ActionType.INIT_SNAPSHOT),
standard_interval=standard_interval,
fault_interval=fault_interval,
times=1,
@ -56,7 +57,7 @@ class SnapshotsService(DatasourceService):
fault_callback=ds_driver.callback_on_fault)
snap_scheduler.schedule(
func=self.entities_to_queue(ds_driver, SyncMode.SNAPSHOT),
func=self.entities_to_queue(ds_driver, ActionType.SNAPSHOT),
initial_delay=standard_interval,
standard_interval=standard_interval,
fault_interval=fault_interval,
@ -66,9 +67,9 @@ class SnapshotsService(DatasourceService):
LOG.info('Vitrage datasources Snapshot Service - Started!')
def entities_to_queue(self, driver, sync_mode):
def entities_to_queue(self, driver, action_type):
def _entities_to_queue():
for entity in driver.get_all(sync_mode):
for entity in driver.get_all(action_type):
self.send_to_queue(entity)
return _entities_to_queue
@ -115,7 +116,7 @@ class ChangesService(DatasourceService):
LOG.debug("start get changes")
for datasource in self.registered_datasources:
try:
for entity in datasource.get_changes(SyncMode.UPDATE):
for entity in datasource.get_changes(ActionType.UPDATE):
self.send_to_queue(entity)
except Exception as e:
LOG.error("Get changes Failed - %s", e.message)

View File

@ -31,16 +31,16 @@ class StaticDriver(DriverBase):
def enrich_event(event, event_type):
pass
def get_all(self, sync_mode):
def get_all(self, action_type):
"""Query all entities and send events to the vitrage events queue"""
return self.make_pickleable(self._get_all_entities(),
STATIC_DATASOURCE,
sync_mode)
action_type)
def get_changes(self, sync_mode):
def get_changes(self, action_type):
return self.make_pickleable(self._get_changes_entities(),
STATIC_DATASOURCE,
sync_mode)
action_type)
def _get_all_entities(self):
"""Internal method to get all entities"""

View File

@ -46,15 +46,15 @@ class StaticTransformer(ResourceTransformerBase):
def _create_entity_key(self, entity_event):
entity_id = entity_event[VProps.ID]
sync_type = entity_event[VProps.TYPE]
key_fields = self._key_values(sync_type, entity_id)
entity_type = entity_event[VProps.TYPE]
key_fields = self._key_values(entity_type, entity_id)
return transformer_base.build_key(key_fields)
def get_type(self):
return STATIC_DATASOURCE
def _create_vertex(self, entity_event):
sync_type = entity_event[VProps.TYPE]
entity_type = entity_event[VProps.TYPE]
entity_id = entity_event[VProps.ID]
sample_timestamp = entity_event[DSProps.SAMPLE_DATE]
update_timestamp = self._format_update_timestamp(
@ -67,7 +67,7 @@ class StaticTransformer(ResourceTransformerBase):
entity_key,
entity_id=entity_id,
entity_category=EntityCategory.RESOURCE,
entity_type=sync_type,
entity_type=entity_type,
sample_timestamp=sample_timestamp,
update_timestamp=update_timestamp,
entity_state=state)

View File

@ -38,15 +38,15 @@ class StaticPhysicalDriver(DriverBase):
self.cfg = conf
self.cache = {}
def get_all(self, sync_mode):
def get_all(self, action_type):
return self.make_pickleable(self._get_all_entities(),
STATIC_PHYSICAL_DATASOURCE,
sync_mode)
action_type)
def get_changes(self, sync_mode):
def get_changes(self, action_type):
return self.make_pickleable(self._get_changes_entities(),
STATIC_PHYSICAL_DATASOURCE,
sync_mode)
action_type)
def _get_all_entities(self):
static_entities = []

View File

@ -52,7 +52,7 @@ class StaticPhysicalTransformer(ResourceTransformerBase):
def _create_vertex(self, entity_event):
sync_type = entity_event[VProps.TYPE]
entity_type = entity_event[VProps.TYPE]
entity_id = entity_event[VProps.ID]
sample_timestamp = entity_event[DSProps.SAMPLE_DATE]
update_timestamp = self._format_update_timestamp(
@ -66,7 +66,7 @@ class StaticPhysicalTransformer(ResourceTransformerBase):
entity_key,
entity_id=entity_id,
entity_category=EntityCategory.RESOURCE,
entity_type=sync_type,
entity_type=entity_type,
sample_timestamp=sample_timestamp,
update_timestamp=update_timestamp,
entity_state=state,
@ -126,8 +126,8 @@ class StaticPhysicalTransformer(ResourceTransformerBase):
def _create_entity_key(self, entity_event):
entity_id = entity_event[VProps.ID]
sync_type = entity_event[VProps.TYPE]
key_fields = self._key_values(sync_type, entity_id)
entity_type = entity_event[VProps.TYPE]
key_fields = self._key_values(entity_type, entity_id)
return transformer_base.build_key(key_fields)
@staticmethod

View File

@ -21,9 +21,9 @@ import six
from vitrage.common import datetime_utils
import vitrage.common.constants as cons
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import EventAction
from vitrage.common.constants import SyncMode
from vitrage.common.constants import UpdateMethod
from vitrage.common.exception import VitrageTransformerError
from vitrage.common import utils
@ -87,7 +87,7 @@ def convert_timestamp_format(current_timestamp_format, timestamp):
def is_update_event(event):
return event[DSProps.SYNC_MODE] == SyncMode.UPDATE
return event[DSProps.ACTION_TYPE] == ActionType.UPDATE
@six.add_metaclass(abc.ABCMeta)
@ -212,21 +212,21 @@ class TransformerBase(object):
:rtype: str
"""
sync_mode = entity_event[DSProps.SYNC_MODE]
action_type = entity_event[DSProps.ACTION_TYPE]
if SyncMode.UPDATE == sync_mode:
if ActionType.UPDATE == action_type:
return self.UPDATE_EVENT_TYPES.get(
entity_event.get(DSProps.EVENT_TYPE, None),
EventAction.UPDATE_ENTITY)
if SyncMode.SNAPSHOT == sync_mode:
if ActionType.SNAPSHOT == action_type:
return EventAction.UPDATE_ENTITY
if SyncMode.INIT_SNAPSHOT == sync_mode:
if ActionType.INIT_SNAPSHOT == action_type:
return EventAction.CREATE_ENTITY
raise VitrageTransformerError(
'Invalid sync mode: (%s)' % sync_mode)
'Invalid action type: (%s)' % action_type)
def _key_values(self, *args):
"""A list of key fields
@ -240,16 +240,16 @@ class TransformerBase(object):
@staticmethod
def _create_end_vertex(entity_event):
sync_type = entity_event[DSProps.SYNC_TYPE]
entity_type = entity_event[DSProps.ENTITY_TYPE]
return graph_utils.create_vertex(
'END_MESSAGE:' + sync_type,
entity_type=sync_type)
'END_MESSAGE:' + entity_type,
entity_type=entity_type)
@staticmethod
def _is_end_message(entity_event):
sync_mode = entity_event[DSProps.SYNC_MODE]
is_snapshot_event = sync_mode == SyncMode.INIT_SNAPSHOT
action_type = entity_event[DSProps.ACTION_TYPE]
is_snapshot_event = action_type == ActionType.INIT_SNAPSHOT
event_type = entity_event.get(DSProps.EVENT_TYPE, None)
return is_snapshot_event and event_type == EventAction.END_MESSAGE

View File

@ -17,8 +17,8 @@ from collections import namedtuple
from oslo_log import log
from oslo_utils import importutils as utils
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import SyncMode
from vitrage.common import file_utils
from vitrage.datasources.alarm_driver_base import AlarmDriverBase
from vitrage.datasources.zabbix.properties import ZabbixProperties as ZProps
@ -63,7 +63,7 @@ class ZabbixDriver(AlarmDriverBase):
LOG.exception('pyzabbix.ZabbixAPI %s', e)
self._client = None
def _sync_type(self):
def _entity_type(self):
return ZABBIX_DATASOURCE
def _alarm_key(self, alarm):
@ -183,7 +183,7 @@ class ZabbixDriver(AlarmDriverBase):
event[ZProps.RESOURCE_TYPE] = v_resource[ZProps.RESOURCE_TYPE]
return ZabbixDriver.make_pickleable([event], ZABBIX_DATASOURCE,
SyncMode.UPDATE)[0]
ActionType.UPDATE)[0]
@staticmethod
def get_event_types():

View File

@ -78,7 +78,7 @@ class ZabbixTransformer(AlarmTransformerBase):
return graph_utils.create_vertex(
self._create_entity_key(entity_event),
entity_category=EntityCategory.ALARM,
entity_type=entity_event[DSProps.SYNC_TYPE],
entity_type=entity_event[DSProps.ENTITY_TYPE],
entity_state=entity_state,
sample_timestamp=sample_timestamp,
update_timestamp=update_timestamp,
@ -138,10 +138,10 @@ class ZabbixTransformer(AlarmTransformerBase):
def _create_entity_key(self, entity_event):
sync_type = entity_event[DSProps.SYNC_TYPE]
entity_type = entity_event[DSProps.ENTITY_TYPE]
alarm_id = entity_event[ZProps.TRIGGER_ID]
resource_name = entity_event[ZProps.RESOURCE_NAME]
return tbase.build_key(self._key_values(sync_type,
return tbase.build_key(self._key_values(entity_type,
resource_name,
alarm_id))

View File

@ -17,10 +17,10 @@ import time
from oslo_log import log
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import EntityCategory
from vitrage.common.constants import EventAction
from vitrage.common.constants import SyncMode
from vitrage.common.constants import VertexProperties as VProps
from vitrage.common.datetime_utils import utcnow
from vitrage.datasources.consistency import CONSISTENCY_DATASOURCE
@ -152,8 +152,8 @@ class ConsistencyEnforcer(object):
def _push_events_to_queue(self, vertices, action):
for vertex in vertices:
event = {
DSProps.SYNC_TYPE: CONSISTENCY_DATASOURCE,
DSProps.SYNC_MODE: SyncMode.UPDATE,
DSProps.ENTITY_TYPE: CONSISTENCY_DATASOURCE,
DSProps.ACTION_TYPE: ActionType.UPDATE,
DSProps.SAMPLE_DATE: str(utcnow()),
DSProps.EVENT_TYPE: action,
VProps.VITRAGE_ID: vertex[VProps.VITRAGE_ID]

View File

@ -67,21 +67,21 @@ class TransformerManager(object):
return transformer
def transform(self, entity_event):
sync_type = self.get_sync_type(entity_event)
return self.get_transformer(sync_type).transform(entity_event)
entity_type = self.get_entity_type(entity_event)
return self.get_transformer(entity_type).transform(entity_event)
def get_enrich_query(self, entity_event):
sync_type = self.get_sync_type(entity_event)
return self.get_transformer(sync_type).get_enrich_query(entity_event)
entity_type = self.get_entity_type(entity_event)
return self.get_transformer(entity_type).get_enrich_query(entity_event)
def extract_key(self, entity_event):
sync_type = self.get_sync_type(entity_event)
return self.get_transformer(sync_type)._create_entity_key()
entity_type = self.get_entity_type(entity_event)
return self.get_transformer(entity_type)._create_entity_key()
@staticmethod
def get_sync_type(entity_event):
def get_entity_type(entity_event):
try:
return entity_event[DSProps.SYNC_TYPE]
return entity_event[DSProps.ENTITY_TYPE]
except KeyError:
raise VitrageTransformerError(
'Entity Event must contains sync_type field.')
'Entity Event must contains entity_type field.')

View File

@ -16,8 +16,8 @@ import copy
from oslo_utils import importutils
from vitrage.common.constants import ActionType as AType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import SyncMode
from vitrage.common.constants import VertexProperties as VProps
from vitrage.common import datetime_utils
from vitrage.evaluator.actions.base import ActionMode
@ -103,8 +103,8 @@ class ActionExecutor(object):
@staticmethod
def _add_default_properties(event):
event[DSProps.SYNC_MODE] = SyncMode.UPDATE
event[DSProps.SYNC_TYPE] = VITRAGE_TYPE
event[DSProps.ACTION_TYPE] = AType.UPDATE
event[DSProps.ENTITY_TYPE] = VITRAGE_TYPE
event[VProps.UPDATE_TIMESTAMP] = str(datetime_utils.utcnow(False))
event[VProps.SAMPLE_TIMESTAMP] = str(datetime_utils.utcnow())

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import SyncMode
from vitrage.entity_graph.initialization_status import InitializationStatus
from vitrage.entity_graph.processor import processor as proc
from vitrage.tests.mocks import mock_driver
@ -38,15 +38,15 @@ class TestFunctionalBase(TestEntityGraphUnitBase):
self.NUM_ZONES,
self.NUM_HOSTS,
snapshot_events=self.NUM_ZONES,
snap_vals={DSProps.SYNC_MODE: SyncMode.INIT_SNAPSHOT})
snap_vals={DSProps.ACTION_TYPE: ActionType.INIT_SNAPSHOT})
gen_list += mock_driver.simple_host_generators(
self.NUM_ZONES,
self.NUM_HOSTS,
self.NUM_HOSTS,
snap_vals={DSProps.SYNC_MODE: SyncMode.INIT_SNAPSHOT})
snap_vals={DSProps.ACTION_TYPE: ActionType.INIT_SNAPSHOT})
gen_list += mock_driver.simple_instance_generators(
self.NUM_HOSTS,
self.NUM_INSTANCES,
self.NUM_INSTANCES,
snap_vals={DSProps.SYNC_MODE: SyncMode.INIT_SNAPSHOT})
snap_vals={DSProps.ACTION_TYPE: ActionType.INIT_SNAPSHOT})
return mock_driver.generate_sequential_events_list(gen_list)

View File

@ -67,7 +67,7 @@ class TestStaticPhysical(TestDataSourcesBase):
snapshot_events=1)
static_events = mock_driver.generate_random_events_list(spec_list)
static_physical_event = static_events[0]
static_physical_event[DSProps.SYNC_TYPE] = SWITCH
static_physical_event[DSProps.ENTITY_TYPE] = SWITCH
static_physical_event['relationships'][0]['name'] = \
self._find_entity_id_by_type(processor.entity_graph,
NOVA_HOST_DATASOURCE)

View File

@ -14,8 +14,8 @@
from oslo_config import cfg
from vitrage.common.constants import ActionType
from vitrage.common.constants import EventAction
from vitrage.common.constants import SyncMode
from vitrage.common.constants import VertexProperties as VProps
from vitrage.datasources.nova.instance.transformer import InstanceTransformer
from vitrage.entity_graph.initialization_status import InitializationStatus
@ -40,7 +40,7 @@ class TestDatasourceInfoMapperFunctional(TestFunctionalBase):
# setup
processor = proc.Processor(self.conf, InitializationStatus())
event = self._create_event(spec_type='INSTANCE_SPEC',
sync_mode=SyncMode.INIT_SNAPSHOT)
action_type=ActionType.INIT_SNAPSHOT)
# action
processor.process_event(event)
@ -57,7 +57,7 @@ class TestDatasourceInfoMapperFunctional(TestFunctionalBase):
# setup
vertex, neighbors, processor = self._create_entity(
spec_type='INSTANCE_SPEC',
sync_mode=SyncMode.INIT_SNAPSHOT)
action_type=ActionType.INIT_SNAPSHOT)
self.assertEqual(2, processor.entity_graph.num_vertices())
neighbors[0].vertex[VProps.STATE] = 'available'

View File

@ -259,8 +259,8 @@ class TestActionExecutor(TestFunctionalBase):
'service': 'Check_MK',
'status': 'CRITICAL',
'status_info': 'test test test',
'vitrage_sync_mode': 'snapshot',
'vitrage_sync_type': 'nagios',
'vitrage_action_type': 'snapshot',
'vitrage_entity_type': 'nagios',
'vitrage_sample_date': '2016-02-07 15:26:04'}
@staticmethod
@ -268,10 +268,10 @@ class TestActionExecutor(TestFunctionalBase):
return {'target': target_vertex.vertex_id,
'update_timestamp': '2016-03-17 11:33:32.443002',
'vitrage_sync_mode': 'update',
'vitrage_action_type': 'update',
'alarm_name': alarm_name,
'state': 'Active',
'type': 'add_vertex',
'vitrage_sync_type': 'vitrage',
'vitrage_entity_type': 'vitrage',
'severity': 'CRITICAL',
'sample_timestamp': '2016-03-17 11:33:32.443002+00:00'}

View File

@ -29,7 +29,7 @@ from vitrage.tests.mocks import utils
LOG = logging.getLogger(__name__)
_TARGET_HOST = 'host-2'
_NAGIOS_TEST_INFO = {'resource_name': _TARGET_HOST, 'sync_mode': 'snapshot'}
_NAGIOS_TEST_INFO = {'resource_name': _TARGET_HOST, 'action_type': 'snapshot'}
class TestScenarioEvaluator(TestFunctionalBase):

View File

@ -350,7 +350,7 @@ def simple_switch_generators(switch_num, host_num,
)
if update_events:
update_vals = {} if not update_vals else update_vals
update_vals['sync_mode'] = 'update'
update_vals['action_type'] = 'update'
test_entity_spec_list.append(
{tg.DYNAMIC_INFO_FKEY: tg.DRIVER_SWITCH_SNAPSHOT_D,
tg.STATIC_INFO_FKEY: None,

View File

@ -1,7 +1,7 @@
{
"vitrage_sample_date": "2015-12-01T12:46:41Z",
"vitrage_sync_type": "consistency",
"vitrage_sync_mode": "update",
"vitrage_entity_type": "consistency",
"vitrage_action_type": "update",
"vitrage_event_type": "delete_entity",
"vitrage_id": "[0-9]{5}"
}

View File

@ -7,8 +7,8 @@
"_loaded": "True",
"host_name": "compute-0-0.local",
"service": "compute",
"vitrage_sync_type": "nova.host",
"vitrage_entity_type": "nova.host",
"zone": "zone0",
"vitrage_sync_mode": "init_snapshot",
"vitrage_action_type": "init_snapshot",
"vitrage_sample_date": "2015-12-01T12:46:41Z"
}

View File

@ -1,7 +1,7 @@
{
"OS-EXT-STS:task_state": null,
"vitrage_sync_mode": "snapshot",
"vitrage_sync_type": "nova.instance",
"vitrage_action_type": "snapshot",
"vitrage_entity_type": "nova.instance",
"vitrage_sample_date": "2015-12-01T12:46:41Z",
"addresses": {
"public": [

View File

@ -1,5 +1,5 @@
{
"vitrage_sync_mode": "update",
"vitrage_action_type": "update",
"vitrage_sample_date": "2015-12-01T12:46:41Z",
"publisher_id": "compute.emalin-devstack",
"vitrage_event_type": "compute.instance.pause.end|compute.instance.delete.end|compute.instance.create.start",

View File

@ -1,5 +1,5 @@
{
"vitrage_sync_type": "nagios",
"vitrage_entity_type": "nagios",
"resource_type": "nova.host",
"resource_name": "compute-[1-9]",
"service": "CPU utilization",
@ -9,5 +9,5 @@
"vitrage_sample_date": "2015-12-01T12:46:41Z",
"attempt": "1/1",
"status_info": "OK - user: 0\\.6%, system: 0\\.3%, wait: 0\\.4%",
"vitrage_sync_mode": "snapshot"
"vitrage_action_type": "snapshot"
}

View File

@ -4,11 +4,11 @@
"creation_time": "2016-08-25T13:03:36",
"stack_owner": "admin",
"project": "a077142e250543be90f6fce8f623d45d",
"vitrage_sync_mode": "init_snapshot",
"vitrage_action_type": "init_snapshot",
"id": "f22416fb-b33c-4e24-822e-0174421f5ece",
"stack_status": "CREATE_COMPLETE",
"vitrage_sample_date": "2016-08-2515:12:28.281460+00:00",
"vitrage_sync_type": "heat.stack",
"vitrage_entity_type": "heat.stack",
"resources": [{
"resource_name": "cinder_volume_1",
"logical_resource_id": "cinder_volume_1",

View File

@ -4,12 +4,12 @@
"stack_name": "newstack",
"tenant_id": "a077142e250543be90f6fce8f623d45d",
"stack_identity": "d2df0a2a-765c-44ef-b117-32d599bc9c3b",
"vitrage_sync_mode": "update",
"vitrage_action_type": "update",
"create_at": "2016-08-25T15:23:02",
"state": "CREATE_COMPLETE",
"vitrage_event_type": "orchestration.stack.create.end",
"vitrage_sample_date": "2016-08-2515:23:23.150274+00:00",
"vitrage_sync_type": "heat.stack",
"vitrage_entity_type": "heat.stack",
"user_identity": "3515b9535e5d4c9e82cb166324ca29dd",
"resources": [{
"resource_name": "cinder_volume_1",

View File

@ -10,7 +10,7 @@
"id": "[1-9]{5}",
"vitrage_sample_date": "2015-12-01T12:46:41Z",
"type": "switch",
"vitrage_sync_mode": "snapshot",
"vitrage_action_type": "snapshot",
"state": "available",
"vitrage_event_type": "entity_update"
}

View File

@ -4,8 +4,8 @@
"created_at": "2015-12-01T12:46:41Z",
"status": "In-use",
"id": "12345",
"vitrage_sync_type": "cinder.volume",
"vitrage_sync_mode": "snapshot",
"vitrage_entity_type": "cinder.volume",
"vitrage_action_type": "snapshot",
"vitrage_sample_date": "2015-12-01T12:46:41Z",
"volume_type": "lvmdriver-1",
"size": "1559"

View File

@ -4,8 +4,8 @@
"updated_at": "2015-12-01T12:46:41Z",
"status": "In-use",
"volume_id": "12345",
"vitrage_sync_type": "cinder.volume",
"vitrage_sync_mode": "update",
"vitrage_entity_type": "cinder.volume",
"vitrage_action_type": "update",
"vitrage_event_type": "volume.create.start",
"vitrage_sample_date": "2015-12-01T12:46:41Z",
"volume_type": "SCSIID",

View File

@ -1,5 +1,5 @@
{
"vitrage_sync_type": "zabbix",
"vitrage_entity_type": "zabbix",
"resource_type": "nova.host",
"resource_name": "compute-[1-9]",
"zabbix_resource_name": "computer-[1-9]",
@ -12,6 +12,6 @@
"vitrage_sample_date": "2015-12-01T12:46:41Z",
"value": "1",
"priority": "1",
"vitrage_sync_mode": "snapshot",
"vitrage_action_type": "snapshot",
"rawtext": "CPU utilization"
}

View File

@ -9,8 +9,8 @@
"_loaded": "True",
"hosts": {},
"vitrage_sample_date": "2015-12-01T12:46:41Z",
"vitrage_sync_type": "nova.zone",
"vitrage_sync_mode": "snapshot",
"vitrage_entity_type": "nova.zone",
"vitrage_action_type": "snapshot",
"zoneName": "zone0",
"zoneState": {
"available": "True"

View File

@ -1,5 +1,5 @@
{
"vitrage_sync_mode": "init_snapshot",
"vitrage_action_type": "init_snapshot",
"id": "host[0-3]",
"name": "host[0-3]",
"zone_id": "zone[0-1]",

View File

@ -1,5 +1,5 @@
{
"vitrage_sync_mode": "init_snapshot",
"vitrage_action_type": "init_snapshot",
"image": "cirros-[a-z]+",
"status": "ACTIVE",
"tenant_id": "[0-9a-f]{32}",
@ -9,7 +9,7 @@
"id": "vm[0-1][0-9]",
"name": "vm[0-9]{3}",
"vitrage_event_type": "update",
"vitrage_sync_type": "nova.instance",
"vitrage_entity_type": "nova.instance",
"vitrage_sample_date": "2015-12-01T12:46:41Z"
}

View File

@ -1,5 +1,5 @@
{
"vitrage_sync_mode": "init_snapshot",
"vitrage_action_type": "init_snapshot",
"id": "zone[0-1]",
"name": "zone[0-1]",
"vitrage_event_type": "update",

View File

@ -162,7 +162,7 @@ class TestCinderVolumeTransformer(base.BaseTest):
is_update_event = tbase.is_update_event(event)
self.assertEqual(EntityCategory.RESOURCE, vertex[VProps.CATEGORY])
self.assertEqual(event[DSProps.SYNC_TYPE], vertex[VProps.TYPE])
self.assertEqual(event[DSProps.ENTITY_TYPE], vertex[VProps.TYPE])
id_field_path = 'volume_id' if is_update_event else 'id'
self.assertEqual(

View File

@ -163,7 +163,7 @@ class TestHeatStackTransformer(base.BaseTest):
is_update_event = tbase.is_update_event(event)
self.assertEqual(EntityCategory.RESOURCE, vertex[VProps.CATEGORY])
self.assertEqual(event[DSProps.SYNC_TYPE], vertex[VProps.TYPE])
self.assertEqual(event[DSProps.ENTITY_TYPE], vertex[VProps.TYPE])
id_field_path = 'stack_identity' if is_update_event else 'id'
self.assertEqual(

View File

@ -15,11 +15,11 @@
from oslo_config import cfg
from oslo_log import log as logging
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import EdgeLabel
from vitrage.common.constants import EntityCategory
from vitrage.common.constants import EventAction
from vitrage.common.constants import SyncMode
from vitrage.common.constants import UpdateMethod
from vitrage.common.constants import VertexProperties as VProps
from vitrage.datasources.alarm_properties import AlarmProperties as AlarmProps
@ -72,7 +72,7 @@ class NagiosTransformerTest(base.BaseTest):
TransformerBase.KEY_SEPARATOR)
self.assertEqual(EntityCategory.ALARM, observed_key_fields[0])
self.assertEqual(event[DSProps.SYNC_TYPE], observed_key_fields[1])
self.assertEqual(event[DSProps.ENTITY_TYPE], observed_key_fields[1])
self.assertEqual(event[NagiosProperties.RESOURCE_NAME],
observed_key_fields[2])
self.assertEqual(event[NagiosProperties.SERVICE],
@ -103,8 +103,8 @@ class NagiosTransformerTest(base.BaseTest):
self._validate_action(alarm, wrapper)
def _validate_action(self, alarm, wrapper):
sync_mode = alarm[DSProps.SYNC_MODE]
if sync_mode in (SyncMode.SNAPSHOT, SyncMode.UPDATE):
action_type = alarm[DSProps.ACTION_TYPE]
if action_type in (ActionType.SNAPSHOT, ActionType.UPDATE):
if alarm[NagiosProperties.STATUS] == 'OK':
self.assertEqual(EventAction.DELETE_ENTITY, wrapper.action)
else:
@ -115,7 +115,7 @@ class NagiosTransformerTest(base.BaseTest):
def _validate_vertex(self, vertex, event):
self.assertEqual(EntityCategory.ALARM, vertex[VProps.CATEGORY])
self.assertEqual(event[DSProps.SYNC_TYPE], vertex[VProps.TYPE])
self.assertEqual(event[DSProps.ENTITY_TYPE], vertex[VProps.TYPE])
self.assertEqual(event[NagiosProperties.SERVICE], vertex[VProps.NAME])
event_type = event.get(DSProps.EVENT_TYPE, None)

View File

@ -17,11 +17,11 @@ import datetime
from oslo_config import cfg
from oslo_log import log as logging
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import EdgeLabel
from vitrage.common.constants import EntityCategory
from vitrage.common.constants import EventAction
from vitrage.common.constants import SyncMode
from vitrage.common.constants import UpdateMethod
from vitrage.common.constants import VertexProperties
from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE
@ -133,7 +133,7 @@ class NovaHostTransformerTest(base.BaseTest):
self.assertEqual(1, len(neighbors))
self._validate_zone_neighbor(neighbors[0], event)
if SyncMode.SNAPSHOT == event[DSProps.SYNC_MODE]:
if ActionType.SNAPSHOT == event[DSProps.ACTION_TYPE]:
self.assertEqual(EventAction.UPDATE_ENTITY, wrapper.action)
else:
self.assertEqual(EventAction.CREATE_ENTITY, wrapper.action)
@ -200,7 +200,7 @@ class NovaHostTransformerTest(base.BaseTest):
zone_num=1,
host_num=1,
snapshot_events=1,
snap_vals={DSProps.SYNC_MODE: SyncMode.SNAPSHOT})
snap_vals={DSProps.ACTION_TYPE: ActionType.SNAPSHOT})
hosts_events = mock_sync.generate_random_events_list(spec_list)
host_transformer = self.transformers[NOVA_HOST_DATASOURCE]
@ -216,7 +216,7 @@ class NovaHostTransformerTest(base.BaseTest):
zone_num=1,
host_num=1,
snapshot_events=1,
snap_vals={DSProps.SYNC_MODE: SyncMode.INIT_SNAPSHOT})
snap_vals={DSProps.ACTION_TYPE: ActionType.INIT_SNAPSHOT})
hosts_events = mock_sync.generate_random_events_list(spec_list)
host_transformer = self.transformers[NOVA_HOST_DATASOURCE]

View File

@ -17,11 +17,11 @@ import datetime
from oslo_config import cfg
from oslo_log import log as logging
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import EdgeLabel
from vitrage.common.constants import EntityCategory
from vitrage.common.constants import EventAction
from vitrage.common.constants import SyncMode
from vitrage.common.constants import UpdateMethod
from vitrage.common.constants import VertexProperties
from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE
@ -118,10 +118,10 @@ class NovaInstanceTransformerTest(base.BaseTest):
host_neighbor = wrapper.neighbors[0]
self._validate_host_neighbor(host_neighbor, event)
sync_mode = event[DSProps.SYNC_MODE]
if sync_mode == SyncMode.INIT_SNAPSHOT:
action_type = event[DSProps.ACTION_TYPE]
if action_type == ActionType.INIT_SNAPSHOT:
self.assertEqual(EventAction.CREATE_ENTITY, wrapper.action)
elif sync_mode == SyncMode.SNAPSHOT:
elif action_type == ActionType.SNAPSHOT:
self.assertEqual(EventAction.UPDATE_ENTITY, wrapper.action)
def test_update_event_transform(self):

View File

@ -152,7 +152,7 @@ class NovaZoneTransformerTest(base.BaseTest):
self._validate_host_neighbor(neighbor,
zone_vertex_id,
hosts,
event[DSProps.SYNC_MODE])
event[DSProps.ACTION_TYPE])
self.assertEqual(1,
cluster_neighbors_counter,
@ -162,7 +162,7 @@ class NovaZoneTransformerTest(base.BaseTest):
host_neighbor,
zone_vertex_id,
hosts,
sync_mode):
action_type):
host_vertex = host_neighbor.vertex
host_vertex_id = host_vertex.get(VertexProperties.ID)

View File

@ -15,8 +15,8 @@
from oslo_config import cfg
from oslo_log import log as logging
from vitrage.common.constants import ActionType
from vitrage.common.constants import EventAction
from vitrage.common.constants import SyncMode
from vitrage.datasources.static import driver
from vitrage.datasources.static import STATIC_DATASOURCE
from vitrage.tests import base
@ -70,7 +70,7 @@ class TestStaticDriver(base.BaseTest):
def test_get_all(self):
# Action
static_entities = self.static_driver.get_all(SyncMode.UPDATE)
static_entities = self.static_driver.get_all(ActionType.UPDATE)
# Test assertions
self.assertEqual(0, len(static_entities))
@ -78,7 +78,7 @@ class TestStaticDriver(base.BaseTest):
# noinspection PyAttributeOutsideInit
def test_get_changes(self):
# Setup
entities = self.static_driver.get_all(SyncMode.UPDATE)
entities = self.static_driver.get_all(ActionType.UPDATE)
self.assertEqual(0, len(entities))
self.conf = cfg.ConfigOpts()

View File

@ -17,9 +17,9 @@ import os
from oslo_config import cfg
from oslo_log import log as logging
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import EventAction
from vitrage.common.constants import SyncMode
from vitrage.common.constants import VertexProperties as VProps
from vitrage.common import file_utils
from vitrage.datasources.static_physical import driver
@ -92,7 +92,8 @@ class TestStaticPhysicalDriver(base.BaseTest):
def test_get_all(self):
# Action
static_entities = self.static_physical_driver.get_all(SyncMode.UPDATE)
static_entities = \
self.static_physical_driver.get_all(ActionType.UPDATE)
# Test assertions
self.assertEqual(5, len(static_entities))
@ -100,7 +101,7 @@ class TestStaticPhysicalDriver(base.BaseTest):
# noinspection PyAttributeOutsideInit
def test_get_changes(self):
# Setup
entities = self.static_physical_driver.get_all(SyncMode.UPDATE)
entities = self.static_physical_driver.get_all(ActionType.UPDATE)
self.assertEqual(5, len(entities))
self.conf = cfg.ConfigOpts()

View File

@ -15,11 +15,11 @@
from oslo_config import cfg
from oslo_log import log as logging
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import EdgeLabel
from vitrage.common.constants import EntityCategory
from vitrage.common.constants import EventAction
from vitrage.common.constants import SyncMode
from vitrage.common.constants import UpdateMethod
from vitrage.common.constants import VertexProperties as VProps
from vitrage.common.datetime_utils import format_unix_timestamp
@ -77,7 +77,7 @@ class ZabbixTransformerTest(base.BaseTest):
TransformerBase.KEY_SEPARATOR)
self.assertEqual(EntityCategory.ALARM, observed_key_fields[0])
self.assertEqual(event[DSProps.SYNC_TYPE], observed_key_fields[1])
self.assertEqual(event[DSProps.ENTITY_TYPE], observed_key_fields[1])
self.assertEqual(event[ZabbixProps.RESOURCE_NAME],
observed_key_fields[2])
self.assertEqual(event[ZabbixProps.TRIGGER_ID],
@ -109,8 +109,8 @@ class ZabbixTransformerTest(base.BaseTest):
self._validate_action(alarm, wrapper)
def _validate_action(self, alarm, wrapper):
sync_mode = alarm[DSProps.SYNC_MODE]
if sync_mode in (SyncMode.SNAPSHOT, SyncMode.UPDATE):
action_type = alarm[DSProps.ACTION_TYPE]
if action_type in (ActionType.SNAPSHOT, ActionType.UPDATE):
if alarm[ZabbixProps.VALUE] == ZabbixTriggerValue.OK:
self.assertEqual(EventAction.DELETE_ENTITY, wrapper.action)
else:
@ -121,7 +121,7 @@ class ZabbixTransformerTest(base.BaseTest):
def _validate_vertex(self, vertex, event):
self.assertEqual(EntityCategory.ALARM, vertex[VProps.CATEGORY])
self.assertEqual(event[DSProps.SYNC_TYPE], vertex[VProps.TYPE])
self.assertEqual(event[DSProps.ENTITY_TYPE], vertex[VProps.TYPE])
self.assertEqual(event[ZabbixProps.DESCRIPTION],
vertex[VProps.NAME])

View File

@ -14,9 +14,9 @@
from oslo_config import cfg
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import EntityCategory
from vitrage.common.constants import SyncMode
from vitrage.datasources.nagios import NAGIOS_DATASOURCE
from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE
from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE
@ -80,24 +80,24 @@ class TestEntityGraphUnitBase(base.BaseTest):
self.NUM_ZONES,
self.NUM_HOSTS,
snapshot_events=self.NUM_ZONES,
snap_vals={DSProps.SYNC_MODE: SyncMode.INIT_SNAPSHOT})
snap_vals={DSProps.ACTION_TYPE: ActionType.INIT_SNAPSHOT})
gen_list += mock_sync.simple_host_generators(
self.NUM_ZONES,
self.NUM_HOSTS,
self.NUM_HOSTS,
snap_vals={DSProps.SYNC_MODE: SyncMode.INIT_SNAPSHOT})
snap_vals={DSProps.ACTION_TYPE: ActionType.INIT_SNAPSHOT})
gen_list += mock_sync.simple_instance_generators(
self.NUM_HOSTS,
self.NUM_INSTANCES,
self.NUM_INSTANCES,
snap_vals={DSProps.SYNC_MODE: SyncMode.INIT_SNAPSHOT})
snap_vals={DSProps.ACTION_TYPE: ActionType.INIT_SNAPSHOT})
return mock_sync.generate_sequential_events_list(gen_list)
def _create_entity(self, processor=None, spec_type=None, sync_mode=None,
def _create_entity(self, processor=None, spec_type=None, action_type=None,
event_type=None, properties=None):
# create instance event with host neighbor
event = self._create_event(spec_type=spec_type,
sync_mode=sync_mode,
action_type=action_type,
event_type=event_type,
properties=properties)
@ -112,7 +112,7 @@ class TestEntityGraphUnitBase(base.BaseTest):
return vertex, neighbors, processor
@staticmethod
def _create_event(spec_type=None, sync_mode=None,
def _create_event(spec_type=None, action_type=None,
event_type=None, properties=None):
# generate event
spec_list = mock_sync.simple_instance_generators(1, 1, 1)
@ -120,8 +120,8 @@ class TestEntityGraphUnitBase(base.BaseTest):
spec_list)
# update properties
if sync_mode is not None:
events_list[0][DSProps.SYNC_MODE] = sync_mode
if action_type is not None:
events_list[0][DSProps.ACTION_TYPE] = action_type
if event_type is not None:
events_list[0][DSProps.EVENT_TYPE] = event_type

View File

@ -14,9 +14,9 @@
from oslo_config import cfg
from vitrage.common.constants import ActionType
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import EventAction
from vitrage.common.constants import SyncMode
from vitrage.common.constants import VertexProperties as VProps
from vitrage.common.datetime_utils import utcnow
from vitrage.datasources.transformer_base import Neighbor
@ -51,13 +51,13 @@ class TestProcessor(TestEntityGraphUnitBase):
# check create instance event
processor = proc.Processor(self.conf, InitializationStatus())
event = self._create_event(spec_type=self.INSTANCE_SPEC,
sync_mode=SyncMode.INIT_SNAPSHOT)
action_type=ActionType.INIT_SNAPSHOT)
processor.process_event(event)
self._check_graph(processor, self.NUM_VERTICES_AFTER_CREATION,
self.NUM_EDGES_AFTER_CREATION)
# check update instance even
event[DSProps.SYNC_MODE] = SyncMode.UPDATE
event[DSProps.ACTION_TYPE] = ActionType.UPDATE
event[DSProps.EVENT_TYPE] = 'compute.instance.volume.attach'
event['hostname'] = 'new_host'
event['instance_id'] = event['id']
@ -68,7 +68,7 @@ class TestProcessor(TestEntityGraphUnitBase):
self.NUM_EDGES_AFTER_CREATION)
# check delete instance event
event[DSProps.SYNC_MODE] = SyncMode.UPDATE
event[DSProps.ACTION_TYPE] = ActionType.UPDATE
event[DSProps.EVENT_TYPE] = 'compute.instance.delete.end'
processor.process_event(event)
self._check_graph(processor, self.NUM_VERTICES_AFTER_DELETION,
@ -133,10 +133,10 @@ class TestProcessor(TestEntityGraphUnitBase):
# setup
vertex1, neighbors1, processor = self._create_entity(
spec_type=self.INSTANCE_SPEC,
sync_mode=SyncMode.INIT_SNAPSHOT)
action_type=ActionType.INIT_SNAPSHOT)
vertex2, neighbors2, processor = self._create_entity(
spec_type=self.INSTANCE_SPEC,
sync_mode=SyncMode.INIT_SNAPSHOT,
action_type=ActionType.INIT_SNAPSHOT,
processor=processor)
self.assertEqual(2, processor.entity_graph.num_edges())
@ -155,10 +155,10 @@ class TestProcessor(TestEntityGraphUnitBase):
# setup
vertex1, neighbors1, processor = self._create_entity(
spec_type=self.INSTANCE_SPEC,
sync_mode=SyncMode.INIT_SNAPSHOT)
action_type=ActionType.INIT_SNAPSHOT)
vertex2, neighbors2, processor = self._create_entity(
spec_type=self.INSTANCE_SPEC,
sync_mode=SyncMode.INIT_SNAPSHOT,
action_type=ActionType.INIT_SNAPSHOT,
processor=processor)
self.assertEqual(2, processor.entity_graph.num_edges())
@ -179,7 +179,7 @@ class TestProcessor(TestEntityGraphUnitBase):
# setup
vertex, neighbors, processor = self._create_entity(
spec_type=self.INSTANCE_SPEC,
sync_mode=SyncMode.INIT_SNAPSHOT)
action_type=ActionType.INIT_SNAPSHOT)
self.assertEqual(1, processor.entity_graph.num_edges())
vertex[VProps.IS_DELETED] = True
processor.entity_graph.update_vertex(vertex)
@ -302,7 +302,7 @@ class TestProcessor(TestEntityGraphUnitBase):
# create instance event with host neighbor
(vertex, neighbors, processor) = self._create_entity(
spec_type=self.INSTANCE_SPEC,
sync_mode=SyncMode.INIT_SNAPSHOT,
action_type=ActionType.INIT_SNAPSHOT,
properties=kwargs,
processor=processor)

View File

@ -45,9 +45,10 @@ class BaseMock(testtools.TestCase):
@staticmethod
def _create_mock_events():
gen_list = mock_sync.simple_zone_generators(
2, 4, snapshot_events=2, snap_vals={'sync_mode': 'init_snapshot'})
2, 4, snapshot_events=2,
snap_vals={'action_type': 'init_snapshot'})
gen_list += mock_sync.simple_host_generators(
2, 4, 4, snap_vals={'sync_mode': 'init_snapshot'})
2, 4, 4, snap_vals={'action_type': 'init_snapshot'})
gen_list += mock_sync.simple_instance_generators(
4, 15, 15, snap_vals={'sync_mode': 'init_snapshot'})
4, 15, 15, snap_vals={'action_type': 'init_snapshot'})
return mock_sync.generate_sequential_events_list(gen_list)