Patch title: s/ececuting/executing/

On Tue, Nov 3, 2015 at 8:05 PM, 'Oleg Ponomarev' via ganeti-devel <
[email protected]> wrote:

> Implement ppost_hooks_exec.py which has already been reffered from
>

referred to by


> forkPostHooksProcess. This python process will be used in order to
> run global POST hooks for opcodes which processes have disappeared.
>

s/which/whose/


>
> Signed-off-by: Oleg Ponomarev <[email protected]>
> ---
>  Makefile.am                   |   3 +-
>  lib/jqueue/post_hooks_exec.py | 116
> ++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 118 insertions(+), 1 deletion(-)
>  create mode 100644 lib/jqueue/post_hooks_exec.py
>
> diff --git a/Makefile.am b/Makefile.am
> index a721089..8ba84a5 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -546,7 +546,8 @@ hypervisor_hv_kvm_PYTHON = \
>
>  jqueue_PYTHON = \
>         lib/jqueue/__init__.py \
> -       lib/jqueue/exec.py
> +       lib/jqueue/exec.py \
> +       lib/jqueue/post_hooks_exec.py
>
>  storage_PYTHON = \
>         lib/storage/__init__.py \
> diff --git a/lib/jqueue/post_hooks_exec.py b/lib/jqueue/post_hooks_exec.py
> new file mode 100644
> index 0000000..77ef644
> --- /dev/null
> +++ b/lib/jqueue/post_hooks_exec.py
> @@ -0,0 +1,116 @@
> +#
> +#
> +
> +# Copyright (C) 2014 Google Inc.
>

s/2014/2015


> +# All rights reserved.
> +#
> +# Redistribution and use in source and binary forms, with or without
> +# modification, are permitted provided that the following conditions are
> +# met:
> +#
> +# 1. Redistributions of source code must retain the above copyright
> notice,
> +# this list of conditions and the following disclaimer.
> +#
> +# 2. Redistributions in binary form must reproduce the above copyright
> +# notice, this list of conditions and the following disclaimer in the
> +# documentation and/or other materials provided with the distribution.
> +#
> +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
> +# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
> +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
> PARTICULAR
> +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
> +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
> +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
> +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> +
> +
> +"""Module implementing executing of an opcode post hooks in a separate
> process
>

the execution of opcode post hooks in a separate process.


> +
> +This process receives job_id from the master process and runs global post
> hooks
>

the job_id


> +for the last opcode which executon has started before the job process
> disappear.
>

whose execution started before the job process disappeared.


> +
> +"""
> +
> +import contextlib
> +import logging
> +import os
> +import sys
> +
> +from ganeti import constants
> +from ganeti.server import masterd
> +from ganeti.rpc import transport
> +from ganeti import utils
> +from ganeti import pathutils
> +from ganeti.utils import livelock
> +from ganeti.hooksmaster import HooksMaster


Since this is a new file, let's do the nice thing and sort the imports.


> +
> +from ganeti.jqueue import JobQueue

+
> +
> +def _GetMasterInfo():
> +  """Retrieve job id from the master process
>

the job id


> +
> +  This also closes standard input/output
> +
> +  @rtype: int
> +
> +  """
> +  logging.debug("Opening transport over stdin/out")
>

Little content, please replace it with ...


> +  with contextlib.closing(transport.FdTransport((0, 1))) as trans:
> +    logging.debug("Reading job id from the master process")
>

... this one. An exception will be signaled if we fail to reach this point
anyway.


> +    job_id = int(trans.Call(""))
> +    logging.debug("Got job id %d", job_id)

+  return job_id
> +
> +
> +def main():
> +
> +  debug = int(os.environ["GNT_DEBUG"])
> +
> +  logname = pathutils.GetLogFilename("jobs")
> +  utils.SetupLogging(logname, "job-post-hooks-startup", debug=debug)
> +  job_id = _GetMasterInfo()
> +  utils.SetupLogging(logname, "job-%s" % (job_id,), debug=debug)
>

We could also use job-%s-post-hooks here to clearly differentiate between
job output and post-hook output. Any thoughts on that?


> +
> +  try:
> +    job = JobQueue.SafeLoadJobFromDisk(None, job_id, try_archived=False,
> +                                       writable=False)
> +    assert job.id == job_id
>

Rather than using an assertion here, please use a more verbose exception.


> +    target_op = None
> +    for op in job.ops:
> +      if op.start_timestamp is None:
> +        break
> +      target_op = op
>

Can there be a situation in which multiple opcodes have been started as


> +
> +    # We should run post hooks only if opcode execution has been started
> +    if target_op is None:
> +      sys.exit(0)
> +
> +    livelock_name = livelock.LiveLockName("post-hooks-executor-%d" %
> job_id)
> +    context = masterd.GanetiContext(livelock_name)
> +    cfg_tmp = context.GetConfig(job_id)
> +    cfg = cfg_tmp.GetDetachedConfig()
> +    cfg_tmp.OutDate()
>

Please add a comment explaining why this invocation is necessary.


> +
> +    hm = HooksMaster(target_op.input.OP_ID, None,
> +                     ([], [cfg.GetMasterNodeName()]),
> +                     context.GetRpc(cfg).call_hooks_runner, None, None,
> None,
> +                     logging.warning, cfg.GetClusterName(),
> +                     cfg.GetMasterNodeName(), job_id)
> +    hm.RunPhase(constants.HOOKS_PHASE_POST, True,
> +                constants.POST_HOOKS_STATUS_DISAPPEARED)
>

Explicitly name keyword args.


> +  except Exception: # pylint: disable=W0703
> +    logging.exception("Exception when trying to run job post hooks %d",
> job_id)
> +  finally:
> +    logging.debug("Post hooks exec for disappeared job %d finalized",
> job_id)
> +    logging.debug("Removing livelock file %s", livelock_name.GetPath())
> +    os.remove(livelock_name.GetPath())
> +
> +  sys.exit(0)
> +
> +if __name__ == '__main__':
> +  main()
> --
> 2.6.0.rc2.230.g3dd15c0
>
>
Hrvoje Ribicic
Ganeti Engineering
Google Germany GmbH
Dienerstr. 12, 80331, München

Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg

Diese E-Mail ist vertraulich. Wenn Sie nicht der richtige Adressat sind,
leiten Sie diese bitte nicht weiter, informieren Sie den Absender und
löschen Sie die E-Mail und alle Anhänge. Vielen Dank.

This e-mail is confidential. If you are not the right addressee please do
not forward it, please inform the sender, and please erase this e-mail
including any attachments. Thanks.

Reply via email to