Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if _returncode:
LOG.debug(_('Result was %s') % _returncode)
if not ignore_exit_code and _returncode not in check_exit_code:
(stdout, stderr) = result
raise ProcessExecutionError(exit_code=_returncode,
stdout=stdout,
stderr=stderr,
cmd=' '.join(cmd))
return result
except ProcessExecutionError:
if not attempts:
raise
else:
LOG.debug(_('%r failed. Retrying.'), cmd)
if delay_on_retry:
greenthread.sleep(random.randint(20, 200) / 100.0)
finally:
# NOTE(termie): this appears to be necessary to let the subprocess
# call clean something up in between calls, without
# it two execute calls in a row hangs the second one
greenthread.sleep(0)
def _echo_response(self, addr):
while True:
try:
if self.enable_manager:
eventlet.greenthread.sleep(0)
response = self.ovsdb_dicts.get(addr).recv(
n_const.BUFFER_SIZE)
sock_json_m = jsonutils.loads(response)
sock_handler_method = sock_json_m.get('method', None)
if sock_handler_method == 'echo':
self.check_c_sock = True
self.ovsdb_dicts.get(addr).send(jsonutils.dumps(
{"result": sock_json_m.get("params", None),
"error": None, "id": sock_json_m['id']}))
if (addr not in self.ovsdb_conn_list):
self.ovsdb_conn_list.append(addr)
break
except Exception:
continue
while True:
try:
out, err = utils.execute('/usr/bin/svcs', '-H', '-o', 'state',
console_fmri)
state = out.strip()
if state == 'online':
break
elif state in ['maintenance', 'offline']:
LOG.error(_("Zone VNC console SMF service '%s' is in the "
"'%s' state. Run 'svcs -x %s' for details.")
% (console_fmri, state, console_fmri))
raise exception.ConsoleNotFoundForInstance(
instance_uuid=instance['uuid'])
# Wait for service state to transition to (hopefully) online
# state or offline/maintenance states.
greenthread.sleep(2)
except processutils.ProcessExecutionError as err:
LOG.error(_("Error querying state of zone VNC console SMF "
"service '%s': %s") % (console_fmri, err))
raise
# TODO(npower): investigate using RAD instead of CLI invocation
try:
# The console SMF service exits with SMF_TEMP_DISABLE to prevent
# unnecessarily coming online at boot. Make that happen.
out, err = utils.execute('/usr/sbin/svccfg', '-s', console_fmri,
'setprop', 'vnc/nova-enabled=false')
out, err = utils.execute('/usr/sbin/svccfg', '-s', console_fmri,
'refresh')
except processutils.ProcessExecutionError as err:
LOG.error(_("Unable to update 'vnc/nova-enabled' property for "
"zone VNC console SMF service "
"'%s': %s") % (console_fmri, err))
def _inner():
if initial_delay:
greenthread.sleep(initial_delay)
try:
while self._running:
idle = self.f(*self.args, **self.kw)
if not self._running:
break
if periodic_interval_max is not None:
idle = min(idle, periodic_interval_max)
LOG.debug(_('Dynamic looping call sleeping for %.02f '
'seconds'), idle)
greenthread.sleep(idle)
except LoopingCallDone as e:
self.stop()
done.send(e.retvalue)
except Exception:
LOG.exception(_('in dynamic looping call'))
done.send_exception(*sys.exc_info())
return
else:
done.send(True)
def _respawn_children(self):
while self.running:
wrap = self._wait_child()
if not wrap:
# Yield to other threads if no children have exited
# Sleep for a short time to avoid excessive CPU usage
# (see bug #1095346)
eventlet.greenthread.sleep(self.wait_interval)
continue
while self.running and len(wrap.children) < wrap.workers:
self._start_child(wrap)
stdout=stdout,
stderr=stderr,
cmd=' '.join(cmd))
return result
except ProcessExecutionError:
if not attempts:
raise
else:
LOG.log(loglevel, '%r failed. Retrying.', cmd)
if delay_on_retry:
greenthread.sleep(random.randint(20, 200) / 100.0)
finally:
# NOTE(termie): this appears to be necessary to let the subprocess
# call clean something up in between calls, without
# it two execute calls in a row hangs the second one
greenthread.sleep(0)
eventlet.greenthread.sleep(
CONF.host.monitoring_interval)
continue
# Check the host status is online or offline.
if CONF.host.restrict_to_remotes:
status_func = self._check_host_status_by_crm_mon
else:
status_func = self._check_host_status_by_cibadmin
if status_func() != 0:
LOG.warning("hostmonitor skips monitoring hosts.")
eventlet.greenthread.sleep(CONF.host.monitoring_interval)
continue
eventlet.greenthread.sleep(CONF.host.monitoring_interval)
except Exception as e:
LOG.exception("Exception caught: %s", e)
return
def _inner():
if initial_delay:
greenthread.sleep(initial_delay)
try:
while self._running:
idle = self.f(*self.args, **self.kw)
if not self._running:
break
if periodic_interval_max is not None:
idle = min(idle, periodic_interval_max)
LOG.debug('Dynamic looping call sleeping for %.02f '
'seconds', idle)
greenthread.sleep(idle)
except LoopingCallDone as e:
self.stop()
done.send(e.retvalue)
except Exception:
LOG.exception(_LE('in dynamic looping call'))
done.send_exception(*sys.exc_info())
return
else:
done.send(True)
if not ignore_exit_code and _returncode not in check_exit_code:
(stdout, stderr) = result
sanitized_stdout = strutils.mask_password(stdout)
sanitized_stderr = strutils.mask_password(stderr)
raise ProcessExecutionError(exit_code=_returncode,
stdout=sanitized_stdout,
stderr=sanitized_stderr,
cmd=sanitized_cmd)
return result
except ProcessExecutionError:
if not attempts:
raise
else:
LOG.log(loglevel, _('%r failed. Retrying.'), sanitized_cmd)
if delay_on_retry:
greenthread.sleep(random.randint(20, 200) / 100.0)
finally:
# NOTE(termie): this appears to be necessary to let the subprocess
# call clean something up in between calls, without
# it two execute calls in a row hangs the second one
greenthread.sleep(0)
def _handle_request(self):
'''First level request handling.'''
attempt = 0
timeout = 0
response = None
while response is None and attempt <= self._retries:
eventlet.greenthread.sleep(timeout)
attempt += 1
req = self._issue_request()
# automatically raises any exceptions returned.
if isinstance(req, httplib.HTTPResponse):
timeout = 0
if attempt <= self._retries and not self._abort:
if req.status in (httplib.UNAUTHORIZED, httplib.FORBIDDEN):
continue
elif req.status == httplib.SERVICE_UNAVAILABLE:
timeout = 0.5
continue
# else fall through to return the error code
LOG.debug("[%(rid)d] Completed request '%(method)s %(url)s'"
": %(status)s",