Merge "PEP8 on the doc and elements files"

This commit is contained in:
Jenkins 2014-08-20 23:13:04 +00:00 committed by Gerrit Code Review
commit 4562892fcf
10 changed files with 135 additions and 113 deletions

View File

@ -1,45 +1,35 @@
# -*- coding: utf-8 -*-
#
# TripleO Image Elements documentation build configuration file, created by
# sphinx-quickstart on Fri Apr 18 09:19:09 2014.
# 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
#
# This file is execfile()d with the current directory set to its
# containing dir.
# http://www.apache.org/licenses/LICENSE-2.0
#
# Note that not all possible configuration values are present in this
# autogenerated file.
# 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.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys
import os
# 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
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# sys.path.insert(0, os.path.abspath('.'))
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['oslosphinx']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
@ -57,13 +47,13 @@ release = '0.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
@ -71,27 +61,27 @@ exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all
# documents.
#default_role = None
# default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# modindex_common_prefix = []
# If true, keep warnings as "system message" paragraphs in the built documents.
#keep_warnings = False
# keep_warnings = False
# -- Options for HTML output ----------------------------------------------
@ -103,26 +93,26 @@ html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# html_favicon = None
# 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,
@ -132,48 +122,48 @@ 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
# directly to the root of the documentation.
#html_extra_path = []
# html_extra_path = []
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'TripleOImageElementsdoc'
@ -181,44 +171,36 @@ htmlhelp_basename = 'TripleOImageElementsdoc'
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
latex_elements = {}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'TripleOImageElements.tex', u'TripleO Image Elements Documentation',
u'OpenStack Developers', 'manual'),
('index', 'TripleOImageElements.tex',
u'TripleO Image Elements Documentation',
u'OpenStack Developers', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# latex_domain_indices = True
# -- Options for manual page output ---------------------------------------
@ -231,7 +213,7 @@ man_pages = [
]
# If true, show URL addresses after external links.
#man_show_urls = False
# man_show_urls = False
# -- Options for Texinfo output -------------------------------------------
@ -240,19 +222,21 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'TripleOImageElements', u'TripleO Image Elements Documentation',
u'OpenStack Developers', 'TripleOImageElements', 'One line description of project.',
'Miscellaneous'),
('index', 'TripleOImageElements',
u'TripleO Image Elements Documentation',
u'OpenStack Developers', 'TripleOImageElements',
'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# texinfo_show_urls = 'footnote'
# If true, do not generate a @detailmenu in the "Top" node's menu.
#texinfo_no_detailmenu = False
# texinfo_no_detailmenu = False

View File

@ -49,7 +49,7 @@ CACHES = {
{{#horizon.caches.memcached}}
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': [{{#nodes}}'{{.}}',{{/nodes}}]
{{/horizon.caches.memcached}}
{{/horizon.caches.memcached}} # flake8: noqa
{{^horizon.caches.memcached}}
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
{{/horizon.caches.memcached}}

View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
#
# Assert users that came from metadata config
#
@ -18,26 +18,32 @@
# under the License.
#
import subprocess
import MySQLdb
import logging
from __future__ import print_function
import argparse
import os
import base64
import json
from base64 import b64encode
import logging
import os
import subprocess
import MySQLdb
logging.basicConfig()
logger = logging.getLogger('mysql-users')
# Try to connect with no password, ~/.my.cnf and /mnt/state/root/metadata.my.cnf
# Try to connect with no password, ~/.my.cnf and
# /mnt/state/root/metadata.my.cnf
# in that order. This should cover os-refresh-config post install and re-image
try:
conn = MySQLdb.Connect()
except Exception as e:
try:
conn = MySQLdb.Connect(read_default_file=os.path.expanduser('~/.my.cnf'))
conn = MySQLdb.Connect(
read_default_file=os.path.expanduser('~/.my.cnf'))
except Exception as e:
conn = MySQLdb.Connect(read_default_file='/mnt/state/root/metadata.my.cnf')
conn = MySQLdb.Connect(
read_default_file='/mnt/state/root/metadata.my.cnf')
cursor = conn.cursor()
rows = cursor.execute("SELECT DISTINCT User FROM mysql.user WHERE user != ''")
existing = set([x[0] for x in cursor.fetchmany(size=rows)])
@ -75,25 +81,25 @@ for createuser in to_create:
if 'password' in dbvalue:
password = dbvalue['password']
else:
password = b64encode(os.urandom(30))
password = base64.b64encode(os.urandom(30))
cmd = "GRANT ALL PRIVILEGES ON `%s`.* TO `%s`@'%%' IDENTIFIED BY '%s'" % (
dbvalue['database'], dbvalue['username'], password)
if opts.noop:
print "%s" % (cmd)
print("%s" % (cmd))
else:
cursor = conn.cursor()
cursor.execute(cmd)
cursor.close()
if 'userhandle' in dbvalue:
# Inform Heat of new password for this user
cmd = ['/opt/aws/bin/cfn-signal', '-i', dbvalue['username'],
'-s', 'true', '--data', password, dbvalue['userhandle']]
if opts.noop:
print cmd
else:
subprocess.check_call(cmd)
# Inform Heat of new password for this user
cmd = ['/opt/aws/bin/cfn-signal', '-i', dbvalue['username'],
'-s', 'true', '--data', password, dbvalue['userhandle']]
if opts.noop:
print(cmd)
else:
subprocess.check_call(cmd)
if to_delete:
logger.warn('The following users are not accounted for: %s' % to_delete)

View File

@ -42,15 +42,19 @@ def load_userfile(path, users):
def secure_installation(rootuser):
# Try to connect with no password, ~/.my.cnf and /mnt/state/root/metadata.my.cnf
# in that order. This should cover os-refresh-config post install and re-image
# Try to connect with no password, ~/.my.cnf and
# /mnt/state/root/metadata.my.cnf in that order.
# This should cover os-refresh-config post install
# and re-image
try:
conn = MySQLdb.Connect()
except Exception as e:
except Exception:
try:
conn = MySQLdb.Connect(read_default_file=os.path.expanduser('~/.my.cnf'))
except Exception as e:
conn = MySQLdb.Connect(read_default_file='/mnt/state/root/metadata.my.cnf')
conn = MySQLdb.Connect(
read_default_file=os.path.expanduser('~/.my.cnf'))
except Exception:
conn = MySQLdb.Connect(
read_default_file='/mnt/state/root/metadata.my.cnf')
with conn:
# Remove Anonymous Users
cursor = conn.cursor()
@ -72,7 +76,8 @@ def secure_installation(rootuser):
cursor.execute(cmd, (rootpwd, "root"))
cursor.execute("FLUSH PRIVILEGES")
# As Above also sets root password .my.cnf with new password
shutil.copy2('/mnt/state/root/metadata.my.cnf',os.path.expanduser('~/.my.cnf'))
shutil.copy2('/mnt/state/root/metadata.my.cnf',
os.path.expanduser('~/.my.cnf'))
cursor.close()
users = {}

View File

@ -87,4 +87,4 @@ if errors:
if reload_nagios:
sys.stderr.write("INFO: reloading nagios.")
subprocess.call(["service","nagios3","reload"])
subprocess.call(["service", "nagios3", "reload"])

View File

@ -12,10 +12,10 @@
# License for the specific language governing permissions and limitations
# under the License.
from tests import base
import tests.base
class TestOsSvcDaemon(base.ScriptTestBase):
class TestOsSvcDaemon(tests.base.ScriptTestBase):
def setUp(self):
super(TestOsSvcDaemon, self).setUp()
self._stub_script('map-services', 'echo $1')

View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# Copyright 2013 Hewlett-Packard Development Company, L.P.
# All Rights Reserved.
#
@ -15,18 +15,21 @@
# under the License.
#
from __future__ import print_function
import base64
import json
import logging
import os
import sys
import subprocess
import sys
logging.basicConfig(level='INFO',
format='[%(asctime)s] (%(name)s) [%(levelname)s] %(message)s')
logging.basicConfig(
level='INFO',
format='[%(asctime)s] (%(name)s) [%(levelname)s] %(message)s')
LOG = logging.getLogger(os.path.basename(sys.argv[0]))
USERS_FILE='/etc/rabbitmq/heat_users.json'
USERS_FILE = '/etc/rabbitmq/heat_users.json'
HANDLE_FILE = '/etc/rabbitmq/heat_password_handle'
# USERS_FILE can exist without any content, in which case it will just be an
@ -39,6 +42,7 @@ if os.path.exists(HANDLE_FILE):
with open(HANDLE_FILE) as hf:
PASSWORD_HANDLE = hf.read().rstrip()
def get_existing_users():
list_users = subprocess.check_output(['rabbitmqctl', 'list_users'],
stderr=subprocess.STDOUT)
@ -88,7 +92,7 @@ for need_user in need:
'--data', password,
PASSWORD_HANDLE])
else:
print '%s:%s' % (username, password)
print('%s:%s' % (username, password))
if 'permissions' in detail:
args = ['rabbitmqctl', 'set_permissions', username]
args.append(detail['permissions']['conf'])

View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
#
# Copyright 2013 Red Hat
# All Rights Reserved.

23
run-flake8 Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
# Copyright 2014 eNovance <licensing@enovance.com>
#
# 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.
#
set -eu
set -o pipefail
flake8
extra_python_files=$(egrep -R --null-data --files-with-matches "^#!/usr/bin/env python" elements/)
echo $extra_python_files
flake8 ${extra_python_files}

View File

@ -18,11 +18,11 @@ commands =
commands = {posargs}
[testenv:pep8]
commands = flake8
commands = ./run-flake8
[flake8]
ignore = E125,H803
exclude = .venv,.tox,dist,doc,*.egg
exclude = .venv,.tox,dist,*.egg
show-source = true
[tox:jenkins]