charm layers hooks/install, how are they "merged"?
fengxia
fxia1 at lenovo.com
Fri Aug 11 14:17:55 UTC 2017
Make sense. Thank you Stuart.
On 08/11/2017 06:31 AM, Stuart Bishop wrote:
> On 11 August 2017 at 09:02, fengxia <fxia1 at lenovo.com> wrote:
>> Hi Juju,
>>
>> I'm building a charm by including two layers in layer.yaml:
>>
>> includes:
>> - 'layer:basic'
>> - 'layer:pylxca'
>>
>> Pylxca is a library I packaged into a "layer" format for reuse.
>>
>> Both layers have a folder called "hooks", and each has a hook called
>> "install". The curious result is that after `charm build`, the pylxca's
>> install hook is the one in dist.
> The pylxca layer should not be adding the hook stubs if the hooks/
> directory. These are declared in layer:basic, and duplicating them in
> the pylxca leads to the problem you describe.
>
>> So my question now is, if I want to use layers, and each layer defines its
>> own hooks so to help its implementation, how does `charm build` handle them?
>> Are they merged? From this test, only the last one will survive. If so, does
>> it mean only one layer can define hooks?
> Only one layer should define the hook stubs. Layers can do it, as you
> have found, and it can be useful in some debugging situations to
> override and inject behaviour, but I don't think should ever go as far
> as a release.
>
> If multiple layers need hook specific code, they can all declare
> handlers with the @hook decorator and they are all run in an arbitrary
> order. Its best to avoid @hook completely though and just use normal
> reactive states. So instead of using @hook('install'), use
> @when_not('mycharm.installed') and have that handler set the
> mycharm.installed state at the end.
>
--
Feng xia
Engineer
Lenovo USA
Phone: 5088011794
fxia1 at lenovo.com
Lenovo.com
Twitter | Facebook | Instagram | Blogs | Forums
More information about the Juju
mailing list