Skip to content

Commit

Permalink
Logging audit for guestagent/couchbase
Browse files Browse the repository at this point in the history
Adjust logging to conform to logging standards.
Cleaned up a few messages that were unclear, and
added some debug messages for recently added
API stubs.

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

Change-Id: I4ed452ddc4e0e9a29f6cbcc9d4e04f3a8b183687
Partial-Bug: #1324206
  • Loading branch information
Amrith Kumar committed Jul 29, 2014
1 parent 5f98abb commit 0d163bf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
20 changes: 14 additions & 6 deletions trove/guestagent/datastore/couchbase/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def prepare(self, context, packages, databases, memory_mb, users,
device.unmount_device(device_path)
device.format()
device.mount(mount_point)
LOG.debug('Mounted the volume.')
LOG.debug('Mounted the volume (%s).' % device_path)
self.app.start_db_with_conf_changes(config_contents)
LOG.info(_('Securing couchbase now.'))
LOG.debug('Securing couchbase now.')
if root_password:
self.app.enable_root(root_password)
self.app.initial_setup()
Expand All @@ -85,7 +85,7 @@ def prepare(self, context, packages, databases, memory_mb, users,
context,
mount_point)
self.app.complete_install_or_restart()
LOG.info(_('"prepare" couchbase call has finished.'))
LOG.info(_('Completed setup of Couchbase database instance.'))

def restart(self, context):
"""
Expand Down Expand Up @@ -190,38 +190,46 @@ def create_backup(self, context, backup_info):
def mount_volume(self, context, device_path=None, mount_point=None):
device = volume.VolumeDevice(device_path)
device.mount(mount_point, write_to_fstab=False)
LOG.debug("Mounted the volume.")
LOG.debug("Mounted the device %s at the mount_point %s." %
(device_path, mount_point))

def unmount_volume(self, context, device_path=None, mount_point=None):
device = volume.VolumeDevice(device_path)
device.unmount(mount_point)
LOG.debug("Unmounted the volume.")
LOG.debug("Unmounted the device %s from the mount point %s." %
(device_path, mount_point))

def resize_fs(self, context, device_path=None, mount_point=None):
device = volume.VolumeDevice(device_path)
device.resize_fs(mount_point)
LOG.debug("Resized the filesystem.")
LOG.debug("Resized the filesystem at %s." % mount_point)

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, master_config):
LOG.debug("Getting replication snapshot.")
raise exception.DatastoreOperationNotSupported(
operation='get_replication_snapshot', datastore=MANAGER)

def attach_replication_slave(self, snapshot, slave_config):
LOG.debug("Attaching replication slave.")
raise exception.DatastoreOperationNotSupported(
operation='attach_replication_slave', datastore=MANAGER)

def detach_replication_slave(self):
LOG.debug("Detaching replication slave.")
raise exception.DatastoreOperationNotSupported(
operation='detach_replication_slave', datastore=MANAGER)

def demote_replication_master(self):
LOG.debug("Demoting replication slave.")
raise exception.DatastoreOperationNotSupported(
operation='demote_replication_master', datastore=MANAGER)
56 changes: 27 additions & 29 deletions trove/guestagent/datastore/couchbase/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ def install_if_needed(self, packages):
"""
Install couchbase if needed, do nothing if it is already installed.
"""
LOG.info(_('Preparing Guest as Couchbase Server'))
LOG.info(_('Preparing Guest as Couchbase Server.'))
if not packager.pkg_is_installed(packages):
LOG.info(_('Installing Couchbase'))
LOG.debug('Installing Couchbase.')
self._install_couchbase(packages)

def initial_setup(self):
self.ip_address = operating_system.get_ip_address()
mount_point = CONF.couchbase.mount_point
try:
LOG.info(_('Couchbase Server change data dir path'))
LOG.info(_('Couchbase Server change data dir path.'))
operating_system.update_owner('couchbase',
'couchbase',
mount_point)
Expand All @@ -76,17 +76,17 @@ def initial_setup(self):
'PWD': pwd}), shell=True)
utils.execute_with_timeout(
system.cmd_rm_old_data_dir, shell=True)
LOG.info(_('Couchbase Server initialize cluster'))
LOG.debug('Couchbase Server initialize cluster.')
utils.execute_with_timeout(
(system.cmd_cluster_init
% {'IP': self.ip_address, 'PWD': pwd}),
shell=True)
utils.execute_with_timeout(system.cmd_set_swappiness, shell=True)
utils.execute_with_timeout(system.cmd_update_sysctl_conf,
shell=True)
LOG.info(_('Couchbase Server initial setup finished'))
except exception.ProcessExecutionError as e:
LOG.error(_('Process execution error %s') % e)
LOG.info(_('Couchbase Server initial setup finished.'))
except exception.ProcessExecutionError:
LOG.exception(_('Error performing initial Couchbase setup.'))
raise RuntimeError("Couchbase Server initial setup failed")

def complete_install_or_restart(self):
Expand All @@ -99,9 +99,8 @@ def _install_couchbase(self, packages):
"""
Install the Couchbase Server.
"""
LOG.debug('Installing Couchbase Server')
msg = "Creating %s" % system.COUCHBASE_CONF_DIR
LOG.debug(msg)
LOG.debug('Installing Couchbase Server. Creating %s' %
system.COUCHBASE_CONF_DIR)
utils.execute_with_timeout('mkdir',
'-p',
system.COUCHBASE_CONF_DIR,
Expand All @@ -110,7 +109,7 @@ def _install_couchbase(self, packages):
pkg_opts = {}
packager.pkg_install(packages, pkg_opts, system.TIME_OUT)
self.start_db()
LOG.debug('Finished installing Couchbase Server')
LOG.debug('Finished installing Couchbase Server.')

def _enable_db_on_boot(self):
"""
Expand All @@ -127,7 +126,7 @@ def _enable_db_on_boot(self):
"Command to enable Couchbase Server on boot not found."))

def _disable_db_on_boot(self):
LOG.info(_("Disabling Couchbase Server on boot"))
LOG.debug("Disabling Couchbase Server on boot.")
try:
couchbase_service = operating_system.service_discovery(
system.SERVICE_CANDIDATES)
Expand All @@ -141,7 +140,7 @@ def stop_db(self, update_db=False, do_not_start_on_reboot=False):
"""
Stops Couchbase Server on the trove instance.
"""
LOG.info(_('Stopping Couchbase Server...'))
LOG.debug('Stopping Couchbase Server.')
if do_not_start_on_reboot:
self._disable_db_on_boot()

Expand All @@ -151,17 +150,17 @@ def stop_db(self, update_db=False, do_not_start_on_reboot=False):
utils.execute_with_timeout(
couchbase_service['cmd_stop'], shell=True)
except KeyError:
raise RuntimeError("Command to stop Couchbase Server not found")
raise RuntimeError("Command to stop Couchbase Server not found.")

if not self.status.wait_for_real_status_to_change_to(
rd_instance.ServiceStatuses.SHUTDOWN,
self.state_change_wait_time, update_db):
LOG.error(_('Could not stop Couchbase Server!'))
LOG.error(_('Could not stop Couchbase Server.'))
self.status.end_install_or_restart()
raise RuntimeError(_("Could not stop Couchbase Server"))
raise RuntimeError(_("Could not stop Couchbase Server."))

def restart(self):
LOG.info(_("Restarting Couchbase Server"))
LOG.info(_("Restarting Couchbase Server."))
try:
self.status.begin_restart()
self.stop_db()
Expand All @@ -173,7 +172,7 @@ def start_db(self, update_db=False):
"""
Start the Couchbase Server.
"""
LOG.info(_("Starting Couchbase Server..."))
LOG.info(_("Starting Couchbase Server."))

self._enable_db_on_boot()
try:
Expand All @@ -189,38 +188,37 @@ def start_db(self, update_db=False):
if not self.status.wait_for_real_status_to_change_to(
rd_instance.ServiceStatuses.RUNNING,
self.state_change_wait_time, update_db):
LOG.error(_("Start up of Couchbase Server failed!"))
LOG.error(_("Start up of Couchbase Server failed."))
try:
utils.execute_with_timeout(system.cmd_kill)
except exception.ProcessExecutionError as p:
LOG.error('Error killing stalled Couchbase start command.')
LOG.error(p)
except exception.ProcessExecutionError:
LOG.exception(_('Error killing Couchbase start command.'))
self.status.end_install_or_restart()
raise RuntimeError("Could not start Couchbase Server")

def enable_root(self, root_password=None):
return CouchbaseRootAccess.enable_root(root_password)

def start_db_with_conf_changes(self, config_contents):
LOG.info(_("Starting Couchbase with configuration changes"))
LOG.info(_("Configuration contents:\n %s") % config_contents)
LOG.info(_("Starting Couchbase with configuration changes."))
LOG.info(_("Configuration contents:\n %s.") % config_contents)
if self.status.is_running:
LOG.error(_("Cannot start Couchbase with configuration changes. "
"Couchbase state == %s!") % self.status)
"Couchbase state == %s.") % self.status)
raise RuntimeError("Couchbase 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.debug("Resetting configuration.")
self._write_config(config_contents)

def _write_config(self, config_contents):
"""
Update contents of Couchbase configuration file
"""
LOG.info(_("Doing nothing."))
return


class CouchbaseAppStatus(service.BaseDbStatus):
Expand All @@ -240,8 +238,8 @@ def _get_actual_db_status(self):
return rd_instance.ServiceStatuses.RUNNING
else:
return rd_instance.ServiceStatuses.SHUTDOWN
except exception.ProcessExecutionError as e:
LOG.error(_("Process execution %s ") % e)
except exception.ProcessExecutionError:
LOG.exception(_("Error getting Couchbase status."))
return rd_instance.ServiceStatuses.SHUTDOWN


Expand Down

0 comments on commit 0d163bf

Please sign in to comment.