From 69773141dd194a9c06685b86e2e88fd78d0bd314 Mon Sep 17 00:00:00 2001 From: Nirav Shah Date: Thu, 22 Jan 2015 21:31:24 -0800 Subject: [PATCH] Fix PostgreSQL volume definitions Add support for resize-volume. Currently, resize-volume (in models.py) calls guest instance's stop_db, via _assert_datastore_is_offline. This stop_db definition requires a keyword argument do_not_start_on_reboot. This patch corrects stop_db implementation, which originally didn't have do_not_start_on_reboot keyword argument. This patch also implements mount_volume, unmount_volume, and resize_fs. It also implements _enable_pgsql_on_boot and _disable_pgsql_on_boot. These definitions are required to fix 1410425 (resize-volume bug in postgresql). The easiest way to verify this bug (and this patch) is to follow these steps: - trove create ps1 100 --datastore postgresql --datastore_version 9.3 --size 1 --databases db1 --users user1:password1 - trove list (note the ID, and verify instance is active) - trove resize-volume 2 - trove list (verify that size is 2) Closes-Bug: #1410425 Change-Id: Ifc245dbf27af0269a2b71995bc2c6e2733420a81 --- .../datastore/postgresql/manager.py | 27 ++++++++++++++++++- .../datastore/postgresql/service/process.py | 26 ++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/trove/guestagent/datastore/postgresql/manager.py b/trove/guestagent/datastore/postgresql/manager.py index 763d0022..94813225 100644 --- a/trove/guestagent/datastore/postgresql/manager.py +++ b/trove/guestagent/datastore/postgresql/manager.py @@ -93,7 +93,32 @@ class Manager( self.create_user(context, users) def get_filesystem_stats(self, context, fs_path): - return dbaas.get_filesystem_volume_stats(fs_path) + mount_point = CONF.get(CONF.datastore_manager).mount_point + return dbaas.get_filesystem_volume_stats(mount_point) def create_backup(self, context, backup_info): backup.backup(context, backup_info) + + def mount_volume(self, context, device_path=None, mount_point=None): + """Mount the volume as specified by device_path to mount_point.""" + device = volume.VolumeDevice(device_path) + device.mount(mount_point, write_to_fstab=False) + LOG.debug( + "Mounted device {device} at mount point {mount}.".format( + device=device_path, mount=mount_point)) + + def unmount_volume(self, context, device_path=None, mount_point=None): + """Unmount the volume as specified by device_path from mount_point.""" + device = volume.VolumeDevice(device_path) + device.unmount(mount_point) + LOG.debug( + "Unmounted device {device} from mount point {mount}.".format( + device=device_path, mount=mount_point)) + + def resize_fs(self, context, device_path=None, mount_point=None): + """Resize the filesystem as specified by device_path at mount_point.""" + device = volume.VolumeDevice(device_path) + device.resize_fs(mount_point) + LOG.debug( + "Resized the filesystem at {mount}.".format( + mount=mount_point)) diff --git a/trove/guestagent/datastore/postgresql/service/process.py b/trove/guestagent/datastore/postgresql/service/process.py index 286c6d82..ab1b197f 100644 --- a/trove/guestagent/datastore/postgresql/service/process.py +++ b/trove/guestagent/datastore/postgresql/service/process.py @@ -18,7 +18,6 @@ from trove.common import utils from trove.guestagent.common import operating_system from trove.guestagent.datastore.postgresql.service.status import PgSqlAppStatus from trove.openstack.common import log as logging -from trove.common.i18n import _ LOG = logging.getLogger(__name__) CONF = cfg.CONF @@ -30,6 +29,7 @@ class PgSqlProcess(object): """Mixin that manages the PgSql process.""" def start_db(self, context): + self._enable_pgsql_on_boot() """Start the PgSql service.""" cmd = operating_system.service_discovery(PGSQL_SERVICE_CANDIDATES) LOG.info( @@ -44,8 +44,30 @@ class PgSqlProcess(object): timeout=30 ) - def stop_db(self, context): + def _enable_pgsql_on_boot(self): + try: + pgsql_service = operating_system.service_discovery( + PGSQL_SERVICE_CANDIDATES) + utils.execute_with_timeout(pgsql_service['cmd_enable'], + shell=True) + except KeyError: + LOG.exception(_("Error enabling PostgreSQL start on boot.")) + raise RuntimeError("Service is not discovered.") + + def _disable_pgsql_on_boot(self): + try: + pgsql_service = operating_system.service_discovery( + PGSQL_SERVICE_CANDIDATES) + utils.execute_with_timeout(pgsql_service['cmd_disable'], + shell=True) + except KeyError: + LOG.exception(_("Error disabling PostgreSQL start on boot.")) + raise RuntimeError("Service is not discovered.") + + def stop_db(self, context, do_not_start_on_reboot=False): """Stop the PgSql service.""" + if do_not_start_on_reboot: + self._disable_pgsql_on_boot() cmd = operating_system.service_discovery(PGSQL_SERVICE_CANDIDATES) LOG.info( _("{guest_id}: Stopping database engine with command ({command}).")