diff --git a/lower-constraints.txt b/lower-constraints.txt index 590961738..44f5e3937 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -102,7 +102,7 @@ python-novaclient==10.1.0 python-openstackclient==3.12.0 python-subunit==1.2.0 python-swiftclient==3.5.0 -pytz==2018.3 +pytz==2013.6 PyYAML==3.12 pyzabbix==0.7.4 reno==2.7.0 diff --git a/requirements.txt b/requirements.txt index 90f4a21fa..4407e2714 100644 --- a/requirements.txt +++ b/requirements.txt @@ -47,3 +47,4 @@ six>=1.11.0 # MIT debtcollector>=1.19.0 # Apache-2.0 cotyledon>=1.6.8 # Apache-2.0 futures>=3.0.0;python_version=='2.7' or python_version=='2.6' # BSD +pytz>=2013.6 # MIT \ No newline at end of file diff --git a/vitrage/api_handler/apis/alarm.py b/vitrage/api_handler/apis/alarm.py index f9fe79533..0a69bcf4a 100755 --- a/vitrage/api_handler/apis/alarm.py +++ b/vitrage/api_handler/apis/alarm.py @@ -11,10 +11,9 @@ # 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 dateutil import parser import json + from oslo_log import log from osprofiler import profiler @@ -107,9 +106,14 @@ class AlarmApis(EntityGraphApisBase): alarm.payload[VProps.VITRAGE_OPERATIONAL_SEVERITY] = \ OperationalAlarmSeverity.OK for alarm in alarms: - alarm.payload[HProps.START_TIMESTAMP] = str(alarm.start_timestamp) + start_timestamp = \ + self.db.history_facade.add_utc_timezone(alarm.start_timestamp) + alarm.payload[HProps.START_TIMESTAMP] = str(start_timestamp) if alarm.end_timestamp <= db_time(): - alarm.payload[HProps.END_TIMESTAMP] = str(alarm.end_timestamp) + end_timestamp = \ + self.db.history_facade.add_utc_timezone( + alarm.end_timestamp) + alarm.payload[HProps.END_TIMESTAMP] = str(end_timestamp) return alarms diff --git a/vitrage/api_handler/apis/rca.py b/vitrage/api_handler/apis/rca.py index 56c789c66..ef2404f77 100644 --- a/vitrage/api_handler/apis/rca.py +++ b/vitrage/api_handler/apis/rca.py @@ -51,9 +51,13 @@ class RcaApis(EntityGraphApisBase): admin=is_admin_project) for n in db_nodes: - n.payload[HProps.START_TIMESTAMP] = str(n.start_timestamp) + start_timestamp = \ + self.db.history_facade.add_utc_timezone(n.start_timestamp) + n.payload[HProps.START_TIMESTAMP] = str(start_timestamp) if n.end_timestamp <= db_time(): - n.payload[HProps.END_TIMESTAMP] = str(n.end_timestamp) + end_timestamp = \ + self.db.history_facade.add_utc_timezone(n.end_timestamp) + n.payload[HProps.END_TIMESTAMP] = str(end_timestamp) vertices = [Vertex(vertex_id=n.vitrage_id, properties=n.payload) for n in db_nodes] diff --git a/vitrage/storage/history_facade.py b/vitrage/storage/history_facade.py index cfd534953..f7f489479 100644 --- a/vitrage/storage/history_facade.py +++ b/vitrage/storage/history_facade.py @@ -14,12 +14,15 @@ from __future__ import absolute_import -from oslo_db.sqlalchemy import utils as sqlalchemyutils -from oslo_log import log -from oslo_utils import timeutils +import pytz import sqlalchemy from sqlalchemy import and_ from sqlalchemy import or_ + +from oslo_db.sqlalchemy import utils as sqlalchemyutils +from oslo_log import log +from oslo_utils import timeutils + from vitrage.common.constants import EdgeLabel as ELable from vitrage.common.constants import HistoryProps as HProps from vitrage.common.exception import VitrageInputError @@ -51,6 +54,11 @@ class HistoryFacadeConnection(object): self._edges.end_all_edges(end_time) self._changes.add_end_changes(changes_to_add, end_time) + @staticmethod + def add_utc_timezone(time): + time = pytz.utc.localize(time) + return time + def count_active_alarms(self, project_id=None, is_admin_project=False): session = self._engine_facade.get_session()