Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Classes & Logic

6 views
Skip to first unread message

Achaemenes

unread,
Dec 7, 2009, 7:18:38 AM12/7/09
to
Hi,

This took some troubleshooting to decipher, and so I'd like to know if
others have come across this problem I've run into...

In the following bundle, I would like some output to tell the user if
a packages has just been installed (not if it was already installed).

In the following, notice section X, section Y, and section Z.

----

bundle agent InstallPackage(pkg, dpkg) {
#. Preconfigure packages and then install them to avoid
interactivity issues

vars:
"Script_$(pkg)" string => "${cf3.path[sbin]}/preConfigure_$
(pkg)";
"dpkgIsInstalled" string => "${cf3.path[sbin]}/
dpkgIsInstalled";

classes:
#"PreConfigure_${pkg}" expression => fileexists("${Script_$
{pkg}}");
#"CanConfigure" expression => classmatch("PreConfigure_$
{pkg}");
"Can_Configure" expression => fileexists("${Script_${pkg}}");
"Must_Configure" not => regcmp("NotApplicable", "$
{pkg}");
"Is_Installed" expression => returnszero("${dpkgIsInstalled}
${dpkg}", "noshell");

# == Section Y Start ==
"aaa" not => "Is_Installed";
"bbb" not => "Must_Configure";
"ccc" or => { "Was_Configured", "bbb" };
"Was_Installed" and => { "aaa", "ccc" };
# == Section Y Finish ==
# == Section Y' Start ==
# "Was_Installed" and => {
# not => "Is_Installed",
# or => {
# "Was_Configured",
# not => "Must_Configure"
# }
# }
# == Section Y' Finish ==

commands:
!Is_Installed&Must_Configure&Can_Configure::
"${Script_${pkg}}"
module => "true",
classes => DefineSoftClass("Was_Configured")
;

packages:
!Is_Installed&(Was_Configured|!Must_Configure)::
"$(dpkg)"
package_policy => "add",
package_method => "AptGet"
# == Section X Start ==
#classes => DefineSoftClass("Was_Installed")
# == Section X Finish ==
;

reports:
#. PreConfiguration...
Was_Configured::
"${ansi.green}Debian:Package:PreConfigured:$(pkg)@$(dpkg)$
{ansi.reset}";

#. Installation...
Was_Installed&Must_Configure&!Can_Configure::
"${ansi.red}Debian:Package:PreConfigureImpossible:$(pkg)@$
(dpkg)${ansi.reset}";
!Was_Installed&!Is_Installed&!Must_Configure&!Was_Configured::
"${ansi.red}Debian:Package:InstallationFailed:$(pkg)@$
(dpkg)${ansi.reset}";
!Was_Installed&Is_Installed::
"${ansi.gray_dark}Debian:Package:InstalledAlready:$(pkg)@$
(dpkg)${ansi.reset}";

# == Section Z Start ==
Was_Installed.Is_Installed::
"${ansi.green}Debian:Package:Installed:$(pkg)@$(dpkg)$
{ansi.reset}";
# == Section Z Finish ==
}

----

The problem: When section X was not commented (original version of the
now fixed cf3 code) - As soon as *any* package was installed, the
class Was_Installed was set, and never unset, so every single package,
installed or not, printed "Debian:Package:Installed:...".

To fix this, I removed section X, and replaced it with the ugly
section Y. Now it at least re-evaluates Was_Installed once per
package, and not once globally per run of cf-agent.

So my questions are:
1. Can someone explain why section X is only evaluated once per cf-
agent run, and not once per package?
2. Section Y is disgusting, section Y' is better, but is invalid
syntax - So is there a better way to do this?

Achaemenes

unread,
Dec 7, 2009, 7:45:06 AM12/7/09
to

Oh, and In case you're curious...

body classes DefineSoftClass(c) {
promise_repaired => { "$
(c)" };
promise_kept => { "$(c)
_Kept" };
repair_failed => { "$(c)_Failed", "Warning" };
repair_denied => { "$(c)_Failed", "$(c)_Denied", "Warning" };
repair_timeout => { "$(c)_Failed", "$(c)_Timeout", "Warning" };
}

cf3 version: 3.0.2

0 new messages