From 242ce6dfd2d9874ef1f8c092d6d209d2069bba24 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 8 Feb 2012 22:16:09 +0100 Subject: [PATCH 01/37] first round of absent/present changes Signed-off-by: Nico Schottelius --- conf/type/__package/man.text | 29 ++++++++++++------------ conf/type/__package_apt/man.text | 9 ++++---- conf/type/__package_luarocks/man.text | 7 +++--- conf/type/__package_pacman/man.text | 7 +++--- conf/type/__package_pip/man.text | 4 ++-- conf/type/__package_pkg_openbsd/man.text | 7 +++--- conf/type/__package_rubygem/man.text | 5 ++-- conf/type/__package_yum/man.text | 5 ++-- 8 files changed, 40 insertions(+), 33 deletions(-) diff --git a/conf/type/__package/man.text b/conf/type/__package/man.text index d0460a31..071a8bfb 100644 --- a/conf/type/__package/man.text +++ b/conf/type/__package/man.text @@ -1,5 +1,5 @@ -cdist-type__user(7) -=================== +cdist-type__package(7) +====================== Steven Armstrong @@ -17,22 +17,23 @@ It dispatches the actual work to the package system dependant types. REQUIRED PARAMETERS ------------------- state:: - The state the package should be in, either "installed" or "removed" + The state the package should be in, either "present" or "absent" + (the old values "installed" or "removed" will be removed in cdist 2.1). OPTIONAL PARAMETERS ------------------- name:: - The name of the package to install. Default is to use the object_id as the - package name. + The name of the package to install. Default is to use the object_id as the + package name. version:: - The version of the package to install. Default is to install the version - choosen by the local package manager. + The version of the package to install. Default is to install the version + choosen by the local package manager. type:: - The package type to use. Default is determined based on the $os explorer - variable. - e.g. __package_apt for Debian - __package_emerge for Gentoo + The package type to use. Default is determined based on the $os explorer + variable. + e.g. __package_apt for Debian + __package_emerge for Gentoo EXAMPLES @@ -40,13 +41,13 @@ EXAMPLES -------------------------------------------------------------------------------- # Install the package vim on the target -__package vim --state installed +__package vim --state present # Same but install specific version -__package vim --state installed --version 7.3.50 +__package vim --state present --version 7.3.50 # Force use of a specific package type -__package vim --state installed --type __package_apt +__package vim --state present --type __package_apt -------------------------------------------------------------------------------- diff --git a/conf/type/__package_apt/man.text b/conf/type/__package_apt/man.text index 905bfb5f..fd9c1a9c 100644 --- a/conf/type/__package_apt/man.text +++ b/conf/type/__package_apt/man.text @@ -17,7 +17,8 @@ manage packages. REQUIRED PARAMETERS ------------------- state:: - Either "installed" or "removed". + The state the package should be in, either "present" or "absent" + (the old values "installed" or "removed" will be removed in cdist 2.1). OPTIONAL PARAMETERS @@ -31,13 +32,13 @@ EXAMPLES -------------------------------------------------------------------------------- # Ensure zsh in installed -__package_apt zsh --state installed +__package_apt zsh --state present # In case you only want *a* webserver, but don't care which one -__package_apt webserver --state installed --name nginx +__package_apt webserver --state present --name nginx # Remove obsolete package -__package_apt puppet --state removed +__package_apt puppet --state absent -------------------------------------------------------------------------------- diff --git a/conf/type/__package_luarocks/man.text b/conf/type/__package_luarocks/man.text index 6c1e6734..4f68875a 100644 --- a/conf/type/__package_luarocks/man.text +++ b/conf/type/__package_luarocks/man.text @@ -1,5 +1,5 @@ cdist-type__package_luarocks(7) -============================== +=============================== Christian G. Warden @@ -16,13 +16,14 @@ LuaRocks is a deployment and management system for Lua modules. REQUIRED PARAMETERS ------------------- state:: - Either "installed" or "removed". + The state the package should be in, either "present" or "absent" + (the old values "installed" or "removed" will be removed in cdist 2.1). OPTIONAL PARAMETERS ------------------- name:: - If supplied, use the name and not the object id as the package name. + If supplied, use the name and not the object id as the package name. EXAMPLES diff --git a/conf/type/__package_pacman/man.text b/conf/type/__package_pacman/man.text index 28766581..52fa05c4 100644 --- a/conf/type/__package_pacman/man.text +++ b/conf/type/__package_pacman/man.text @@ -17,13 +17,14 @@ packages. REQUIRED PARAMETERS ------------------- state:: - Either "installed" or "removed". + The state the package should be in, either "present" or "absent" + (the old values "installed" or "removed" will be removed in cdist 2.1). OPTIONAL PARAMETERS ------------------- name:: - If supplied, use the name and not the object id as the package name. + If supplied, use the name and not the object id as the package name. EXAMPLES @@ -49,5 +50,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2011 Nico Schottelius. Free use of this software is +Copyright \(C) 2011-2012 Nico Schottelius. Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__package_pip/man.text b/conf/type/__package_pip/man.text index 1822ffca..bc773763 100644 --- a/conf/type/__package_pip/man.text +++ b/conf/type/__package_pip/man.text @@ -23,10 +23,10 @@ state:: OPTIONAL PARAMETERS ------------------- name:: - If supplied, use the name and not the object id as the package name. + If supplied, use the name and not the object id as the package name. pip:: - Instead of using pip from PATH, use the specific pip path. + Instead of using pip from PATH, use the specific pip path. EXAMPLES diff --git a/conf/type/__package_pkg_openbsd/man.text b/conf/type/__package_pkg_openbsd/man.text index 555bb0ac..0f594b96 100644 --- a/conf/type/__package_pkg_openbsd/man.text +++ b/conf/type/__package_pkg_openbsd/man.text @@ -16,16 +16,17 @@ This type is usually used on OpenBSD to manage packages. REQUIRED PARAMETERS ------------------- state:: - Either "installed" or "removed". + The state the package should be in, either "present" or "absent" + (the old values "installed" or "removed" will be removed in cdist 2.1). OPTIONAL PARAMETERS ------------------- name:: - If supplied, use the name and not the object id as the package name. + If supplied, use the name and not the object id as the package name. flavor:: - If supplied, use to avoid ambiguity. + If supplied, use to avoid ambiguity. EXAMPLES diff --git a/conf/type/__package_rubygem/man.text b/conf/type/__package_rubygem/man.text index c6248ee3..6db8f42b 100644 --- a/conf/type/__package_rubygem/man.text +++ b/conf/type/__package_rubygem/man.text @@ -16,13 +16,14 @@ Rubygems is the default package management system for the Ruby programming langu REQUIRED PARAMETERS ------------------- state:: - Either "installed" or "removed". + The state the package should be in, either "present" or "absent" + (the old values "installed" or "removed" will be removed in cdist 2.1). OPTIONAL PARAMETERS ------------------- name:: - If supplied, use the name and not the object id as the package name. + If supplied, use the name and not the object id as the package name. EXAMPLES diff --git a/conf/type/__package_yum/man.text b/conf/type/__package_yum/man.text index c9cad340..d90a2af7 100644 --- a/conf/type/__package_yum/man.text +++ b/conf/type/__package_yum/man.text @@ -18,13 +18,14 @@ slightly confusing error message "Error: Nothing to do". REQUIRED PARAMETERS ------------------- state:: - Either "installed" or "removed". + The state the package should be in, either "present" or "absent" + (the old values "installed" or "removed" will be removed in cdist 2.1). OPTIONAL PARAMETERS ------------------- name:: - If supplied, use the name and not the object id as the package name. + If supplied, use the name and not the object id as the package name. EXAMPLES From 2aed047f7565cc22512dbc61ab3d42c8ad15eb57 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 8 Feb 2012 22:23:31 +0100 Subject: [PATCH 02/37] 2nd correction round for manpages Signed-off-by: Nico Schottelius --- conf/type/__package_luarocks/man.text | 4 ++-- conf/type/__package_pacman/man.text | 6 +++--- conf/type/__package_pkg_openbsd/man.text | 8 ++++---- conf/type/__package_rubygem/man.text | 4 ++-- conf/type/__package_yum/man.text | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/conf/type/__package_luarocks/man.text b/conf/type/__package_luarocks/man.text index 4f68875a..8b041b7c 100644 --- a/conf/type/__package_luarocks/man.text +++ b/conf/type/__package_luarocks/man.text @@ -31,10 +31,10 @@ EXAMPLES -------------------------------------------------------------------------------- # Ensure luasocket is installed -__package_luarocks luasocket --state installed +__package_luarocks luasocket --state present # Remove package -__package_luarocks luasocket --state removed +__package_luarocks luasocket --state absent -------------------------------------------------------------------------------- diff --git a/conf/type/__package_pacman/man.text b/conf/type/__package_pacman/man.text index 52fa05c4..fe2abac8 100644 --- a/conf/type/__package_pacman/man.text +++ b/conf/type/__package_pacman/man.text @@ -32,13 +32,13 @@ EXAMPLES -------------------------------------------------------------------------------- # Ensure zsh in installed -__package_pacman zsh --state installed +__package_pacman zsh --state present # If you don't want to follow pythonX packages, but always use python -__package_pacman python --state installed --name python2 +__package_pacman python --state present --name python2 # Remove obsolete package -__package_pacman puppet --state removed +__package_pacman puppet --state absent -------------------------------------------------------------------------------- diff --git a/conf/type/__package_pkg_openbsd/man.text b/conf/type/__package_pkg_openbsd/man.text index 0f594b96..71cf9d4e 100644 --- a/conf/type/__package_pkg_openbsd/man.text +++ b/conf/type/__package_pkg_openbsd/man.text @@ -34,16 +34,16 @@ EXAMPLES -------------------------------------------------------------------------------- # Ensure zsh is installed -__package_pkg_openbsd zsh --state installed +__package_pkg_openbsd zsh --state present # Ensure vim is installed, use flavor no_x11 -__package_pkg_openbsd vim --state installed --flavor no_x11 +__package_pkg_openbsd vim --state present --flavor no_x11 # If you don't want to follow pythonX packages, but always use python -__package_pkg_openbsd python --state installed --name python2 +__package_pkg_openbsd python --state present --name python2 # Remove obsolete package -__package_pkg_openbsd puppet --state removed +__package_pkg_openbsd puppet --state absent -------------------------------------------------------------------------------- diff --git a/conf/type/__package_rubygem/man.text b/conf/type/__package_rubygem/man.text index 6db8f42b..79bb8b52 100644 --- a/conf/type/__package_rubygem/man.text +++ b/conf/type/__package_rubygem/man.text @@ -31,10 +31,10 @@ EXAMPLES -------------------------------------------------------------------------------- # Ensure sinatra is installed -__package_rubygem sinatra --state installed +__package_rubygem sinatra --state present # Remove package -__package_rubygem rails --state removed +__package_rubygem rails --state absent -------------------------------------------------------------------------------- diff --git a/conf/type/__package_yum/man.text b/conf/type/__package_yum/man.text index d90a2af7..9dfb394e 100644 --- a/conf/type/__package_yum/man.text +++ b/conf/type/__package_yum/man.text @@ -33,13 +33,13 @@ EXAMPLES -------------------------------------------------------------------------------- # Ensure zsh in installed -__package_yum zsh --state installed +__package_yum zsh --state present # If you don't want to follow pythonX packages, but always use python -__package_yum python --state installed --name python2 +__package_yum python --state present --name python2 # Remove obsolete package -__package_yum puppet --state removed +__package_yum puppet --state absent -------------------------------------------------------------------------------- From 602e57455db6f09d48bc2f578d89fb13b7cb0d6b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 8 Feb 2012 22:23:49 +0100 Subject: [PATCH 03/37] support absent/present in __package_apt Signed-off-by: Nico Schottelius --- conf/type/__package_apt/explorer/pkg_status | 8 ++++---- conf/type/__package_apt/gencode-remote | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/conf/type/__package_apt/explorer/pkg_status b/conf/type/__package_apt/explorer/pkg_status index dbb3af3e..04926b60 100755 --- a/conf/type/__package_apt/explorer/pkg_status +++ b/conf/type/__package_apt/explorer/pkg_status @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -28,11 +28,11 @@ else fi # Except dpkg failing, if package is not known / installed -packages="$(apt-cache showpkg "$name" | sed -e "1,/Reverse Provides:/d" | cut -d ' ' -f 1) $name" +packages="$(apt-cache showpkg "$name" | sed -e "1,/Reverse Provides:/d" | cut -d ' ' -f 1) $name" for p in $packages; do if [ -n "$(dpkg -s "$p" 2>/dev/null | grep "^Status: install ok installed$")" ]; then - echo "installed $p" + echo "present $p" exit 0 fi done -echo "removed" +echo absent diff --git a/conf/type/__package_apt/gencode-remote b/conf/type/__package_apt/gencode-remote index 594ab8cb..da58ca1b 100755 --- a/conf/type/__package_apt/gencode-remote +++ b/conf/type/__package_apt/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -28,11 +28,18 @@ else fi state_should="$(cat "$__object/parameter/state")" + +# Correct pre 2.1 naming - FIXME in 2.1 +case "$state_should" in + installed) state_should="present" ;; + removed) state_should="absent" ;; +esac + state_is="$(cat "$__object/explorer/pkg_status")" case "$state_is" in - installed*) + present*) name="$(echo "$state_is" | cut -d ' ' -f 2)" - state_is="installed" + state_is="present" ;; esac @@ -40,10 +47,10 @@ aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes" if [ "$state_is" != "$state_should" ]; then case "$state_should" in - installed) + present) echo $aptget install \"$name\" ;; - removed) + absent) echo $aptget remove \"$name\" ;; *) @@ -52,4 +59,3 @@ if [ "$state_is" != "$state_should" ]; then ;; esac fi - From 8e5a0f83c5c7b5f42539fe44c0f02f503a409171 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 9 Feb 2012 10:10:13 +0100 Subject: [PATCH 04/37] rename explorer to state, being more consistent internally Signed-off-by: Nico Schottelius --- conf/type/__package_apt/explorer/{pkg_status => state} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename conf/type/__package_apt/explorer/{pkg_status => state} (100%) diff --git a/conf/type/__package_apt/explorer/pkg_status b/conf/type/__package_apt/explorer/state similarity index 100% rename from conf/type/__package_apt/explorer/pkg_status rename to conf/type/__package_apt/explorer/state From 52849b91c581ede9f57e9549fbda4bcfbe5fcea2 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 9 Feb 2012 10:25:05 +0100 Subject: [PATCH 05/37] warn about deprecated usage Signed-off-by: Nico Schottelius --- conf/type/__package_apt/gencode-remote | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/conf/type/__package_apt/gencode-remote b/conf/type/__package_apt/gencode-remote index da58ca1b..32049a27 100755 --- a/conf/type/__package_apt/gencode-remote +++ b/conf/type/__package_apt/gencode-remote @@ -31,11 +31,19 @@ state_should="$(cat "$__object/parameter/state")" # Correct pre 2.1 naming - FIXME in 2.1 case "$state_should" in - installed) state_should="present" ;; - removed) state_should="absent" ;; + # FIXME: print warning to stderr! + installed) + echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 + state_should="present" + ;; + removed) + echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 + state_should="absent" + ;; esac -state_is="$(cat "$__object/explorer/pkg_status")" +# FIXME: use grep directly, state is a list, not a line! +state_is="$(cat "$__object/explorer/state")" case "$state_is" in present*) name="$(echo "$state_is" | cut -d ' ' -f 2)" From 3c19e7ab4c937bd6452d1f8a777288ab31163a47 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 9 Feb 2012 11:54:13 +0100 Subject: [PATCH 06/37] update __package_pacman for absent/present Signed-off-by: Nico Schottelius --- .../__package_pacman/explorer/pkg_version | 4 +-- conf/type/__package_pacman/gencode-remote | 33 +++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/conf/type/__package_pacman/explorer/pkg_version b/conf/type/__package_pacman/explorer/pkg_version index 4f612423..c33820f8 100755 --- a/conf/type/__package_pacman/explorer/pkg_version +++ b/conf/type/__package_pacman/explorer/pkg_version @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -18,7 +18,7 @@ # along with cdist. If not, see . # # -# Retrieve the status of a package - parsed dpkg output +# Retrieve the status of a package - parsed pacman output # if [ -f "$__object/parameter/name" ]; then diff --git a/conf/type/__package_pacman/gencode-remote b/conf/type/__package_pacman/gencode-remote index 3c4fdda7..1516370c 100755 --- a/conf/type/__package_pacman/gencode-remote +++ b/conf/type/__package_pacman/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -33,21 +33,34 @@ else name="$__object_id" fi -state="$(cat "$__object/parameter/state")" +state_should="$(cat "$__object/parameter/state")" +case "$state_should" in + installed) + echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 + state_should="present" + ;; + removed) + echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 + state_should="absent" + ;; +esac + pkg_version="$(cat "$__object/explorer/pkg_version")" +if [ -z "$pkg_version" ]; then + state_is="absent" +else + state_is="present" +fi -case "$state" in - installed) +# Exit if nothing is needed to be done +[ "$state_is" = "$state_should ] && exit 0 - # Empty? Not installed. - if [ -z "$pkg_version" ]; then +case "$state_should" in + present) echo pacman "$pacopts" -S \"$name\" - fi ;; - removed) - if [ "$pkg_version" ]; then + absent) echo pacman "$pacopts" -R \"$name\" - fi ;; *) echo "Unknown state: $state" >&2 From 1713a70428427b8d33a7c223cfed8943f8332e78 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 9 Feb 2012 19:06:13 +0100 Subject: [PATCH 07/37] begin changes to __package_luarocks and __package_pkg_openbsd Signed-off-by: Nico Schottelius --- conf/type/__package_apt/gencode-remote | 1 - conf/type/__package_luarocks/gencode-remote | 2 +- .../type/__package_pkg_openbsd/gencode-remote | 73 ++++++++++++------- 3 files changed, 46 insertions(+), 30 deletions(-) diff --git a/conf/type/__package_apt/gencode-remote b/conf/type/__package_apt/gencode-remote index 32049a27..47e76ec8 100755 --- a/conf/type/__package_apt/gencode-remote +++ b/conf/type/__package_apt/gencode-remote @@ -31,7 +31,6 @@ state_should="$(cat "$__object/parameter/state")" # Correct pre 2.1 naming - FIXME in 2.1 case "$state_should" in - # FIXME: print warning to stderr! installed) echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 state_should="present" diff --git a/conf/type/__package_luarocks/gencode-remote b/conf/type/__package_luarocks/gencode-remote index 179022b1..29fd7e38 100755 --- a/conf/type/__package_luarocks/gencode-remote +++ b/conf/type/__package_luarocks/gencode-remote @@ -29,7 +29,7 @@ else name="$__object_id" fi -state="$(cat "$__object/parameter/state")" +state_should="$(cat "$__object/parameter/state")" is_installed="$(grep "(installed)" "$__object/explorer/pkg_status" || true)" case "$state" in diff --git a/conf/type/__package_pkg_openbsd/gencode-remote b/conf/type/__package_pkg_openbsd/gencode-remote index eee2a3d9..e8309f20 100755 --- a/conf/type/__package_pkg_openbsd/gencode-remote +++ b/conf/type/__package_pkg_openbsd/gencode-remote @@ -1,6 +1,7 @@ #!/bin/sh # # 2011 Andi Brönnimann (andi-cdist at v-net.ch) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -42,44 +43,60 @@ else name="$__object_id" fi -state="$(cat "$__object/parameter/state")" +state_should="$(cat "$__object/parameter/state")" +# Correct pre 2.1 naming - FIXME in 2.1 +case "$state_should" in + installed) + echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 + state_should="present" + ;; + removed) + echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 + state_should="absent" + ;; +esac + pkg_version="$(cat "$__object/explorer/pkg_version")" # TODO: Shouldn't be hardcoded echo export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/$os_version/packages/$machine/ -case "$state" in - installed) - # Empty? Not installed. - if [ -z "$pkg_version" ]; then - # use this because pkg_add doesn't properly handle errors - cat << eof - status=\$(pkg_add "$pkgopts" "$name--$flavor") +if [ "$pkg_version" ]; then + state_is="present" +else + state_is="absent" +fi - # no error - if [ -n "\$status" ]; then - echo "Error: \$status" - exit 1 - fi -eof - fi - ;; - removed) - if [ "$pkg_version" ]; then - # use this because pkg_add doesn't properly handle errors - cat << eof - status=\$(pkg_delete "$pkgopts" "$name--$flavor") +[ "$state_is" = "$state_should" ] && exit 0 - # no error - if [ -n "\$status" ]; then - echo "Error: \$status" - exit 1 - fi +case "$state_should" in + present) + # use this because pkg_add doesn't properly handle errors + cat << eof +status=\$(pkg_add "$pkgopts" "$name--$flavor") + +# no error +if [ -n "\$status" ]; then + echo "Error: \$status" + exit 1 +fi +eof + ;; + + absent) + # use this because pkg_add doesn't properly handle errors + cat << eof +status=\$(pkg_delete "$pkgopts" "$name--$flavor") + +# no error +if [ -n "\$status" ]; then + echo "Error: \$status" + exit 1 +fi eof - fi ;; *) - echo "Unknown state: $state" >&2 + echo "Unknown state: $state_should" >&2 exit 1 ;; esac From ad4aa19c3e54d16096dca9555e3398a9ce941522 Mon Sep 17 00:00:00 2001 From: Benedikt Koeppel Date: Sun, 12 Feb 2012 15:08:34 +0100 Subject: [PATCH 08/37] new type __run_command This cdist type allows you to run a specific command once at installation time. optional parameter: --command Command (with arguments) to run. --- conf/type/__run_command/gencode-remote | 26 ++++++++ conf/type/__run_command/man.text | 70 ++++++++++++++++++++++ conf/type/__run_command/parameter/optional | 1 + conf/type/__run_command/parameter/required | 0 4 files changed, 97 insertions(+) create mode 100755 conf/type/__run_command/gencode-remote create mode 100644 conf/type/__run_command/man.text create mode 100644 conf/type/__run_command/parameter/optional create mode 100644 conf/type/__run_command/parameter/required diff --git a/conf/type/__run_command/gencode-remote b/conf/type/__run_command/gencode-remote new file mode 100755 index 00000000..7ffd9a7b --- /dev/null +++ b/conf/type/__run_command/gencode-remote @@ -0,0 +1,26 @@ +#!/bin/sh +# +# 2012 Benedikt Koeppel (code at benediktkoeppel.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# + +if [ -f "$__object/parameter/command" ]; then + cat "$__object/parameter/command" +else + echo "$name" +fi diff --git a/conf/type/__run_command/man.text b/conf/type/__run_command/man.text new file mode 100644 index 00000000..5ea553c3 --- /dev/null +++ b/conf/type/__run_command/man.text @@ -0,0 +1,70 @@ +cdist-type__run_command(7) +========================== +Benedikt Koeppel + + +NAME +---- +cdist-type__run_command - Run a command + + +DESCRIPTION +----------- +This cdist type allows you to run a specific command once at installation time. + + +REQUIRED PARAMETERS +------------------- + + +OPTIONAL PARAMETERS +------------------- +command:: + Command (with arguments) to run. + + If no command is give, then the object_id is executed. + + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Run a command +__run_command "/etc/init.d/mysql restart" +# runs `/etc/init.d/mysql restart` (the "object_id") + +# Run the same command: +__run_command restart-mysql --command "/etc/init.d/mysql restart" +# runs `/etc/init.d/mysql restart` (the --command argument) +# additionally, it can easily be referenced (for example in a require="..." +#as __run_command/restart-mysql + +# Run a script: +__run_command install-pear --command "$(cat <<-EOF + /usr/bin/pear install --force Auth + /usr/bin/pear install --force HTML_Template_IT-1.2.1 + /usr/bin/pear install --force MDB2 + /usr/bin/pear install --force MDB2#mysql + /usr/bin/pear config-set preferred_state beta; + /usr/bin/pear install --force --alldeps Spreadsheet_Excel_Writer; + /usr/bin/pear config-set preferred_state stable + /usr/bin/pear install --force HTTP_Request + /usr/bin/pear install --force Mail + /usr/bin/pear install --force Auth_HTTP + /usr/bin/pear install --force XML_RPC +EOF +)" + +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2012 Benedikt Koeppel. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__run_command/parameter/optional b/conf/type/__run_command/parameter/optional new file mode 100644 index 00000000..aa56d324 --- /dev/null +++ b/conf/type/__run_command/parameter/optional @@ -0,0 +1 @@ +command diff --git a/conf/type/__run_command/parameter/required b/conf/type/__run_command/parameter/required new file mode 100644 index 00000000..e69de29b From 362bdcdbdddcc013e66d79877c38549f5dc1b8de Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 15 Feb 2012 13:57:45 +0100 Subject: [PATCH 09/37] implement boolean parameters Signed-off-by: Steven Armstrong --- .../fixtures/conf/type/__arguments_boolean/parameter/boolean | 2 ++ .../fixtures/conf/type/__arguments_optional/parameter/optional | 1 + .../fixtures/conf/type/__arguments_required/parameter/required | 2 ++ .../type/fixtures/__with_boolean_parameters/parameter/boolean | 2 ++ lib/cdist/test/type/fixtures/__without_boolean_parameters/.keep | 0 5 files changed, 7 insertions(+) create mode 100644 lib/cdist/test/emulator/fixtures/conf/type/__arguments_boolean/parameter/boolean create mode 100644 lib/cdist/test/emulator/fixtures/conf/type/__arguments_optional/parameter/optional create mode 100644 lib/cdist/test/emulator/fixtures/conf/type/__arguments_required/parameter/required create mode 100644 lib/cdist/test/type/fixtures/__with_boolean_parameters/parameter/boolean create mode 100644 lib/cdist/test/type/fixtures/__without_boolean_parameters/.keep diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__arguments_boolean/parameter/boolean b/lib/cdist/test/emulator/fixtures/conf/type/__arguments_boolean/parameter/boolean new file mode 100644 index 00000000..3215c409 --- /dev/null +++ b/lib/cdist/test/emulator/fixtures/conf/type/__arguments_boolean/parameter/boolean @@ -0,0 +1,2 @@ +boolean1 +boolean2 diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__arguments_optional/parameter/optional b/lib/cdist/test/emulator/fixtures/conf/type/__arguments_optional/parameter/optional new file mode 100644 index 00000000..31647628 --- /dev/null +++ b/lib/cdist/test/emulator/fixtures/conf/type/__arguments_optional/parameter/optional @@ -0,0 +1 @@ +optional1 diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__arguments_required/parameter/required b/lib/cdist/test/emulator/fixtures/conf/type/__arguments_required/parameter/required new file mode 100644 index 00000000..e0fba2c9 --- /dev/null +++ b/lib/cdist/test/emulator/fixtures/conf/type/__arguments_required/parameter/required @@ -0,0 +1,2 @@ +required1 +required2 diff --git a/lib/cdist/test/type/fixtures/__with_boolean_parameters/parameter/boolean b/lib/cdist/test/type/fixtures/__with_boolean_parameters/parameter/boolean new file mode 100644 index 00000000..3215c409 --- /dev/null +++ b/lib/cdist/test/type/fixtures/__with_boolean_parameters/parameter/boolean @@ -0,0 +1,2 @@ +boolean1 +boolean2 diff --git a/lib/cdist/test/type/fixtures/__without_boolean_parameters/.keep b/lib/cdist/test/type/fixtures/__without_boolean_parameters/.keep new file mode 100644 index 00000000..e69de29b From 0760ff3c94edefc815697caae1807ae7894771c0 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 15 Feb 2012 14:44:16 +0100 Subject: [PATCH 10/37] implement boolean parameters, forgotten files ;-) Signed-off-by: Steven Armstrong --- lib/cdist/core/cdist_type.py | 17 +++++++++ lib/cdist/emulator.py | 5 ++- lib/cdist/test/emulator/__init__.py | 58 ++++++++++++++++++++++++++++- lib/cdist/test/type/__init__.py | 11 ++++++ 4 files changed, 89 insertions(+), 2 deletions(-) diff --git a/lib/cdist/core/cdist_type.py b/lib/cdist/core/cdist_type.py index 55609e7e..1d2472c4 100644 --- a/lib/cdist/core/cdist_type.py +++ b/lib/cdist/core/cdist_type.py @@ -82,6 +82,7 @@ class CdistType(object): self.__explorers = None self.__required_parameters = None self.__optional_parameters = None + self.__boolean_parameters = None def __repr__(self): return '' % self.name @@ -144,3 +145,19 @@ class CdistType(object): finally: self.__optional_parameters = parameters return self.__optional_parameters + + @property + def boolean_parameters(self): + """Return a list of boolean parameters""" + if not self.__boolean_parameters: + parameters = [] + try: + with open(os.path.join(self.absolute_path, "parameter", "boolean")) as fd: + for line in fd: + parameters.append(line.strip()) + except EnvironmentError: + # error ignored + pass + finally: + self.__boolean_parameters = parameters + return self.__boolean_parameters diff --git a/lib/cdist/emulator.py b/lib/cdist/emulator.py index 6d6050e8..c4b84feb 100644 --- a/lib/cdist/emulator.py +++ b/lib/cdist/emulator.py @@ -87,7 +87,7 @@ class Emulator(object): def commandline(self): """Parse command line""" - parser = argparse.ArgumentParser(add_help=False) + parser = argparse.ArgumentParser(add_help=False, argument_default=argparse.SUPPRESS) for parameter in self.cdist_type.optional_parameters: argument = "--" + parameter @@ -95,6 +95,9 @@ class Emulator(object): for parameter in self.cdist_type.required_parameters: argument = "--" + parameter parser.add_argument(argument, dest=parameter, action='store', required=True) + for parameter in self.cdist_type.boolean_parameters: + argument = "--" + parameter + parser.add_argument(argument, dest=parameter, action='store_const', const='') # If not singleton support one positional parameter if not self.cdist_type.is_singleton: diff --git a/lib/cdist/test/emulator/__init__.py b/lib/cdist/test/emulator/__init__.py index f1ea5832..370d3d82 100644 --- a/lib/cdist/test/emulator/__init__.py +++ b/lib/cdist/test/emulator/__init__.py @@ -126,7 +126,7 @@ class AutoRequireEmulatorTestCase(test.CdistTestCase): self.assertEqual(sorted(cdist_object.requirements), sorted(expected)) -class ArgumentsWithDashesTestCase(test.CdistTestCase): +class ArgumentsTestCase(test.CdistTestCase): def setUp(self): self.temp_dir = self.mkdtemp() @@ -159,3 +159,59 @@ class ArgumentsWithDashesTestCase(test.CdistTestCase): cdist_type = core.CdistType(self.local.type_path, '__arguments_with_dashes') cdist_object = core.CdistObject(cdist_type, self.local.object_path, 'some-id') self.assertTrue('with-dash' in cdist_object.parameters) + + def test_boolean(self): + type_name = '__arguments_boolean' + object_id = 'some-id' + argv = [type_name, object_id, '--boolean1'] + os.environ.update(self.env) + emu = emulator.Emulator(argv) + emu.run() + + cdist_type = core.CdistType(self.local.type_path, type_name) + cdist_object = core.CdistObject(cdist_type, self.local.object_path, object_id) + self.assertTrue('boolean1' in cdist_object.parameters) + self.assertFalse('boolean2' in cdist_object.parameters) + # empty file -> True + self.assertTrue(cdist_object.parameters['boolean1'] == '') + + def test_required(self): + type_name = '__arguments_required' + object_id = 'some-id' + value = 'some value' + argv = [type_name, object_id, '--required1', value, '--required2', value] + os.environ.update(self.env) + emu = emulator.Emulator(argv) + emu.run() + + cdist_type = core.CdistType(self.local.type_path, type_name) + cdist_object = core.CdistObject(cdist_type, self.local.object_path, object_id) + self.assertTrue('required1' in cdist_object.parameters) + self.assertTrue('required2' in cdist_object.parameters) + self.assertEqual(cdist_object.parameters['required1'], value) + self.assertEqual(cdist_object.parameters['required2'], value) + +# def test_required_missing(self): +# type_name = '__arguments_required' +# object_id = 'some-id' +# value = 'some value' +# argv = [type_name, object_id, '--required1', value] +# os.environ.update(self.env) +# emu = emulator.Emulator(argv) +# +# self.assertRaises(SystemExit, emu.run) + + def test_optional(self): + type_name = '__arguments_optional' + object_id = 'some-id' + value = 'some value' + argv = [type_name, object_id, '--optional1', value] + os.environ.update(self.env) + emu = emulator.Emulator(argv) + emu.run() + + cdist_type = core.CdistType(self.local.type_path, type_name) + cdist_object = core.CdistObject(cdist_type, self.local.object_path, object_id) + self.assertTrue('optional1' in cdist_object.parameters) + self.assertFalse('optional2' in cdist_object.parameters) + self.assertEqual(cdist_object.parameters['optional1'], value) diff --git a/lib/cdist/test/type/__init__.py b/lib/cdist/test/type/__init__.py index 2ef14a4c..5e774aa9 100644 --- a/lib/cdist/test/type/__init__.py +++ b/lib/cdist/test/type/__init__.py @@ -145,3 +145,14 @@ class TypeTestCase(test.CdistTestCase): base_path = fixtures cdist_type = core.CdistType(base_path, '__without_optional_parameters') self.assertEqual(cdist_type.optional_parameters, []) + + def test_with_boolean_parameters(self): + base_path = fixtures + cdist_type = core.CdistType(base_path, '__with_boolean_parameters') + self.assertEqual(cdist_type.boolean_parameters, ['boolean1', 'boolean2']) + + def test_without_boolean_parameters(self): + base_path = fixtures + cdist_type = core.CdistType(base_path, '__without_boolean_parameters') + self.assertEqual(cdist_type.boolean_parameters, []) + From 79dedb5bb52cd856ecef5e12340e2c38a42bf0a0 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 16 Feb 2012 10:17:09 +0100 Subject: [PATCH 11/37] document boolean parameters Signed-off-by: Steven Armstrong --- doc/man/cdist-reference.text.sh | 7 ++++-- doc/man/man7/cdist-type.text | 41 +++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/doc/man/cdist-reference.text.sh b/doc/man/cdist-reference.text.sh index 81e58ab2..a76e7941 100755 --- a/doc/man/cdist-reference.text.sh +++ b/doc/man/cdist-reference.text.sh @@ -101,12 +101,15 @@ conf/type//gencode-local:: conf/type//gencode-remote:: Used to generate code to be executed on the client. -conf/type//parameters/required:: +conf/type//parameter/required:: Parameters required by type, \n seperated list. -conf/type//parameters/optional:: +conf/type//parameter/optional:: Parameters optionally accepted by type, \n seperated list. +conf/type//parameter/boolean:: + Boolean parameters accepted by type, \n seperated list. + conf/type//explorer:: Location of the type specific explorers. This directory is referenced by the variable __type_explorer (see below). diff --git a/doc/man/man7/cdist-type.text b/doc/man/man7/cdist-type.text index 48d412f1..1147511e 100644 --- a/doc/man/man7/cdist-type.text +++ b/doc/man/man7/cdist-type.text @@ -40,7 +40,7 @@ A list of supported types can be found in the cdist-reference(7) manpage. SINGLETON TYPES --------------- -If a type is flagged as a singleton, it may be used only +If a type is flagged as a singleton, it may be used only once per host. This is useful for types which can be used only once on a system. Singleton types do not take an object name as argument. @@ -72,15 +72,42 @@ To begin a new type, just create the directory **conf/type/__NAME**. DEFINING PARAMETERS ------------------- -Every type consists of optional and required parameters, which must -be created in a newline seperated file in ***parameters/required*** and -***parameters/optional***. If either or both missing, the type will have -no required, no optional or no parameters at all. +Every type consists of required, optional and boolean parameters, which must +be created in a newline seperated file in ***parameter/required***, +***parameter/optional*** and ***parameter/boolean***. If either is missing, +the type will have no required, no optional, no boolean or no parameters at +all. Example: -------------------------------------------------------------------------------- echo servername >> conf/type/__nginx_vhost/parameter/required echo logdirectory >> conf/type/__nginx_vhost/parameter/optional +echo use_ssl >> conf/type/__nginx_vhost/parameter/boolean +-------------------------------------------------------------------------------- + + +USING PARAMETERS +---------------- +The parameters given to a type can be accessed and used in all type scripts +(e.g manifest, gencode-*, explorer/*). Note that boolean parameters are +represented by file existence. File exists -> True, +file does not exist -> False + +Example: (e.g. in conf/type/__nginx_vhost/manifest) +-------------------------------------------------------------------------------- +# required parameter +servername="$(cat "$__object/parameter/servername")" + +# optional parameter +if [ -f "$__object/parameter/logdirectory" ]; then + logdirectory="$(cat "$__object/parameter/logdirectory")" +fi + +# boolean parameter +if [ -f "$__object/parameter/use_ssl" ]; then + # file exists -> True + # do some fancy ssl stuff +fi -------------------------------------------------------------------------------- @@ -116,7 +143,7 @@ SINGLETON - ONLY INSTANCE ONLY ------------------------------ If you want to ensure that a type can only be used once per target, you can mark it as a singleton: Just create the (empty) file "singleton" in your type -directory: +directory: -------------------------------------------------------------------------------- touch conf/type/__NAME/singleton @@ -128,7 +155,7 @@ This will also change the way your type must be called: __YOURTYPE --parameter value -------------------------------------------------------------------------------- -As you can see, the object ID is omitted, because it does not make any sense, +As you can see, the object ID is omitted, because it does not make any sense, if your type can be used only once. From baf8614e6cfab4467a62c57c66f82cd4940939ee Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 16 Feb 2012 11:13:50 +0100 Subject: [PATCH 12/37] ++changes(2.0.8) Signed-off-by: Nico Schottelius --- doc/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/changelog b/doc/changelog index 507726bc..ab006435 100644 --- a/doc/changelog +++ b/doc/changelog @@ -9,6 +9,7 @@ Changelog * Cleanup: Do not output failing script, but path to script only * Cleanup: Remove support for __debug variable in manifests (Type != Core debugging) + * Feature Core: Support boolean parameters (Steven Armstrong) 2.0.7: 2012-02-13 * Bugfix __file: Use chmod after chown/chgrp (Matt Coddington) From 8f46b2ca05e3bd12d78f37e112a03627c6c4b87e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 16 Feb 2012 23:08:02 +0100 Subject: [PATCH 13/37] reorder Signed-off-by: Nico Schottelius --- doc/dev/todo/niconext | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/dev/todo/niconext b/doc/dev/todo/niconext index bead6d72..fc815bc2 100644 --- a/doc/dev/todo/niconext +++ b/doc/dev/todo/niconext @@ -1,11 +1,11 @@ - introduce default parameters -- cleanup object_id handling - - have a look at singletons - - ensure that all types, which support --state support present and absent (consistent look and feel) +- cleanup object_id handling + - have a look at singletons + -------------------------------------------------------------------------------- - update/create docs From aa53a3f221e6a631482a7b68c7a3cb9afc385333 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 16 Feb 2012 23:12:49 +0100 Subject: [PATCH 14/37] better warning Signed-off-by: Nico Schottelius --- conf/type/__package_apt/gencode-remote | 4 ++-- conf/type/__package_pacman/gencode-remote | 4 ++-- conf/type/__package_pkg_openbsd/gencode-remote | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/conf/type/__package_apt/gencode-remote b/conf/type/__package_apt/gencode-remote index 47e76ec8..406708c2 100755 --- a/conf/type/__package_apt/gencode-remote +++ b/conf/type/__package_apt/gencode-remote @@ -32,11 +32,11 @@ state_should="$(cat "$__object/parameter/state")" # Correct pre 2.1 naming - FIXME in 2.1 case "$state_should" in installed) - echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 + echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="present" ;; removed) - echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 + echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="absent" ;; esac diff --git a/conf/type/__package_pacman/gencode-remote b/conf/type/__package_pacman/gencode-remote index 1516370c..6d445ddc 100755 --- a/conf/type/__package_pacman/gencode-remote +++ b/conf/type/__package_pacman/gencode-remote @@ -36,11 +36,11 @@ fi state_should="$(cat "$__object/parameter/state")" case "$state_should" in installed) - echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 + echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="present" ;; removed) - echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 + echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="absent" ;; esac diff --git a/conf/type/__package_pkg_openbsd/gencode-remote b/conf/type/__package_pkg_openbsd/gencode-remote index e8309f20..0cf27a93 100755 --- a/conf/type/__package_pkg_openbsd/gencode-remote +++ b/conf/type/__package_pkg_openbsd/gencode-remote @@ -47,11 +47,11 @@ state_should="$(cat "$__object/parameter/state")" # Correct pre 2.1 naming - FIXME in 2.1 case "$state_should" in installed) - echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 + echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="present" ;; removed) - echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 + echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="absent" ;; esac From 272c12e3f7c8996a8ae4f8085d1fd1417367a24a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 16 Feb 2012 23:15:31 +0100 Subject: [PATCH 15/37] correct parameters in __package_luarocks Signed-off-by: Nico Schottelius --- conf/type/__package_luarocks/gencode-remote | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/conf/type/__package_luarocks/gencode-remote b/conf/type/__package_luarocks/gencode-remote index 29fd7e38..17599bd3 100755 --- a/conf/type/__package_luarocks/gencode-remote +++ b/conf/type/__package_luarocks/gencode-remote @@ -30,6 +30,18 @@ else fi state_should="$(cat "$__object/parameter/state")" +# Correct pre 2.1 naming - FIXME in 2.1 +case "$state_should" in + installed) + echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + state_should="present" + ;; + removed) + echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + state_should="absent" + ;; +esac + is_installed="$(grep "(installed)" "$__object/explorer/pkg_status" || true)" case "$state" in From 76a3c2066905a9b27b33b2487cab6c0997050a2a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 16 Feb 2012 23:16:26 +0100 Subject: [PATCH 16/37] setup state_is Signed-off-by: Nico Schottelius --- conf/type/__package_luarocks/gencode-remote | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/conf/type/__package_luarocks/gencode-remote b/conf/type/__package_luarocks/gencode-remote index 17599bd3..2c1aa763 100755 --- a/conf/type/__package_luarocks/gencode-remote +++ b/conf/type/__package_luarocks/gencode-remote @@ -42,7 +42,12 @@ case "$state_should" in ;; esac -is_installed="$(grep "(installed)" "$__object/explorer/pkg_status" || true)" + +if grep -q "(installed)" "$__object/explorer/pkg_status"; then + state_is="present" +else + state_is="absent" +fi case "$state" in installed) From 9fab782a0cbb1f9dd6af6a1e348b76a95aa7897b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 16 Feb 2012 23:18:26 +0100 Subject: [PATCH 17/37] update __package_luarocks to new style state checking Signed-off-by: Nico Schottelius --- conf/type/__package_luarocks/gencode-remote | 35 ++++++++++----------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/conf/type/__package_luarocks/gencode-remote b/conf/type/__package_luarocks/gencode-remote index 2c1aa763..bfde7792 100755 --- a/conf/type/__package_luarocks/gencode-remote +++ b/conf/type/__package_luarocks/gencode-remote @@ -24,9 +24,9 @@ if [ -f "$__object/parameter/name" ]; then - name="$(cat "$__object/parameter/name")" + name="$(cat "$__object/parameter/name")" else - name="$__object_id" + name="$__object_id" fi state_should="$(cat "$__object/parameter/state")" @@ -49,21 +49,18 @@ else state_is="absent" fi -case "$state" in - installed) - # Install only if non-existent - if [ -z "$is_installed" ]; then - echo luarocks install \"$name\" - fi - ;; - removed) - # Remove only if existent - if [ -n "$is_installed" ]; then - echo luarocks remove \"$name\" - fi - ;; - *) - echo "Unknown state: $state" >&2 - exit 1 - ;; +# Leave if nothing is to be done +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + echo luarocks install \"$name\" + ;; + absent) + echo luarocks remove \"$name\" + ;; + *) + echo "Unknown state: $state" >&2 + exit 1 + ;; esac From e4aafe0af96ac6fc79faf99580defe8964a38a04 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 16 Feb 2012 23:23:19 +0100 Subject: [PATCH 18/37] support absent/present in __package_rubygem Signed-off-by: Nico Schottelius --- .../type/__package_pkg_openbsd/gencode-remote | 1 - conf/type/__package_rubygem/gencode-remote | 57 +++++++++++-------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/conf/type/__package_pkg_openbsd/gencode-remote b/conf/type/__package_pkg_openbsd/gencode-remote index 0cf27a93..97f3f101 100755 --- a/conf/type/__package_pkg_openbsd/gencode-remote +++ b/conf/type/__package_pkg_openbsd/gencode-remote @@ -29,7 +29,6 @@ os_version="$(cat "$__global/explorer/os_version")" machine="$(cat "$__global/explorer/machine")" - if [ -f "$__object/parameter/flavor" ]; then flavor="$(cat "$__object/parameter/flavor")" fi diff --git a/conf/type/__package_rubygem/gencode-remote b/conf/type/__package_rubygem/gencode-remote index daaba524..b48874c7 100755 --- a/conf/type/__package_rubygem/gencode-remote +++ b/conf/type/__package_rubygem/gencode-remote @@ -21,31 +21,42 @@ # Manage Rubygem packages # - if [ -f "$__object/parameter/name" ]; then - name="$(cat "$__object/parameter/name")" + name="$(cat "$__object/parameter/name")" else - name="$__object_id" + name="$__object_id" fi -state="$(cat "$__object/parameter/state")" -is_installed="$(grep "true" "$__object/explorer/pkg_status" || true)" - -case "$state" in - installed) - # Install only if non-existent - if [ -z "$is_installed" ]; then - echo gem install \"$name\" --no-ri --no-rdoc - fi - ;; - removed) - # Remove only if existent - if [ -n "$is_installed" ]; then - echo gem uninstall \"$name\" - fi - ;; - *) - echo "Unknown state: $state" >&2 - exit 1 - ;; +state_should="$(cat "$__object/parameter/state")" +# Correct pre 2.1 naming - FIXME in 2.1 +case "$state_should" in + installed) + echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + state_should="present" + ;; + removed) + echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + state_should="absent" + ;; +esac + +if grep -q true "$__object/explorer/pkg_status"; then + state_is="present" +else + state_is="absent" +fi + +[ "$state_is" = "$state_should ] && exit 0 + +case "$state_should" in + present) + echo gem install \"$name\" --no-ri --no-rdoc + ;; + absent) + echo gem uninstall \"$name\" + ;; + *) + echo "Unknown state: $state" >&2 + exit 1 + ;; esac From 2f01fd6ce05072faf76c4ee74c25f8b579719585 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 16 Feb 2012 23:26:23 +0100 Subject: [PATCH 19/37] support absent/present in __package_yum Signed-off-by: Nico Schottelius --- conf/type/__package_yum/gencode-remote | 46 +++++++++++++++++--------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/conf/type/__package_yum/gencode-remote b/conf/type/__package_yum/gencode-remote index b24ed220..35e8bd6b 100755 --- a/conf/type/__package_yum/gencode-remote +++ b/conf/type/__package_yum/gencode-remote @@ -27,7 +27,17 @@ else name="$__object_id" fi -state="$(cat "$__object/parameter/state")" +state_should="$(cat "$__object/parameter/state")" +case "$state_should" in + installed) + echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + state_should="present" + ;; + removed) + echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + state_should="absent" + ;; +esac if grep -q -E "(centos|redhat|amazon)" "$__global/explorer/os"; then opts="-y --quiet" @@ -37,19 +47,23 @@ fi not_installed="^no package provides" -case "$state" in - installed) - if grep -q "$not_installed" "$__object/explorer/pkg_version"; then - echo yum $opts install \"$name\" - fi - ;; - removed) - if ! grep -q "$not_installed" "$__object/explorer/pkg_version"; then - echo yum $opts remove \"$name\" - fi - ;; - *) - echo "Unknown state: $state" >&2 - exit 1 - ;; +if grep -q "$not_installed" "$__object/explorer/pkg_version"; then + state_is="absent" +else + state_is="present" +fi + +[ "$state_is" = "$state_should ] && exit 0 + +case "$state_should" in + present) + echo yum $opts install \"$name\" + ;; + absent) + echo yum $opts remove \"$name\" + ;; + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; esac From 48f3252de58ec1504efc270fc338e1f72d20763c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 16 Feb 2012 23:29:51 +0100 Subject: [PATCH 20/37] correct state error message to use new variable Signed-off-by: Nico Schottelius --- conf/type/__package_apt/gencode-remote | 2 +- conf/type/__package_luarocks/gencode-remote | 2 +- conf/type/__package_pacman/gencode-remote | 2 +- conf/type/__package_pip/gencode-remote | 4 ++++ conf/type/__package_rubygem/gencode-remote | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/conf/type/__package_apt/gencode-remote b/conf/type/__package_apt/gencode-remote index 406708c2..ed5ca5bb 100755 --- a/conf/type/__package_apt/gencode-remote +++ b/conf/type/__package_apt/gencode-remote @@ -61,7 +61,7 @@ if [ "$state_is" != "$state_should" ]; then echo $aptget remove \"$name\" ;; *) - echo "Unknown state: $state" >&2 + echo "Unknown state: $state_should" >&2 exit 1 ;; esac diff --git a/conf/type/__package_luarocks/gencode-remote b/conf/type/__package_luarocks/gencode-remote index bfde7792..b4970daa 100755 --- a/conf/type/__package_luarocks/gencode-remote +++ b/conf/type/__package_luarocks/gencode-remote @@ -60,7 +60,7 @@ case "$state_should" in echo luarocks remove \"$name\" ;; *) - echo "Unknown state: $state" >&2 + echo "Unknown state: $state_should" >&2 exit 1 ;; esac diff --git a/conf/type/__package_pacman/gencode-remote b/conf/type/__package_pacman/gencode-remote index 6d445ddc..5c45fbce 100755 --- a/conf/type/__package_pacman/gencode-remote +++ b/conf/type/__package_pacman/gencode-remote @@ -63,7 +63,7 @@ case "$state_should" in echo pacman "$pacopts" -R \"$name\" ;; *) - echo "Unknown state: $state" >&2 + echo "Unknown state: $state_should" >&2 exit 1 ;; esac diff --git a/conf/type/__package_pip/gencode-remote b/conf/type/__package_pip/gencode-remote index e60d74c5..0f15abdc 100644 --- a/conf/type/__package_pip/gencode-remote +++ b/conf/type/__package_pip/gencode-remote @@ -47,4 +47,8 @@ case "$state_should" in absent) echo $pip uninstall -q -y pyro ;; + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; esac diff --git a/conf/type/__package_rubygem/gencode-remote b/conf/type/__package_rubygem/gencode-remote index b48874c7..cca016cf 100755 --- a/conf/type/__package_rubygem/gencode-remote +++ b/conf/type/__package_rubygem/gencode-remote @@ -56,7 +56,7 @@ case "$state_should" in echo gem uninstall \"$name\" ;; *) - echo "Unknown state: $state" >&2 + echo "Unknown state: $state_should" >&2 exit 1 ;; esac From 6afcb0e9ee32794719cb0bc0f406eebdf3e62d1f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 16 Feb 2012 23:34:22 +0100 Subject: [PATCH 21/37] indent + simplify Signed-off-by: Nico Schottelius --- conf/type/__package_apt/gencode-remote | 28 +++++++++++------------ conf/type/__package_pacman/gencode-remote | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/conf/type/__package_apt/gencode-remote b/conf/type/__package_apt/gencode-remote index ed5ca5bb..f0c6090b 100755 --- a/conf/type/__package_apt/gencode-remote +++ b/conf/type/__package_apt/gencode-remote @@ -52,17 +52,17 @@ esac aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes" -if [ "$state_is" != "$state_should" ]; then - case "$state_should" in - present) - echo $aptget install \"$name\" - ;; - absent) - echo $aptget remove \"$name\" - ;; - *) - echo "Unknown state: $state_should" >&2 - exit 1 - ;; - esac -fi +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + echo $aptget install \"$name\" + ;; + absent) + echo $aptget remove \"$name\" + ;; + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; +esac diff --git a/conf/type/__package_pacman/gencode-remote b/conf/type/__package_pacman/gencode-remote index 5c45fbce..73ed0997 100755 --- a/conf/type/__package_pacman/gencode-remote +++ b/conf/type/__package_pacman/gencode-remote @@ -53,7 +53,7 @@ else fi # Exit if nothing is needed to be done -[ "$state_is" = "$state_should ] && exit 0 +[ "$state_is" = "$state_should" ] && exit 0 case "$state_should" in present) From 31aa102b209e066b4abacd4b5b13fa6e5d1cd655 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 16 Feb 2012 23:37:08 +0100 Subject: [PATCH 22/37] ++changes(2.0.8) Signed-off-by: Nico Schottelius --- doc/changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/changelog b/doc/changelog index ab006435..0bdbeb32 100644 --- a/doc/changelog +++ b/doc/changelog @@ -9,6 +9,8 @@ Changelog * Cleanup: Do not output failing script, but path to script only * Cleanup: Remove support for __debug variable in manifests (Type != Core debugging) + * Cleanup: Change __package_* to support absent/present (default state + name now). The values removed/installed will be removed in cdist 2.1. * Feature Core: Support boolean parameters (Steven Armstrong) 2.0.7: 2012-02-13 From 78bdbce7004bc46ab8b1203df93dcda122981710 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 16 Feb 2012 23:38:09 +0100 Subject: [PATCH 23/37] absent/present implemented in __package_absent_present branch Signed-off-by: Nico Schottelius --- doc/dev/todo/niconext | 3 --- 1 file changed, 3 deletions(-) diff --git a/doc/dev/todo/niconext b/doc/dev/todo/niconext index fc815bc2..d37a0f9f 100644 --- a/doc/dev/todo/niconext +++ b/doc/dev/todo/niconext @@ -1,8 +1,5 @@ - introduce default parameters -- ensure that all types, which support --state support - present and absent (consistent look and feel) - - cleanup object_id handling - have a look at singletons From 9e4b3d23256563319e7113280639ae61e5095d2b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Feb 2012 10:27:23 +0100 Subject: [PATCH 24/37] +mirror Signed-off-by: Nico Schottelius --- build | 1 + 1 file changed, 1 insertion(+) diff --git a/build b/build index 2d98e862..b209e1c2 100755 --- a/build +++ b/build @@ -130,6 +130,7 @@ case "$1" in git push --mirror git push --mirror github git push --mirror sf + git push --mirror ethz ;; clean) From 9eeac41bea71b836331da32a53d48405eb978f62 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Feb 2012 11:20:47 +0100 Subject: [PATCH 25/37] ++ideas Signed-off-by: Nico Schottelius --- doc/dev/todo/niconext | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/dev/todo/niconext b/doc/dev/todo/niconext index d37a0f9f..aa5f6001 100644 --- a/doc/dev/todo/niconext +++ b/doc/dev/todo/niconext @@ -1,10 +1,13 @@ - introduce default parameters + - valid for optional parameters only + - stored in parameter/default/$name + + - when/where to save? in emulator? + - read vi fsproperty? - cleanup object_id handling - have a look at singletons --------------------------------------------------------------------------------- - - update/create docs - cdist-cache:: How to get use information about the hosts we have been working on [advanced] From 241f66a537c32c346011d64c0cc7b7816df97b21 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Feb 2012 11:24:29 +0100 Subject: [PATCH 26/37] +quotes Signed-off-by: Nico Schottelius --- conf/type/__package_rubygem/gencode-remote | 2 +- conf/type/__package_yum/gencode-remote | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/type/__package_rubygem/gencode-remote b/conf/type/__package_rubygem/gencode-remote index cca016cf..4a8f21ee 100755 --- a/conf/type/__package_rubygem/gencode-remote +++ b/conf/type/__package_rubygem/gencode-remote @@ -46,7 +46,7 @@ else state_is="absent" fi -[ "$state_is" = "$state_should ] && exit 0 +[ "$state_is" = "$state_should" ] && exit 0 case "$state_should" in present) diff --git a/conf/type/__package_yum/gencode-remote b/conf/type/__package_yum/gencode-remote index 35e8bd6b..7f294a46 100755 --- a/conf/type/__package_yum/gencode-remote +++ b/conf/type/__package_yum/gencode-remote @@ -53,7 +53,7 @@ else state_is="present" fi -[ "$state_is" = "$state_should ] && exit 0 +[ "$state_is" = "$state_should" ] && exit 0 case "$state_should" in present) From e0f80f01030f0a46275be01eb4ff2bde6c89bd98 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Feb 2012 11:54:34 +0100 Subject: [PATCH 27/37] include object_name in warning Signed-off-by: Nico Schottelius --- conf/type/__package_apt/gencode-remote | 4 ++-- conf/type/__package_luarocks/gencode-remote | 4 ++-- conf/type/__package_pacman/gencode-remote | 4 ++-- conf/type/__package_pkg_openbsd/gencode-remote | 4 ++-- conf/type/__package_rubygem/gencode-remote | 4 ++-- conf/type/__package_yum/gencode-remote | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/conf/type/__package_apt/gencode-remote b/conf/type/__package_apt/gencode-remote index f0c6090b..0bcdb946 100755 --- a/conf/type/__package_apt/gencode-remote +++ b/conf/type/__package_apt/gencode-remote @@ -32,11 +32,11 @@ state_should="$(cat "$__object/parameter/state")" # Correct pre 2.1 naming - FIXME in 2.1 case "$state_should" in installed) - echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="present" ;; removed) - echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="absent" ;; esac diff --git a/conf/type/__package_luarocks/gencode-remote b/conf/type/__package_luarocks/gencode-remote index b4970daa..327f812c 100755 --- a/conf/type/__package_luarocks/gencode-remote +++ b/conf/type/__package_luarocks/gencode-remote @@ -33,11 +33,11 @@ state_should="$(cat "$__object/parameter/state")" # Correct pre 2.1 naming - FIXME in 2.1 case "$state_should" in installed) - echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="present" ;; removed) - echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="absent" ;; esac diff --git a/conf/type/__package_pacman/gencode-remote b/conf/type/__package_pacman/gencode-remote index 73ed0997..9defabe8 100755 --- a/conf/type/__package_pacman/gencode-remote +++ b/conf/type/__package_pacman/gencode-remote @@ -36,11 +36,11 @@ fi state_should="$(cat "$__object/parameter/state")" case "$state_should" in installed) - echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="present" ;; removed) - echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="absent" ;; esac diff --git a/conf/type/__package_pkg_openbsd/gencode-remote b/conf/type/__package_pkg_openbsd/gencode-remote index 97f3f101..26dd4689 100755 --- a/conf/type/__package_pkg_openbsd/gencode-remote +++ b/conf/type/__package_pkg_openbsd/gencode-remote @@ -46,11 +46,11 @@ state_should="$(cat "$__object/parameter/state")" # Correct pre 2.1 naming - FIXME in 2.1 case "$state_should" in installed) - echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="present" ;; removed) - echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="absent" ;; esac diff --git a/conf/type/__package_rubygem/gencode-remote b/conf/type/__package_rubygem/gencode-remote index 4a8f21ee..638c4252 100755 --- a/conf/type/__package_rubygem/gencode-remote +++ b/conf/type/__package_rubygem/gencode-remote @@ -31,11 +31,11 @@ state_should="$(cat "$__object/parameter/state")" # Correct pre 2.1 naming - FIXME in 2.1 case "$state_should" in installed) - echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="present" ;; removed) - echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="absent" ;; esac diff --git a/conf/type/__package_yum/gencode-remote b/conf/type/__package_yum/gencode-remote index 7f294a46..a10e60dd 100755 --- a/conf/type/__package_yum/gencode-remote +++ b/conf/type/__package_yum/gencode-remote @@ -30,11 +30,11 @@ fi state_should="$(cat "$__object/parameter/state")" case "$state_should" in installed) - echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="present" ;; removed) - echo "WARNING: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 state_should="absent" ;; esac From 0f649577ad82bc894265ad07a111f4c8b0f9cd94 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Feb 2012 12:10:42 +0100 Subject: [PATCH 28/37] update __process to new style, warn if not present/absent Signed-off-by: Nico Schottelius --- conf/type/__process/gencode-remote | 51 ++++++++++++++++++------------ conf/type/__process/man.text | 18 ++++++----- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/conf/type/__process/gencode-remote b/conf/type/__process/gencode-remote index be0e0cae..3411734e 100755 --- a/conf/type/__process/gencode-remote +++ b/conf/type/__process/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -25,33 +25,44 @@ else name="$__object_id" fi -runs="$(cat "$__object/explorer/runs")" state_should="$(cat "$__object/parameter/state")" +case "$state_should" in + running) + echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + state_should="present" + ;; + stopped) + echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 + state_should="absent" + ;; +esac + +runs="$(cat "$__object/explorer/runs")" +if [ "$runs" ]; then + state_is="present" +else + state_is="absent" +fi + +[ "$state_is" = "$state_should" ] && exit 0 case "$state_should" in - running|present) - # Does not run, start it! - if [ -z "$runs" ]; then - if [ -f "$__object/parameter/start" ]; then + present) + if [ -f "$__object/parameter/start" ]; then cat "$__object/parameter/start" - else + else echo "$name" - fi - fi - ;; - stopped|absent) - # Runs, kill it! - if [ "$runs" ]; then + fi + ;; + absent) if [ -f "$__object/parameter/stop" ]; then cat "$__object/parameter/stop" else echo kill "${runs}" fi - fi - ;; - *) - echo "Unknown state: $state_should" >&2 - exit 1 - ;; - + ;; + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; esac diff --git a/conf/type/__process/man.text b/conf/type/__process/man.text index fbd54847..961a7f9a 100644 --- a/conf/type/__process/man.text +++ b/conf/type/__process/man.text @@ -16,7 +16,9 @@ This cdist type allows you to define the state of a process. REQUIRED PARAMETERS ------------------- state:: - State of the process: Either stopped or running. + State of the process: Either present or absent + (old values "stopped" and "running" are deprecated and will be removed in + cdist 2.1). OPTIONAL PARAMETERS @@ -40,23 +42,23 @@ EXAMPLES -------------------------------------------------------------------------------- # Start if not running -__process /usr/sbin/syslog-ng --state running +__process /usr/sbin/syslog-ng --state present # Start if not running with a different binary -__process /usr/sbin/nginx --state running --start "/etc/rc.d/nginx start" +__process /usr/sbin/nginx --state present --start "/etc/rc.d/nginx start" # Stop the process using kill (the type default) - DO NOT USE THIS -__process /usr/sbin/sshd --state stopped +__process /usr/sbin/sshd --state absent # Stop the process using /etc/rc.d/sshd stop - THIS ONE NOT AS WELL -__process /usr/sbin/sshd --state stopped --stop "/etc/rc.d/sshd stop" +__process /usr/sbin/sshd --state absent --stop "/etc/rc.d/sshd stop" # Ensure cups is running, which runs with -C ...: -__process cups --start "/etc/rc.d/cups start" --state running \ +__process cups --start "/etc/rc.d/cups start" --state present \ --name "/usr/sbin/cupsd -C /etc/cups/cupsd.conf" # Ensure rpc.statd is running (which usually runs with -L) using a regexp -__process rpcstatd --state running --start "/etc/init.d/statd start" \ +__process rpcstatd --state present --start "/etc/init.d/statd start" \ --name "rpc.statd.*" -------------------------------------------------------------------------------- @@ -68,5 +70,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2011 Nico Schottelius. Free use of this software is +Copyright \(C) 2011-2012 Nico Schottelius. Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3). From ae898ac870ecd9035acc585948a0ab0faac1c84b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Feb 2012 12:21:03 +0100 Subject: [PATCH 29/37] +kbdirq Signed-off-by: Nico Schottelius --- doc/dev/logs/2012-02-17.keyboardirq | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 doc/dev/logs/2012-02-17.keyboardirq diff --git a/doc/dev/logs/2012-02-17.keyboardirq b/doc/dev/logs/2012-02-17.keyboardirq new file mode 100644 index 00000000..93e62fbf --- /dev/null +++ b/doc/dev/logs/2012-02-17.keyboardirq @@ -0,0 +1,26 @@ +Somewhere there is still a race condition: + +INFO: monitoring03: Running manifest and explorers for __file/etc/yum.repos.d/epel.repo +^C^CTraceback (most recent call last): + File "./bin/cdist", line 204, in + import logging + File "/usr/lib/python3.2/logging/__init__.py", line 27, in + from string import Template + File "/usr/lib/python3.2/string.py", line 178, in + class Formatter: + File "/usr/lib/python3.2/string.py", line 179, in Formatter + def format(self, format_string, *args, **kwargs): +KeyboardInterrupt + +During handling of the above exception, another exception occurred: + +Traceback (most recent call last): + File "./bin/cdist", line 232, in + sys.exit(0) +NameError: name 'sys' is not defined +^C^CFatal Python error: Py_Initialize: can't initialize sys standard streams +Traceback (most recent call last): + File "/usr/lib/python3.2/encodings/latin_1.py", line 8, in + """ +KeyboardInterrupt +^C% [12:19] brief:cdist% From 61666664c160dd78e179d39bf5f795785ada19c8 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Feb 2012 12:51:14 +0100 Subject: [PATCH 30/37] ++changes(2.0.8) Signed-off-by: Nico Schottelius --- doc/changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/changelog b/doc/changelog index 0bdbeb32..06a8ded4 100644 --- a/doc/changelog +++ b/doc/changelog @@ -11,6 +11,8 @@ Changelog debugging) * Cleanup: Change __package_* to support absent/present (default state name now). The values removed/installed will be removed in cdist 2.1. + * Cleanup: Change __process to support absent/present (default state + name now). The values running/stopped will be removed in cdist 2.1. * Feature Core: Support boolean parameters (Steven Armstrong) 2.0.7: 2012-02-13 From aa81486fe9caf6034560fdc8e24b2610e945a8bd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Feb 2012 13:47:00 +0100 Subject: [PATCH 31/37] sys.exit() in try Signed-off-by: Nico Schottelius --- bin/cdist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/cdist b/bin/cdist index 06e82cc9..971288fd 100755 --- a/bin/cdist +++ b/bin/cdist @@ -228,7 +228,7 @@ if __name__ == "__main__": else: commandline() - except KeyboardInterrupt: sys.exit(0) - sys.exit(0) + except KeyboardInterrupt: + sys.exit(0) From 5e20ba5a1354e0a530ca92f1c165322391bff320 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Feb 2012 13:59:16 +0100 Subject: [PATCH 32/37] ++logs, +import sys at top level Signed-off-by: Nico Schottelius --- bin/cdist | 4 +++- doc/dev/logs/2012-02-17.keyboardirq | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bin/cdist b/bin/cdist index 971288fd..5456b134 100755 --- a/bin/cdist +++ b/bin/cdist @@ -200,11 +200,13 @@ def emulator(): sys.exit(1) if __name__ == "__main__": + # Sys is needed for sys.exit() + import sys + try: import logging import os import re - import sys cdistpythonversion = '3.2' if sys.version < cdistpythonversion: diff --git a/doc/dev/logs/2012-02-17.keyboardirq b/doc/dev/logs/2012-02-17.keyboardirq index 93e62fbf..8ce59681 100644 --- a/doc/dev/logs/2012-02-17.keyboardirq +++ b/doc/dev/logs/2012-02-17.keyboardirq @@ -24,3 +24,25 @@ Traceback (most recent call last): """ KeyboardInterrupt ^C% [12:19] brief:cdist% + + +-------------------------------------------------------------------------------- +[13:50] brief:cdist% ./bin/cdist config -vp monitoring02 +INFO: monitoring02: Running global explorers +INFO: monitoring02: Running initial manifest /home/users/nico/privat/firmen/local.ch/vcs/cdist/conf/manifest +INFO: monitoring02: Running object manifests and type explorers +INFO: monitoring02: Running manifest and explorers for __localch_shinken/singleton +^CTraceback (most recent call last): + File "/usr/lib/python3.2/site.py", line 58, in + import traceback + File "/usr/lib/python3.2/traceback.py", line 3, in + import linecache + File "/usr/lib/python3.2/linecache.py", line 10, in + import tokenize + File "/usr/lib/python3.2/tokenize.py", line 49, in + class TokenInfo(collections.namedtuple('TokenInfo', 'type string start end line')): + File "/usr/lib/python3.2/collections.py", line 363, in namedtuple + exec(class_definition, namespace) + File "", line 1, in +KeyboardInterrupt + From 1dfb5872644d5dcc1ae207586b970419a4ba4047 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Feb 2012 14:07:00 +0100 Subject: [PATCH 33/37] ++changes(2.0.8) Signed-off-by: Nico Schottelius --- doc/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/changelog b/doc/changelog index 06a8ded4..cb72068e 100644 --- a/doc/changelog +++ b/doc/changelog @@ -5,6 +5,7 @@ Changelog * Exception: No braces means author == Nico Schottelius 2.0.8: + * Bugfix core: Remove another nasty traceback when sending SIGINT (aka Ctrl-C) * Cleanup: Better hint to source of error * Cleanup: Do not output failing script, but path to script only * Cleanup: Remove support for __debug variable in manifests (Type != Core From 39417fee8f9487565f94bdba81dbec001e774eae Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 17 Feb 2012 14:15:38 +0100 Subject: [PATCH 34/37] ++todo Signed-off-by: Nico Schottelius --- doc/dev/todo/TAKEME | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/dev/todo/TAKEME b/doc/dev/todo/TAKEME index b40936f6..3007cedb 100644 --- a/doc/dev/todo/TAKEME +++ b/doc/dev/todo/TAKEME @@ -37,3 +37,4 @@ TYPES - Add testing framework (proposed by Evax Software) - __user add option to include --create-home +- Merge __addifnosuchline and __removeline into __line + --state present|absent From cfb8e7d37237e54a7bfd8b430e9ce4e4e5387397 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 20 Feb 2012 10:22:52 +0100 Subject: [PATCH 35/37] move __run_command to types_submitted_for_inclusion directory Signed-off-by: Nico Schottelius --- .../__run_command/README.inclusion | 6 ++++++ .../__run_command/gencode-remote | 0 .../types_submitted_for_inclusion}/__run_command/man.text | 0 .../__run_command/parameter/optional | 0 .../__run_command/parameter/required | 0 5 files changed, 6 insertions(+) create mode 100644 other/types_submitted_for_inclusion/__run_command/README.inclusion rename {conf/type => other/types_submitted_for_inclusion}/__run_command/gencode-remote (100%) rename {conf/type => other/types_submitted_for_inclusion}/__run_command/man.text (100%) rename {conf/type => other/types_submitted_for_inclusion}/__run_command/parameter/optional (100%) rename {conf/type => other/types_submitted_for_inclusion}/__run_command/parameter/required (100%) diff --git a/other/types_submitted_for_inclusion/__run_command/README.inclusion b/other/types_submitted_for_inclusion/__run_command/README.inclusion new file mode 100644 index 00000000..f7c95da7 --- /dev/null +++ b/other/types_submitted_for_inclusion/__run_command/README.inclusion @@ -0,0 +1,6 @@ +This type is not much of use, as any type can issue code to be executed. +Thus you can implement the code directly in the calling type. + Or if you need to reuse it, create a type on its own. + +Because this seems to be a common misunderstanding when people come from "non managed areas", + where script iexecution is the main focus, I documented this in cdist-hacker to clearify. diff --git a/conf/type/__run_command/gencode-remote b/other/types_submitted_for_inclusion/__run_command/gencode-remote similarity index 100% rename from conf/type/__run_command/gencode-remote rename to other/types_submitted_for_inclusion/__run_command/gencode-remote diff --git a/conf/type/__run_command/man.text b/other/types_submitted_for_inclusion/__run_command/man.text similarity index 100% rename from conf/type/__run_command/man.text rename to other/types_submitted_for_inclusion/__run_command/man.text diff --git a/conf/type/__run_command/parameter/optional b/other/types_submitted_for_inclusion/__run_command/parameter/optional similarity index 100% rename from conf/type/__run_command/parameter/optional rename to other/types_submitted_for_inclusion/__run_command/parameter/optional diff --git a/conf/type/__run_command/parameter/required b/other/types_submitted_for_inclusion/__run_command/parameter/required similarity index 100% rename from conf/type/__run_command/parameter/required rename to other/types_submitted_for_inclusion/__run_command/parameter/required From edcb2363e9cae80b368e12cd895d30ab52b8f06d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 20 Feb 2012 11:18:37 +0100 Subject: [PATCH 36/37] ++version(2.0.8) Signed-off-by: Nico Schottelius --- doc/changelog | 2 +- lib/cdist/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/changelog b/doc/changelog index cb72068e..96681617 100644 --- a/doc/changelog +++ b/doc/changelog @@ -4,7 +4,7 @@ Changelog * Changes are always commented with their author in (braces) * Exception: No braces means author == Nico Schottelius -2.0.8: +2.0.8: 2012-02-20 * Bugfix core: Remove another nasty traceback when sending SIGINT (aka Ctrl-C) * Cleanup: Better hint to source of error * Cleanup: Do not output failing script, but path to script only diff --git a/lib/cdist/__init__.py b/lib/cdist/__init__.py index 4742a937..c1e16ffb 100644 --- a/lib/cdist/__init__.py +++ b/lib/cdist/__init__.py @@ -19,7 +19,7 @@ # # -VERSION = "2.0.7" +VERSION = "2.0.8" BANNER = """ .. . .x+=:. s From a2a0fd6b975a0fe962c2fd0e57d73cbd928f01a3 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 20 Feb 2012 17:07:06 +0100 Subject: [PATCH 37/37] +error log (2 missing bits) Signed-off-by: Nico Schottelius --- .../2012-02-20.error-does-not-contain-host | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 doc/dev/logs/2012-02-20.error-does-not-contain-host diff --git a/doc/dev/logs/2012-02-20.error-does-not-contain-host b/doc/dev/logs/2012-02-20.error-does-not-contain-host new file mode 100644 index 00000000..5838c011 --- /dev/null +++ b/doc/dev/logs/2012-02-20.error-does-not-contain-host @@ -0,0 +1,26 @@ +- errors do not contain host +- it's not logged which hosts failed! + +INFO: monitoring02: Running manifest and explorers for __directory/opt/local.ch/sys/shinken/host.d +INFO: monitoring03: Running manifest and explorers for __file/usr/sbin/iptables-rebuild +INFO: monitoring03: Running manifest and explorers for __git/opt/local.ch/sys/shinken/shinken +INFO: monitoring02: Running manifest and explorers for __file/etc/iptables.d/005_start +INFO: monitoring03: Running manifest and explorers for __localch_rsyncd/singleton +ERROR: Object __localch_iptables/xensnmp already exists with conflicting parameters: +/home/users/nico/privat/firmen/local.ch/vcs/cdist/conf/manifest/init: {'rule': '-A RH-Firewall-1-INPUT -p tcp --dport 161 -j ACCEPT'} +/home/users/nico/privat/firmen/local.ch/vcs/cdist/conf/type/__localch_rsyncd/manifest: {'rule': '-A RH-Firewall-1-INPUT -p tcp --dport 873 -j ACCEPT'} +ERROR: Command failed: /bin/sh -e /home/users/nico/privat/firmen/local.ch/vcs/cdist/conf/type/__localch_rsyncd/manifest +INFO: monitoring02: Running manifest and explorers for __file/etc/iptables.d/500_xensnmp +INFO: monitoring02: Running manifest and explorers for __file/etc/iptables.d/995_end +INFO: monitoring02: Running manifest and explorers for __file/etc/rsyncd.conf +INFO: monitoring02: Running manifest and explorers for __file/etc/yum.repos.d/epel.repo +INFO: monitoring02: Running manifest and explorers for __file/etc/yum.repos.d/rpmforge.repo +INFO: monitoring02: Running manifest and explorers for __file/usr/sbin/iptables-rebuild +INFO: monitoring02: Running manifest and explorers for __git/opt/local.ch/sys/shinken/shinken +INFO: monitoring02: Running manifest and explorers for __localch_rsyncd/singleton +ERROR: Object __localch_iptables/xensnmp already exists with conflicting parameters: +/home/users/nico/privat/firmen/local.ch/vcs/cdist/conf/manifest/init: {'rule': '-A RH-Firewall-1-INPUT -p tcp --dport 161 -j ACCEPT'} +/home/users/nico/privat/firmen/local.ch/vcs/cdist/conf/type/__localch_rsyncd/manifest: {'rule': '-A RH-Firewall-1-INPUT -p tcp --dport 873 -j ACCEPT'} +ERROR: Command failed: /bin/sh -e /home/users/nico/privat/firmen/local.ch/vcs/cdist/conf/type/__localch_rsyncd/manifest +INFO: Total processing time for 2 host(s): 14.245397090911865 +[16:53] brief:cdist%