[Avocado-devel] Implement fetch-assets command line

Amador Pahim amador at pahim.org
Wed Sep 25 13:16:55 UTC 2019


On Tue, Sep 24, 2019 at 9:42 PM Willian Rampazzo <wrampazz at redhat.com> wrote:
>
> Hello everyone,
>
> I started working on Trello card
> https://trello.com/c/T3SC1sZs/1521-implement-fetch-assets-command-line
> as part of a broader card,
> https://trello.com/c/CKP7YS6G/1481-on-cache-check-for-asset-fetcher
> and I would like to bring my findings to a discussion.
>
> One way to implement that would be to parse the test source looking
> for the fetch_asset call and execute it. In theory, it is a straight
> forward implementation.
>
> I have started working in the parser. After some simple tests, some
> complex situations started to show up. Let me bring an existing
> example, examples/tests/assets.py:
>
>     def setUp(self):
>         mirrors = ['https://mirrors.peers.community/mirrors/gnu/hello/',
>                    'https://mirrors.kernel.org/gnu/hello/',
>                    'http://gnu.c3sl.ufpr.br/ftp/',
>                    'ftp://ftp.funet.fi/pub/gnu/prep/hello/']
>         hello = 'hello-2.9.tar.gz'
>         hello_locations = ["%s/%s" % (loc, hello) for loc in mirrors]
>         hello_sig = 'hello-2.9.tar.gz.sig'
>         hello_sig_locations = ["%s/%s" % (loc, hello_sig) for loc in mirrors]
>         self.hello = self.fetch_asset(
>             name=hello,
>             locations=hello_locations)
>         self.hello_sig = self.fetch_asset(
>             name=hello_sig,
>             asset_hash='f3b9fae20c35740004ae7b8de1301836dab4ac30',
>             locations=hello_sig_locations)
>
> When the parser finds the fetch_asset call, it needs to inspect its
> arguments, looking for variables. If any variable is found, it needs
> to walk back the code looking for its assignment, so it is able to
> execute it prior to the fetch_asset execution. If the variables
> consist of other variables, the parser, again, needs to walk back in
> the code looking for those assignments, and so on.
>
> There are countless ways of creating the right side of a variable
> assignment, from a single string assignment to a function that builds
> the content, or conditional assignments.
>
> My initial idea is to cover variables consisting of other variables
> and list comprehension, just like in the example. For now, other
> complex constructions would be out of this implementation.
>
> Any comment, concern, suggestion, is appreciated here as it would help
> to build a more robust code.

The problem with not covering all the cases is that, well, you're not
covering all the cases :)
And the parsing of code to execute snippets out of it is always a
tricky thing to do. What if your variable is being filled by a
function call that acquires data from an external source that requires
a specific environment... how to reproduce that environment in the
command liner? There are way too many cases were things can go wrong.

Have you considered adding support for args-from-config-file in the
asset fetcher? Something like:

asset.Asset(args_from_config='/foo/bar/my_asset_01.yaml')

Or, instead of a separate config file, I'd also consider some reserved
keys in the parametrization interface (we have some already:
https://avocado-framework.readthedocs.io/en/latest/WritingTests.html?highlight=timeout#setting-a-test-timeout).

That way you would enable the asset fetcher caching tool to read from
the same configuration input and cache things in advance. Anyone
willing to use that feature would have to either use the
args_from_config also in their tests or specify the args accordingly.

>
> Best regards,
>
> Willian Rampazzo
> Software Engineer
> Red Hat Brazil
> 2717 337F 7E4A 5FDF
>


-- 
Pahim




More information about the Avocado-devel mailing list