本文整理汇总了Python中trove.common.utils.execute_with_timeout函数的典型用法代码示例。如果您正苦于以下问题:Python execute_with_timeout函数的具体用法?Python execute_with_timeout怎么用?Python execute_with_timeout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execute_with_timeout函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _truncate_backup_chain
def _truncate_backup_chain(self):
"""Truncate all backups in the backup chain after the
specified parent backup."""
with LocalOracleClient(self.db_name, service=True) as client:
max_recid = sql_query.Query()
max_recid.columns = ["max(recid)"]
max_recid.tables = ["v$backup_piece"]
max_recid.where = ["handle like '%%%s%%'" % self.parent_id]
q = sql_query.Query()
q.columns = ["recid"]
q.tables = ["v$backup_piece"]
q.where = ["recid > (%s)" % str(max_recid)]
client.execute(str(q))
delete_list = [ str(row[0]) for row in client ]
if delete_list:
cmd = ("""\"\
rman target %(admin_user)s/%(admin_pswd)[email protected]/%(db_name)s <<EOF
run {
delete force noprompt backupset %(delete_list)s;
}
EXIT;
EOF\"
""" % {'admin_user': ADMIN_USER, 'admin_pswd': self.oracnf.admin_password,
'db_name': self.db_name, 'delete_list': ",".join(delete_list)})
utils.execute_with_timeout("su - oracle -c " + cmd,
run_as_root=True,
root_helper='sudo',
timeout=LARGE_TIMEOUT,
shell=True,
log_output_on_error=True)
示例2: _get_actual_db_status
def _get_actual_db_status(self):
try:
out, err = utils.execute_with_timeout(
"/usr/bin/mysqladmin",
"ping", run_as_root=True, root_helper="sudo",
log_output_on_error=True)
LOG.info(_("MySQL Service Status is RUNNING."))
return rd_instance.ServiceStatuses.RUNNING
except exception.ProcessExecutionError:
LOG.exception(_("Failed to get database status."))
try:
out, err = utils.execute_with_timeout("/bin/ps", "-C",
"mysqld", "h")
pid = out.split()[0]
# TODO(rnirmal): Need to create new statuses for instances
# where the mysql service is up, but unresponsive
LOG.info(_('MySQL Service Status %(pid)s is BLOCKED.') %
{'pid': pid})
return rd_instance.ServiceStatuses.BLOCKED
except exception.ProcessExecutionError:
LOG.exception(_("Process execution failed."))
mysql_args = load_mysqld_options()
pid_file = mysql_args.get('pid_file',
['/var/run/mysqld/mysqld.pid'])[0]
if os.path.exists(pid_file):
LOG.info(_("MySQL Service Status is CRASHED."))
return rd_instance.ServiceStatuses.CRASHED
else:
LOG.info(_("MySQL Service Status is SHUTDOWN."))
return rd_instance.ServiceStatuses.SHUTDOWN
示例3: clear_storage
def clear_storage(self):
mount_point = "/var/lib/mongodb/*"
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)
示例4: start_db
def start_db(self, update_db=False):
"""
Start the Couchbase Server.
"""
LOG.info(_("Starting Couchbase Server..."))
self._enable_db_on_boot()
try:
couchbase_service = operating_system.service_discovery(
system.SERVICE_CANDIDATES)
utils.execute_with_timeout(
couchbase_service['cmd_start'], shell=True)
except exception.ProcessExecutionError:
pass
except KeyError:
raise RuntimeError("Command to start Couchbase Server not found.")
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!"))
try:
utils.execute_with_timeout(system.cmd_kill)
except exception.ProcessExecutionError as p:
LOG.error('Error killing stalled Couchbase start command.')
LOG.error(p)
self.status.end_install_or_restart()
raise RuntimeError("Could not start Couchbase Server")
示例5: _write_mycnf
def _write_mycnf(self, admin_password, config_contents, overrides=None):
"""
Install the set of mysql my.cnf templates.
Update the os_admin user and password to the my.cnf
file for direct login from localhost.
"""
LOG.info(_("Writing my.cnf templates."))
if admin_password is None:
admin_password = get_auth_password()
with open(TMP_MYCNF, 'w') as t:
t.write(config_contents)
utils.execute_with_timeout("sudo", "mv", TMP_MYCNF,
MYSQL_CONFIG)
self._write_temp_mycnf_with_admin_account(MYSQL_CONFIG,
TMP_MYCNF,
admin_password)
utils.execute_with_timeout("sudo", "mv", TMP_MYCNF,
MYSQL_CONFIG)
self.wipe_ib_logfiles()
# write configuration file overrides
if overrides:
self._write_config_overrides(overrides)
示例6: _run_post_backup
def _run_post_backup(self):
try:
for cmd in self.post_backup_commands:
utils.execute_with_timeout(*cmd)
except exception.ProcessExecutionError as p:
LOG.error(p)
raise p
示例7: update_owner
def update_owner(self, path):
LOG.info(_("Set owner to 'mongodb' for %s ") % system.CONFIG)
utils.execute_with_timeout("chown", "-R", "mongodb", path,
run_as_root=True, root_helper="sudo")
LOG.info(_("Set group to 'mongodb' for %s ") % system.CONFIG)
utils.execute_with_timeout("chgrp", "-R", "mongodb", path,
run_as_root=True, root_helper="sudo")
示例8: _spawn_with_init_file
def _spawn_with_init_file(self, temp_file):
child = pexpect.spawn("sudo mysqld_safe --init-file=%s" %
temp_file.name)
try:
i = child.expect(['Starting mysqld daemon'])
if i == 0:
LOG.info(_("Starting MySQL"))
except pexpect.TIMEOUT:
LOG.exception(_("Got a timeout launching mysqld_safe"))
finally:
# There is a race condition here where we kill mysqld before
# the init file been executed. We need to ensure mysqld is up.
self.poll_until_then_raise(
self.mysql_is_running,
base.RestoreError("Reset root password failed: "
"mysqld did not start!"))
LOG.info(_("Root password reset successfully."))
LOG.debug("Cleaning up the temp mysqld process.")
utils.execute_with_timeout("mysqladmin", "-uroot",
"--protocol=tcp", "shutdown")
utils.execute_with_timeout("killall", "mysqld_safe",
root_helper="sudo", run_as_root=True)
self.poll_until_then_raise(
self.mysql_is_not_running,
base.RestoreError("Reset root password failed: "
"mysqld did not stop!"))
示例9: _perform_recover
def _perform_recover(self):
recover_cmd = ("""\"export ORACLE_SID=%(db_name)s
rman target %(admin_user)s/%(admin_pswd)s <<EOF
run {
recover database;
}
EXIT;
EOF\"
""" % {'admin_user': ADMIN_USER, 'admin_pswd': ADMIN_PSWD,
'db_name': self.db_name})
cmd = "su - oracle -c " + recover_cmd
try:
utils.execute_with_timeout(cmd,
run_as_root=True, root_helper='sudo',
timeout=LARGE_TIMEOUT,
shell=True, log_output_on_error=True)
except exception.ProcessExecutionError as p:
# Ignore the "media recovery requesting unknown archived log" error
# because RMAN would throw this error even when recovery is
# successful.
# If there are in fact errors when recovering the database, the
# database open step following will fail anyway.
if str(p).find('media recovery requesting unknown archived log') != -1:
pass
else:
raise(p)
示例10: _disable_mysql_on_boot
def _disable_mysql_on_boot(self):
try:
utils.execute_with_timeout(self.mysql_service['cmd_disable'],
shell=True)
except KeyError:
LOG.exception(_("Error disabling MySQL start on boot."))
raise RuntimeError(_("Service is not discovered."))
示例11: _disable_db_on_boot
def _disable_db_on_boot(self):
LOG.info(_("Disabling MongoDB on boot."))
try:
mongo_service = self._get_service()
utils.execute_with_timeout(mongo_service["cmd_disable"], shell=True)
except KeyError:
raise RuntimeError("MongoDB service is not discovered.")
示例12: init_storage_structure
def init_storage_structure(self, mount_point):
try:
cmd = system.INIT_FS % mount_point
utils.execute_with_timeout(cmd, shell=True)
except exception.ProcessExecutionError as e:
LOG.error(_("Error while initiating storage structure."))
LOG.error(e)
示例13: _execute_shell_cmd
def _execute_shell_cmd(cmd, options, *args, **kwargs):
"""Execute a given shell command passing it
given options (flags) and arguments.
Takes optional keyword arguments:
:param as_root: Execute as root.
:type as_root: boolean
: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.
"""
exec_args = {}
if kwargs.pop('as_root', False):
exec_args['run_as_root'] = True
exec_args['root_helper'] = 'sudo'
if 'timeout' in kwargs:
exec_args['timeout'] = kwargs.pop('timeout')
if kwargs:
raise UnknownArgumentError(_("Got unknown keyword args: %r") % kwargs)
cmd_flags = _build_command_options(options)
cmd_args = cmd_flags + list(args)
utils.execute_with_timeout(cmd, *cmd_args, **exec_args)
示例14: _post_restore
def _post_restore(self):
utils.execute_with_timeout("sudo", "chown", "-R", "-f",
"mysql", self.restore_location)
self._delete_old_binlogs()
self._reset_root_password()
app = dbaas.MySqlApp(dbaas.MySqlAppStatus.get())
app.start_mysql()
示例15: pre_restore
def pre_restore(self):
try:
utils.execute_with_timeout("rm -rf " + system.COUCHBASE_DUMP_DIR,
shell=True)
except exception.ProcessExecutionError as p:
LOG.error(p)
raise p