Update hacking for Python3

The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Fix problems found.

Depends-On: https://review.opendev.org/722854
Change-Id: I190f32b2eea20024c71fc74bac7f5d011768473c
This commit is contained in:
Andreas Jaeger 2020-04-10 14:29:37 +02:00 committed by Jonathan Rosser
parent d719094a04
commit 2860f1bda5
9 changed files with 97 additions and 81 deletions

View File

@ -23,8 +23,8 @@
# serve to show the default.
import os
import sys
import subprocess
import sys
import openstackdocstheme
@ -46,18 +46,22 @@ title = 'OpenStack-Ansible Documentation'
current_series = openstackdocstheme.ext._get_series_name()
if current_series == "latest":
latest_tag = "master"
rdo_series = previous_series_name
suse_series = previous_series_name.capitalize()
latest_tag = "master"
rdo_series = previous_series_name
suse_series = previous_series_name.capitalize()
else:
series_names = current_series.capitalize()
latest_tag = subprocess.check_output(["git", "describe", "--abbrev=0", "--tag"]).strip().decode()
rdo_series = current_series_name
suse_series = current_series_name.capitalize()
series_names = current_series.capitalize()
latest_tag = subprocess.check_output(["git", "describe", "--abbrev=0",
"--tag"]).strip().decode()
rdo_series = current_series_name
suse_series = current_series_name.capitalize()
deploy_guide_prefix = "https://docs.openstack.org/project-deploy-guide/openstack-ansible/{}/%s".format(current_series)
dev_docs_prefix = "https://docs.openstack.org/openstack-ansible/{}/%s".format(current_series)
role_docs_prefix = "https://docs.openstack.org/openstack-ansible-%s/{}".format(current_series)
deploy_guide_prefix = ("https://docs.openstack.org/project-deploy-guide/"
"openstack-ansible/{}/%s".format(current_series))
dev_docs_prefix = ("https://docs.openstack.org/openstack-ansible/"
"{}/%s".format(current_series))
role_docs_prefix = ("https://docs.openstack.org/openstack-ansible-"
"%s/{}".format(current_series))
# Substitutions loader
rst_epilog = """
@ -65,14 +69,14 @@ rst_epilog = """
.. |rdo_series| replace:: {rdo_series}
.. |suse_series| replace:: {suse_series}
""".format(
latest_tag=latest_tag,
rdo_series=rdo_series,
suse_series=suse_series
latest_tag=latest_tag,
rdo_series=rdo_series,
suse_series=suse_series
)
# Format: Reference name: (string containing %s for substitution, linkname)
extlinks = {'deploy_guide': (deploy_guide_prefix, ''),
'dev_docs': (dev_docs_prefix, ''),
'dev_docs': (dev_docs_prefix, ''),
'role_docs': (role_docs_prefix, '')
}
@ -98,7 +102,7 @@ extensions = [
]
# Add any paths that contain templates here, relative to this directory.
#templates_path = ['_templates']
# templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'

View File

@ -22,11 +22,9 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
import imp
import os
import re
import sys
import subprocess
import sys
import openstackdocstheme
import yaml
@ -38,7 +36,7 @@ description = 'OpenStack-Ansible deploys OpenStack environments using Ansible.'
previous_series_name = 'stein'
current_series_name = 'train'
## General information about the project.
# General information about the project.
author = 'OpenStack-Ansible Contributors'
category = 'Miscellaneous'
copyright = '2014-2018, OpenStack-Ansible Contributors'
@ -49,14 +47,16 @@ title = 'OpenStack-Ansible Documentation'
current_series = openstackdocstheme.ext._get_series_name()
if current_series == "latest":
latest_tag = "master"
branch = "master"
upgrade_warning = "Upgrading to master is not recommended. Master is under heavy development, and is not stable."
latest_tag = "master"
branch = "master"
upgrade_warning = ("Upgrading to master is not recommended. "
"Master is under heavy development, and is not stable.")
else:
series_names = current_series.capitalize()
latest_tag = subprocess.check_output(["git", "describe", "--abbrev=0", "--tag"]).strip().decode()
branch = "stable/{}".format(current_series)
upgrade_warning = "The upgrade is always under active development."
series_names = current_series.capitalize()
latest_tag = subprocess.check_output(["git", "describe", "--abbrev=0",
"--tag"]).strip().decode()
branch = "stable/{}".format(current_series)
upgrade_warning = "The upgrade is always under active development."
CONF_PATH = os.path.dirname(os.path.realpath(__file__))
GNOCCHI_DETAILS = '../../playbooks/defaults/repo_packages/gnocchi.yml'
@ -65,8 +65,11 @@ with open(os.path.join(CONF_PATH, GNOCCHI_DETAILS), 'r') as fdesc:
gnocchi_branch = gnocchi_file_content['gnocchi_git_track_branch']
# References variable for substitutions
deploy_guide_prefix = "https://docs.openstack.org/project-deploy-guide/openstack-ansible/{}/%s".format(current_series)
dev_docs_prefix = "https://docs.openstack.org/openstack-ansible/{}/%s".format(current_series)
deploy_guide_prefix = ("https://docs.openstack.org/"
"project-deploy-guide/openstack-ansible/"
"{}/%s".format(current_series))
dev_docs_prefix = ("https://docs.openstack.org/openstack-ansible/"
"{}/%s".format(current_series))
# Substitutions loader
rst_epilog = """
@ -77,19 +80,19 @@ rst_epilog = """
.. |current_release_formal_name| replace:: {current_release_formal_name}
.. |latest_tag| replace:: {latest_tag}
.. |upgrade_warning| replace:: {upgrade_warning}
""".format(
current_release_git_branch_name=branch,
current_release_gnocchi_git_branch_name=gnocchi_branch,
previous_series_name=previous_series_name,
previous_release_formal_name=previous_series_name.capitalize(),
current_release_formal_name=current_series_name.capitalize(),
latest_tag=latest_tag,
upgrade_warning=upgrade_warning,
""".format( # noqa: E501
current_release_git_branch_name=branch,
current_release_gnocchi_git_branch_name=gnocchi_branch,
previous_series_name=previous_series_name,
previous_release_formal_name=previous_series_name.capitalize(),
current_release_formal_name=current_series_name.capitalize(),
latest_tag=latest_tag,
upgrade_warning=upgrade_warning,
)
# Format: Reference name: (string containing %s for substitution, linkname)
extlinks = {'deploy_guide': (deploy_guide_prefix, ''),
'dev_docs': (dev_docs_prefix, '')
'dev_docs': (dev_docs_prefix, '')
}
# If extensions (or modules to document with autodoc) are in another directory,
@ -142,9 +145,7 @@ language = None
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = [
'admin/maintenance-tasks/galera.rst'
]
exclude_patterns = ['admin/maintenance-tasks/galera.rst']
# The reST default role (used for this markup: `text`) to use for all
# documents.

View File

@ -204,12 +204,12 @@ def write_hostnames(save_path, hostnames_ips):
with open(hostnames_ip_file, 'wb') as f:
f.write(
('# This file is managed by openstack-ansible. No manual edits.\n'
+ json.dumps(
hostnames_ips,
indent=4,
separators=(',', ': '),
sort_keys=True
)).encode('ascii')
+ json.dumps(
hostnames_ips,
indent=4,
separators=(',', ': '),
sort_keys=True
)).encode('ascii')
)
@ -234,9 +234,11 @@ def _load_from_json(filename, preferred_path=None, raise_if_missing=True):
def load_inventory(preferred_path=None, default_inv=None, filename=None):
"""Create an inventory dictionary from the given source file or a default
inventory. If an inventory is found then a backup tarball is created
as well.
"""Create an inventory dictionary.
Create inventory dictionary from the given source file or a default
inventory. If an inventory is found then a backup tarball is created
as well.
:param preferred_path: ``str`` Path to the inventory directory to try FIRST
:param default_inv: ``dict`` Default inventory skeleton
@ -252,7 +254,7 @@ def load_inventory(preferred_path=None, default_inv=None, filename=None):
inv_fn = INVENTORY_FILENAME
inventory, file_loaded = _load_from_json(inv_fn, preferred_path,
raise_if_missing=False)
raise_if_missing=False)
if file_loaded is not False:
load_path = os.path.dirname(file_loaded)
else:
@ -327,8 +329,8 @@ def load_user_configuration(config_path=None):
# Exit if no user_config was found and loaded
if not user_defined_config:
raise MissingDataSource(_get_search_paths(config_path) +
_get_search_paths(config_path, 'conf.d'))
raise MissingDataSource(_get_search_paths(config_path)
+ _get_search_paths(config_path, 'conf.d'))
logger.debug("User configuration loaded from: {}".format(user_config_file))
return user_defined_config

View File

@ -53,13 +53,13 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
author = u'OpenStack-Ansible Contributors'
category = u'Miscellaneous'
copyright = u'2014-2016, OpenStack-Ansible Contributors'
description = u'OpenStack-Ansible deploys OpenStack environments using Ansible.'
project = u'OpenStack-Ansible'
target_name = u'openstack-ansible'
title = u'OpenStack-Ansible Release Notes'
author = 'OpenStack-Ansible Contributors'
category = 'Miscellaneous'
copyright = '2014-2016, OpenStack-Ansible Contributors'
description = 'OpenStack-Ansible deploys OpenStack environments using Ansible.'
project = 'OpenStack-Ansible'
target_name = 'openstack-ansible'
title = 'OpenStack-Ansible Release Notes'
# The link to the browsable source code (for the left hand menu)
oslosphinx_cgit_link = (

View File

@ -31,7 +31,8 @@ import yaml
# we setup a representation for dict objects and register it
# with the yaml class.
def represent_dict(self, data):
def key_function((key, value)):
def key_function(elem):
key = elem[0]
# Prioritizes certain keys when sorting.
prio = {"model": 0, "pk": 1, "fields": 2}.get(key, 99)
return (prio, key)
@ -39,6 +40,7 @@ def represent_dict(self, data):
items.sort(key=key_function)
return self.represent_mapping(u'tag:yaml.org,2002:map', items)
yaml.add_representer(dict, represent_dict)
@ -100,5 +102,6 @@ def main():
except yaml.YAMLError as exc:
print(exc)
if __name__ == "__main__":
main()

View File

@ -40,7 +40,8 @@ import yaml
# we setup a representation for dict objects and register it
# with the yaml class.
def represent_dict(self, data):
def key_function((key, value)):
def key_function(elem):
key = elem[0]
# Prioritizes certain keys when sorting.
prio = {"version": 0, "projects": 1, "repo": 2, "hash": 3}.get(key, 99)
return (prio, key)
@ -48,6 +49,7 @@ def represent_dict(self, data):
items.sort(key=key_function)
return self.represent_mapping(u'tag:yaml.org,2002:map', items)
yaml.add_representer(dict, represent_dict)
@ -56,7 +58,7 @@ yaml.add_representer(dict, represent_dict)
def yaml_dump(dump, indentSize=2):
stream = StringIO(dump)
out = StringIO()
pat = re.compile('(\s*)([^:]*)(:*)')
pat = re.compile(r'(\s*)([^:]*)(:*)')
last = None
prefix = 0
@ -134,5 +136,6 @@ def main():
# Print the output, formatted as expected
print(yaml_dump(output))
if __name__ == "__main__":
main()

View File

@ -3,7 +3,7 @@
# process, which may cause wedges in the gate later.
# Keep hacking first, it pulls in the right versions of flake8, mccabe and pyflakes
hacking>=1.1.0,<1.2.0 # Apache-2.0
hacking>=3.0,<3.1.0 # Apache-2.0
bashate>=0.5.1 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0
mock>=2.0.0 # BSD

View File

@ -29,11 +29,11 @@ INV_DIR = 'inventory'
sys.path.append(path.join(os.getcwd(), INV_DIR))
from osa_toolkit import dictutils
import dynamic_inventory
from osa_toolkit import filesystem as fs
from osa_toolkit import generate as di
from osa_toolkit import tools
import dynamic_inventory # noqa: E402
from osa_toolkit import dictutils # noqa: E402
from osa_toolkit import filesystem as fs # noqa: E402
from osa_toolkit import generate as di # noqa: E402
from osa_toolkit import tools # noqa: E402
TARGET_DIR = path.join(os.getcwd(), 'tests', 'inventory')
BASE_ENV_DIR = INV_DIR
@ -1106,7 +1106,6 @@ class TestOverridingEnvVars(OverridingEnvBase):
# a partial override file
vol = self.cinder_config['container_skel']['cinder_volumes_container']
keys = vol.keys()
to_delete = []
for key in vol.keys():
if not key == 'properties':
@ -1445,7 +1444,8 @@ class TestInventoryGroupConstraints(unittest.TestCase):
# This should only work on groups, but stuff like '_meta' and 'all'
# are in here, too.
for key, values in inventory.items():
# The keys for children/hosts can exist, the important part is being empty lists.
# The keys for children/hosts can exist, the important part is
# being empty lists.
has_children = bool(inventory.get('children'))
has_hosts = bool(inventory.get('hosts'))
@ -1482,7 +1482,6 @@ class TestInventoryGroupConstraints(unittest.TestCase):
"""Integration test making sure the whole script fails."""
env = self._create_bad_env(self.env)
config = get_config()
kwargs = {
@ -1494,7 +1493,7 @@ class TestInventoryGroupConstraints(unittest.TestCase):
mocks['load_environment'].return_value = env
mocks['load_user_configuration'].return_value = config
with self.assertRaises(di.GroupConflict) as context:
with self.assertRaises(di.GroupConflict):
get_inventory()
def test_group_validation_unit(self):
@ -1516,6 +1515,7 @@ class TestInventoryGroupConstraints(unittest.TestCase):
self.assertTrue(result)
class TestL3ProviderNetworkConfig(TestConfigCheckBase):
def setUp(self):
super(TestL3ProviderNetworkConfig, self).setUp()
@ -1534,15 +1534,16 @@ class TestL3ProviderNetworkConfig(TestConfigCheckBase):
self.inventory = get_inventory()
def test_address_prefix_name_applied(self):
aio2_host_vars = self.inventory['_meta']['hostvars']['aio2']
aio2_container_networks = aio2_host_vars['container_networks']
self.assertIsInstance(aio2_container_networks['management_address'],
dict)
aio2_host_vars = self.inventory['_meta']['hostvars']['aio2']
aio2_container_networks = aio2_host_vars['container_networks']
self.assertIsInstance(aio2_container_networks['management_address'],
dict)
def test_host_outside_reference_group_excluded(self):
aio1_host_vars = self.inventory['_meta']['hostvars']['aio1']
aio1_container_networks = aio1_host_vars['container_networks']
self.assertNotIn('management_address', aio1_container_networks)
aio1_host_vars = self.inventory['_meta']['hostvars']['aio1']
aio1_container_networks = aio1_host_vars['container_networks']
self.assertNotIn('management_address', aio1_container_networks)
if __name__ == '__main__':
unittest.main(catchbreak=True)

View File

@ -77,7 +77,9 @@ commands =
# Ignores the following rules due to how ansible modules work in general
# F403 'from ansible.module_utils.basic import *' used;
# unable to detect undefined names
ignore=F403
# E124 closing bracket does not match visual indentation
# W503 line break before binary operator
ignore=F403,E124,W503
[testenv:bashate]
commands =