Merge "Enabling H403, H702 rules"

This commit is contained in:
Jenkins 2013-12-12 19:32:19 +00:00 committed by Gerrit Code Review
commit 7d3421c846
12 changed files with 65 additions and 37 deletions

View File

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

View File

@ -28,7 +28,8 @@ ENV = jinja2.Environment(loader=jinja2.ChoiceLoader([
class SingleInstanceConfigTemplate(object): class SingleInstanceConfigTemplate(object):
"""This class selects a single configuration file by database type for """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): def __init__(self, datastore_manager, flavor_dict, instance_id):
"""Constructor """Constructor

View File

@ -146,7 +146,8 @@ class MgmtInstanceController(InstanceController):
@admin_context @admin_context
def root(self, req, tenant_id, id): def root(self, req, tenant_id, id):
"""Return the date and time root was enabled on an instance, """Return the date and time root was enabled on an instance,
if ever.""" if ever.
"""
LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("req : '%s'\n\n") % req)
LOG.info(_("Showing root history for tenant '%s'") % tenant_id) LOG.info(_("Showing root history for tenant '%s'") % tenant_id)
LOG.info(_("id : '%s'\n\n") % 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): def index(self, req, tenant_id, instance_id):
"""Returns True if root is enabled for the given instance; """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(_("Getting root enabled for instance '%s'") % instance_id)
LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("req : '%s'\n\n") % req)
context = req.environ[wsgi.CONTEXT_KEY] context = req.environ[wsgi.CONTEXT_KEY]
@ -209,7 +210,7 @@ class UserAccessController(wsgi.Controller):
user_id = correct_id_with_req(user_id, req) user_id = correct_id_with_req(user_id, req)
user = self._get_user(context, instance_id, user_id) user = self._get_user(context, instance_id, user_id)
if not user: 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) raise exception.UserNotFound(uuid=user)
username, hostname = unquote_user_host(user_id) username, hostname = unquote_user_host(user_id)
access = models.User.access(context, instance_id, username, hostname) 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_id = correct_id_with_req(user_id, req)
user = self._get_user(context, instance_id, user_id) user = self._get_user(context, instance_id, user_id)
if not user: 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) raise exception.UserNotFound(uuid=user)
username, hostname = unquote_user_host(user_id) username, hostname = unquote_user_host(user_id)
databases = [db['name'] for db in body['databases']] 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_id = correct_id_with_req(user_id, req)
user = self._get_user(context, instance_id, user_id) user = self._get_user(context, instance_id, user_id)
if not user: 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) raise exception.UserNotFound(uuid=user)
username, hostname = unquote_user_host(user_id) username, hostname = unquote_user_host(user_id)
access = models.User.access(context, instance_id, username, hostname) access = models.User.access(context, instance_id, username, hostname)

View File

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

View File

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

View File

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

View File

@ -42,7 +42,8 @@ user = None
def assert_attributes_equal(name, os_flavor, dbaas_flavor): def assert_attributes_equal(name, os_flavor, dbaas_flavor):
"""Given an attribute name and two objects, """Given an attribute name and two objects,
ensures the attribute is equal.""" ensures the attribute is equal.
"""
assert_true(hasattr(os_flavor, name), assert_true(hasattr(os_flavor, name),
"open stack flavor did not have attribute %s" % name) "open stack flavor did not have attribute %s" % name)
assert_true(hasattr(dbaas_flavor, 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']) enabled=not test_config.values['root_removed_from_instance_api'])
def test_root_still_enabled_details(self): def test_root_still_enabled_details(self):
"""Use instance details to test that after root was reset, """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) instance = self.dbaas.instances.get(instance_info.id)
assert_true(hasattr(instance, 'rootEnabled'), assert_true(hasattr(instance, 'rootEnabled'),
"Instance has no rootEnabled property.") "Instance has no rootEnabled property.")

View File

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

View File

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