PEP8 on the doc and elements files

ensure the Python scripts in the doc and elements directories are PEP8
compliant.

test_os_svc_daemon.py test is fixed in another patch:
  I9b1859f9fc5846c7c42606644231105618e1a1a0.

Change-Id: If5068ef77d6643c19de36bfcf4b4bf790f86b538
This commit is contained in:
Gonéri Le Bouder 2014-08-18 13:40:52 +02:00
parent 77c3177911
commit 0172b5aacc
10 changed files with 135 additions and 113 deletions

View File

@ -1,19 +1,17 @@
# -*- 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
@ -29,17 +27,9 @@ import os
# 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.
@ -181,22 +171,14 @@ 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',
('index', 'TripleOImageElements.tex',
u'TripleO Image Elements Documentation',
u'OpenStack Developers', 'manual'),
]
@ -240,8 +222,10 @@ 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.',
('index', 'TripleOImageElements',
u'TripleO Image Elements Documentation',
u'OpenStack Developers', 'TripleOImageElements',
'One line description of project.',
'Miscellaneous'),
]

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,12 +81,12 @@ 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)
@ -91,7 +97,7 @@ for createuser in to_create:
cmd = ['/opt/aws/bin/cfn-signal', '-i', dbvalue['username'],
'-s', 'true', '--data', password, dbvalue['userhandle']]
if opts.noop:
print cmd
print(cmd)
else:
subprocess.check_call(cmd)

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

@ -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,14 +15,17 @@
# 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',
logging.basicConfig(
level='INFO',
format='[%(asctime)s] (%(name)s) [%(levelname)s] %(message)s')
LOG = logging.getLogger(os.path.basename(sys.argv[0]))
@ -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]