Graduation Prep: Initial Import Fixup

This commit fixes up the initial import, correcting import paths,
moving some code into a "private" module, updating requirements
files, etc.
This commit is contained in:
Solly Ross 2015-06-03 13:20:40 -04:00
parent 01d69037e0
commit 4faad94ced
37 changed files with 134 additions and 154 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@
# Packages # Packages
*.egg *.egg
*.eggs
*.egg-info *.egg-info
dist dist
build build

View File

@ -0,0 +1,25 @@
# Copyright 2013 Red Hat, Inc.
#
# 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.
"""Provides a way to generate serializable reports
This package/module provides mechanisms for defining reports
which may then be serialized into various data types. Each
report ( :class:`oslo_reports.report.BasicReport` )
is composed of one or more report sections
( :class:`oslo_reports.report.BasicSection` ),
which contain generators which generate data models
( :class:`oslo_reports.models.base.ReportModels` ),
which are then serialized by views.
"""

View File

@ -12,14 +12,13 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
"""Provides a way to generate serializable reports """Various utilities for report generation
This package/module provides mechanisms for defining reports This module includes various utilities
which may then be serialized into various data types. Each used in generating reports.
report ( :class:`openstack.common.report.report.BasicReport` )
is composed of one or more report sections
( :class:`openstack.common.report.report.BasicSection` ),
which contain generators which generate data models
( :class:`openstack.common.report.models.base.ReportModels` ),
which are then serialized by views.
""" """
class StringWithAttrs(str):
"""A String that can have arbitrary attributes"""
pass

View File

@ -15,7 +15,7 @@
"""Provides Data Model Generators """Provides Data Model Generators
This module defines classes for generating data models This module defines classes for generating data models
( :class:`openstack.common.report.models.base.ReportModel` ). ( :class:`oslo_reports.models.base.ReportModel` ).
A generator is any object which is callable with no parameters A generator is any object which is callable with no parameters
and returns a data model. and returns a data model.
""" """

View File

@ -16,19 +16,19 @@
This module defines a class for configuration This module defines a class for configuration
generators for generating the model in generators for generating the model in
:mod:`openstack.common.report.models.conf`. :mod:`oslo_reports.models.conf`.
""" """
from oslo_config import cfg from oslo_config import cfg
from openstack.common.report.models import conf as cm from oslo_reports.models import conf as cm
class ConfigReportGenerator(object): class ConfigReportGenerator(object):
"""A Configuration Data Generator """A Configuration Data Generator
This generator returns This generator returns
:class:`openstack.common.report.models.conf.ConfigModel`, :class:`oslo_reports.models.conf.ConfigModel`,
by default using the configuration options stored by default using the configuration options stored
in :attr:`oslo_config.cfg.CONF`, which is where in :attr:`oslo_config.cfg.CONF`, which is where
OpenStack stores everything. OpenStack stores everything.

View File

@ -22,14 +22,14 @@ import os
import psutil import psutil
from openstack.common.report.models import process as pm from oslo_reports.models import process as pm
class ProcessReportGenerator(object): class ProcessReportGenerator(object):
"""A Process Data Generator """A Process Data Generator
This generator returns a This generator returns a
:class:`openstack.common.report.models.process.ProcessModel` :class:`oslo_reports.models.process.ProcessModel`
based on the current process (which will also include based on the current process (which will also include
all subprocesses, recursively) using the :class:`psutil.Process` class`. all subprocesses, recursively) using the :class:`psutil.Process` class`.
""" """

View File

@ -16,27 +16,43 @@
This module defines classes for threading-related This module defines classes for threading-related
generators for generating the models in generators for generating the models in
:mod:`openstack.common.report.models.threading`. :mod:`oslo_reports.models.threading`.
""" """
from __future__ import absolute_import from __future__ import absolute_import
import gc
import sys import sys
import threading import threading
import greenlet from oslo_reports.models import threading as tm
from oslo_reports.models import with_default_views as mwdv
from oslo_reports.views.text import generic as text_views
from openstack.common.report.models import threading as tm
from openstack.common.report.models import with_default_views as mwdv def _find_objects(t):
from openstack.common.report import utils as rutils """Find Objects in the GC State
from openstack.common.report.views.text import generic as text_views
This horribly hackish method locates objects of a
given class in the current python instance's garbage
collection state. In case you couldn't tell, this is
horribly hackish, but is necessary for locating all
green threads, since they don't keep track of themselves
like normal threads do in python.
:param class t: the class of object to locate
:rtype: list
:returns: a list of objects of the given type
"""
return [o for o in gc.get_objects() if isinstance(o, t)]
class ThreadReportGenerator(object): class ThreadReportGenerator(object):
"""A Thread Data Generator """A Thread Data Generator
This generator returns a collection of This generator returns a collection of
:class:`openstack.common.report.models.threading.ThreadModel` :class:`oslo_reports.models.threading.ThreadModel`
objects by introspecting the current python state using objects by introspecting the current python state using
:func:`sys._current_frames()` . Its constructor may optionally :func:`sys._current_frames()` . Its constructor may optionally
be passed a frame object. This frame object will be interpreted be passed a frame object. This frame object will be interpreted
@ -67,19 +83,21 @@ class GreenThreadReportGenerator(object):
"""A Green Thread Data Generator """A Green Thread Data Generator
This generator returns a collection of This generator returns a collection of
:class:`openstack.common.report.models.threading.GreenThreadModel` :class:`oslo_reports.models.threading.GreenThreadModel`
objects by introspecting the current python garbage collection objects by introspecting the current python garbage collection
state, and sifting through for :class:`greenlet.greenlet` objects. state, and sifting through for :class:`greenlet.greenlet` objects.
.. seealso:: .. seealso::
Function :func:`openstack.common.report.utils._find_objects` Function :func:`_find_objects`
""" """
def __call__(self): def __call__(self):
import greenlet
threadModels = [ threadModels = [
tm.GreenThreadModel(gr.gr_frame) tm.GreenThreadModel(gr.gr_frame)
for gr in rutils._find_objects(greenlet.greenlet) for gr in _find_objects(greenlet.greenlet)
] ]
return mwdv.ModelWithDefaultViews(threadModels, return mwdv.ModelWithDefaultViews(threadModels,

View File

@ -17,17 +17,17 @@
This module defines a class for OpenStack This module defines a class for OpenStack
version and package information version and package information
generators for generating the model in generators for generating the model in
:mod:`openstack.common.report.models.version`. :mod:`oslo_reports.models.version`.
""" """
from openstack.common.report.models import version as vm from oslo_reports.models import version as vm
class PackageReportGenerator(object): class PackageReportGenerator(object):
"""A Package Information Data Generator """A Package Information Data Generator
This generator returns This generator returns
:class:`openstack.common.report.models.version.PackageModel`, :class:`oslo_reports.models.version.PackageModel`,
extracting data from the given version object, which should follow extracting data from the given version object, which should follow
the general format defined in Nova's version information (i.e. it the general format defined in Nova's version information (i.e. it
should contain the methods vendor_string, product_string, and should contain the methods vendor_string, product_string, and

View File

@ -58,11 +58,11 @@ import sys
from oslo_utils import timeutils from oslo_utils import timeutils
from openstack.common.report.generators import conf as cgen from oslo_reports.generators import conf as cgen
from openstack.common.report.generators import process as prgen from oslo_reports.generators import process as prgen
from openstack.common.report.generators import threading as tgen from oslo_reports.generators import threading as tgen
from openstack.common.report.generators import version as pgen from oslo_reports.generators import version as pgen
from openstack.common.report import report from oslo_reports import report
class GuruMeditation(object): class GuruMeditation(object):

View File

@ -18,8 +18,8 @@ This module defines a class representing the data
model for :mod:`oslo_config` configuration options model for :mod:`oslo_config` configuration options
""" """
from openstack.common.report.models import with_default_views as mwdv from oslo_reports.models import with_default_views as mwdv
from openstack.common.report.views.text import generic as generic_text_views from oslo_reports.views.text import generic as generic_text_views
class ConfigModel(mwdv.ModelWithDefaultViews): class ConfigModel(mwdv.ModelWithDefaultViews):

View File

@ -18,8 +18,8 @@ This module defines a class representing a process,
potentially with subprocesses. potentially with subprocesses.
""" """
import openstack.common.report.models.with_default_views as mwdv import oslo_reports.models.with_default_views as mwdv
import openstack.common.report.views.text.process as text_views import oslo_reports.views.text.process as text_views
class ProcessModel(mwdv.ModelWithDefaultViews): class ProcessModel(mwdv.ModelWithDefaultViews):

View File

@ -20,8 +20,8 @@ thread, and stack trace data models
import traceback import traceback
from openstack.common.report.models import with_default_views as mwdv from oslo_reports.models import with_default_views as mwdv
from openstack.common.report.views.text import threading as text_views from oslo_reports.views.text import threading as text_views
class StackTraceModel(mwdv.ModelWithDefaultViews): class StackTraceModel(mwdv.ModelWithDefaultViews):

View File

@ -18,8 +18,8 @@ This module defines a class representing the data
model for OpenStack package and version information model for OpenStack package and version information
""" """
from openstack.common.report.models import with_default_views as mwdv from oslo_reports.models import with_default_views as mwdv
from openstack.common.report.views.text import generic as generic_text_views from oslo_reports.views.text import generic as generic_text_views
class PackageModel(mwdv.ModelWithDefaultViews): class PackageModel(mwdv.ModelWithDefaultViews):

View File

@ -14,10 +14,10 @@
import copy import copy
from openstack.common.report.models import base as base_model from oslo_reports.models import base as base_model
from openstack.common.report.views.json import generic as jsonviews from oslo_reports.views.json import generic as jsonviews
from openstack.common.report.views.text import generic as textviews from oslo_reports.views.text import generic as textviews
from openstack.common.report.views.xml import generic as xmlviews from oslo_reports.views.xml import generic as xmlviews
class ModelWithDefaultViews(base_model.ReportModel): class ModelWithDefaultViews(base_model.ReportModel):
@ -35,11 +35,11 @@ class ModelWithDefaultViews(base_model.ReportModel):
The default 'default views' are The default 'default views' are
text text
:class:`openstack.common.report.views.text.generic.KeyValueView` :class:`oslo_reports.views.text.generic.KeyValueView`
xml xml
:class:`openstack.common.report.views.xml.generic.KeyValueView` :class:`oslo_reports.views.xml.generic.KeyValueView`
json json
:class:`openstack.common.report.views.json.generic.KeyValueView` :class:`oslo_reports.views.json.generic.KeyValueView`
.. function:: to_type() .. function:: to_type()

View File

@ -19,7 +19,7 @@ All reports take the form of a report class containing various report
sections. sections.
""" """
from openstack.common.report.views.text import header as header_views from oslo_reports.views.text import header as header_views
class BasicReport(object): class BasicReport(object):
@ -45,7 +45,7 @@ class BasicReport(object):
list. The view is called on the model which results from list. The view is called on the model which results from
the generator when the report is run. A generator is simply the generator when the report is run. A generator is simply
a method or callable object which takes no arguments and a method or callable object which takes no arguments and
returns a :class:`openstack.common.report.models.base.ReportModel` returns a :class:`oslo_reports.models.base.ReportModel`
or similar object. or similar object.
:param view: the top-level view for the section :param view: the top-level view for the section
@ -110,11 +110,11 @@ class ReportOfType(BasicReport):
.. seealso:: .. seealso::
Class :class:`openstack.common.report.models.with_default_view.ModelWithDefaultView` # noqa Class :class:`oslo_reports.models.with_default_view.ModelWithDefaultView` # noqa
(the entire class) (the entire class)
Class :class:`openstack.common.report.models.base.ReportModel` Class :class:`oslo_reports.models.base.ReportModel`
:func:`openstack.common.report.models.base.ReportModel.set_current_view_type` # noqa :func:`oslo_reports.models.base.ReportModel.set_current_view_type` # noqa
:param str tp: the type of the report :param str tp: the type of the report
""" """
@ -167,13 +167,13 @@ class TextReport(ReportOfType):
list. The view is called on the model which results from list. The view is called on the model which results from
the generator when the report is run. A generator is simply the generator when the report is run. A generator is simply
a method or callable object which takes no arguments and a method or callable object which takes no arguments and
returns a :class:`openstack.common.report.models.base.ReportModel` returns a :class:`oslo_reports.models.base.ReportModel`
or similar object. or similar object.
The model is told to serialize as text (if possible) at serialization The model is told to serialize as text (if possible) at serialization
time by wrapping the generator. The view model's attached view time by wrapping the generator. The view model's attached view
(if any) is wrapped in a (if any) is wrapped in a
:class:`openstack.common.report.views.text.header.TitledView` :class:`oslo_reports.views.text.header.TitledView`
:param str heading: the title for the section :param str heading: the title for the section
:param generator: the method or class which generates the model :param generator: the method or class which generates the model

View File

@ -1,46 +0,0 @@
# Copyright 2013 Red Hat, Inc.
#
# 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.
"""Various utilities for report generation
This module includes various utilities
used in generating reports.
"""
import gc
class StringWithAttrs(str):
"""A String that can have arbitrary attributes
"""
pass
def _find_objects(t):
"""Find Objects in the GC State
This horribly hackish method locates objects of a
given class in the current python instance's garbage
collection state. In case you couldn't tell, this is
horribly hackish, but is necessary for locating all
green threads, since they don't keep track of themselves
like normal threads do in python.
:param class t: the class of object to locate
:rtype: list
:returns: a list of objects of the given type
"""
return [o for o in gc.get_objects() if isinstance(o, t)]

View File

@ -17,8 +17,8 @@ import re
from oslotest import base from oslotest import base
from openstack.common.report.models import base as base_model from oslo_reports.models import base as base_model
from openstack.common.report import report from oslo_reports import report
class BasicView(object): class BasicView(object):

View File

@ -27,8 +27,8 @@ import mock
from oslotest import base from oslotest import base
import six import six
from openstack.common.report import guru_meditation_report as gmr from oslo_reports import guru_meditation_report as gmr
from openstack.common.report.models import with_default_views as mwdv from oslo_reports.models import with_default_views as mwdv
class FakeVersionObj(object): class FakeVersionObj(object):

View File

@ -20,10 +20,10 @@ import mock
from oslo_config import cfg from oslo_config import cfg
from oslotest import base from oslotest import base
from openstack.common.report.generators import conf as os_cgen from oslo_reports.generators import conf as os_cgen
from openstack.common.report.generators import threading as os_tgen from oslo_reports.generators import threading as os_tgen
from openstack.common.report.generators import version as os_pgen from oslo_reports.generators import version as os_pgen
from openstack.common.report.models import threading as os_tmod from oslo_reports.models import threading as os_tmod
class TestOpenstackGenerators(base.BaseTestCase): class TestOpenstackGenerators(base.BaseTestCase):
@ -49,7 +49,7 @@ class TestOpenstackGenerators(base.BaseTestCase):
def __init__(self, thread_id, tb): def __init__(self, thread_id, tb):
self.traceback = tb self.traceback = tb
with mock.patch('openstack.common.report.models' with mock.patch('oslo_reports.models'
'.threading.ThreadModel', FakeModel): '.threading.ThreadModel', FakeModel):
model = os_tgen.ThreadReportGenerator("fake traceback")() model = os_tgen.ThreadReportGenerator("fake traceback")()
curr_thread = model.get(threading.current_thread().ident, None) curr_thread = model.get(threading.current_thread().ident, None)

View File

@ -1,28 +0,0 @@
# -*- coding: utf-8 -*-
# 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.
"""
test_reports
----------------------------------
Tests for `reports` module.
"""
from oslotest import base
class TestReports(base.BaseTestCase):
def test_something(self):
pass

View File

@ -17,12 +17,12 @@ import copy
import mock import mock
from oslotest import base from oslotest import base
from openstack.common.report.models import base as base_model from oslo_reports.models import base as base_model
from openstack.common.report.models import with_default_views as mwdv from oslo_reports.models import with_default_views as mwdv
from openstack.common.report import report from oslo_reports import report
from openstack.common.report.views import jinja_view as jv from oslo_reports.views import jinja_view as jv
from openstack.common.report.views.json import generic as json_generic from oslo_reports.views.json import generic as json_generic
from openstack.common.report.views.text import generic as text_generic from oslo_reports.views.text import generic as text_generic
def mwdv_generator(): def mwdv_generator():

View File

@ -17,7 +17,7 @@
This modules defines several basic views for serializing This modules defines several basic views for serializing
data to JSON. Submodels that have already been serialized data to JSON. Submodels that have already been serialized
as JSON may have their string values marked with `__is_json__ as JSON may have their string values marked with `__is_json__
= True` using :class:`openstack.common.report.utils.StringWithAttrs` = True` using :class:`oslo_reports._utils.StringWithAttrs`
(each of the classes within this module does this automatically, (each of the classes within this module does this automatically,
and non-naive serializers check for this attribute and handle and non-naive serializers check for this attribute and handle
such strings specially) such strings specially)
@ -27,7 +27,7 @@ import copy
from oslo_serialization import jsonutils as json from oslo_serialization import jsonutils as json
from openstack.common.report import utils as utils from oslo_reports import _utils as utils
class BasicKeyValueView(object): class BasicKeyValueView(object):

View File

@ -18,14 +18,14 @@ This module provides a view for
visualizing processes in human-readable formm visualizing processes in human-readable formm
""" """
import openstack.common.report.views.jinja_view as jv import oslo_reports.views.jinja_view as jv
class ProcessView(jv.JinjaView): class ProcessView(jv.JinjaView):
"""A Process View """A Process View
This view displays process models defined by This view displays process models defined by
:class:`openstack.common.report.models.process.ProcessModel` :class:`oslo_reports.models.process.ProcessModel`
""" """
VIEW_TEXT = ( VIEW_TEXT = (

View File

@ -19,14 +19,14 @@ visualizing threads, green threads, and stack traces
in human-readable form. in human-readable form.
""" """
from openstack.common.report.views import jinja_view as jv from oslo_reports.views import jinja_view as jv
class StackTraceView(jv.JinjaView): class StackTraceView(jv.JinjaView):
"""A Stack Trace View """A Stack Trace View
This view displays stack trace models defined by This view displays stack trace models defined by
:class:`openstack.common.report.models.threading.StackTraceModel` :class:`oslo_reports.models.threading.StackTraceModel`
""" """
VIEW_TEXT = ( VIEW_TEXT = (
@ -52,7 +52,7 @@ class GreenThreadView(object):
"""A Green Thread View """A Green Thread View
This view displays a green thread provided by the data This view displays a green thread provided by the data
model :class:`openstack.common.report.models.threading.GreenThreadModel` model :class:`oslo_reports.models.threading.GreenThreadModel`
""" """
FORMAT_STR = "------{thread_str: ^60}------" + "\n" + "{stack_trace}" FORMAT_STR = "------{thread_str: ^60}------" + "\n" + "{stack_trace}"
@ -68,7 +68,7 @@ class ThreadView(object):
"""A Thread Collection View """A Thread Collection View
This view displays a python thread provided by the data This view displays a python thread provided by the data
model :class:`openstack.common.report.models.threading.ThreadModel` # noqa model :class:`oslo_reports.models.threading.ThreadModel` # noqa
""" """
FORMAT_STR = "------{thread_str: ^60}------" + "\n" + "{stack_trace}" FORMAT_STR = "------{thread_str: ^60}------" + "\n" + "{stack_trace}"

View File

@ -17,7 +17,7 @@
This modules defines several basic views for serializing This modules defines several basic views for serializing
data to XML. Submodels that have already been serialized data to XML. Submodels that have already been serialized
as XML may have their string values marked with `__is_xml__ as XML may have their string values marked with `__is_xml__
= True` using :class:`openstack.common.report.utils.StringWithAttrs` = True` using :class:`oslo_reports._utils.StringWithAttrs`
(each of the classes within this module does this automatically, (each of the classes within this module does this automatically,
and non-naive serializers check for this attribute and handle and non-naive serializers check for this attribute and handle
such strings specially) such strings specially)
@ -29,7 +29,7 @@ import xml.etree.ElementTree as ET
import six import six
from openstack.common.report import utils as utils from oslo_reports import _utils as utils
class KeyValueView(object): class KeyValueView(object):

View File

@ -2,4 +2,10 @@
# of appearance. Changing the order has an impact on the overall integration # of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later. # process, which may cause wedges in the gate later.
pbr>=0.11,<2.0
Jinja2>=2.6 # BSD License (3 clause)
Babel>=1.3 Babel>=1.3
oslo.serialization>=1.4.0 # Apache-2.0
psutil>=1.1.1,<2.0.0
six>=1.9.0
oslo.i18n>=1.5.0 # Apache-2.0

View File

@ -8,3 +8,8 @@ oslotest>=1.5.1
# These are needed for docs generation # These are needed for docs generation
oslosphinx>=2.5.0 oslosphinx>=2.5.0
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
# for testing optional parts
oslo.config>=1.11.0 # Apache-2.0
eventlet>=0.17.3
greenlet>=0.3.2