Cleanup py27 support

This repo is now testing only with Python 3, so let's make
a few cleanups:
- Remove python 2.7 stanza from setup.py
- Add requires on python >= 3.6 to setup.cfg so that pypi and pip
  know about the requirement
- Remove obsolete sections from setup.cfg
- Update classifiers
- Update requirements, no need for python_version anymore
- Switch to using sphinx-build with warnings enabled, fix
  warnings found with autodoc
- Cleanup doc/source/conf.py to remove now obsolete content.
- Use newer openstackdocstheme version, switch to using apidoc
- Remove install_command from tox.ini, the default is fine
- Change some imports to use python3 changed names

Change-Id: Ibb2e614c7db8a01e41caed8314c1d46479c78295
This commit is contained in:
Andreas Jaeger 2020-04-12 19:26:00 +02:00
parent b9ef93c2f1
commit 72de51b01c
9 changed files with 61 additions and 84 deletions

View File

@ -14,7 +14,6 @@
import sys import sys
import os import os
from freezer_dr import __version__ as FREEZER_DR_VERSION
# If extensions (or modules to document with autodoc) are in another directory, # If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the # add these directories to sys.path here. If the directory is relative to the
@ -29,7 +28,7 @@ from freezer_dr import __version__ as FREEZER_DR_VERSION
# Add any Sphinx extension module names here, as strings. They can be # Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones. # ones.
extensions = ['sphinx.ext.autodoc', extensions = ['sphinxcontrib.apidoc',
'sphinx.ext.viewcode', 'sphinx.ext.viewcode',
'openstackdocstheme'] 'openstackdocstheme']
@ -49,15 +48,6 @@ master_doc = 'index'
project = u'Freezer' project = u'Freezer'
copyright = u'2016, OpenStack' copyright = u'2016, OpenStack'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = FREEZER_DR_VERSION
# The full version, including alpha/beta/rc tags.
release = FREEZER_DR_VERSION
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
#language = None #language = None
@ -130,7 +120,7 @@ html_theme = 'openstackdocs'
# Add any paths that contain custom static files (such as style sheets) here, # Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files, # relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css". # so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static'] # html_static_path = ['_static']
# Add any extra paths that contain custom files (such as robots.txt or # Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied # .htaccess) here, relative to this directory. These files are copied
@ -262,4 +252,12 @@ texinfo_documents = [
# Example configuration for intersphinx: refer to the Python standard library. # Example configuration for intersphinx: refer to the Python standard library.
#intersphinx_mapping = {'http://docs.python.org/': None} #intersphinx_mapping = {'http://docs.python.org/': None}
# -- sphinxcontrib.apidoc configuration --------------------------------------
apidoc_module_dir = '../../freezer_dr'
apidoc_output_dir = 'api'
apidoc_excluded_paths = [
'tests',
]

View File

@ -1,8 +1,4 @@
.. Freezer Disaster Recovery documentation master file, created by =====================================================
sphinx-quickstart on Thu Feb 4 22:27:35 2016.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to Freezer's Disaster Recovery documentation! Welcome to Freezer's Disaster Recovery documentation!
===================================================== =====================================================
@ -24,4 +20,4 @@ Indices and tables
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 1
api/autoindex api/modules

View File

@ -14,15 +14,15 @@
from freezer_dr.common.osclient import OSClient from freezer_dr.common.osclient import OSClient
from freezer_dr.monitors.common.driver import MonitorBaseDriver from freezer_dr.monitors.common.driver import MonitorBaseDriver
from httplib import HTTPConnection from http.client import HTTPConnection
from httplib import HTTPSConnection from http.client import HTTPSConnection
from httplib import socket from http.client import socket
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log from oslo_log import log
from time import sleep from time import sleep
from urlparse import urlparse from urllib.parse import urlparse
CONF = cfg.CONF CONF = cfg.CONF
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)

View File

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import httplib import http.client
import time import time
import urlparse import urllib.parse
from monascaclient import client from monascaclient import client
from oslo_config import cfg from oslo_config import cfg
@ -29,9 +29,11 @@ LOG = log.getLogger(__name__)
class MonascaDriver(driver.MonitorBaseDriver): class MonascaDriver(driver.MonitorBaseDriver):
"""Monasca monitoring driver to monitor compute nodes. It makes use of """Monasca monitoring driver to monitor compute nodes. It makes use of
Monasca to monitor the compute nodes. Metric information needed. 'hostname' Monasca to monitor the compute nodes. Metric information
must be used in dimensions to filter the values in alarms. You need to needed. 'hostname' must be used in dimensions to filter the
define alarms for all hosts with the required metrics.""" values in alarms. You need to define alarms for all hosts with
the required metrics.
"""
_OPTS = [ _OPTS = [
cfg.StrOpt('keystone_url', cfg.StrOpt('keystone_url',
@ -131,20 +133,21 @@ class MonascaDriver(driver.MonitorBaseDriver):
def get_data(self): def get_data(self):
"""This function returns monitoring data from Monasca. It calls """This function returns monitoring data from Monasca. It calls
_get_raw_data to get raw data and then process these data returns _get_raw_data to get raw data and then process these data returns
a normalized dict a normalized dict
:return: doct contains: :return: dict contains::
{
hostname1: { {
metric_name1: ['Ok', 'ALARM', 'UNDETERMINED'] hostname1: {
metric_name2: ['OK', 'OK', 'OK'] metric_name1: ['Ok', 'ALARM', 'UNDETERMINED']
}, metric_name2: ['OK', 'OK', 'OK']
hostname2: { },
metric_name1: ['Ok', 'ALARM', 'OK'] hostname2: {
metric_name2: ['ALARM', 'UNDETERMINED', 'OK'] metric_name1: ['Ok', 'ALARM', 'OK']
} metric_name2: ['ALARM', 'UNDETERMINED', 'OK']
} }
""" }
"""
data = self._get_raw_data() data = self._get_raw_data()
data2 = {} data2 = {}
for host, metric_results in data.items(): for host, metric_results in data.items():
@ -183,10 +186,10 @@ class MonascaDriver(driver.MonitorBaseDriver):
def analyze_nodes(self, nodes): def analyze_nodes(self, nodes):
"""It will check if the nodes are in 'OK' state or not. If not they """It will check if the nodes are in 'OK' state or not. If not they
will considered down. We have three states as follow: will considered down. We have three states as follow:
1. OK 1. OK
2. ALARM 2. ALARM
3. UNDEFINED 3. UNDEFINED
""" """
# @todo(szaher) use list comprehension instead of loops # @todo(szaher) use list comprehension instead of loops
# list below is correct and should return the extact same value like # list below is correct and should return the extact same value like
@ -267,16 +270,16 @@ class MonascaDriver(driver.MonitorBaseDriver):
return eval(aggregate) return eval(aggregate)
def is_alive(self): def is_alive(self):
url = urlparse.urlparse(self.conf.monasca_url) url = urllib.parse.urlparse(self.conf.monasca_url)
if url.scheme == 'https': if url.scheme == 'https':
http_connector = httplib.HTTPSConnection http_connector = http.client.HTTPSConnection
else: else:
http_connector = httplib.HTTPConnection http_connector = http.client.HTTPConnection
try: try:
connection = http_connector(host=url.netloc) connection = http_connector(host=url.netloc)
connection.request('HEAD', url=url.path) connection.request('HEAD', url=url.path)
response = connection.getresponse() response = connection.getresponse()
except httplib.socket.error: except http.client.socket.error:
return False return False
try: try:
if getattr(response, 'status') in [200, 401]: if getattr(response, 'status') in [200, 401]:

View File

@ -50,7 +50,7 @@ msgpack==0.5.6
munch==2.2.0 munch==2.2.0
netaddr==0.7.19 netaddr==0.7.19
netifaces==0.10.6 netifaces==0.10.6
openstackdocstheme==1.18.1 openstackdocstheme==1.31.2
openstacksdk==0.12.0 openstacksdk==0.12.0
os-brick==2.2.0 os-brick==2.2.0
os-client-config==1.29.0 os-client-config==1.29.0
@ -107,6 +107,7 @@ setuptools==21.0.0
simplejson==3.13.2 simplejson==3.13.2
snowballstemmer==1.2.1 snowballstemmer==1.2.1
Sphinx==1.6.2 Sphinx==1.6.2
sphinxcontrib-apidoc==0.2.0
sphinxcontrib-websupport==1.0.1 sphinxcontrib-websupport==1.0.1
stestr==2.0.0 stestr==2.0.0
stevedore==1.28.0 stevedore==1.28.0

View File

@ -6,6 +6,7 @@ description-file =
author = Freezer Team author = Freezer Team
author-email = openstack-discuss@lists.openstack.org author-email = openstack-discuss@lists.openstack.org
home-page = https://docs.openstack.org/freezer/latest/ home-page = https://docs.openstack.org/freezer/latest/
python-requires = >=3.6
classifier = classifier =
Environment :: OpenStack Environment :: OpenStack
Intended Audience :: Developers Intended Audience :: Developers
@ -14,6 +15,8 @@ classifier =
License :: OSI Approved :: Apache Software License License :: OSI Approved :: Apache Software License
Operating System :: POSIX :: Linux Operating System :: POSIX :: Linux
Programming Language :: Python Programming Language :: Python
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3 Programming Language :: Python :: 3
Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.7
@ -35,21 +38,6 @@ keywords =
packages = packages =
freezer_dr freezer_dr
[global]
setup-hooks =
pbr.hooks.setup_hook
[build_sphinx]
source-dir = doc/source
build-dir = doc/build
all_files = 1
[pbr]
# Have pbr generate the module indexes like sphinx autodoc
autodoc_index_modules = True
warnerrors = True
[entry_points] [entry_points]
oslo.config.opts = oslo.config.opts =
freezer-dr = freezer_dr.common.config:list_opts freezer-dr = freezer_dr.common.config:list_opts

View File

@ -13,17 +13,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
import setuptools import setuptools
# In python < 2.7.4, a lazy loading of package `pbr` will break
# setuptools if some other modules registered functions in `atexit`.
# solution from: http://bugs.python.org/issue15881#msg170215
try:
import multiprocessing # noqa
except ImportError:
pass
setuptools.setup( setuptools.setup(
setup_requires=['pbr>=2.0.0'], setup_requires=['pbr>=2.0.0'],
pbr=True) pbr=True)

View File

@ -5,12 +5,12 @@
astroid==1.6.5 # LGPLv2.1 astroid==1.6.5 # LGPLv2.1
# hacking pins flake8 etc # hacking pins flake8 etc
hacking>=1.1.0,<1.2.0 # Apache-2.0 hacking>=3.0,<3.1.0 # Apache-2.0
coverage>=4.0 coverage>=4.0
mock>=2.0.0 mock>=2.0.0
pylint==1.9.2 # GPLv2 pylint==1.9.2 # GPLv2
stestr>=2.0.0 # Apache-2.0 stestr>=2.0.0 # Apache-2.0
testtools>=2.2.0 testtools>=2.2.0
sphinx!=1.6.6,!=1.6.7,>=1.6.2,<2.0.0;python_version=='2.7' # BSD sphinx!=1.6.6,!=1.6.7,!=2.1.0,>=1.6.2 # BSD
sphinx!=1.6.6,!=1.6.7,!=2.1.0,>=1.6.2;python_version>='3.4' # BSD openstackdocstheme>=1.31.2 # Apache-2.0
openstackdocstheme>=1.18.1 # Apache-2.0 sphinxcontrib-apidoc>=0.2.0

10
tox.ini
View File

@ -6,12 +6,12 @@ skipsdist = True
[testenv] [testenv]
basepython = python3 basepython = python3
usedevelop = True usedevelop = True
deps = -r{toxinidir}/requirements.txt deps =
-r{toxinidir}/test-requirements.txt -c{env:UPPER_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
passenv = passenv =
http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY
install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages}
setenv = setenv =
VIRTUAL_ENV={envdir} VIRTUAL_ENV={envdir}
OS_TEST_PATH = ./tests/unit OS_TEST_PATH = ./tests/unit
@ -38,7 +38,7 @@ commands = {posargs}
[testenv:docs] [testenv:docs]
commands = commands =
python setup.py build_sphinx sphinx-build -W -b html doc/source doc/build/html
[testenv:py36] [testenv:py36]
basepython = python3.6 basepython = python3.6