Check if instance_id is not None

get_label returns instance_id that can be None [1].
It could lead to the exception [2]. The patch will
resolve it.

[1] https://github.com/openstack/vitrage/blob/master/vitrage/datasources/prometheus/properties.py#L56
[2] http://paste.openstack.org/show/738265/

Change-Id: Ic914832fde53cd904bfc0e3313348d3025c69ca0
This commit is contained in:
Kien Nguyen 2018-12-24 16:06:01 +07:00
parent f617f65a1b
commit d7d4188d06

View File

@ -148,17 +148,18 @@ class PrometheusDriver(AlarmDriverBase):
alarm[DSProps.EVENT_TYPE] = event_type alarm[DSProps.EVENT_TYPE] = event_type
alarm[PProps.STATUS] = details[PProps.STATUS] alarm[PProps.STATUS] = details[PProps.STATUS]
instance_id = get_label(alarm, PLabels.INSTANCE) instance_id = get_label(alarm, PLabels.INSTANCE)
if ':' in instance_id: if instance_id is not None:
instance_id = instance_id[:instance_id.index(':')] if ':' in instance_id:
instance_id = instance_id[:instance_id.index(':')]
# The 'instance' label can be instance ip or hostname. # The 'instance' label can be instance ip or hostname.
# we try to fetch the instance id from nova by its ip, # we try to fetch the instance id from nova by its ip,
# and if not found we leave it as it is. # and if not found we leave it as it is.
nova_instance = self.nova_client.servers.list( nova_instance = self.nova_client.servers.list(
search_opts={'all_tenants': 1, 'ip': instance_id}) search_opts={'all_tenants': 1, 'ip': instance_id})
if nova_instance: if nova_instance:
instance_id = nova_instance[0].id instance_id = nova_instance[0].id
alarm[PLabels.INSTANCE_ID] = instance_id alarm[PLabels.INSTANCE_ID] = instance_id
old_alarm = self._old_alarm(alarm) old_alarm = self._old_alarm(alarm)
alarm = self._filter_and_cache_alarm( alarm = self._filter_and_cache_alarm(