How to set state in @hook code block?

John Meinel john at arbash-meinel.com
Thu Jul 20 06:06:56 UTC 2017


I'm pretty sure hooks execute in the parent directory.
So if you have
charm/
 hooks/
   db-relation-changed
   myfiles/
     test.yaml

you need to
 open("hooks/myfiles/test.yaml")


John
=:->

On Jul 20, 2017 04:58, "fengxia" <fxia1 at lenovo.com> wrote:

> Hi Juju,
>
> I think I read at some point in the official document that you can't set
> state from hook.
>
> However, this is what I'm trying to achieve: in @hook('config-changed'), I
> will pass in a file path as a config value. Files are part of the charm so
> they are installed in /var/lib/juju/agents/unit-mycharm/myfiles/ on the
> unit node. But when @hook('config-changed') is triggered, my code to
> "open('/path/file')" actually complains "file not found". This makes me
> wonder that hook is not visible of the charm directory?
>
> So I'm thinking this can be worked around if I set_state("mystate") from
> hook. But doing so didn't trigger @when("mystate").
>
> What's the right way to do this then?
>
> --
> Feng xia
> Engineer
> Lenovo USA
>
> Phone: 5088011794
> fxia1 at lenovo.com
>
> Lenovo.com
> Twitter | Facebook | Instagram | Blogs | Forums
>
>
> --
> Juju mailing list
> Juju at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailm
> an/listinfo/juju
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju/attachments/20170720/4d855666/attachment.html>


More information about the Juju mailing list