<div dir="ltr">Hey Lukáš, what I meant by a DAG of dependencies is that  tests in the chain may depend on the output of a previous test to execute a subsequent test, to borrow from the cloud provisioning example you'd outlined<div><br></div><div>Test Cloud Provision</div><div><br></div><div>SubTest1- Provision a cloud service</div><div>SubTest2- Run a configuration check</div><div><br></div><div>At this point there may be several paths to go by depending on the results of the test, for example<br></div><div><br></div><div>SubTest4.1- Stress CPU </div><div>Or</div><div>SubTest4.2- Stress Storage </div><div><br></div><div><br></div><div>I definitely like the idea, just wondering how it will handle relationship definitions between independent tests </div><div><br></div><div>Thanks!<br></div><div><br></div><div>-</div><div>Vincent</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 25, 2016 at 6:18 AM, Lukáš Doktor <span dir="ltr"><<a href="mailto:ldoktor@redhat.com" target="_blank">ldoktor@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Vincent,<br>
<br>
could you please provide an example? I'm not sure I understand your concern. The beauty of nested tests is the simplicity. Basically the main test just triggers the test(s) and waits for them to finish. Then it can decide what to do with the results (bail out, ignore, include in results, trigger another test(s), ...).<br>
<br>
For complex tasks (like the advanced example) synchronization mechanisms would have to be used for example inside the `Setup a fake network` test to wait till all the tests finish and then post-process/stop the fake network.<br>
<br>
Obviously there is nothing what should prevent nested tests to invoke another nested tests, but then the situation is the same. They act as nested-main test for the nested-nested tests and when the nested-nested tests finish it reports the single result and the main test retrieves just the single result and it could decide what to do next.<br>
<br>
All of those together should allow great flexibility and understandable/predictable results.<br>
<br>
Regards,<br>
Lukáš<br>
<br>
<br>
Dne 25.5.2016 v 07:40 Vincent Matossian napsal(a):<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
Hi Lukáš,<br>
<br>
I often come up with the need to orchestrate test units, so your note is<br>
quite interesting to me. I wonder about the high-level workflow that<br>
weaves through those nested tests, these can end up being quite complex,<br>
and it seems that having a way to describe what to do at every step<br>
would need to be done as part of the description of the relationships<br>
between nested tests.<br>
<br>
The examples you showed had a fairly linear/serial relationship, do you<br>
consider cases that are better described as directed acyclic graphs?<br>
<br>
In the end it's a tradeoff between what capabilities to push in the core<br>
test framework vs what remains strictly in the body of the test up to<br>
the test writer to implement.<br>
<br>
Thanks<br>
<br>
-<br>
Vincent<br>
<br>
<br>
On Tue, May 24, 2016 at 7:53 AM, Lukáš Doktor <<a href="mailto:ldoktor@redhat.com" target="_blank">ldoktor@redhat.com</a><br></span><div><div class="h5">
<mailto:<a href="mailto:ldoktor@redhat.com" target="_blank">ldoktor@redhat.com</a>>> wrote:<br>
<br>
    Hello guys,<br>
<br>
    this version returns to roots and tries to define clearly the single<br>
    solution I find teasing for multi-host and other complex tests.<br>
<br>
    Changes:<br>
<br>
        v2: Rewritten from scratch<br>
        v2: Added examples for the demonstration to avoid confusion<br>
        v2: Removed the mht format (which was there to demonstrate manual<br>
            execution)<br>
        v2: Added 2 solutions for multi-tests<br>
        v2: Described ways to support synchronization<br>
        v3: Renamed to multi-stream as it befits the purpose<br>
        v3: Improved introduction<br>
        v3: Workers are renamed to streams<br>
        v3: Added example which uses library, instead of new test<br>
        v3: Multi-test renamed to nested tests<br>
        v3: Added section regarding Job API RFC<br>
        v3: Better description of the Synchronization section<br>
        v3: Improved conclusion<br>
        v3: Removed the "Internal API" section (it was a transition between<br>
            no support and "nested test API", not a "real" solution)<br>
        v3: Using per-test granularity in nested tests (requires plugins<br>
            refactor from Job API, but allows greater flexibility)<br>
        v4: Removed "Standard python libraries" section (rejected)<br>
        v4: Removed "API backed by cmdline" (rejected)<br>
        v4: Simplified "Synchronization" section (only describes the<br>
            purpose)<br>
        v4: Refined all sections<br>
        v4: Improved the complex example and added comments<br>
        v4: Formulated the problem of multiple tasks in one stream<br>
        v4: Rejected the idea of bounding it inside MultiTest class<br>
            inherited from avocado.Test, using a library-only approach<br>
        v5: Avoid mapping ideas to multi-stream definition and clearly<br>
            define the idea I bear in my head for test building blocks<br>
            called nested tests.<br>
<br>
<br>
    Motivation<br>
    ==========<br>
<br>
    Allow building complex tests out of existing tests producing a<br>
    single result depending on the complex test's requirements.<br>
    Important thing is, that the complex test might run those tests on<br>
    the same, but also on a different machine allowing simple<br>
    development of multi-host tests. Note that the existing tests should<br>
    stay (mostly) unchanged and executable as simple scenarios, or<br>
    invoked by those complex tests.<br>
<br>
    Examples of what could be implemented using this feature:<br>
<br>
    1. Adding background (stress) tasks to existing test producing<br>
    real-world scenarios.<br>
       * cpu stress test + cpu hotplug test<br>
       * memory stress test + migration<br>
       * network+cpu+memory test on host, memory test on guest while<br>
         running migration<br>
       * running several migration tests (of the same and different type)<br>
<br>
    2. Multi-host tests implemented by splitting them into components<br>
    and leveraging them from the main test.<br>
       * multi-host migration<br>
       * stressing a service from different machines<br>
<br>
<br>
    Nested tests<br>
    ============<br>
<br>
    Test<br>
    ----<br>
<br>
    A test is a receipt explaining prerequisites, steps to check how the<br>
    unit under testing behaves and cleanup after successful or<br>
    unsuccessful execution.<br>
<br>
    Test itself contains lots of neat features to simplify logging,<br>
    results analysis and error handling evolved to simplify testing.<br>
<br>
    Test runner<br>
    -----------<br>
<br>
    Is responsible for driving the test(s) execution, which includes the<br>
    standard test workflow (setUp/test/tearDown), handle plugin hooks<br>
    (results/pre/post) as well as safe interruption.<br>
<br>
    Nested test<br>
    -----------<br>
<br>
    Is a test invoked by other test. It can either be executed in<br>
    foreground (while the main test is waiting) or in background along<br>
    with the main (and other background tests) test. It should follow<br>
    the default test workflow (setUp/test/tearDown), it should keep all<br>
    the neat test feature like logging and error handling and the<br>
    results should also go into the main test's output, with the nested<br>
    test's id  as prefix. All the produced files of the nested test<br>
    should be located in a new directory inside the main test results<br>
    dir in order to be able to browse either overall results (main test<br>
    + nested tests) or just the nested tests ones.<br>
<br>
    Resolver<br>
    --------<br>
<br>
    Resolver is an avocado component resolving a test reference into a<br>
    list of test templates compound of the test name, params and other<br>
    `avocado.Test.__init__` arguments.<br>
<br>
    Very simple example<br>
    -------------------<br>
<br>
    This example demonstrates how to use existing test (SimpleTest<br></div></div>
    "/usr/bin/wget <a href="http://example.org" rel="noreferrer" target="_blank">example.org</a> <<a href="http://example.org" rel="noreferrer" target="_blank">http://example.org</a>>") in order to create<span class=""><br>
    a complex scenario (download the main page from <a href="http://example.org" rel="noreferrer" target="_blank">example.org</a><br></span>
    <<a href="http://example.org" rel="noreferrer" target="_blank">http://example.org</a>> from multiple computers almost concurrently),<span class=""><br>
    without any modifications of the `SimpleTest`.<br>
<br>
        import avocado<br>
<br>
        class WgetExample(avocado.Test):<br>
            def test(self):<br>
                # Initialize nested test runner<br>
                self.runner = avocado.NestedRunner(self)<br>
                # This is what one calls on "avocado run"<br>
                test_reference = "/usr/bin/wget <a href="http://example.org" rel="noreferrer" target="_blank">example.org</a><br></span>
    <<a href="http://example.org" rel="noreferrer" target="_blank">http://example.org</a>>"<div><div class="h5"><br>
                # This is the resolved list of templates<br>
                tests = avocado.resolver.resolve(test_reference)<br>
                # We could support list of results, but for simplicity<br>
                # allow only single test.<br>
                assert len(tests) == 1, ("Resolver produced multiple test "<br>
                                         "names: %s\n%s" % (test_reference,<br>
                                                            tests)<br>
                test = tests[0]<br>
                for machine in self.params.get("machines"):<br>
                    # Query a background job on the machine (local or<br>
                    # remote) and return test id in order to query for<br>
                    # the particular results or task interruption, ...<br>
                    self.runner.run_bg(machine, test)<br>
                # Wait for all background tasks to finish, raise exception<br>
                # if any of them fails.<br>
                self.runner.wait(ignore_errors=False)<br>
<br>
    When nothing fails, this usage has no benefit over the simple<br>
    logging into a machine and firing up the command. The difference is,<br>
    when something does not work as expected. With nested test, one get<br>
    a runner exception if the machine is unreachable. And on test error<br>
    he gets not only overall log, but also the per-nested-test results<br>
    simplifying the error analysis. For 1, 2 or 3 machines, this makes<br>
    no difference, but imagine you want to run this from hundreds of<br>
    machines. Try finding the exception there.<br>
<br>
    Yes, you can implement the above without nested tests, but it<br>
    requires a lot of boilerplate code to establish the connection (or<br>
    raise an exception explaining why it was not possible and I'm not<br>
    talking about "unable to establish connection", but granularity like<br>
    "Invalid password", "Host is down", ...). Then you'd have to setup<br>
    the output logging for that particular task, add the prefix, run the<br>
    task (handling all possible exceptions) and interpret the results.<br>
    All of this to get the same benefits very simple avocado test<br>
    provides you.<br>
<br>
    Advanced example<br>
    ----------------<br>
<br>
    Imagine a very complex scenario, for example a cloud with several<br>
    services. One could write a big-fat test tailored just for this<br>
    scenario and keep adding sub-scenarios producing unreadable source code.<br>
<br>
    With nested tests one could split this task into tests:<br>
<br>
     * Setup a fake network<br>
     * Setup cloud service<br>
     * Setup in-cloud service A/B/C/D/...<br>
     * Test in-cloud service A/B/C/D/...<br>
     * Stress network<br>
     * Migrate nodes<br>
<br>
    New variants could be easily added, for example DDoS attack to some<br>
    nodes, node hotplug/unplug, ... by invoking those existing tests and<br>
    combining them into a complex test.<br>
<br>
    Additionally note that some of the tests, eg. the setup cloud<br>
    service and setup in-cloud service are quite generic tests, what<br>
    could be reused many times in different tests. Yes, one could write<br>
    a library to do that, but in that library he'd have to handle all<br>
    exceptions and provide nice logging, while not clutter the main<br>
    output with unnecessary information.<br>
<br>
    Job results<br>
    -----------<br>
<br>
    Combine (multiple) test results into understandable format. There<br>
    are several formats, the most generic one is file format:<br>
<br>
    .<br>
    ├── id  -- id of this job<br>
    ├── job.log  -- overall job log<br>
    └── test-results  -- per-test-directories with test results<br>
        ├── 1-passtest.py:PassTest.test  -- first test's results<br>
        └── 2-failtest.py:FailTest.test  -- second test's results<br>
<br>
    Additionally it contains other files and directories produced by<br>
    avocado plugins like json, xunit, html results, sysinfo gathering<br>
    and info regarding the replay feature.<br>
<br>
    Test results<br>
    ------------<br>
<br>
    In the end, every test produces results, which is what we're<br>
    interested in. The results must clearly define the test status,<br>
    should provide a record of what was executed and in case of failure,<br>
    they should provide all the information in order to find the cause<br>
    and understand the failure.<br>
<br>
    Standard tests does that by providing test log (debug, info,<br>
    warning, error, critical), stdout, stderr, allowing to write to<br>
    whiteboard and attach files in the results directory. Additionally<br>
    due to structure of the test one knows what stage(s) of the test<br>
    failed and pinpoint exact location of the failure (traceback in the<br>
    log).<br>
<br>
    .<br>
    ├── data  -- place for other files produced by a test<br>
    ├── debug.log  -- debug, info, warn, error log<br>
    ├── remote.log  -- additional log regarding remote session<br>
    ├── stderr  -- standard error<br>
    ├── stdout  -- standard output<br>
    ├── sysinfo  -- provided by sysinfo plugin<br>
    │   ├── post<br>
    │   ├── pre<br>
    │   └── profile<br>
    └── whiteboard  -- file for arbitrary test data<br>
<br>
    I'd like to extend this structure of either a directory "subtests",<br>
    or convention for directories intended for nested test results<br>
    `r"\d+-.*"`.<br>
<br>
    The `r"\d+-.*"` reflects the current test-id notation, which nested<br>
    tests should also respect, replacing the serialized-id by<br>
    in-test-serialized-id. That way we easily identify which of the<br>
    nested tests was executed first (which does not necessarily mean it<br>
    finished as first).<br>
<br>
    In the end nested tests should be assigned a directory inside the<br>
    main test's results (or main test's results/subtests) and it should<br>
    produce the data/debug.log/stdout/stderr/whiteboard in there as well<br>
    as propagate the debug.log with a prefix to the main test's<br>
    debug.log (as well as job.log).<br>
<br>
    └── 1-parallel_wget.py:WgetExample.test  -- main test<br>
        ├── data<br>
        ├── debug.log  -- contains main log + nested logs with prefixes<br>
        ├── remote.log<br>
        ├── stderr<br>
        ├── stdout<br>
        ├── sysinfo<br>
        │   ├── post<br>
        │   ├── pre<br>
        │   └── profile<br>
        ├── whiteboard<br></div></div>
        ├── 1-_usr_bin_wget\ <a href="http://example.org" rel="noreferrer" target="_blank">example.org</a> <<a href="http://example.org" rel="noreferrer" target="_blank">http://example.org</a>>  -- first<span class=""><br>
    nested test<br>
        │   ├── data<br>
        │   ├── debug.log  -- contains only this nested test log<br>
        │   ├── remote.log<br>
        │   ├── stderr<br>
        │   ├── stdout<br>
        │   └── whiteboard<br></span>
        ├── 2-_usr_bin_wget\ <a href="http://example.org" rel="noreferrer" target="_blank">example.org</a> <<a href="http://example.org" rel="noreferrer" target="_blank">http://example.org</a>>  -- second<br>
    nested test<br>
    ...<br>
        └── 3-_usr_bin_wget\ <a href="http://example.org" rel="noreferrer" target="_blank">example.org</a> <<a href="http://example.org" rel="noreferrer" target="_blank">http://example.org</a>>  -- third<span class=""><br>
    nested test<br>
    ...<br>
<br>
    Note that nested tests can finish with any result and it's up to the<br>
    main test to evaluate that. This means that theoretically you could<br>
    find nested tests which states `FAIL` or `ERROR` in the end. That<br>
    might be confusing, so I think the `NestedRunner` should append last<br>
    line to the test's log saying `Expected FAILURE` to avoid confusion<br>
    while looking at results.<br>
<br>
    Note2: It might be impossible to pass messages in real-time across<br>
    multiple machines, so I think at the end the main job.log should be<br>
    copied to `raw_job.log` and the `job.log` should be reordered<br>
    according to date-time of the messages. (alternatively we could only<br>
    add a contrib script to do that).<br>
<br>
<br>
    Conclusion<br>
    ==========<br>
<br>
    I believe nested tests would help people covering very complex<br>
    scenarios by splitting them into pieces similarly to Lego. It allows<br>
    easier per-component development, consistent results which are easy<br>
    to analyze as one can see both, the overall picture and the specific<br>
    pieces and it allows fixing bugs in all tests by fixing the single<br>
    piece (nested test).<br>
<br>
<br>
    _______________________________________________<br>
    Avocado-devel mailing list<br></span>
    <a href="mailto:Avocado-devel@redhat.com" target="_blank">Avocado-devel@redhat.com</a> <mailto:<a href="mailto:Avocado-devel@redhat.com" target="_blank">Avocado-devel@redhat.com</a>><br>
    <a href="https://www.redhat.com/mailman/listinfo/avocado-devel" rel="noreferrer" target="_blank">https://www.redhat.com/mailman/listinfo/avocado-devel</a><br>
<br>
<br>
</blockquote>
<br>
<br>
</blockquote></div><br></div>