Foreman_hooks when cancelBuild and Build being pressed

Hello Dominic?,
I'm still playing with you foreman_hooks plugin trying to figure out which
events I should listen to cancelBuild or Build (setBuild) is being pressed.

So far I could only succeed with registering to the host/update event. Is
this the right event to being triggered when pressing those buttons?

On the other hand it looks like those events are only triggered once. When
I press cancleBuild/Build a second time no new event is triggered.

Am I doing something wrong or is this a bug or a works as designed?

Thanks for your help
Marc.

Try using the host/after_build event which should fire when a host goes
into build mode. There's also host/before_provision which should fire
when a host completes its build (the wget command at the end of a
kickstart/finish script), but may also happen when cancel build is
clicked - I haven't tested.

We should add events into Foreman core for similar events if you have
any ideas (or that doesn't work as intended), do let us know. I'd like
to do one for when the host requests its provision/kickstart file, which
is similar to what Greg does in his IRC notifications plugin.

··· On 17/04/13 09:50, Marc Grimme wrote: > Hello Dominic?, > I'm still playing with you foreman_hooks plugin trying to figure out > which events I should listen to cancelBuild or Build (setBuild) is being > pressed. > > So far I could only succeed with registering to the host/update event. > Is this the right event to being triggered when pressing those buttons? > > On the other hand it looks like those events are only triggered once. > When I press cancleBuild/Build a second time no new event is triggered. > > Am I doing something wrong or is this a bug or a works as designed?


Dominic Cleal
Red Hat Engineering

Hi Dominic,
finally I can provide some input on the latest version of the foreman_hooks.
First and foremost thanks for you help (on IRC).

Now the events get triggered - as far as I can judge - as expected.
When I create a machine a "create" event is triggered when I cancelBuild a
"update" and "before_provision". With setBuild a "update" and "after_build".

Nevertheless there are - in my point of view - some things that should be
noted.

When a script fails all the other hooks get called nevertheless. This
should be noted somehow.

When a script fails (at least when hitting cancleBuild or setBuild) an
error code 500 is caused that leaves a nice backtrace in my webbrowser. I
think this should be dealt with in the foreman webui. For error messages
look here http://paste.fedoraproject.org/7938/31242913/.

Last but not least if my script does not listen to stdin a exception is
thrown. Looks like this happens only at the first script.
I need to look into this in more detail.

Hope this info helps.

Regards Marc.

··· On Wednesday, April 17, 2013 10:50:40 AM UTC+2, Marc Grimme wrote: > > Hello Dominic?, > I'm still playing with you foreman_hooks plugin trying to figure out which > events I should listen to cancelBuild or Build (setBuild) is being pressed. > > So far I could only succeed with registering to the host/update event. Is > this the right event to being triggered when pressing those buttons? > > On the other hand it looks like those events are only triggered once. When > I press cancleBuild/Build a second time no new event is triggered. > > Am I doing something wrong or is this a bug or a works as designed? > > Thanks for your help > Marc. >

So I was able to fix it myself.
I updated my develop Branch to develop HEAD and now everything works fine.

This means with foreman 1.1 stable it might not work.

Just to let you know.
Regards Marc.

··· On Wednesday, April 17, 2013 11:14:58 AM UTC+2, Dominic Cleal wrote: > > On 17/04/13 09:50, Marc Grimme wrote: > > Hello Dominic?, > > I'm still playing with you foreman_hooks plugin trying to figure out > > which events I should listen to cancelBuild or Build (setBuild) is being > > pressed. > > > > So far I could only succeed with registering to the host/update event. > > Is this the right event to being triggered when pressing those buttons? > > > > On the other hand it looks like those events are only triggered once. > > When I press cancleBuild/Build a second time no new event is triggered. > > > > Am I doing something wrong or is this a bug or a works as designed? > > Try using the host/after_build event which should fire when a host goes > into build mode. There's also host/before_provision which should fire > when a host completes its build (the wget command at the end of a > kickstart/finish script), but may also happen when cancel build is > clicked - I haven't tested. > > We should add events into Foreman core for similar events if you have > any ideas (or that doesn't work as intended), do let us know. I'd like > to do one for when the host requests its provision/kickstart file, which > is similar to what Greg does in his IRC notifications plugin. > > -- > Dominic Cleal > Red Hat Engineering >

Was that with host/update, or after_build/before_provision?

··· On 17/04/13 10:27, Marc Grimme wrote: > So I was able to fix it myself. > I updated my develop Branch to develop HEAD and now everything works fine. > > This means with foreman 1.1 stable it might not work. > > Just to let you know.


Dominic Cleal
Red Hat Engineering

I listen to all events and (sym-)linking the scripts in order to get a
feeling about which event is called when.
So right now the following log message occurs (when either pressing
cancelBuild or Build):

··· * * *Mi 17. Apr 11:21:32 CEST 2013: received update on mg-vmware-test3.qa.atix* *Data foreman_hooks.xCvPSCXw5N: * *{"host":{"architecture_id":1,"build":true, ...* * * *Mi 17. Apr 11:25:51 CEST 2013: received update on mg-vmware-test3.qa.atix* *Data foreman_hooks.Gl7mYkJbxW: * *{"host":{"architecture_id":1,"build":false,..*

Based on the log.sh example you provided inside the foreman_hooks plugin.
I think only the “update” event is triggered.

Perhaps I got something wrong with the directories currently I have a
directory called:
after_build and before_provision inside the config/hooks/host/manage path.
Looks as follows:
*marc@mobilix-20:/data/home/marc/src/foreman/config/hooks/host/managed$ ls
-l **
after_build:
total 4
-rwxr-xr-x 1 marc users 32 Apr 9 17:35 01-echo-test.sh
lrwxrwxrwx 1 marc users 19 Apr 16 17:15 01-log.sh -> …/update/01-log.sh
lrwxrwxrwx 1 marc users 28 Apr 8 13:02 10-echo-test.sh ->
…/provision/10-echo-test.sh

lrwxrwxrwx 1 marc users 29 Apr 8 13:02 10-error-test.sh ->
…/provision/10-error-test.sh

lrwxrwxrwx 1 marc users 26 Apr 16 17:17 hook_functions.sh ->
…/…/…/hook_functions.sh

*
*
before_provision:
total 4
-rwxr-xr-x 1 marc users 32 Apr 9 17:35 01-echo-test.sh
lrwxrwxrwx 1 marc users 19 Apr 16 17:15 01-log.sh -> …/update/01-log.sh
lrwxrwxrwx 1 marc users 28 Apr 8 13:02 10-echo-test.sh ->
…/provision/10-echo-test.sh

lrwxrwxrwx 1 marc users 29 Apr 8 13:02 10-error-test.sh ->
…/provision/10-error-test.sh

lrwxrwxrwx 1 marc users 26 Apr 16 17:17 hook_functions.sh ->
…/…/…/hook_functions.sh

*
*
create:
total 4
-rwxr-xr-x 1 marc users 32 Apr 9 17:34 01-echo-test.sh
lrwxrwxrwx 1 marc users 19 Apr 16 17:15 01-log.sh -> …/update/01-log.sh
lrwxrwxrwx 1 marc users 28 Apr 8 11:44 10-echo-test.sh ->
…/provision/10-echo-test.sh

lrwxrwxrwx 1 marc users 29 Apr 8 11:43 10-error-test.sh ->
…/provision/10-error-test.sh

lrwxrwxrwx 1 marc users 26 Apr 16 17:17 hook_functions.sh ->
…/…/…/hook_functions.sh

*
*
destroy:
total 4
-rwxr-xr-x 1 marc users 32 Apr 9 17:35 01-echo-test.sh
lrwxrwxrwx 1 marc users 19 Apr 16 17:15 01-log.sh -> …/update/01-log.sh
lrwxrwxrwx 1 marc users 28 Apr 8 11:44 10-echo-test.sh ->
…/provision/10-echo-test.sh

lrwxrwxrwx 1 marc users 29 Apr 8 11:44 10-error-test.sh ->
…/provision/10-error-test.sh

lrwxrwxrwx 1 marc users 26 Apr 16 17:17 hook_functions.sh ->
…/…/…/hook_functions.sh

*
*
provision:
total 12
-rwxr-xr-x 1 marc users 32 Apr 9 17:35 01-echo-test.sh
lrwxrwxrwx 1 marc users 19 Apr 16 17:15 01-log.sh -> …/update/01-log.sh
-rwxr-xr-x 1 marc users 33 Apr 8 10:56 10-echo-test.sh
-rwxr-xr-x 1 marc users 47 Apr 8 11:51 10-error-test.sh
lrwxrwxrwx 1 marc users 26 Apr 16 17:17 hook_functions.sh ->
…/…/…/hook_functions.sh

*
*
update:
total 12
-rwxr-xr-x 1 marc users 71 Apr 17 10:39 01-echo-test.sh
-rwxr-xr-x 1 marc users 683 Apr 17 11:25 01-log.sh
*lrwxrwxrwx 1 marc users 26 Apr 16 17:15 hook_functions.sh ->
…/…/…/hook_functions.sh
*

Anything wrong with this layout?

Regards Marc.

On Wednesday, April 17, 2013 11:28:30 AM UTC+2, Dominic Cleal wrote:

On 17/04/13 10:27, Marc Grimme wrote:

So I was able to fix it myself.
I updated my develop Branch to develop HEAD and now everything works
fine.

This means with foreman 1.1 stable it might not work.

Just to let you know.

Was that with host/update, or after_build/before_provision?


Dominic Cleal
Red Hat Engineering

> I listen to all events and (sym-)linking the scripts in order to get a
> feeling about which event is called when.
> So right now the following log message occurs (when either pressing
> cancelBuild or Build):
> /
> /
> /Mi 17. Apr 11:21:32 CEST 2013: received update on mg-vmware-test3.qa.atix/
> /Data foreman_hooks.xCvPSCXw5N: /
> /{"host":{"architecture_id":1,"build":true, …/
> /
> /
> /Mi 17. Apr 11:25:51 CEST 2013: received update on mg-vmware-test3.qa.atix/
> /Data foreman_hooks.Gl7mYkJbxW: /
> /{"host":{"architecture_id":1,"build":false,…/
>
> Based on the log.sh example you provided inside the foreman_hooks plugin.
> I think only the "update" event is triggered.

Thanks very much for spotting this. I hadn't actually tried hooking
these events, just assumed they would work as the other callbacks did.
Clearly that was a mistake!

I've had to rework how I hook these, as using ActiveRecord::Observer is
no good for these ActiveSupport::Callbacks events. I've pushed a new
version to my repo, but haven't released it yet. If you're able to test
that it works for you too first, I'd appreciate it.

> Perhaps I got something wrong with the directories currently I have a
> directory called:
> after_build and before_provision inside the config/hooks/host/manage path.
> Looks as follows:

That all looks good, it matches what I test with. I need to work out
how to write automated tests for it.

··· On 17/04/13 10:41, Marc Grimme wrote:


Dominic Cleal
Red Hat Engineering