We cannot use StringIO, as it does not provide fileno(). (fileno is used by
subprocess.Popen)

On Tue, Aug 25, 2015 at 10:57 AM Klaus Aehlig <[email protected]> wrote:

> On Mon, Aug 24, 2015 at 07:01:17PM +0200, 'Bhimanavajjula Aditya' via
> ganeti-devel wrote:
> > repair_command takes two strings as input cmd, and inp.
> > This patch generalizes RunRestrictedCmd to RunCmd. RunCmd
> > can now pass a string as stdin input to the command that
> > will rull.
> >
> > Signed-off-by: Bhimanavajjula Aditya <[email protected]>
> > ---
> >  lib/backend.py                     | 41 ++++++++++++++++++++++----------
> >  lib/pathutils.py                   |  4 ++++
> >  lib/rpc_defs.py                    |  4 ++++
> >  lib/server/noded.py                | 18 +++++++++++++-
> >  test/py/ganeti.backend_unittest.py | 48
> +++++++++++++++++++-------------------
> >  5 files changed, 78 insertions(+), 37 deletions(-)
> >
> > diff --git a/lib/backend.py b/lib/backend.py
> > index cc96689..6ed07e6 100644
> > --- a/lib/backend.py
> > +++ b/lib/backend.py
> > @@ -5473,18 +5473,25 @@ def _PrepareRestrictedCmd(path, cmd,
> >    return _verify_cmd(path, cmd)
> >
> >
> > -def RunRestrictedCmd(cmd,
> > -                     _lock_timeout=_RCMD_LOCK_TIMEOUT,
> > -                     _lock_file=pathutils.RESTRICTED_COMMANDS_LOCK_FILE,
> > -                     _path=pathutils.RESTRICTED_COMMANDS_DIR,
> > -                     _sleep_fn=time.sleep,
> > -                     _prepare_fn=_PrepareRestrictedCmd,
> > -                     _runcmd_fn=utils.RunCmd,
> > -                     _enabled=constants.ENABLE_RESTRICTED_COMMANDS):
> > -  """Executes a restricted command after performing strict tests.
> > +def RunCmd(cmd,
>
> Why rename RunRestrictedCmd to RunCmd? The method still verifies
> restrictions, and hence is fundamentally different then RunCmd from
> utils---a difference that gets blurred by your renaming.
>
> >        if status:
> > +        if inp:
> > +          input_fd = tempfile.TemporaryFile()
> > +          input_fd.write(inp)
> > +          input_fd.flush()
> > +          input_fd.seek(0)
> > +        else:
> > +          input_fd = None
>
> Why generate a real file, if all we need is a file-like object?
> Can't we use an in-memory file-like object, like StringIO?
>
>
> --
> Klaus Aehlig
> Google Germany GmbH, Dienerstr. 12, 80331 Muenchen
> Registergericht und -nummer: Hamburg, HRB 86891
> Sitz der Gesellschaft: Hamburg
> Geschaeftsfuehrer: Graham Law, Christine Elizabeth Flores
>

Reply via email to