#219 Add fmf to standard-inventory-qcow2 provisioner.
Merged by astepano. Opened by astepano.
qcow2_fmf  into  master

Download 219.patch

I would probably suggest to use something like this:

config = fmf.Tree('.').find("/provision").data['standard-inventory-qcow2']

Then you can easily access all configuration values directly:

config['qemu']['net_nic']['model']

Hope this helps.

@psss

cat provision.fmf 
---
# qemu options: https://qemu.weilnetz.de/doc/qemu-doc.html
standard-inventory-qcow2:
  qemu:
    # RAM size in megabytes. Optionally, a suffix of “M” or “G”.
    m: 3G
    net_nic:
      # Use qemu-system-x86_64 -net nic,model=help for a list of available devices.
      model: e1000
standard-inventory-docker:
  dumb_option: dumb_parameter
# vim:ft=yaml: ts=2 sts=2 sw=2 expandtab

Of course we can use : config['qemu']['net_nic']['model']
With above approach we must always run in try/catch + specify backup code to set default value.

If we want to use function, as I did, that we need represent ['qemu']['net_nic']['model'] as a parameter to function fmf_get(). How to do this ? I use list.

Think about fmf_get() as the same as dict.get(key[, default]).

@psss I have a question:

fmf.Tree('.') - does it scans all work dir each time?

If I want to get many parameters, how is to safe to call fmf.Tree('.') each time?

Thank you for your time.

rebased onto 016263398d388930688c2a625eae8dc13417fd98

I see. Thanks for clarification. Make sense to handle default values in the functin. Regarding the scanning: Yes, when construction a new tree the directory is scanned again. It might make sense to implement something like this:

class Config(object):
    tree = None
    def get(self):
        if self.tree is None:
            Config.tree = fmf.Tree(".")
        return self.tree

If this is more common use case we could also consider support for simple caching directly in FMF. BTW, the extended .get() functionality might be an interesting future feature as well.

@psss I was trying to use .find(), but it is not easy as it would seem:

for node in tree.climb(): print node.name
empty/3/output-document-file
empty/3/output-document-pipe
empty/provision

works:

tree.find("empty/provision")
Out[25]: <fmf.base.Tree at 0x248dcd0>

but doesn't work:

tree.find("/provision")

Nothing

rebased onto fc31b6a2cdd3b3cfdaf075491be4b3f9b22b9e45

Yes, Tree.find() expects a full name of the node to be found. If you need to search among multiple nodes you can use Tree.prune(names=[".*/provision"]) which supports regular expressions. The FmfMetadataTree class looks fine.

rebased onto 7e98dc554011a820f5830b96faa0147235f2fad6

@psss Thank you for the Tree.prune() hint. I updated PR.

pretty please pagure-ci rebuild

rebased onto dad29c5e36a81291e221aa19aecbcce98b1590eb

pretty please pagure-ci rebuild

rebased onto bf3a444451eb1a9c6f73d6c913af45adb34e5884

pretty please pagure-ci rebuild

rebased onto 43d5594826c851e2df42ed19b2861b70d77c4283

pretty please pagure-ci rebuild

Commit 9e216f62 fixes this pull-request

Pull-Request has been merged by astepano

Pull-Request has been merged by astepano

FYI, as this seems to be quite useful feature (and possible common use case) I've implemented the deep dictionary attribute retrieval directly in fmf:

https://github.com/psss/fmf/commit/b537c59

@psss nice, when it is in stable RPM branch we can update this code.
Thank you.

It would be nice if you could provide some example how to use this.

I've added basic documentation including a simple example here:
https://fedoraproject.org/wiki/CI/Metadata#Provision

Metadata