On Mon, May 15, 2017 at 05:40:34PM +0200, Jiri Pirko wrote:
Thu, May 11, 2017 at 02:41:14PM CEST, olichtne(a)redhat.com wrote:
>From: Ondrej Lichtner <olichtne(a)redhat.com>
>
>Module implementing the BaseRecipe class. Every LNST Recipe written by
>testers should be inherited from this class. An LNST Recipe is composed
>of several parts:
>* Requirements definition
>* Parameter definition (optional)
>* Test definition
>
>Further documentation can be read in the classes doc string.
>
>Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
[...]
>+ def __init__(self, **kwargs):
>+ """
>+ The __init__ method does 2 things:
>+ * copies Requirements -- since Requirements are defined as class
>+ attributes, we need to copy the objects to avoid conflicts with
>+ multiple instances of the same class etc...
>+ The copied objects are stored under a Requirements object available
>+ through the 'req' attribute. This way you can optionally change
the
>+ Requirements of an instantiated Recipe.
>+ * copies and instantiates Parameters -- Parameters are also class
>+ attributes so they need to be copied into a Parameters() object
>+ (accessible in the 'params' attribute).
>+ Next, the copied objects are loaded with values from kwargs
>+ and checked if mandatory Parameters have values.
>+ """
>+ self.matched = None
>+ self.req = _Requirements()
>+ self.params = Parameters()
>+ for x in dir(self):
I bet you can figure out some more descriptive variable name :)
is 'attr' better? :)
>
> >+ val = getattr(self, x)
> >+ if isinstance(val, HostReq):
> >+ setattr(self.req, x, copy.deepcopy(val))
> >+ elif isinstance(val, Param):
> >+ setattr(self.params, x, copy.deepcopy(val))
> >+
> >+ for name, val in kwargs.items():
> >+ try:
> >+ param = getattr(self.params, name)
> >+ param.set_val(val)
> >+ except:
> >+ raise RecipeError("Unknown parameter
{}".format(name))
> >+
> >+ for name, param in self.params:
> >+ if param.mandatory and not param.set:
> >+ raise RecipeError("Parameter {} is
mandatory".format(name))
> >+
> >+ def _set_hosts(self, hosts):
> >+ self.matched = hosts
> >+
> >+ def test(self):
> >+ """Method to be implemented by the
Tester"""
> >+ raise NotImplementedError("Method test must be defined by a child
class.")
> >--
> >2.12.2
> >_______________________________________________
> >LNST-developers mailing list -- lnst-developers(a)lists.fedorahosted.org
> >To unsubscribe send an email to lnst-developers-leave(a)lists.fedorahosted.org