Logging audit for guestagent/mongodb

Adjust logging to conform to logging standards.
Cleaned up a few messages that were unclear and changed several
LOG.info messages to LOG.debug.

Also fixed a pattern of exception handlers using LOG.error
merely to log the exception (instead of LOG.exception)

Change-Id: I3bd544b761b449d1181792ff498f9c171331df16
Partial-Bug: #1324206
This commit is contained in:
Amrith Kumar 2014-07-17 14:40:47 -04:00
parent 546b4048aa
commit 42c4825baa
2 changed files with 83 additions and 49 deletions

View File

@ -49,7 +49,8 @@ class Manager(periodic_task.PeriodicTasks):
config_contents=None, root_password=None, overrides=None,
cluster_config=None):
"""Makes ready DBAAS on a Guest container."""
LOG.debug("Prepare MongoDB instance")
LOG.debug("Preparing MongoDB instance.")
self.status.begin_install()
self.app.install_if_needed(packages)
@ -66,7 +67,7 @@ class Manager(periodic_task.PeriodicTasks):
device.mount(mount_point)
operating_system.update_owner('mongodb', 'mongodb', mount_point)
LOG.debug("Mounted the volume %(path)s as %(mount)s" %
LOG.debug("Mounted the volume %(path)s as %(mount)s." %
{'path': device_path, "mount": mount_point})
conf_changes = self.get_config_changes(cluster_config, mount_point)
@ -90,15 +91,16 @@ class Manager(periodic_task.PeriodicTasks):
self.app.start_db_with_conf_changes(config_contents)
else:
LOG.error("Bad cluster configuration; instance type given "
"as %s" % cluster_config['instance_type'])
LOG.error(_("Bad cluster configuration; instance type "
"given as %s.") % cluster_config['instance_type'])
self.status.set_status(ds_instance.ServiceStatuses.FAILED)
return
self.status.set_status(ds_instance.ServiceStatuses.BUILD_PENDING)
LOG.info(_('"prepare" call has finished.'))
LOG.info(_('Completed setup of MongoDB database instance.'))
def get_config_changes(self, cluster_config, mount_point=None):
LOG.debug("Getting configuration changes.")
config_changes = {}
if cluster_config is not None:
config_changes['bind_ip'] = operating_system.get_ip_address()
@ -117,76 +119,95 @@ class Manager(periodic_task.PeriodicTasks):
return config_changes
def restart(self, context):
LOG.debug("Restarting MongoDB.")
self.app.restart()
def start_db_with_conf_changes(self, context, config_contents):
LOG.debug("Starting MongoDB with configuration changes.")
self.app.start_db_with_conf_changes(config_contents)
def stop_db(self, context, do_not_start_on_reboot=False):
LOG.debug("Stopping MongoDB.")
self.app.stop_db(do_not_start_on_reboot=do_not_start_on_reboot)
def reset_configuration(self, context, configuration):
LOG.debug("Resetting MongoDB configuration.")
self.app.reset_configuration(configuration)
def get_filesystem_stats(self, context, fs_path):
"""Gets the filesystem stats for the path given."""
LOG.debug("Getting file system status.")
return dbaas.get_filesystem_volume_stats(system.MONGODB_MOUNT_POINT)
def change_passwords(self, context, users):
LOG.debug("Changing password.")
raise exception.DatastoreOperationNotSupported(
operation='change_passwords', datastore=MANAGER)
def update_attributes(self, context, username, hostname, user_attrs):
LOG.debug("Updating database attributes.")
raise exception.DatastoreOperationNotSupported(
operation='update_attributes', datastore=MANAGER)
def create_database(self, context, databases):
LOG.debug("Creating database.")
raise exception.DatastoreOperationNotSupported(
operation='create_database', datastore=MANAGER)
def create_user(self, context, users):
LOG.debug("Creating user.")
raise exception.DatastoreOperationNotSupported(
operation='create_user', datastore=MANAGER)
def delete_database(self, context, database):
LOG.debug("Deleting database.")
raise exception.DatastoreOperationNotSupported(
operation='delete_database', datastore=MANAGER)
def delete_user(self, context, user):
LOG.debug("Deleting user.")
raise exception.DatastoreOperationNotSupported(
operation='delete_user', datastore=MANAGER)
def get_user(self, context, username, hostname):
LOG.debug("Getting user.")
raise exception.DatastoreOperationNotSupported(
operation='get_user', datastore=MANAGER)
def grant_access(self, context, username, hostname, databases):
LOG.debug("Granting acccess.")
raise exception.DatastoreOperationNotSupported(
operation='grant_access', datastore=MANAGER)
def revoke_access(self, context, username, hostname, database):
LOG.debug("Revoking access.")
raise exception.DatastoreOperationNotSupported(
operation='revoke_access', datastore=MANAGER)
def list_access(self, context, username, hostname):
LOG.debug("Listing access.")
raise exception.DatastoreOperationNotSupported(
operation='list_access', datastore=MANAGER)
def list_databases(self, context, limit=None, marker=None,
include_marker=False):
LOG.debug("Listing databases.")
raise exception.DatastoreOperationNotSupported(
operation='list_databases', datastore=MANAGER)
def list_users(self, context, limit=None, marker=None,
include_marker=False):
LOG.debug("Listing users.")
raise exception.DatastoreOperationNotSupported(
operation='list_users', datastore=MANAGER)
def enable_root(self, context):
LOG.debug("Enabling root.")
raise exception.DatastoreOperationNotSupported(
operation='enable_root', datastore=MANAGER)
def is_root_enabled(self, context):
LOG.debug("Checking if root is enabled.")
raise exception.DatastoreOperationNotSupported(
operation='is_root_enabled', datastore=MANAGER)
@ -195,81 +216,91 @@ class Manager(periodic_task.PeriodicTasks):
operation='_perform_restore', datastore=MANAGER)
def create_backup(self, context, backup_info):
LOG.debug("Creating backup.")
raise exception.DatastoreOperationNotSupported(
operation='create_backup', datastore=MANAGER)
def mount_volume(self, context, device_path=None, mount_point=None):
LOG.debug("Mounting the device %s at the mount point %s." %
(device_path, mount_point))
device = volume.VolumeDevice(device_path)
device.mount(mount_point, write_to_fstab=False)
LOG.debug("Mounted the volume.")
def unmount_volume(self, context, device_path=None, mount_point=None):
LOG.debug("Unmounting the device %s from the mount point %s." %
(device_path, mount_point))
device = volume.VolumeDevice(device_path)
device.unmount(mount_point)
LOG.debug("Unmounted the volume.")
def resize_fs(self, context, device_path=None, mount_point=None):
LOG.debug("Resizing the filesystem at %s." % mount_point)
device = volume.VolumeDevice(device_path)
device.resize_fs(mount_point)
LOG.debug("Resized the filesystem")
def update_overrides(self, context, overrides, remove=False):
LOG.debug("Updating overrides.")
raise exception.DatastoreOperationNotSupported(
operation='update_overrides', datastore=MANAGER)
def apply_overrides(self, context, overrides):
LOG.debug("Applying overrides.")
raise exception.DatastoreOperationNotSupported(
operation='apply_overrides', datastore=MANAGER)
def get_replication_snapshot(self, context, snapshot_info,
replica_source_config=None):
LOG.debug("Getting replication snapshot.")
raise exception.DatastoreOperationNotSupported(
operation='get_replication_snapshot', datastore=MANAGER)
def attach_replication_slave(self, context, snapshot, slave_config):
LOG.debug("Attaching replica.")
raise exception.DatastoreOperationNotSupported(
operation='attach_replication_slave', datastore=MANAGER)
def detach_replica(self, context):
LOG.debug("Detaching replica.")
raise exception.DatastoreOperationNotSupported(
operation='detach_replica', datastore=MANAGER)
def demote_replication_master(self, context):
LOG.debug("Demoting replica source.")
raise exception.DatastoreOperationNotSupported(
operation='demote_replication_master', datastore=MANAGER)
def add_members(self, context, members):
try:
LOG.debug("add_members called")
LOG.debug("args: members=%s" % members)
LOG.debug("add_members called.")
LOG.debug("args: members=%s." % members)
self.app.add_members(members)
LOG.debug("add_members call has finished")
LOG.debug("add_members call has finished.")
except Exception:
self.status.set_status(ds_instance.ServiceStatuses.FAILED)
raise
def add_config_servers(self, context, config_servers):
try:
LOG.debug("add_config_servers called")
LOG.debug("args: config_servers=%s" % config_servers)
LOG.debug("add_config_servers called.")
LOG.debug("args: config_servers=%s." % config_servers)
self.app.add_config_servers(config_servers)
LOG.debug("add_config_servers call has finished")
LOG.debug("add_config_servers call has finished.")
except Exception:
self.status.set_status(ds_instance.ServiceStatuses.FAILED)
raise
def add_shard(self, context, replica_set_name, replica_set_member):
try:
LOG.debug("add_shard called")
LOG.debug("args: replica_set_name=%s, replica_set_member=%s" % (
replica_set_name, replica_set_member))
LOG.debug("add_shard called.")
LOG.debug("args: replica_set_name=%s, replica_set_member=%s." %
(replica_set_name, replica_set_member))
self.app.add_shard(replica_set_name, replica_set_member)
LOG.debug("add_shard call has finished")
LOG.debug("add_shard call has finished.")
except Exception:
self.status.set_status(ds_instance.ServiceStatuses.FAILED)
raise
def cluster_complete(self, context):
# Now that cluster creation is complete, start status checks
LOG.debug("Cluster creation complete, starting status checks.")
status = self.status._get_actual_db_status()
self.status.set_status(status)

View File

@ -43,11 +43,11 @@ class MongoDBApp(object):
def install_if_needed(self, packages):
"""Prepare the guest machine with a MongoDB installation."""
LOG.info(_("Preparing Guest as MongoDB"))
LOG.info(_("Preparing Guest as MongoDB."))
if not system.PACKAGER.pkg_is_installed(packages):
LOG.debug("Installing packages: %s" % str(packages))
LOG.debug("Installing packages: %s." % str(packages))
system.PACKAGER.pkg_install(packages, {}, system.TIME_OUT)
LOG.info(_("Finished installing MongoDB server"))
LOG.info(_("Finished installing MongoDB server."))
def _get_service(self):
if self.status._is_query_router() is True:
@ -58,7 +58,7 @@ class MongoDBApp(object):
service_discovery(system.MONGOD_SERVICE_CANDIDATES))
def _enable_db_on_boot(self):
LOG.info(_("Enabling MongoDB on boot"))
LOG.info(_("Enabling MongoDB on boot."))
try:
mongo_service = self._get_service()
utils.execute_with_timeout(mongo_service['cmd_enable'],
@ -67,7 +67,7 @@ class MongoDBApp(object):
raise RuntimeError(_("MongoDB service is not discovered."))
def _disable_db_on_boot(self):
LOG.info(_("Disabling MongoDB on boot"))
LOG.info(_("Disabling MongoDB on boot."))
try:
mongo_service = self._get_service()
utils.execute_with_timeout(mongo_service['cmd_disable'],
@ -76,7 +76,7 @@ class MongoDBApp(object):
raise RuntimeError("MongoDB service is not discovered.")
def stop_db(self, update_db=False, do_not_start_on_reboot=False):
LOG.info(_("Stopping MongoDB"))
LOG.info(_("Stopping MongoDB."))
if do_not_start_on_reboot:
self._disable_db_on_boot()
@ -91,12 +91,12 @@ class MongoDBApp(object):
if not self.status.wait_for_real_status_to_change_to(
ds_instance.ServiceStatuses.SHUTDOWN,
self.state_change_wait_time, update_db):
LOG.error(_("Could not stop MongoDB"))
LOG.error(_("Could not stop MongoDB."))
self.status.end_install_or_restart()
raise RuntimeError(_("Could not stop MongoDB"))
def restart(self):
LOG.info(_("Restarting MongoDB"))
LOG.info(_("Restarting MongoDB."))
try:
self.status.begin_restart()
self.stop_db()
@ -105,7 +105,7 @@ class MongoDBApp(object):
self.status.end_install_or_restart()
def start_db(self, update_db=False):
LOG.info(_("Starting MongoDB"))
LOG.info(_("Starting MongoDB."))
self._enable_db_on_boot()
@ -121,7 +121,7 @@ class MongoDBApp(object):
if not self.status.wait_for_real_status_to_change_to(
ds_instance.ServiceStatuses.RUNNING,
self.state_change_wait_time, update_db):
LOG.error(_("Start up of MongoDB failed"))
LOG.error(_("Start up of MongoDB failed."))
# If it won't start, but won't die either, kill it by hand so we
# don't let a rouge process wander around.
try:
@ -130,29 +130,29 @@ class MongoDBApp(object):
pid = "".join(out.split(" ")[1:2])
utils.execute_with_timeout(
system.MONGODB_KILL % pid, shell=True)
except exception.ProcessExecutionError as p:
LOG.error("Error killing stalled MongoDB start command.")
LOG.error(p)
except exception.ProcessExecutionError:
LOG.exception(_("Error killing MongoDB start command."))
# There's nothing more we can do...
self.status.end_install_or_restart()
raise RuntimeError("Could not start MongoDB")
raise RuntimeError("Could not start MongoDB.")
def start_db_with_conf_changes(self, config_contents):
LOG.info(_("Starting MongoDB with configuration changes"))
LOG.info(_("Configuration contents:\n %s") % config_contents)
LOG.info(_("Starting MongoDB with configuration changes."))
LOG.info(_("Configuration contents:\n %s.") % config_contents)
if self.status.is_running:
LOG.error(_("Cannot start MongoDB with configuration changes. "
"MongoDB state == %s!") % self.status)
"MongoDB state == %s.") % self.status)
raise RuntimeError("MongoDB is not stopped.")
self._write_config(config_contents)
self.start_db(True)
def reset_configuration(self, configuration):
config_contents = configuration['config_contents']
LOG.info(_("Resetting configuration"))
LOG.info(_("Resetting configuration."))
self._write_config(config_contents)
def update_config_contents(self, config_contents, parameters):
LOG.info(_("Updating configuration contents."))
if not config_contents:
config_contents = self._read_config()
@ -168,14 +168,14 @@ class MongoDBApp(object):
"""
Update contents of MongoDB configuration file
"""
LOG.info(_("Updating MongoDB config"))
LOG.info(_("Updating MongoDB config."))
if config_contents:
LOG.info(_("Writing %s") % system.TMP_CONFIG)
LOG.info(_("Writing %s.") % system.TMP_CONFIG)
try:
with open(system.TMP_CONFIG, 'w') as t:
t.write(config_contents)
LOG.info(_("Moving %(a)s to %(b)s")
LOG.info(_("Moving %(a)s to %(b)s.")
% {'a': system.TMP_CONFIG, 'b': CONFIG_FILE})
utils.execute_with_timeout("mv",
system.TMP_CONFIG,
@ -186,14 +186,14 @@ class MongoDBApp(object):
os.unlink(system.TMP_CONFIG)
raise
else:
LOG.info(_("Empty config_contents. Do nothing"))
LOG.debug("Empty config_contents. Do nothing.")
def _read_config(self):
try:
with open(CONFIG_FILE, 'r') as f:
return f.read()
except IOError:
LOG.info(_("Config file %s not found") % CONFIG_FILE)
LOG.info(_("Config file %s not found.") % CONFIG_FILE)
return ''
def _delete_config_parameters(self, config_contents, parameters):
@ -211,11 +211,12 @@ class MongoDBApp(object):
def clear_storage(self):
mount_point = "/var/lib/mongodb/*"
LOG.debug("Clearing storage at %s." % mount_point)
try:
cmd = "sudo rm -rf %s" % mount_point
utils.execute_with_timeout(cmd, shell=True)
except exception.ProcessExecutionError as e:
LOG.error(_("Process execution %s") % e)
except exception.ProcessExecutionError:
LOG.exception(_("Error clearing storage."))
def add_config_servers(self, config_server_hosts):
"""
@ -224,7 +225,7 @@ class MongoDBApp(object):
config_contents = self._read_config()
configdb_contents = ','.join(['%s:27019' % host
for host in config_server_hosts])
LOG.debug("Config server list %s" % configdb_contents)
LOG.debug("Config server list %s." % configdb_contents)
# remove db path from config and update configdb
contents = self._delete_config_parameters(config_contents,
["dbpath", "nojournal",
@ -232,17 +233,19 @@ class MongoDBApp(object):
"noprealloc", "configdb"])
contents = self._add_config_parameter(contents,
"configdb", configdb_contents)
LOG.info(_("Rewriting configuration"))
LOG.info(_("Rewriting configuration."))
self.start_db_with_conf_changes(contents)
def write_mongos_upstart(self):
upstart_contents = (system.MONGOS_UPSTART_CONTENTS.
format(config_file_placeholder=CONFIG_FILE))
LOG.info(_("Writing %s") % system.TMP_MONGOS_UPSTART)
LOG.info(_("Writing %s.") % system.TMP_MONGOS_UPSTART)
with open(system.TMP_MONGOS_UPSTART, 'w') as t:
t.write(upstart_contents)
LOG.info(_("Moving %(a)s to %(b)s")
LOG.info(_("Moving %(a)s to %(b)s.")
% {'a': system.TMP_MONGOS_UPSTART,
'b': system.MONGOS_UPSTART})
utils.execute_with_timeout("mv", system.TMP_MONGOS_UPSTART,
@ -371,8 +374,8 @@ class MongoDbAppStatus(service.BaseDbStatus):
else:
return ds_instance.ServiceStatuses.SHUTDOWN
except exception.ProcessExecutionError as e:
LOG.error(_("Process execution %s") % e)
LOG.exception(_("Process execution %s.") % e)
return ds_instance.ServiceStatuses.SHUTDOWN
except OSError as e:
LOG.error(_("OS Error %s") % e)
LOG.exception(_("OS Error %s.") % e)
return ds_instance.ServiceStatuses.SHUTDOWN