diff options
-rw-r--r-- | devstack/plugin.sh | 2 | ||||
-rw-r--r-- | trove/guestagent/common/operating_system.py | 35 | ||||
-rw-r--r-- | trove/guestagent/datastore/experimental/mongodb/service.py | 3 | ||||
-rw-r--r-- | trove/guestagent/datastore/experimental/mongodb/system.py | 2 | ||||
-rw-r--r-- | trove/guestagent/datastore/service.py | 4 | ||||
-rw-r--r-- | trove/tests/unittests/guestagent/test_dbaas.py | 12 |
6 files changed, 36 insertions, 22 deletions
diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 25237ea2..8ffc9f12 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -226,7 +226,7 @@ function finalize_trove_network { iniset $TROVE_CONF DEFAULT network_label_regex .* iniset $TROVE_CONF DEFAULT ip_regex .* - iniset $TROVE_CONF DEFAULT blacklist_regex ^10.0.1.* + iniset $TROVE_CONF DEFAULT black_list_regex ^10.0.1.* iniset $TROVE_CONF DEFAULT default_neutron_networks $management_network_id iniset $TROVE_CONF DEFAULT network_driver trove.network.neutron.NeutronDriver diff --git a/trove/guestagent/common/operating_system.py b/trove/guestagent/common/operating_system.py index 44ca9cb6..59525948 100644 --- a/trove/guestagent/common/operating_system.py +++ b/trove/guestagent/common/operating_system.py @@ -332,23 +332,23 @@ def file_discovery(file_candidates): return '' -def start_service(service_candidates): - _execute_service_command(service_candidates, 'cmd_start') +def start_service(service_candidates, **kwargs): + _execute_service_command(service_candidates, 'cmd_start', **kwargs) -def stop_service(service_candidates): - _execute_service_command(service_candidates, 'cmd_stop') +def stop_service(service_candidates, **kwargs): + _execute_service_command(service_candidates, 'cmd_stop', **kwargs) -def enable_service_on_boot(service_candidates): - _execute_service_command(service_candidates, 'cmd_enable') +def enable_service_on_boot(service_candidates, **kwargs): + _execute_service_command(service_candidates, 'cmd_enable', **kwargs) -def disable_service_on_boot(service_candidates): - _execute_service_command(service_candidates, 'cmd_disable') +def disable_service_on_boot(service_candidates, **kwargs): + _execute_service_command(service_candidates, 'cmd_disable', **kwargs) -def _execute_service_command(service_candidates, command_key): +def _execute_service_command(service_candidates, command_key, **kwargs): """ :param service_candidates List of possible system service names. :type service_candidates list @@ -357,13 +357,28 @@ def _execute_service_command(service_candidates, command_key): 'service_discovery'. :type command_key string + :param timeout: Number of seconds if specified, + default if not. + There is no timeout if set to None. + :type timeout: integer + + :raises: :class:`UnknownArgumentError` if passed unknown args. :raises: :class:`UnprocessableEntity` if no candidate names given. :raises: :class:`RuntimeError` if command not found. """ + + exec_args = {} + if 'timeout' in kwargs: + exec_args['timeout'] = kwargs.pop('timeout') + + if kwargs: + raise UnknownArgumentError(_("Got unknown keyword args: %r") % kwargs) + if service_candidates: service = service_discovery(service_candidates) if command_key in service: - utils.execute_with_timeout(service[command_key], shell=True) + utils.execute_with_timeout(service[command_key], shell=True, + **exec_args) else: raise RuntimeError(_("Service control command not available: %s") % command_key) diff --git a/trove/guestagent/datastore/experimental/mongodb/service.py b/trove/guestagent/datastore/experimental/mongodb/service.py index 6be8fe3f..c420fa04 100644 --- a/trove/guestagent/datastore/experimental/mongodb/service.py +++ b/trove/guestagent/datastore/experimental/mongodb/service.py @@ -458,8 +458,7 @@ class MongoDBAppStatus(service.BaseDbStatus): return ds_instance.ServiceStatuses.SHUTDOWN def cleanup_stalled_db_services(self): - out, err = utils.execute_with_timeout(system.FIND_PID, shell=True) - pid = "".join(out.split(" ")[1:2]) + pid, err = utils.execute_with_timeout(system.FIND_PID, shell=True) utils.execute_with_timeout(system.MONGODB_KILL % pid, shell=True) diff --git a/trove/guestagent/datastore/experimental/mongodb/system.py b/trove/guestagent/datastore/experimental/mongodb/system.py index 35a2cd38..b36509eb 100644 --- a/trove/guestagent/datastore/experimental/mongodb/system.py +++ b/trove/guestagent/datastore/experimental/mongodb/system.py @@ -36,7 +36,7 @@ MONGO_KEY_FILE = '/etc/mongo_key' MONGOS_SERVICE_CANDIDATES = ["mongos"] MONGOD_SERVICE_CANDIDATES = ["mongodb", "mongod"] MONGODB_KILL = "sudo kill %s" -FIND_PID = "ps xau | grep 'mongo[ds]'" +FIND_PID = "ps xaco pid,cmd | awk '/mongo(d|db|s)/ {print $1}'" TIME_OUT = 1000 MONGO_USER = {operating_system.REDHAT: "mongod", diff --git a/trove/guestagent/datastore/service.py b/trove/guestagent/datastore/service.py index 648e0388..f5042f3a 100644 --- a/trove/guestagent/datastore/service.py +++ b/trove/guestagent/datastore/service.py @@ -237,7 +237,7 @@ class BaseDbStatus(object): :raises: :class:`RuntimeError` on failure. """ LOG.info(_("Starting database service.")) - operating_system.start_service(service_candidates) + operating_system.start_service(service_candidates, timeout=timeout) self.wait_for_database_service_start(timeout, update_db=update_db) @@ -284,7 +284,7 @@ class BaseDbStatus(object): :raises: :class:`RuntimeError` on failure. """ LOG.info(_("Stopping database service.")) - operating_system.stop_service(service_candidates) + operating_system.stop_service(service_candidates, timeout=timeout) LOG.debug("Waiting for database to shutdown.") if not self._wait_for_database_service_status( diff --git a/trove/tests/unittests/guestagent/test_dbaas.py b/trove/tests/unittests/guestagent/test_dbaas.py index 548fde12..a41c05de 100644 --- a/trove/tests/unittests/guestagent/test_dbaas.py +++ b/trove/tests/unittests/guestagent/test_dbaas.py @@ -2117,7 +2117,7 @@ class BaseDbStatusTest(trove_testtools.TestCase): service_call.assert_called_once_with( rd_instance.ServiceStatuses.RUNNING, 10, False) os_cmd['start_service'].assert_called_once_with( - service_candidates) + service_candidates, timeout=10) os_cmd['enable_service_on_boot'].assert_called_once_with( service_candidates) @@ -2132,7 +2132,7 @@ class BaseDbStatusTest(trove_testtools.TestCase): service_call.assert_called_once_with( rd_instance.ServiceStatuses.RUNNING, 10, False) os_cmd['start_service'].assert_called_once_with( - service_candidates) + service_candidates, timeout=10) self.assertFalse(os_cmd['enable_service_on_boot'].called) # Test a failing call. @@ -2148,7 +2148,7 @@ class BaseDbStatusTest(trove_testtools.TestCase): status.start_db_service, service_candidates, 10, enable_on_boot=True) os_cmd['start_service'].assert_called_once_with( - service_candidates) + service_candidates, timeout=10) self.assertFalse(os_cmd['enable_service_on_boot'].called) def test_stop_db_service(self): @@ -2166,7 +2166,7 @@ class BaseDbStatusTest(trove_testtools.TestCase): service_call.assert_called_once_with( rd_instance.ServiceStatuses.SHUTDOWN, 10, False) os_cmd['stop_service'].assert_called_once_with( - service_candidates) + service_candidates, timeout=10) os_cmd['disable_service_on_boot'].assert_called_once_with( service_candidates) @@ -2181,7 +2181,7 @@ class BaseDbStatusTest(trove_testtools.TestCase): service_call.assert_called_once_with( rd_instance.ServiceStatuses.SHUTDOWN, 10, False) os_cmd['stop_service'].assert_called_once_with( - service_candidates) + service_candidates, timeout=10) self.assertFalse(os_cmd['disable_service_on_boot'].called) # Test a failing call. @@ -2197,7 +2197,7 @@ class BaseDbStatusTest(trove_testtools.TestCase): status.stop_db_service, service_candidates, 10, disable_on_boot=True) os_cmd['stop_service'].assert_called_once_with( - service_candidates) + service_candidates, timeout=10) self.assertFalse(os_cmd['disable_service_on_boot'].called) def test_restart_db_service(self): |