<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>Hi guys,</p>
    <p>First of all, thanks again for your help. I really appreciate it.</p>
    <p>I found an interesting behavior. If I set loglevel=info in
      /etc/avocado/avocado.conf, it will not produce any content in
      stderr.expected and stdout.expected. If I set loglevel=debug, then
      it will work as it should. I don't mind running in debug mode, but
      I am not sure the behavior should be affected by loglevel.<br>
    </p>
    <p>Anyway, the question I have is about using --output-check-record
      when multiplexing. I notice that the files stdout.expected and
      stderr.expected get overwritten on each variant. I will assume
      there is a way to save each of the variant results and then use
      them to check. The problem is that I went through the
      documentation and didn't find anything that talks about it.</p>
    <p>Thanks again.</p>
    <p>BTW, is the whole development team Brazilian?</p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 09/08/2016 08:05 PM, Lucas Meneghel
      Rodrigues wrote:<br>
    </div>
    <blockquote
cite="mid:CAJnY6jr6wvAHBzPBd2OfoLvxCUUsf-Fps+Ds_vQsaFbYQ=E6iA@mail.gmail.com"
      type="cite">
      <div dir="ltr">Yep, that was the problem. The pipe won't work if
        shell=False (default).
        <div><br>
          Now, on the rationale why shell=False is the default,
          basically, it's unsafe, see:</div>
        <div><br>
        </div>
        <div><a moz-do-not-send="true"
            href="https://docs.python.org/2/library/subprocess.html">https://docs.python.org/2/library/subprocess.html</a><br>
          <br>
          With shell=True, the expected standard output starts to
          appear.</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr">On Thu, Sep 8, 2016 at 4:01 PM Lucas Meneghel
          Rodrigues <<a moz-do-not-send="true"
            href="mailto:lookkas@gmail.com">lookkas@gmail.com</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">
          <div dir="ltr">By the way, you *must* set shell=True to use
            pipes (which I did forget). Otherwise the pipes won't work.</div>
          <br>
          <div class="gmail_quote">
            <div dir="ltr">On Thu, Sep 8, 2016 at 4:00 PM Lucas Meneghel
              Rodrigues <<a moz-do-not-send="true"
                href="mailto:lookkas@gmail.com" target="_blank">lookkas@gmail.com</a>>
              wrote:<br>
            </div>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div dir="ltr">I think you guys are missing the point
                here. I just tried Marcos's test here and that's what I
                get with Avocado LTS 36.2:<br>
                <br>
                <div>$ avocado run xentest.py --output-check-record all</div>
                <div>JOB ID     :
                  c44d95698bc6a20329691a9c10370c3b63c8944f</div>
                <div>JOB LOG    :
                  /home/lmr/avocado/job-results/job-2016-09-08T15.54-c44d956/job.log</div>
                <div>TESTS      : 1</div>
                <div> (1/1) xentest.py:xentest.test_xen_start_stop:
                  ERROR (0.01 s)</div>
                <div>RESULTS    : PASS 0 | ERROR 1 | FAIL 0 | SKIP 0 |
                  WARN 0 | INTERRUPT 0</div>
                <div>JOB HTML   :
/home/lmr/avocado/job-results/job-2016-09-08T15.54-c44d956/html/results.html</div>
                <div>TESTS TIME : 0.01 s</div>
                <div>$ ls</div>
                <div>xentest.py  xentest.pyc  xentest.py.data</div>
                <div>$ cat xentest.py.data/stdout.expected </div>
                <div>$ cat xentest.py.data/stderr.expected </div>
                <div>xc: error: Could not obtain handle on privileged
                  command interface (2 = No such file or directory):
                  Internal error</div>
                <div>libxl: error: libxl.c:116:libxl_ctx_alloc: cannot
                  open libxc handle: No such file or directory</div>
                <div>cannot init xl context</div>
                <div><br>
                  Keep in mind that I have installed only the basic xen
                  packages, so my 'xl' doesn't work. Avocado does its
                  job and creates xentest.py.data, with the expected
                  outputs.</div>
                <div><br>
                </div>
                <div>So no, you don't need to avoid the pipes, and
                  everything should work. The caveat is that avocado
                  creates xentest.py.data with the recorded files in the
                  same dir of your test file. You have to test that with
                  your version of avocado and verify if the
                  directory/files are created or not. If not, it's a
                  bug, although I think we have a functional test to
                  avoid such a bug.</div>
                <div><br>
                </div>
                <div>So for me here, everything is worked as designed. I
                  modified xentest.py to use avocado libs:</div>
                <div><br>
                </div>
                <div>
                  <div>#!/usr/bin/env python</div>
                  <div># vim: tabstop=8 expandtab shiftwidth=4
                    softtabstop=4</div>
                  <div><br>
                  </div>
                  <div>import os</div>
                  <div>import sys</div>
                  <div>import string</div>
                  <div>import logging</div>
                  <div>import commands</div>
                  <div>import time</div>
                  <div><br>
                  </div>
                  <div>from avocado import Test</div>
                  <div>from avocado import main</div>
                  <div>from avocado.utils import process</div>
                  <div>from autotest.client import utils</div>
                  <div>from autotest.client import xen</div>
                  <div><br>
                  </div>
                  <div>progress_log = logging.getLogger("progress")</div>
                  <div><br>
                  </div>
                  <div>class xentest(Test):</div>
                  <div>    """</div>
                  <div>    Test</div>
                  <div>    """</div>
                  <div>    def exec_xl(self):</div>
                  <div>        """</div>
                  <div>        Start xen Guest</div>
                  <div>        """</div>
                  <div>        sleeptime = self.params.get('sleep_time')</div>
                  <div>        guestdef = self.params.get('guest_cfg')</div>
                  <div>        runaction = self.params.get('run_action')</div>
                  <div>        domname = self.params.get('domain_name')</div>
                  <div>        <a moz-do-not-send="true"
                      href="http://progress_log.info" target="_blank">progress_log.info</a>('%s:
                    Running action %s', <a moz-do-not-send="true"
                      href="http://self.name" target="_blank">self.name</a>,
                    runaction)</div>
                  <div>        time.sleep(sleeptime)</div>
                  <div>        if runaction == 'create':</div>
                  <div>            cmd = ('/usr/sbin/xl %s %s' %
                    (runaction, guestdef))</div>
                  <div>            if process.system(cmd,
                    ignore_status=False) == "0":</div>
                  <div>                pass</div>
                  <div>            else:</div>
                  <div>                return False</div>
                  <div>        else:</div>
                  <div>            cmd = ('/usr/sbin/xl %s %s' %
                    (runaction, domname))</div>
                  <div>            if process.system(cmd,
                    ignore_status=False) == "0":</div>
                  <div>                pass</div>
                  <div>            else:</div>
                  <div>                return False</div>
                  <div><br>
                  </div>
                  <div>    def test_xen_start_stop(self):</div>
                  <div>        """</div>
                  <div>        Get Xen version</div>
                  <div>        """</div>
                  <div>        fd = open('/tmp/xenver.log', 'w')</div>
                  <div>        fd.write('### %s\n' % time.time())</div>
                  <div>        cmd = "xl info|grep xen_version| awk
                    '{print $3}'"</div>
                  <div>        xenversion = process.system_output(cmd,
                    ignore_status=False)</div>
                  <div>        process.system('ls -la
                    /usr/share/avocado/tests 2>&1')</div>
                  <div>        print('Xen Version = %s.\n' % xenversion)</div>
                  <div>        fd.write('Xen Version = %s.\n' %
                    xenversion)</div>
                  <div>        fd.write('### %s\n' % time.time())</div>
                  <div>        if self.exec_xl() == "0":</div>
                  <div>           pass</div>
                  <div>        else:</div>
                  <div>            return False</div>
                  <div>        fd.close()</div>
                  <div><br>
                  </div>
                  <div>if __name__ == "__main__":</div>
                  <div>    main()</div>
                </div>
                <div><br>
                  I hope this helps,</div>
                <div><br>
                </div>
                <div>Lucas</div>
              </div>
              <br>
              <div class="gmail_quote">
                <div dir="ltr">On Thu, Sep 8, 2016 at 3:55 PM Marcos E.
                  Matsunaga <<a moz-do-not-send="true"
                    href="mailto:Marcos.Matsunaga@oracle.com"
                    target="_blank">Marcos.Matsunaga@oracle.com</a>>
                  wrote:<br>
                </div>
                <blockquote class="gmail_quote" style="margin:0 0 0
                  .8ex;border-left:1px #ccc solid;padding-left:1ex">
                  <div bgcolor="#FFFFFF" text="#000000">
                    <p>Thanks Amador,</p>
                    <p>I assumed it would have the same behavior as
                      utils.system and completely ignored the pipe.</p>
                  </div>
                  <div bgcolor="#FFFFFF" text="#000000">
                    <p><br>
                    </p>
                    <br>
                    <div>On 09/08/2016 07:39 PM, Amador Segundo wrote:<br>
                    </div>
                    <blockquote type="cite">
                      <p dir="ltr">On Sep 8, 2016 8:19 PM, "Marcos E.
                        Matsunaga" <<a moz-do-not-send="true"
                          href="mailto:Marcos.Matsunaga@oracle.com"
                          target="_blank">Marcos.Matsunaga@oracle.com</a>>
                        wrote:<br>
                        ><br>
                        > Hi Cleber,<br>
                        ><br>
                        > Sorry for being a pain. I've tried to use
                        process.system to execute commands, but I got an
                        error, that's why I kept the autotest libraries
                        (I actually copied from one of the files in
                        io-github-autotest-libvirt).<br>
                        ><br>
                        > The error I'm getting is:<br>
                        ><br>
                        > 2016-09-08 13:49:25,844 sysinfo         
                        L0371 INFO | Profiler disabled<br>
                        > 2016-09-08 13:49:25,845 test           
                         L0214 INFO | START
1-/root/avocado-vt/io-fs-autotest-xen/xen/tests/xentest.py:xentest.test_xen_start_stop;1<br>
                        > 2016-09-08 13:49:25,846 process         
                        L0334 INFO | Running 'xl info|grep xen_version|
                        awk '{print $3}''<br>
                        > 2016-09-08 13:49:25,863 process         
                        L0435 INFO | Command 'xl info|grep xen_version|
                        awk '{print $3}'' finished with 1 after
                        0.00377798080444s</p>
                      <p dir="ltr">The problem here is the pipe. You can
                        collect the output and parse it inside the
                        python code. Something.like:</p>
                      <p dir="ltr">output = process.system_output("xl
                        info")<br>
                        for line in output.splitlines():<br>
                            if 'xen_version' in line:<br>
                                var = line.split()[3]<br>
                                break<br>
                        ...</p>
                      <p dir="ltr">> 2016-09-08 13:49:25,863
                        stacktrace       L0038 ERROR|<br>
                        > 2016-09-08 13:49:25,863 stacktrace     
                         L0041 ERROR| Reproduced traceback from:
                        /usr/lib/python2.7/site-packages/avocado/core/test.py:448<br>
                        > 2016-09-08 13:49:25,864 stacktrace     
                         L0044 ERROR| Traceback (most recent call last):<br>
                        > 2016-09-08 13:49:25,864 stacktrace     
                         L0044 ERROR|   File
                        "/root/avocado-vt/io-fs-autotest-xen/xen/tests/xentest.py",
                        line 52, in test_xen_start_stop<br>
                        > 2016-09-08 13:49:25,864 stacktrace     
                         L0044 ERROR| xenversion =
                        process.system_output(cmd, ignore_status=False)<br>
                        > 2016-09-08 13:49:25,864 stacktrace     
                         L0044 ERROR|   File
                        "/usr/lib/python2.7/site-packages/avocado/utils/process.py",
                        line 1139, in system_output<br>
                        > 2016-09-08 13:49:25,864 stacktrace     
                         L0044 ERROR| sudo=sudo)<br>
                        > 2016-09-08 13:49:25,864 stacktrace     
                         L0044 ERROR|   File
                        "/usr/lib/python2.7/site-packages/avocado/utils/process.py",
                        line 1046, in run<br>
                        > 2016-09-08 13:49:25,864 stacktrace     
                         L0044 ERROR|     raise CmdError(cmd, sp.result)<br>
                        > 2016-09-08 13:49:25,864 stacktrace     
                         L0044 ERROR| CmdError: Command 'xl info|grep
                        xen_version| awk '{print $3}'' failed (rc=1)<br>
                        > 2016-09-08 13:49:25,864 stacktrace     
                         L0045 ERROR|<br>
                        > 2016-09-08 13:49:25,865 test           
                         L0563 ERROR| Traceback (most recent call last):<br>
                        ><br>
                        > 2016-09-08 13:49:25,865 test           
                         L0563 ERROR|   File
                        "/usr/lib/python2.7/site-packages/avocado/core/test.py",
                        line 503, in _run_avocado<br>
                        >     raise test_exception<br>
                        ><br>
                        > 2016-09-08 13:49:25,865 test           
                         L0563 ERROR| CmdError: Command 'xl info|grep
                        xen_version| awk '{print $3}'' failed (rc=1)<br>
                        ><br>
                        > I looked at
                        "/usr/lib/python2.7/site-packages/avocado/utils/process.py",
                        line 1139 and didn't see anything that could be
                        causing the problem. I even tried to add
                        "sudo=False" argument in process.system, but I
                        get the same error.<br>
                        ><br>
                        > Thanks again.<br>
                        ><br>
                        ><br>
                        > On 09/08/2016 06:36 PM, Cleber Rosa wrote:<br>
                        >><br>
                        >> On 09/08/2016 01:50 PM, Marcos E.
                        Matsunaga wrote:<br>
                        >>><br>
                        >>> On 09/08/2016 05:44 PM, Cleber Rosa
                        wrote:<br>
                        >>>><br>
                        >>>> On 09/08/2016 11:34 AM, Marcos
                        E. Matsunaga wrote:<br>
                        >>>>><br>
                        >>>>> Hi Cleber,<br>
                        >>>>><br>
                        >>>>> Thanks for your quick
                        reply. That's exactly what I understood, but
                        here<br>
                        >>>>> is what is happening<br>
                        >>>>><br>
                        >>>>> I have a directory
                        ~/avocado/xen/tests where I have the xentest.py<br>
                        >>>>> script. When I execute it,
                        it does create the directory<br>
                        >>>>>
                        ~/avocado/xen/tests/xentest.py.data with
                        stderr.expected and<br>
                        >>>>> stdout.expected (empty). It
                        also creates the two files (stdout and<br>
                        >>>>> stderr) in the
                        job-results/latest directory, but also empty.<br>
                        >>>>><br>
                        >>>>> The weird thing is that
                        instead of saving, it reports to the job.log as<br>
                        >>>>> an error "L0151 ERROR|
                        [stderr] Parsing config from /VM/guest1/<a
                          moz-do-not-send="true" href="http://vm.cf"
                          target="_blank">vm.cf</a>".<br>
                        >>>>><br>
                        >>>>> That's why I think I am
                        missing something.<br>
                        >>>><br>
                        >>>> Can you post the full test code
                        and the resulting `job.log` file?<br>
                        >>><br>
                        >>> Sure.. It is attached.<br>
                        >>> And the multiplex file I am using
                        is:<br>
                        >>><br>
                        >>> xentest:<br>
                        >>>      guest1:<br>
                        >>>          action: !mux<br>
                        >>>              start:<br>
                        >>>                  run_action:
                        "create"<br>
                        >>>                  domain_name:
                        "perf1"<br>
                        >>>                  sleep_time: 1<br>
                        >>>              stop:<br>
                        >>>                  run_action:
                        "shutdown"<br>
                        >>>                  domain_name:
                        "perf1"<br>
                        >>>                  sleep_time: 60<br>
                        >>>          guest_cfg:
                        /Repo/VM/perf1/vm.cfg<br>
                        >>><br>
                        >>>>> Thanks again for your help.<br>
                        >>>>><br>
                        >>>>> On 09/08/2016 02:59 PM,
                        Cleber Rosa wrote:<br>
                        >>>>>><br>
                        >>>>>> On 09/08/2016 10:25 AM,
                        Marcos E. Matsunaga wrote:<br>
                        >>>>>>><br>
                        >>>>>>> Hi All,<br>
                        >>>>>>><br>
                        >>>>>>> I am new to avocado
                        and have just started to look into it.<br>
                        >>>>>>><br>
                        >>>>>>> I have been playing
                        with avocado on Fedora 24 for a few weeks. I<br>
                        >>>>>>> wrote a<br>
                        >>>>>>> small script to run
                        commands and was exploring the option<br>
                        >>>>>>>
                        "--output-check-record", but it never populate
                        the files<br>
                        >>>>>>> stderr.expected<br>
                        >>>>>>> and
                        stdout.expected. Instead, it prints an error
                        with "[stderr]" in<br>
                        >>>>>>> the<br>
                        >>>>>>> job.log file. My
                        understanding is that the output (stderr and
                        stdout)<br>
                        >>>>>>> of commands/scripts
                        executed by avocado would be captured and saved
                        on<br>
                        >>>>>>> those files (like
                        on synctest.py example), but it doesn't. I want
                        to<br>
                        >>>>>>> know if I am doing
                        something wrong or it is a bug.<br>
                        >>>>>>><br>
                        >>>>>> Hi Marcos,<br>
                        >>>>>><br>
                        >>>>>> Avocado creates the
                        `stdout` and `stderr` files in the test result<br>
                        >>>>>> directory.  In the
                        synctest example, for instance, my contains:<br>
                        >>>>>><br>
                        >>>>>> $ avocado run
                        examples/tests/synctest.py<br>
                        >>>>>> $ cat<br>
                        >>>>>>
~/avocado/job-results/latest/test-results/1-examples_tests_synctest.py\:SyncTest.test/stdout<br>
                        >>>>>><br>
                        >>>>>><br>
                        >>>>>><br>
                        >>>>>> PAR : waiting<br>
                        >>>>>> PASS : sync interrupted<br>
                        >>>>>><br>
                        >>>>>> `stderr` is actually
                        empty for that test:<br>
                        >>>>>><br>
                        >>>>>> $ wc -l<br>
                        >>>>>>
~/avocado/job-results/latest/test-results/1-examples_tests_synctest.py\:SyncTest.test/stderr<br>
                        >>>>>><br>
                        >>>>>><br>
                        >>>>>> 0<br>
                        >>>>>>
/home/cleber/avocado/job-results/latest/test-results/1-examples_tests_synctest.py:SyncTest.test/stderr<br>
                        >>>>>><br>
                        >>>>>><br>
                        >>>>>><br>
                        >>>>>> What you have to do is,
                        once you're satisfied with those outputs, and<br>
                        >>>>>> they're considered "the
                        gold standard", you'd move those to the test<br>
                        >>>>>> *data directory*.<br>
                        >>>>>><br>
                        >>>>>> So, if you test is
                        hosted at, `/tests/xl.py`, you'd created the<br>
                        >>>>>> `/tests/xl.py.data`,
                        and put those files there, named
                        `stdout.expected`<br>
                        >>>>>> and `stderr.expected`.<br>
                        >>>>>><br>
                        >>>>>> Whenever you run
                        `avocado run --output-check-record all
                        /tests/xl.py`,<br>
                        >>>>>> those files will be
                        used and the output of the *current* test
                        execution<br>
                        >>>>>> will be compared to
                        those "gold standards".<br>
                        >>>>>><br>
                        >>>>>>> The script is very
                        simple and the way I execute the command is:<br>
                        >>>>>>><br>
                        >>>>>>> cmd =
                        ('/usr/sbin/xl create /VM/guest1/vm.cfg')<br>
                        >>>>>>> if
                        utils.system(cmd) == "0":<br>
                        >><br>
                        >> The issue seems to be related to the
                        fact that you're using old autotest<br>
                        >> libraries to execute your external
                        commands.<br>
                        >><br>
                        >> The output record/check support is
                        built into Avocado's libraries,<br>
                        >> namely `avocado.utils.process`.<br>
                        >><br>
                        >> Try to replace your code with:<br>
                        >><br>
                        >>     from avocado.utils import process<br>
                        >>     ...<br>
                        >>     process.system(cmd)<br>
                        >><br>
                        >> Also, mixing and matching autotest and
                        avocado libraries in the same<br>
                        >> test code is not something I'd
                        recommend.  Not that it's guaranteed to<br>
                        >> break. I'd recomend to (try to) move to
                        avocado libraries, or keep an<br>
                        >> eye on strange behavior like this.<br>
                        >><br>
                        >>>>>>>          pass<br>
                        >>>>>>> else:<br>
                        >>>>>>>          return
                        False<br>
                        >>>>>>><br>
                        >>>>>>> The command send to
                        stdout:<br>
                        >>>>>>><br>
                        >>>>>>> Parsing config from
                        /VM/guest1/vm.cfg<br>
                        >>>>>>><br>
                        >>>>>>> I run the test as:<br>
                        >>>>>>><br>
                        >>>>>>> avocado run
                        --output-check-record all xentest.py<br>
                        >>>>>>><br>
                        >>>>>>> The job.log file
                        contains:<br>
                        >>>>>>><br>
                        >>>>>>> 2016-09-07
                        13:04:48,015 test             L0214 INFO | START<br>
                        >>>>>>>
1-/root/avocado-vt/io-fs-autotest-xen/xen/tests/xentest.py:xentest.test_xen_start_stop;1<br>
                        >>>>>>><br>
                        >>>>>>><br>
                        >>>>>>><br>
                        >>>>>>> 2016-09-07
                        13:04:48,051 xentest          L0033 INFO |<br>
                        >>>>>>>
1-/root/avocado-vt/io-fs-autotest-xen/xen/tests/xentest.py:xentest.test_xen_start_stop;1:<br>
                        >>>>>>><br>
                        >>>>>>><br>
                        >>>>>>> Running action
                        create<br>
                        >>>>>>> 2016-09-07
                        13:04:49,067 utils            L0151 ERROR|
                        [stderr] Parsing<br>
                        >>>>>>> config from
                        /VM/guest1/vm.cfg<br>
                        >>>>>>> 2016-09-07
                        13:04:49,523 test             L0586 INFO | PASS<br>
                        >>>>>>>
1-/root/avocado-vt/io-fs-autotest-xen/xen/tests/xentest.py:xentest.test_xen_start_stop;1<br>
                        >>>>>>><br>
                        >>>>>>><br>
                        >>>>>>><br>
                        >>>>>>><br>
                        >>>>>>> Thanks for your
                        time and help.<br>
                        >>>>>><br>
                        >>>>>> Let me know if it's
                        clear now! And thanks for trying Avocado out!<br>
                        >>>>>><br>
                        ><br>
                        > -- <br>
                        ><br>
                        > Regards,<br>
                        ><br>
                        > Marcos Eduardo Matsunaga<br>
                        ><br>
                        > Oracle USA<br>
                        > Linux Engineering<br>
                        ><br>
                        > “The statements and opinions expressed here
                        are my own and do not<br>
                        > necessarily represent those of Oracle
                        Corporation.”<br>
                        ></p>
                    </blockquote>
                    <br>
                    <pre cols="72">-- 

Regards,

Marcos Eduardo Matsunaga

Oracle USA
Linux Engineering

“The statements and opinions expressed here are my own and do not
necessarily represent those of Oracle Corporation.”
</pre>
                  </div>
                </blockquote>
              </div>
            </blockquote>
          </div>
        </blockquote>
      </div>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 

Regards,

Marcos Eduardo Matsunaga

Oracle USA
Linux Engineering

“The statements and opinions expressed here are my own and do not
necessarily represent those of Oracle Corporation.”
</pre>
  </body>
</html>