Merge "Added support of resize-flavor to Redis datastore"
This commit is contained in:
commit
2f703fe36e
@ -110,10 +110,9 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
def start_db_with_conf_changes(self, context, config_contents):
|
||||
"""
|
||||
Start this redis instance with new conf changes.
|
||||
Right now this does nothing.
|
||||
"""
|
||||
raise exception.DatastoreOperationNotSupported(
|
||||
operation='start_db_with_conf_changes', datastore=MANAGER)
|
||||
app = RedisApp(RedisAppStatus.get())
|
||||
app.start_db_with_conf_changes(config_contents)
|
||||
|
||||
def stop_db(self, context, do_not_start_on_reboot=False):
|
||||
"""
|
||||
|
@ -20,6 +20,7 @@ from trove.common import utils as utils
|
||||
from trove.common import exception
|
||||
from trove.common import instance as rd_instance
|
||||
from trove.guestagent import pkg
|
||||
from trove.guestagent.common import operating_system
|
||||
from trove.guestagent.datastore import service
|
||||
from trove.guestagent.datastore.redis import system
|
||||
from trove.openstack.common import log as logging
|
||||
@ -174,34 +175,29 @@ class RedisApp(object):
|
||||
"""
|
||||
Enables redis on boot.
|
||||
"""
|
||||
LOG.info(_('Enabling redis on boot.'))
|
||||
if os.path.isfile(system.REDIS_INIT):
|
||||
LOG.info(_("OS Using Upstart"))
|
||||
cmd = "sudo sed -i '/^manual$/d' %s" % (system.REDIS_INIT)
|
||||
utils.execute_with_timeout(cmd,
|
||||
shell=True)
|
||||
else:
|
||||
cmd = 'sudo %s' % (system.REDIS_CMD_ENABLE)
|
||||
utils.execute_with_timeout(cmd,
|
||||
shell=True)
|
||||
LOG.info(_('Enabling Redis on boot.'))
|
||||
try:
|
||||
redis_service = operating_system.service_discovery(
|
||||
system.SERVICE_CANDIDATES)
|
||||
utils.execute_with_timeout(
|
||||
redis_service['cmd_enable'], shell=True)
|
||||
except KeyError:
|
||||
raise RuntimeError(_(
|
||||
"Command to enable Redis on boot not found."))
|
||||
|
||||
def _disable_redis_on_boot(self):
|
||||
"""
|
||||
Disables redis on boot.
|
||||
"""
|
||||
LOG.info(_('Disabling redis on boot.'))
|
||||
if os.path.isfile(system.REDIS_INIT):
|
||||
LOG.info(_("OS Using Upstart"))
|
||||
utils.execute_with_timeout('echo',
|
||||
"'manual'",
|
||||
'>>',
|
||||
system.REDIS_INIT,
|
||||
run_as_root=True,
|
||||
root_helper='sudo')
|
||||
else:
|
||||
cmd = 'sudo %s' % (system.REDIS_CMD_DISABLE)
|
||||
utils.execute_with_timeout(cmd,
|
||||
shell=True)
|
||||
LOG.info(_("Disabling Redis on boot."))
|
||||
try:
|
||||
redis_service = operating_system.service_discovery(
|
||||
system.SERVICE_CANDIDATES)
|
||||
utils.execute_with_timeout(
|
||||
redis_service['cmd_disable'], shell=True)
|
||||
except KeyError:
|
||||
raise RuntimeError(
|
||||
"Command to disable Redis on boot not found.")
|
||||
|
||||
def stop_db(self, update_db=False, do_not_start_on_reboot=False):
|
||||
"""
|
||||
@ -242,6 +238,20 @@ class RedisApp(object):
|
||||
run_as_root=True,
|
||||
root_helper='sudo')
|
||||
|
||||
def start_db_with_conf_changes(self, config_contents):
|
||||
LOG.info(_('Starting redis with conf changes...'))
|
||||
if self.status.is_running:
|
||||
raise RuntimeError('Cannot start_db_with_conf_changes because '
|
||||
'status is %s' % self.status)
|
||||
LOG.info(_("Initiating config."))
|
||||
self.write_config(config_contents)
|
||||
self.start_redis(True)
|
||||
|
||||
def reset_configuration(self, configuration):
|
||||
config_contents = configuration['config_contents']
|
||||
LOG.info(_("Resetting configuration"))
|
||||
self.write_config(config_contents)
|
||||
|
||||
def start_redis(self, update_db=False):
|
||||
"""
|
||||
Start the redis daemon.
|
||||
|
@ -29,6 +29,7 @@ REDIS_CMD_DISABLE = 'update-rc.d redis-server disable'
|
||||
REDIS_CMD_START = 'service redis-server start || /bin/true'
|
||||
REDIS_CMD_STOP = 'service redis-server stop || /bin/true'
|
||||
REDIS_PACKAGE = 'redis-server'
|
||||
SERVICE_CANDIDATES = ['redis-server']
|
||||
|
||||
if OS is 'redhat':
|
||||
REDIS_BIN = '/usr/libexec/redis-server'
|
||||
|
@ -1238,48 +1238,52 @@ class TestRedisApp(testtools.TestCase):
|
||||
self.assertTrue(utils.execute_with_timeout.called)
|
||||
|
||||
def test_enable_redis_on_boot_without_upstart(self):
|
||||
with patch.object(os.path, 'isfile', return_value=False):
|
||||
cmd = '123'
|
||||
with patch.object(operating_system, 'service_discovery',
|
||||
return_value={'cmd_enable': cmd}):
|
||||
with patch.object(utils, 'execute_with_timeout',
|
||||
return_value=None):
|
||||
self.app._enable_redis_on_boot()
|
||||
os.path.isfile.assert_any_call(RedisSystem.REDIS_INIT)
|
||||
operating_system.service_discovery.assert_any_call(
|
||||
RedisSystem.SERVICE_CANDIDATES)
|
||||
utils.execute_with_timeout.assert_any_call(
|
||||
'sudo ' + RedisSystem.REDIS_CMD_ENABLE,
|
||||
shell=True)
|
||||
cmd, shell=True)
|
||||
|
||||
def test_enable_redis_on_boot_with_upstart(self):
|
||||
with patch.object(os.path, 'isfile', return_value=True):
|
||||
cmd = '123'
|
||||
with patch.object(operating_system, 'service_discovery',
|
||||
return_value={'cmd_enable': cmd}):
|
||||
with patch.object(utils, 'execute_with_timeout',
|
||||
return_value=None):
|
||||
self.app._enable_redis_on_boot()
|
||||
os.path.isfile.assert_any_call(RedisSystem.REDIS_INIT)
|
||||
operating_system.service_discovery.assert_any_call(
|
||||
RedisSystem.SERVICE_CANDIDATES)
|
||||
utils.execute_with_timeout.assert_any_call(
|
||||
"sudo sed -i '/^manual$/d' " + RedisSystem.REDIS_INIT,
|
||||
shell=True)
|
||||
cmd, shell=True)
|
||||
|
||||
def test_disable_redis_on_boot_with_upstart(self):
|
||||
with patch.object(os.path, 'isfile', return_value=True):
|
||||
cmd = '123'
|
||||
with patch.object(operating_system, 'service_discovery',
|
||||
return_value={'cmd_disable': cmd}):
|
||||
with patch.object(utils, 'execute_with_timeout',
|
||||
return_value=None):
|
||||
self.app._disable_redis_on_boot()
|
||||
os.path.isfile.assert_any_call(RedisSystem.REDIS_INIT)
|
||||
operating_system.service_discovery.assert_any_call(
|
||||
RedisSystem.SERVICE_CANDIDATES)
|
||||
utils.execute_with_timeout.assert_any_call(
|
||||
'echo',
|
||||
"'manual'",
|
||||
'>>',
|
||||
RedisSystem.REDIS_INIT,
|
||||
run_as_root=True,
|
||||
root_helper='sudo')
|
||||
cmd, shell=True)
|
||||
|
||||
def test_disable_redis_on_boot_without_upstart(self):
|
||||
with patch.object(os.path, 'isfile', return_value=False):
|
||||
cmd = '123'
|
||||
with patch.object(operating_system, 'service_discovery',
|
||||
return_value={'cmd_disable': cmd}):
|
||||
with patch.object(utils, 'execute_with_timeout',
|
||||
return_value=None):
|
||||
self.app._disable_redis_on_boot()
|
||||
os.path.isfile.assert_any_call(RedisSystem.REDIS_INIT)
|
||||
operating_system.service_discovery.assert_any_call(
|
||||
RedisSystem.SERVICE_CANDIDATES)
|
||||
utils.execute_with_timeout.assert_any_call(
|
||||
'sudo ' + RedisSystem.REDIS_CMD_DISABLE,
|
||||
shell=True)
|
||||
cmd, shell=True)
|
||||
|
||||
def test_stop_db_without_fail(self):
|
||||
mock_status = MagicMock()
|
||||
|
Loading…
x
Reference in New Issue
Block a user