Merge remote-tracking branch 'starlingx/master' into f/centos8

Change-Id: I940b46be3ee1b71847be9d35fc0d42ffc035235b
Signed-off-by: Saul Wold <sgw@linux.intel.com>
This commit is contained in:
Saul Wold 2020-02-04 13:32:34 -08:00
commit b5673f078b
20 changed files with 208 additions and 219 deletions

2
.gitignore vendored
View File

@ -22,6 +22,8 @@ develop-eggs
dist
eggs
sdist
.stestr
.ipynb_checkpoints
# Sphinx documentation
doc/build

View File

@ -11,10 +11,14 @@
- openstack-tox-linters
- openstack-tox-pep8
- stx-fault-build
- fault-rest-api-py27
- fault-rest-api-py35
gate:
jobs:
- openstack-tox-linters
- openstack-tox-pep8
- fault-rest-api-py27
- fault-rest-api-py35
# Perform just a build
- job:
@ -48,3 +52,27 @@
fault: https://opendev.org/starlingx/fault
integ: https://opendev.org/starlingx/integ
update: https://opendev.org/starlingx/update
- job:
name: fault-rest-api-py27
parent: tox
description: |
Run py27 test for fm-rest-api
nodeset: ubuntu-xenial
required-projects:
- starlingx/config
vars:
tox_envlist: py27
tox_extra_args: -c fm-rest-api/fm/tox.ini
- job:
name: fault-rest-api-py35
parent: tox
description: |
Run py35 test for fm-rest-api
nodeset: ubuntu-xenial
required-projects:
- starlingx/config
vars:
tox_envlist: py35
tox_extra_args: -c fm-rest-api/fm/tox.ini

View File

@ -42,7 +42,7 @@ master_doc = 'index'
# General information about the project.
repository_name = 'openstack/stx-fault'
project = u'stx-fault'
project = u'StarlingX Fault Management'
bug_project = 'starlingx'
bug_tag = 'stx.fault'

View File

@ -1,12 +1,14 @@
=======================
stx-fault API Reference
=======================
==============================
Fault Management API Reference
==============================
Use the StarlingX stx-fault API for alarm and event collection of the cloud platform.
Use the StarlingX Fault Management API for alarm and event collection of the
cloud platform.
stx-fault API content can be searched using the :ref:`search page <search>`.
Search Fault Management API content using the :ref:`search page <search>`.
API Reference
-------------
API reference
-------------
.. toctree::

View File

@ -23,7 +23,7 @@
# -- Project information -----------------------------------------------------
project = u'stx-fault'
project = u'StarlingX Fault Management'
copyright = u'2018, StarlingX'
author = u'StarlingX'

View File

@ -1,8 +1,8 @@
=======================
stx-fault Documentation
=======================
==================================
StarlingX Fault Management Project
==================================
Following is the documentation for StarlingX fault management.
The starlingx/fault project provides fault management.
--------
Overview
@ -61,31 +61,31 @@ Finally, the StarlingX dashboard includes a view/panel that allows you to more
easily view and interpret FM operations.
-------------
Release Notes
Release notes
-------------
.. toctree::
:maxdepth: 1
Release Notes <https://docs.starlingx.io/releasenotes/stx-fault>
Release notes <https://docs.starlingx.io/releasenotes/fault>
-------------
API Reference
API reference
-------------
.. toctree::
:maxdepth: 1
API Reference <https://docs.starlingx.io/api-ref/stx-fault>
API reference <https://docs.starlingx.io/api-ref/fault>
-----
Links
-----
* Source: `stx-fault`_
* Code Review: `Gerrit`_
* Bugs: `Storyboard`_
* Source: `starlingx/fault`_
* Code review: `Gerrit`_
* Project tracking: `Storyboard`_
.. _stx-fault: https://opendev.org/starlingx/fault
.. _starlingx/fault: https://opendev.org/starlingx/fault
.. _Gerrit: https://review.opendev.org/#/q/project:starlingx/fault
.. _Storyboard: https://storyboard.openstack.org/#!/project/starlingx/fault

View File

@ -0,0 +1,5 @@
[DEFAULT]
test_path=./fm/tests
top_dir=./
#parallel_class=True

View File

@ -1,184 +0,0 @@
# Copyright 2011 OpenStack Foundation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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.
"""
Time related utilities and helper functions.
"""
import calendar
import datetime
import iso8601
# ISO 8601 extended time format with microseconds
_ISO8601_TIME_FORMAT_SUBSECOND = '%Y-%m-%dT%H:%M:%S.%f'
_ISO8601_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S'
PERFECT_TIME_FORMAT = _ISO8601_TIME_FORMAT_SUBSECOND
def isotime(at=None, subsecond=False):
"""Stringify time in ISO 8601 format"""
if not at:
at = utcnow()
st = at.strftime(_ISO8601_TIME_FORMAT
if not subsecond
else _ISO8601_TIME_FORMAT_SUBSECOND)
tz = at.tzinfo.tzname(None) if at.tzinfo else 'UTC'
st += ('Z' if tz == 'UTC' else tz)
return st
def parse_isotime(timestr):
"""Parse time from ISO 8601 format"""
try:
return iso8601.parse_date(timestr)
except iso8601.ParseError as e:
raise ValueError(e.message)
except TypeError as e:
raise ValueError(e.message)
def strtime(at=None, fmt=PERFECT_TIME_FORMAT):
"""Returns formatted utcnow."""
if not at:
at = utcnow()
return at.strftime(fmt)
def parse_strtime(timestr, fmt=PERFECT_TIME_FORMAT):
"""Turn a formatted time back into a datetime."""
return datetime.datetime.strptime(timestr, fmt)
def normalize_time(timestamp):
"""Normalize time in arbitrary timezone to UTC naive object"""
offset = timestamp.utcoffset()
if offset is None:
return timestamp
return timestamp.replace(tzinfo=None) - offset
def is_older_than(before, seconds):
"""Return True if before is older than seconds."""
if isinstance(before, str):
before = parse_strtime(before).replace(tzinfo=None)
return utcnow() - before > datetime.timedelta(seconds=seconds)
def is_newer_than(after, seconds):
"""Return True if after is newer than seconds."""
if isinstance(after, str):
after = parse_strtime(after).replace(tzinfo=None)
return after - utcnow() > datetime.timedelta(seconds=seconds)
def utcnow_ts():
"""Timestamp version of our utcnow function."""
return calendar.timegm(utcnow().timetuple())
def utcnow():
"""Overridable version of utils.utcnow."""
if utcnow.override_time:
try:
return utcnow.override_time.pop(0)
except AttributeError:
return utcnow.override_time
return datetime.datetime.utcnow()
def iso8601_from_timestamp(timestamp):
"""Returns a iso8601 formated date from timestamp"""
return isotime(datetime.datetime.utcfromtimestamp(timestamp))
utcnow.override_time = None
def set_time_override(override_time=datetime.datetime.utcnow()):
"""
Override utils.utcnow to return a constant time or a list thereof,
one at a time.
"""
utcnow.override_time = override_time
def advance_time_delta(timedelta):
"""Advance overridden time using a datetime.timedelta."""
assert(utcnow.override_time is not None)
try:
for dt in utcnow.override_time:
dt += timedelta
except TypeError:
utcnow.override_time += timedelta
def advance_time_seconds(seconds):
"""Advance overridden time by seconds."""
advance_time_delta(datetime.timedelta(0, seconds))
def clear_time_override():
"""Remove the overridden time."""
utcnow.override_time = None
def marshall_now(now=None):
"""Make an rpc-safe datetime with microseconds.
Note: tzinfo is stripped, but not required for relative times."""
if not now:
now = utcnow()
return dict(day=now.day, month=now.month, year=now.year, hour=now.hour,
minute=now.minute, second=now.second,
microsecond=now.microsecond)
def unmarshall_time(tyme):
"""Unmarshall a datetime dict."""
return datetime.datetime(day=tyme['day'],
month=tyme['month'],
year=tyme['year'],
hour=tyme['hour'],
minute=tyme['minute'],
second=tyme['second'],
microsecond=tyme['microsecond'])
def delta_seconds(before, after):
"""
Compute the difference in seconds between two date, time, or
datetime objects (as a float, to microsecond resolution).
"""
delta = after - before
try:
return delta.total_seconds()
except AttributeError:
return ((delta.days * 24 * 3600) + delta.seconds +
float(delta.microseconds) / (10 ** 6))
def is_soon(dt, window):
"""
Determines if time is going to happen in the next window seconds.
:params dt: the time
:params window: minimum seconds to remain to consider the time not soon
:return: True if expiration is within the given duration
"""
soon = (utcnow() + datetime.timedelta(seconds=window))
return normalize_time(dt) <= soon

View File

@ -21,7 +21,6 @@
#
import six
import uuid
from oslo_log import log
from oslo_concurrency import lockutils
@ -30,10 +29,6 @@ from fm.common import constants
LOG = log.getLogger(__name__)
def generate_uuid():
return str(uuid.uuid4())
def synchronized(name, external=True):
if external:
lock_path = constants.FM_LOCK_PATH

View File

@ -23,7 +23,6 @@ from sqlalchemy.orm.exc import NoResultFound
from fm.api import config
from fm.common import constants
from fm.common import exceptions
from fm.common import utils
from fm.db import api
from fm.db.sqlalchemy import models
from fm import objects
@ -182,7 +181,7 @@ class Connection(api.Connection):
def alarm_create(self, values):
if not values.get('uuid'):
values['uuid'] = utils.generate_uuid()
values['uuid'] = uuidutils.generate_uuid()
alarm = models.Alarm()
alarm.update(values)
with _session_for_write() as session:
@ -311,7 +310,7 @@ class Connection(api.Connection):
def event_log_create(self, values):
if not values.get('uuid'):
values['uuid'] = utils.generate_uuid()
values['uuid'] = uuidutils.generate_uuid()
event_log = models.EventLog()
event_log.update(values)
count = self.event_log_get_count()

View File

@ -26,7 +26,7 @@ import uuid
import six
from fm.common.i18n import _
from fm.common import timeutils
from oslo_utils import timeutils
def datetime_or_none(dt):

View File

@ -0,0 +1,14 @@
# Copyright 2020 Intel Corporation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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.

View File

@ -0,0 +1,46 @@
# Copyright 2020 Intel Corporation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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.
"""Base classes for our unit tests.
Allows overriding of config for use of fakes, and some black magic for
inline callbacks.
"""
import fixtures
import testtools
from oslo_config import cfg
from oslo_log import log as logging
CONF = cfg.CONF
class TestCase(testtools.TestCase):
"""Test case base class for all unit tests."""
def setUp(self):
"""Run before each test method to initialize test environment."""
super(TestCase, self).setUp()
def fake_logging_setup(*args):
pass
self.useFixture(
fixtures.MonkeyPatch('oslo_log.log.setup', fake_logging_setup))
logging.register_options(CONF)
def tearDown(self):
super(TestCase, self).tearDown()

View File

@ -0,0 +1,34 @@
# Copyright 2020 Intel Corporation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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 fm.common import utils
from fm.tests import base
class FaultUtilsTestCase(base.TestCase):
def test_safe_rstrip(self):
input_int = 1
self.assertEqual(input_int, utils.safe_rstrip(input_int))
input_str = "string input"
self.assertEqual(input_str, utils.safe_rstrip(input_str))
input_str = "string to strip \r\n\t"
output_str = "string to strip"
self.assertEqual(output_str, utils.safe_rstrip(input_str))
input_str = "string to strip ssss"
output_str = "string to strip"
self.assertEqual(output_str, utils.safe_rstrip(input_str, "s "))

View File

@ -1 +1,13 @@
-r requirements.txt
hacking!=0.13.0,<0.14,>=0.12.0
bashate >= 0.2
PyYAML >= 3.1.0
yamllint >= 0.5.2
stestr
testtools!=1.2.0,>=0.9.36
iso8601
stestr
mock
cython
oslo.log
oslo.concurrency

34
fm-rest-api/fm/tox.ini Normal file
View File

@ -0,0 +1,34 @@
[tox]
envlist = py27,py35
minversion = 2.3
skipsdist = True
stxdir = {toxinidir}/../../../
[testenv]
install_command = pip install -U {opts} {packages}
setenv = VIRTUAL_ENV={envdir}
OS_STDOUT_CAPTURE=1
OS_STDERR_CAPTURE=1
OS_TEST_TIMEOUT=60
deps = -r{toxinidir}/test-requirements.txt
-e{[tox]stxdir}/config/tsconfig/tsconfig
[testenv:venv]
basepython = python3
commands = {posargs}
[testenv:py27]
basepython = python2.7
commands =
stestr run {posargs}
stestr slowest
[testenv:py35]
basepython = python3.5
commands =
stestr run {posargs}
stestr slowest

View File

@ -47,7 +47,7 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = u'stx-fault'
project = u'StarlingX Fault Management'
# Release notes are version independent, no need to set version and release
release = ''

View File

@ -1,6 +1,6 @@
=======================
stx-fault Release Notes
=======================
========================================
StarlingX Fault Management Release Notes
========================================
.. toctree::
:maxdepth: 2

View File

@ -2,4 +2,4 @@ hacking!=0.13.0,<0.14,>=0.12.0
bashate >= 0.2
PyYAML >= 3.1.0
yamllint >= 0.5.2
spec_cleaner>=1.0.9
#spec_cleaner>=1.0.9

View File

@ -2,6 +2,7 @@
envlist = linters,pep8,rpm-packaging-lint
minversion = 2.3
skipsdist = True
stxdir = {toxinidir}/../
[testenv]
install_command = pip install -U {opts} {packages}
@ -128,3 +129,4 @@ commands = {toxinidir}/devstack/build.sh
basepython = python3
whitelist_externals = cat
commands = cat /etc/fm/fm.conf