Enabling H403, H702 rules

Reasons
- Currently H403, H702 rules are ignored
- Project has files violating H403, H702 rules.

Changes
- Enables H403, H702 rules.
- Updates the code not following H403, H702 rules.

Change-Id: Ie6f289bf10ee6d6c61feeee0d9905361f236813b
Closes-Bug: #1258592
This commit is contained in:
Sushil Kumar 2013-12-06 17:36:08 +00:00
parent 25ec5f1690
commit 9e6b4daef6
12 changed files with 65 additions and 37 deletions

View File

@ -37,7 +37,7 @@ commands = {posargs}
[flake8]
show-source = True
ignore = F403,F821,H301,H306,H402,H403,H404,H702
ignore = F403,F821,H301,H306,H402,H404
builtins = _
exclude=.venv,.tox,dist,doc,openstack,*egg,rsdns,tools,etc,build
filename=*.py,trove-*

View File

@ -28,7 +28,8 @@ ENV = jinja2.Environment(loader=jinja2.ChoiceLoader([
class SingleInstanceConfigTemplate(object):
"""This class selects a single configuration file by database type for
rendering on the guest """
rendering on the guest
"""
def __init__(self, datastore_manager, flavor_dict, instance_id):
"""Constructor

View File

@ -146,7 +146,8 @@ class MgmtInstanceController(InstanceController):
@admin_context
def root(self, req, tenant_id, id):
"""Return the date and time root was enabled on an instance,
if ever."""
if ever.
"""
LOG.info(_("req : '%s'\n\n") % req)
LOG.info(_("Showing root history for tenant '%s'") % tenant_id)
LOG.info(_("id : '%s'\n\n") % id)

View File

@ -40,7 +40,8 @@ class RootController(wsgi.Controller):
def index(self, req, tenant_id, instance_id):
"""Returns True if root is enabled for the given instance;
False otherwise. """
False otherwise.
"""
LOG.info(_("Getting root enabled for instance '%s'") % instance_id)
LOG.info(_("req : '%s'\n\n") % req)
context = req.environ[wsgi.CONTEXT_KEY]
@ -209,7 +210,7 @@ class UserAccessController(wsgi.Controller):
user_id = correct_id_with_req(user_id, req)
user = self._get_user(context, instance_id, user_id)
if not user:
LOG.error(_("No such user: %(user)s " % {'user': user}))
LOG.error(_("No such user: %(user)s ") % {'user': user})
raise exception.UserNotFound(uuid=user)
username, hostname = unquote_user_host(user_id)
access = models.User.access(context, instance_id, username, hostname)
@ -224,7 +225,7 @@ class UserAccessController(wsgi.Controller):
user_id = correct_id_with_req(user_id, req)
user = self._get_user(context, instance_id, user_id)
if not user:
LOG.error(_("No such user: %(user)s " % {'user': user}))
LOG.error(_("No such user: %(user)s ") % {'user': user})
raise exception.UserNotFound(uuid=user)
username, hostname = unquote_user_host(user_id)
databases = [db['name'] for db in body['databases']]
@ -239,7 +240,7 @@ class UserAccessController(wsgi.Controller):
user_id = correct_id_with_req(user_id, req)
user = self._get_user(context, instance_id, user_id)
if not user:
LOG.error(_("No such user: %(user)s " % {'user': user}))
LOG.error(_("No such user: %(user)s ") % {'user': user})
raise exception.UserNotFound(uuid=user)
username, hostname = unquote_user_host(user_id)
access = models.User.access(context, instance_id, username, hostname)

View File

@ -111,7 +111,8 @@ class API(proxy.RpcProxy):
def change_passwords(self, users):
"""Make an asynchronous call to change the passwords of one or more
users."""
users.
"""
LOG.debug(_("Changing passwords for users on Instance %s"), self.id)
self._cast("change_passwords", users=users)
@ -166,7 +167,8 @@ class API(proxy.RpcProxy):
def create_database(self, databases):
"""Make an asynchronous call to create a new database
within the specified container"""
within the specified container
"""
LOG.debug(_("Creating databases for Instance %s"), self.id)
self._cast("create_database", databases=databases)
@ -178,7 +180,8 @@ class API(proxy.RpcProxy):
def delete_database(self, database):
"""Make an asynchronous call to delete an existing database
within the specified container"""
within the specified container
"""
LOG.debug(_("Deleting database %(database)s for "
"Instance %(instance_id)s") % {'database': database,
'instance_id': self.id})
@ -186,19 +189,22 @@ class API(proxy.RpcProxy):
def enable_root(self):
"""Make a synchronous call to enable the root user for
access from anywhere"""
access from anywhere
"""
LOG.debug(_("Enable root user for Instance %s"), self.id)
return self._call("enable_root", AGENT_LOW_TIMEOUT)
def disable_root(self):
"""Make a synchronous call to disable the root user for
access from anywhere"""
access from anywhere
"""
LOG.debug(_("Disable root user for Instance %s"), self.id)
return self._call("disable_root", AGENT_LOW_TIMEOUT)
def is_root_enabled(self):
"""Make a synchronous call to check if root access is
available for the container"""
available for the container
"""
LOG.debug(_("Check root access for Instance %s"), self.id)
return self._call("is_root_enabled", AGENT_LOW_TIMEOUT)
@ -239,7 +245,8 @@ class API(proxy.RpcProxy):
def reset_configuration(self, configuration):
"""Ignore running state of MySQL, and just change the config file
to a new flavor."""
to a new flavor.
"""
LOG.debug(_("Sending the call to change MySQL conf file on the Guest "
"with a timeout of %s.") % AGENT_HIGH_TIMEOUT)
self._call("reset_configuration", AGENT_HIGH_TIMEOUT,

View File

@ -304,7 +304,8 @@ class MySqlAdmin(object):
def create_user(self, users):
"""Create users and grant them privileges for the
specified databases."""
specified databases.
"""
with LocalSqlClient(get_engine()) as client:
for item in users:
user = models.MySQLUser()
@ -392,7 +393,8 @@ class MySqlAdmin(object):
def enable_root(self, root_password=None):
"""Enable the root user global access and/or
reset the root password."""
reset the root password.
"""
return MySqlRootAccess.enable_root(root_password)
def report_root_enabled(self, context=None):
@ -519,7 +521,8 @@ class MySqlAdmin(object):
def list_access(self, username, hostname):
"""Show all the databases to which the user has more than
USAGE granted."""
USAGE granted.
"""
user = self._get_user(username, hostname)
return user.databases
@ -577,7 +580,8 @@ class MySqlApp(object):
def install_if_needed(self, packages):
"""Prepare the guest machine with a secure
mysql server installation."""
mysql server installation.
"""
LOG.info(_("Preparing Guest as MySQL Server"))
if not packager.pkg_is_installed(packages):
LOG.debug(_("Installing mysql server"))
@ -827,7 +831,8 @@ class MySqlRootAccess(object):
@classmethod
def enable_root(cls, root_password=None):
"""Enable the root user global access and/or
reset the root password."""
reset the root password.
"""
user = models.RootUser()
user.name = "root"
user.host = "%"

View File

@ -121,8 +121,8 @@ class NotifyMixin(object):
# Update payload with all other kwargs
payload.update(kwargs)
LOG.debug(_('Sending event: %(event_type)s, %(payload)s' %
{'event_type': event_type, 'payload': payload}))
LOG.debug(_('Sending event: %(event_type)s, %(payload)s') %
{'event_type': event_type, 'payload': payload})
notifier.notify(self.context, publisher_id, event_type, 'INFO',
payload)
@ -661,9 +661,9 @@ class BuiltInstanceTasks(BuiltInstance, NotifyMixin, ConfigurationMixin):
LOG.debug(_("end _resize_active_volume for id: %s") %
self.server.id)
LOG.exception(_("Failed to detach volume %(volume_id)s "
"instance %(id)s: %(e)s" %
"instance %(id)s: %(e)s") %
{'volume_id': self.volume_id, 'id':
self.server.id, 'e': str(e)}))
self.server.id, 'e': str(e)})
self.restart()
raise

View File

@ -42,7 +42,8 @@ user = None
def assert_attributes_equal(name, os_flavor, dbaas_flavor):
"""Given an attribute name and two objects,
ensures the attribute is equal."""
ensures the attribute is equal.
"""
assert_true(hasattr(os_flavor, name),
"open stack flavor did not have attribute %s" % name)
assert_true(hasattr(dbaas_flavor, name),

View File

@ -163,7 +163,8 @@ class TestRoot(object):
enabled=not test_config.values['root_removed_from_instance_api'])
def test_root_still_enabled_details(self):
"""Use instance details to test that after root was reset,
it's still enabled."""
it's still enabled.
"""
instance = self.dbaas.instances.get(instance_info.id)
assert_true(hasattr(instance, 'rootEnabled'),
"Instance has no rootEnabled property.")

View File

@ -53,7 +53,8 @@ class UserAccessBase(object):
def _grant_access_singular(self, user, databases, expected_response=202):
"""Grant a single user access to the databases listed.
Potentially, expect an exception in the process."""
Potentially, expect an exception in the process.
"""
try:
self.dbaas.users.grant(instance_info.id, user, databases)
except exceptions.BadRequest:
@ -67,13 +68,15 @@ class UserAccessBase(object):
def _grant_access_plural(self, users, databases, expected_response=202):
"""Grant each user in the list access to all the databases listed.
Potentially, expect an exception in the process."""
Potentially, expect an exception in the process.
"""
for user in users:
self._grant_access_singular(user, databases, expected_response)
def _revoke_access_singular(self, user, database, expected_response=202):
"""Revoke from a user access to the given database .
Potentially, expect an exception in the process."""
Potentially, expect an exception in the process.
"""
try:
self.dbaas.users.revoke(instance_info.id, user, database)
assert_true(expected_response, self.dbaas.last_http_code)
@ -84,7 +87,8 @@ class UserAccessBase(object):
def _revoke_access_plural(self, users, databases, expected_response=202):
"""Revoke from each user access to each database.
Potentially, expect an exception in the process."""
Potentially, expect an exception in the process.
"""
for user in users:
for database in databases:
self._revoke_access_singular(user,
@ -93,7 +97,8 @@ class UserAccessBase(object):
def _test_access(self, users, databases, expected_response=200):
"""Verify that each user in the list has access to each database in
the list."""
the list.
"""
for user in users:
access = self.dbaas.users.list_access(instance_info.id, user)
assert_equal(expected_response, self.dbaas.last_http_code)

View File

@ -636,7 +636,8 @@ def wire_HTTPConnection_to_WSGI(host, app):
class HTTPConnectionDecorator(object):
"""Wraps the real HTTPConnection class so that when you instantiate
the class you might instead get a fake instance."""
the class you might instead get a fake instance.
"""
def __init__(self, wrapped):
self.wrapped = wrapped

View File

@ -75,7 +75,8 @@ class SwiftStorageSaveChecksumTests(testtools.TestCase):
def test_swift_segment_checksum_etag_mismatch(self):
"""This tests that when etag doesn't match segment uploaded checksum
False is returned and None for checksum and location"""
False is returned and None for checksum and location
"""
context = TroveContext()
# this backup_id will trigger fake swift client with calculate_etag
# enabled to spit out a bad etag when a segment object is uploaded
@ -106,7 +107,8 @@ class SwiftStorageSaveChecksumTests(testtools.TestCase):
def test_swift_checksum_etag_mismatch(self):
"""This tests that when etag doesn't match swift checksum False is
returned and None for checksum and location"""
returned and None for checksum and location
"""
context = TroveContext()
# this backup_id will trigger fake swift client with calculate_etag
# enabled to spit out a bad etag when a segment object is uploaded
@ -138,7 +140,8 @@ class SwiftStorageSaveChecksumTests(testtools.TestCase):
class SwiftStorageLoad(testtools.TestCase):
"""SwiftStorage.load is used to return SwiftDownloadStream which is used
to download a backup object from Swift"""
to download a backup object from Swift
"""
def setUp(self):
super(SwiftStorageLoad, self).setUp()
@ -149,7 +152,8 @@ class SwiftStorageLoad(testtools.TestCase):
def test_run_verify_checksum(self):
"""This tests that swift download cmd runs if original backup checksum
matches swift object etag"""
matches swift object etag
"""
context = TroveContext()
location = "/backup/location/123"
@ -185,8 +189,9 @@ class SwiftStorageLoad(testtools.TestCase):
def test_run_verify_checksum_mismatch(self):
"""This tests that SwiftDownloadIntegrityError is raised and swift
download cmd does not run when original backup checksum does not match
swift object etag"""
download cmd does not run when original backup checksum
does not match swift object etag
"""
context = TroveContext()
location = "/backup/location/123"