From 72de51b01c180fb18f062c7b47e25e8044aeb237 Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Sun, 12 Apr 2020 19:26:00 +0200 Subject: [PATCH] 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 --- doc/source/conf.py | 24 ++++---- doc/source/index.rst | 8 +-- freezer_dr/monitors/drivers/default/driver.py | 8 +-- freezer_dr/monitors/drivers/monasca/driver.py | 57 ++++++++++--------- lower-constraints.txt | 3 +- setup.cfg | 18 +----- setup.py | 9 --- test-requirements.txt | 8 +-- tox.ini | 10 ++-- 9 files changed, 61 insertions(+), 84 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 3c2d781..8c1088d 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -14,7 +14,6 @@ import sys import os -from freezer_dr import __version__ as FREEZER_DR_VERSION # 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 @@ -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 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ['sphinx.ext.autodoc', +extensions = ['sphinxcontrib.apidoc', 'sphinx.ext.viewcode', 'openstackdocstheme'] @@ -49,15 +48,6 @@ master_doc = 'index' project = u'Freezer' 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 # for a list of supported languages. #language = None @@ -130,7 +120,7 @@ html_theme = 'openstackdocs' # 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, # 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 # .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. -#intersphinx_mapping = {'http://docs.python.org/': None} \ No newline at end of file +#intersphinx_mapping = {'http://docs.python.org/': None} + +# -- sphinxcontrib.apidoc configuration -------------------------------------- + +apidoc_module_dir = '../../freezer_dr' +apidoc_output_dir = 'api' +apidoc_excluded_paths = [ + 'tests', +] diff --git a/doc/source/index.rst b/doc/source/index.rst index 6b53e87..e654110 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -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! ===================================================== @@ -24,4 +20,4 @@ Indices and tables .. toctree:: :maxdepth: 1 - api/autoindex + api/modules diff --git a/freezer_dr/monitors/drivers/default/driver.py b/freezer_dr/monitors/drivers/default/driver.py index aeaa135..a885a41 100644 --- a/freezer_dr/monitors/drivers/default/driver.py +++ b/freezer_dr/monitors/drivers/default/driver.py @@ -14,15 +14,15 @@ from freezer_dr.common.osclient import OSClient from freezer_dr.monitors.common.driver import MonitorBaseDriver -from httplib import HTTPConnection -from httplib import HTTPSConnection -from httplib import socket +from http.client import HTTPConnection +from http.client import HTTPSConnection +from http.client import socket from oslo_config import cfg from oslo_log import log from time import sleep -from urlparse import urlparse +from urllib.parse import urlparse CONF = cfg.CONF LOG = log.getLogger(__name__) diff --git a/freezer_dr/monitors/drivers/monasca/driver.py b/freezer_dr/monitors/drivers/monasca/driver.py index be6a386..329a92c 100644 --- a/freezer_dr/monitors/drivers/monasca/driver.py +++ b/freezer_dr/monitors/drivers/monasca/driver.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import httplib +import http.client import time -import urlparse +import urllib.parse from monascaclient import client from oslo_config import cfg @@ -29,9 +29,11 @@ LOG = log.getLogger(__name__) class MonascaDriver(driver.MonitorBaseDriver): """Monasca monitoring driver to monitor compute nodes. It makes use of - Monasca to monitor the compute nodes. Metric information needed. 'hostname' - must be used in dimensions to filter the values in alarms. You need to - define alarms for all hosts with the required metrics.""" + Monasca to monitor the compute nodes. Metric information + needed. 'hostname' must be used in dimensions to filter the + values in alarms. You need to define alarms for all hosts with + the required metrics. + """ _OPTS = [ cfg.StrOpt('keystone_url', @@ -131,20 +133,21 @@ class MonascaDriver(driver.MonitorBaseDriver): def get_data(self): """This function returns monitoring data from Monasca. It calls - _get_raw_data to get raw data and then process these data returns - a normalized dict - :return: doct contains: - { - hostname1: { - metric_name1: ['Ok', 'ALARM', 'UNDETERMINED'] - metric_name2: ['OK', 'OK', 'OK'] - }, - hostname2: { - metric_name1: ['Ok', 'ALARM', 'OK'] - metric_name2: ['ALARM', 'UNDETERMINED', 'OK'] - } - } - """ + _get_raw_data to get raw data and then process these data returns + a normalized dict + :return: dict contains:: + + { + hostname1: { + metric_name1: ['Ok', 'ALARM', 'UNDETERMINED'] + metric_name2: ['OK', 'OK', 'OK'] + }, + hostname2: { + metric_name1: ['Ok', 'ALARM', 'OK'] + metric_name2: ['ALARM', 'UNDETERMINED', 'OK'] + } + } + """ data = self._get_raw_data() data2 = {} for host, metric_results in data.items(): @@ -183,10 +186,10 @@ class MonascaDriver(driver.MonitorBaseDriver): def analyze_nodes(self, nodes): """It will check if the nodes are in 'OK' state or not. If not they - will considered down. We have three states as follow: - 1. OK - 2. ALARM - 3. UNDEFINED + will considered down. We have three states as follow: + 1. OK + 2. ALARM + 3. UNDEFINED """ # @todo(szaher) use list comprehension instead of loops # list below is correct and should return the extact same value like @@ -267,16 +270,16 @@ class MonascaDriver(driver.MonitorBaseDriver): return eval(aggregate) def is_alive(self): - url = urlparse.urlparse(self.conf.monasca_url) + url = urllib.parse.urlparse(self.conf.monasca_url) if url.scheme == 'https': - http_connector = httplib.HTTPSConnection + http_connector = http.client.HTTPSConnection else: - http_connector = httplib.HTTPConnection + http_connector = http.client.HTTPConnection try: connection = http_connector(host=url.netloc) connection.request('HEAD', url=url.path) response = connection.getresponse() - except httplib.socket.error: + except http.client.socket.error: return False try: if getattr(response, 'status') in [200, 401]: diff --git a/lower-constraints.txt b/lower-constraints.txt index ec8ce68..fc17a15 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -50,7 +50,7 @@ msgpack==0.5.6 munch==2.2.0 netaddr==0.7.19 netifaces==0.10.6 -openstackdocstheme==1.18.1 +openstackdocstheme==1.31.2 openstacksdk==0.12.0 os-brick==2.2.0 os-client-config==1.29.0 @@ -107,6 +107,7 @@ setuptools==21.0.0 simplejson==3.13.2 snowballstemmer==1.2.1 Sphinx==1.6.2 +sphinxcontrib-apidoc==0.2.0 sphinxcontrib-websupport==1.0.1 stestr==2.0.0 stevedore==1.28.0 diff --git a/setup.cfg b/setup.cfg index 6a1babb..d7cf82c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,6 +6,7 @@ description-file = author = Freezer Team author-email = openstack-discuss@lists.openstack.org home-page = https://docs.openstack.org/freezer/latest/ +python-requires = >=3.6 classifier = Environment :: OpenStack Intended Audience :: Developers @@ -14,6 +15,8 @@ classifier = License :: OSI Approved :: Apache Software License Operating System :: POSIX :: Linux Programming Language :: Python + Programming Language :: Python :: Implementation :: CPython + Programming Language :: Python :: 3 :: Only Programming Language :: Python :: 3 Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 @@ -35,21 +38,6 @@ keywords = packages = 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] oslo.config.opts = freezer-dr = freezer_dr.common.config:list_opts diff --git a/setup.py b/setup.py index 566d844..cd35c3c 100644 --- a/setup.py +++ b/setup.py @@ -13,17 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT 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( setup_requires=['pbr>=2.0.0'], pbr=True) diff --git a/test-requirements.txt b/test-requirements.txt index 9f319c4..2d62c43 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,12 +5,12 @@ astroid==1.6.5 # LGPLv2.1 # 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 mock>=2.0.0 pylint==1.9.2 # GPLv2 stestr>=2.0.0 # Apache-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;python_version>='3.4' # BSD -openstackdocstheme>=1.18.1 # Apache-2.0 +sphinx!=1.6.6,!=1.6.7,!=2.1.0,>=1.6.2 # BSD +openstackdocstheme>=1.31.2 # Apache-2.0 +sphinxcontrib-apidoc>=0.2.0 diff --git a/tox.ini b/tox.ini index a58cd85..e30bf3c 100644 --- a/tox.ini +++ b/tox.ini @@ -6,12 +6,12 @@ skipsdist = True [testenv] basepython = python3 usedevelop = True -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt +deps = + -c{env:UPPER_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} + -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt passenv = 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 = VIRTUAL_ENV={envdir} OS_TEST_PATH = ./tests/unit @@ -38,7 +38,7 @@ commands = {posargs} [testenv:docs] commands = - python setup.py build_sphinx + sphinx-build -W -b html doc/source doc/build/html [testenv:py36] basepython = python3.6