omaciel/robottelo — pull request #319 by AdamSaleh (2014-01-24 19:31:54+00:00)
Title: Records models draft

Epic pull request :)

Ok, so first, some philosophy, or where I want to end up:

1) I want to be able to ask robottelo for any "object" in foreman, get a valid definition,
and the choose to create/read/update/delete it with api/cli/ui.

2) I want to easily compare between the information that api/cli/ui is giving me

3) I want to be able to do this even for complicated objects, such as "hosts", that have many related fields, and even constraints on them, or "architecure" and "operatingsystem" that have many-to-many relationship

Some of it works already, albeit with quirks. I can recursively create Host with api, and create, read and most importantly compare Domain and Operatingsystem with Api and Cli.

If you try branch, and resolve dependencies (mostly "pip install rstr" ?) these three test files should pass (they did for me)

python -m unittest tests.api.test_host
python -m unittest tests.parity.test_operatingsystem
python -m unittest tests.parity.test_domain

Quirks:

1) I needed to enforce host.name.suffix(host.name.domain), or assertion h_created == ApiCrud.create(h).name wouldn't hold
2) cli uses "-" in keywords and api "_", this can be translated automaticaly
3) cli uses "/" in dates and api uses "-" in dates ... I don't know yet
4) when using cli to create domain its stdout is "Domain [domain_name] was created", operating system is just
"Operating system was created" without the name
5) I am trying to distinguish between "realistic" and "magic" functions :-)

Realistic function should model closely the functionality of respective api/cli/ui. Example is CliCrud.record_create,
where CliCrud.record_create(operating_system) will return an empty operating system record, because cli doesn't even return os name.

Magic function should use as much information as possible, for example ApiCrud.record_create_recursive(host) will resolve everything necessary for a creation of host.

This is not as consistent as I'd like (for example I probably shouldn't parse the result json in ApiCrud.record_create_recursive and just call ApiCrud.record_resolve_recursive to get all the information)

6) Cli doesn't have magic recursive functions yet
7) api is inconsistent as well, i.e when creating host, it returns name of its environment as well, but for operating system returns just the id
7) still don't have much of many-to-many recursive done, only thing is one-to-many required for host api create

There seem to be two ways to do this. In api, there you just specify the list of ids that relate to current record.
In cli there seem to be add_related and remove_related for related one-to-many fields. I'd like to do both :) But this would add development time.