From 824381e6cac28acbf3c5cd84d9d9000b3b37249e Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Fri, 17 Jan 2014 23:35:02 +0100 Subject: [PATCH 01/16] new special value require="CDIST_HONOR_MANIFEST_ORDER" which tells cdist to execute types in the manifest order --- cdist/emulator.py | 16 ++++++++++++++++ docs/man/man7/cdist-manifest.text | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/cdist/emulator.py b/cdist/emulator.py index b70ef956..fe2af4c1 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -71,6 +71,7 @@ class Emulator(object): raise MissingRequiredEnvironmentVariableError(e.args[0]) self.object_base_path = os.path.join(self.global_path, "object") + self.typeorder_path = os.path.join(self.global_path, "typeorder") self.type_name = os.path.basename(argv[0]) self.cdist_type = core.CdistType(self.type_base_path, self.type_name) @@ -152,6 +153,9 @@ class Emulator(object): else: self.cdist_object.create() self.cdist_object.parameters = self.parameters + # record the created object in typeorder file + with open(self.typeorder_path, 'a') as tofd: + tofd.write(self.cdist_object.name + os.linesep) # Record / Append source self.cdist_object.source.append(self.object_source) @@ -188,6 +192,18 @@ class Emulator(object): # Ignore empty fields - probably the only field anyway if len(requirement) == 0: continue + + if requirement == "CDIST_HONOR_MANIFEST_ORDER": + # load object name created bevor this one from typeorder file ... + with open(self.typeorder_path, 'r') as tofd: + lines = tofd.readlines() + # replace the placeholder with the last created object + try: + requirement = lines[-2].strip() + except IndexError: + # if no second last line, we are on the first object, so do not set a requirement + continue + # Raises an error, if object cannot be created try: cdist_object = self.cdist_object.object_from_name(requirement) diff --git a/docs/man/man7/cdist-manifest.text b/docs/man/man7/cdist-manifest.text index 92d0b897..d2738c2b 100644 --- a/docs/man/man7/cdist-manifest.text +++ b/docs/man/man7/cdist-manifest.text @@ -128,6 +128,22 @@ All objects that are created in a type manifest are automatically required from the type that is calling them. This is called "autorequirement" in cdist jargon. +You can tell cdist to execute all types in the order in which they are created +in the manifest by setting require to the special value of +"CDIST_HONOR_MANIFEST_ORDER". + +-------------------------------------------------------------------------------- + +# Tells cdist to execute all types in the order in which they are created ... +export require="CDIST_HONOR_MANIFEST_ORDER" +__sample_type 1 +__sample_type 2 +__example_type 23 +# Now this types are executed in the creation order +-------------------------------------------------------------------------------- + + + EXAMPLES -------- From 61aec12ba1b0b0f55ec418895b61d46701c56b30 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Sat, 18 Jan 2014 19:23:21 +0100 Subject: [PATCH 02/16] Try2 to make cdist honor the manifest order, this implementation has some more lines of code, but no collision with the require variable. --- cdist/emulator.py | 36 ++++++++++++++++++------------- docs/man/man7/cdist-manifest.text | 22 ++++++++++++++----- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/cdist/emulator.py b/cdist/emulator.py index fe2af4c1..eeb441aa 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -154,8 +154,8 @@ class Emulator(object): self.cdist_object.create() self.cdist_object.parameters = self.parameters # record the created object in typeorder file - with open(self.typeorder_path, 'a') as tofd: - tofd.write(self.cdist_object.name + os.linesep) + with open(self.typeorder_path, 'a') as typeorderfile: + print(self.cdist_object.name, file=typeorderfile) # Record / Append source self.cdist_object.source.append(self.object_source) @@ -184,6 +184,24 @@ class Emulator(object): def record_requirements(self): """record requirements""" + #from pudb import set_trace; set_trace(); + + if "EXECUTE_TYPES_IN_CREATION_ORDER" in self.env and self.env['EXECUTE_TYPES_IN_CREATION_ORDER'] == 'true': + # load object name created bevor this one from typeorder file ... + with open(self.typeorder_path, 'r') as typecreationfile: + typecreationorder = typecreationfile.readlines() + # get the type created bevore this one ... + try: + lastcreatedtype = typecreationorder[-2].strip() + if 'require' in self.env: + self.env['require'] += " " + lastcreatedtype + else: + self.env['require'] = lastcreatedtype + self.log.debug("Injecting require for EXECUTE_TYPES_IN_CREATION_ORDER: %s for %s", lastcreatedtype, self.cdist_object.name) + except IndexError: + # if no second last line, we are on the first type, so do not set a requirement + pass + if "require" in self.env: requirements = self.env['require'] @@ -192,18 +210,6 @@ class Emulator(object): # Ignore empty fields - probably the only field anyway if len(requirement) == 0: continue - - if requirement == "CDIST_HONOR_MANIFEST_ORDER": - # load object name created bevor this one from typeorder file ... - with open(self.typeorder_path, 'r') as tofd: - lines = tofd.readlines() - # replace the placeholder with the last created object - try: - requirement = lines[-2].strip() - except IndexError: - # if no second last line, we are on the first object, so do not set a requirement - continue - # Raises an error, if object cannot be created try: cdist_object = self.cdist_object.object_from_name(requirement) @@ -212,7 +218,7 @@ class Emulator(object): raise - self.log.debug("Recording requirement: " + requirement) + self.log.debug("Recording requirement: %s", requirement) # Save the sanitised version, not the user supplied one # (__file//bar => __file/bar) diff --git a/docs/man/man7/cdist-manifest.text b/docs/man/man7/cdist-manifest.text index d2738c2b..d2f5ba05 100644 --- a/docs/man/man7/cdist-manifest.text +++ b/docs/man/man7/cdist-manifest.text @@ -128,18 +128,30 @@ All objects that are created in a type manifest are automatically required from the type that is calling them. This is called "autorequirement" in cdist jargon. + +EXECUTE_TYPES_IN_CREATION_ORDER is a EXPERIMENTAL FEATURE ! You can tell cdist to execute all types in the order in which they are created -in the manifest by setting require to the special value of -"CDIST_HONOR_MANIFEST_ORDER". +in the manifest by exporting EXECUTE_TYPES_IN_CREATION_ORDER with the value true. -------------------------------------------------------------------------------- # Tells cdist to execute all types in the order in which they are created ... -export require="CDIST_HONOR_MANIFEST_ORDER" +export EXECUTE_TYPES_IN_CREATION_ORDER=true __sample_type 1 -__sample_type 2 +require="__some_type_somewhere/id" __sample_type 2 __example_type 23 -# Now this types are executed in the creation order +# Now this types are executed in the creation order until the variable is unset +unset EXECUTE_TYPES_IN_CREATION_ORDER +# all now following types cdist makes the order .. +__not_in_order_type 42 + +# how it works : +# this lines above are translated to: +__sample_type 1 +require="__some_type_somewhere/id __sample_type/1" __sample_type 2 +require="__sample_type/2" __example_type 23 +__not_in_order_type 42 + -------------------------------------------------------------------------------- From 3c52710763a3f8537f732e716e53439d1b6af494 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Mon, 3 Feb 2014 21:43:39 +0100 Subject: [PATCH 03/16] little changes for using default parameters correctly --- cdist/conf/type/__git/gencode-remote | 15 +++++---------- cdist/conf/type/__git/manifest | 3 +-- cdist/conf/type/__git/parameter/default/branch | 1 + cdist/conf/type/__git/parameter/default/group | 1 + cdist/conf/type/__git/parameter/default/mode | 1 + cdist/conf/type/__git/parameter/default/owner | 1 + cdist/conf/type/__git/parameter/default/state | 1 + cdist/conf/type/__jail/gencode-local | 12 ++---------- cdist/conf/type/__jail/gencode-remote | 13 +++---------- cdist/conf/type/__jail/manifest | 6 +----- .../type/__jail/parameter/default/devfs-ruleset | 1 + cdist/conf/type/__jail/parameter/default/jailbase | 1 + cdist/conf/type/__jail/parameter/default/jaildir | 1 + cdist/conf/type/__package_yum/gencode-remote | 6 +----- .../type/__package_yum/parameter/default/state | 1 + cdist/conf/type/__package_zypper/gencode-remote | 13 ++----------- .../type/__package_zypper/parameter/default/state | 1 + cdist/conf/type/__user_groups/gencode-remote | 2 +- .../type/__user_groups/parameter/default/state | 1 + 19 files changed, 27 insertions(+), 54 deletions(-) create mode 100644 cdist/conf/type/__git/parameter/default/branch create mode 100644 cdist/conf/type/__git/parameter/default/group create mode 100644 cdist/conf/type/__git/parameter/default/mode create mode 100644 cdist/conf/type/__git/parameter/default/owner create mode 100644 cdist/conf/type/__git/parameter/default/state create mode 100644 cdist/conf/type/__jail/parameter/default/devfs-ruleset create mode 100644 cdist/conf/type/__jail/parameter/default/jailbase create mode 100644 cdist/conf/type/__jail/parameter/default/jaildir create mode 100644 cdist/conf/type/__package_yum/parameter/default/state create mode 100644 cdist/conf/type/__package_zypper/parameter/default/state create mode 100644 cdist/conf/type/__user_groups/parameter/default/state diff --git a/cdist/conf/type/__git/gencode-remote b/cdist/conf/type/__git/gencode-remote index d719a492..c4fc1ef2 100644 --- a/cdist/conf/type/__git/gencode-remote +++ b/cdist/conf/type/__git/gencode-remote @@ -23,22 +23,17 @@ state_is="$(cat "$__object/explorer/state")" owner_is="$(cat "$__object/explorer/owner")" group_is="$(cat "$__object/explorer/group")" -state_should=present -[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" +state_should="$(cat "$__object/parameter/state")" -branch=master -[ -f "$__object/parameter/branch" ] && branch="$(cat "$__object/parameter/branch")" +branch="$(cat "$__object/parameter/branch")" source="$(cat "$__object/parameter/source")" destination="/$__object_id" -owner="" -[ -f "$__object/parameter/owner" ] && owner="$(cat "$__object/parameter/owner")" -group="" -[ -f "$__object/parameter/group" ] && group="$(cat "$__object/parameter/group")" -mode="" -[ -f "$__object/parameter/mode" ] && mode="$(cat "$__object/parameter/mode")" +owner="$(cat "$__object/parameter/owner")" +group="$(cat "$__object/parameter/group")" +mode="$(cat "$__object/parameter/mode")" [ "$state_should" = "$state_is" -a \ "$owner" = "$owner_is" -a \ diff --git a/cdist/conf/type/__git/manifest b/cdist/conf/type/__git/manifest index 8d6a29e4..7f6fee84 100644 --- a/cdist/conf/type/__git/manifest +++ b/cdist/conf/type/__git/manifest @@ -23,8 +23,7 @@ __package git --state present -state_should=present -[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" +state_should="$(cat "$__object/parameter/state")" # Let __directory handle removal of git repos diff --git a/cdist/conf/type/__git/parameter/default/branch b/cdist/conf/type/__git/parameter/default/branch new file mode 100644 index 00000000..1f7391f9 --- /dev/null +++ b/cdist/conf/type/__git/parameter/default/branch @@ -0,0 +1 @@ +master diff --git a/cdist/conf/type/__git/parameter/default/group b/cdist/conf/type/__git/parameter/default/group new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__git/parameter/default/group @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__git/parameter/default/mode b/cdist/conf/type/__git/parameter/default/mode new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__git/parameter/default/mode @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__git/parameter/default/owner b/cdist/conf/type/__git/parameter/default/owner new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__git/parameter/default/owner @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__git/parameter/default/state b/cdist/conf/type/__git/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__git/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__jail/gencode-local b/cdist/conf/type/__jail/gencode-local index d6384156..08c7b7bf 100755 --- a/cdist/conf/type/__jail/gencode-local +++ b/cdist/conf/type/__jail/gencode-local @@ -22,17 +22,9 @@ # virtual machines. # -if [ -f "$__object/parameter/jaildir" ]; then - jaildir="$(cat "$__object/parameter/jaildir")" -else - jaildir="/usr/jail" -fi +jaildir="$(cat "$__object/parameter/jaildir")" -if [ -f "$__object/parameter/jailbase" ]; then - jailbase="$(cat "$__object/parameter/jailbase")" -else - jailbase="" -fi +jailbase="$(cat "$__object/parameter/jailbase")" state="$(cat "$__object/parameter/state")" diff --git a/cdist/conf/type/__jail/gencode-remote b/cdist/conf/type/__jail/gencode-remote index afbb81a5..141c8150 100755 --- a/cdist/conf/type/__jail/gencode-remote +++ b/cdist/conf/type/__jail/gencode-remote @@ -66,11 +66,7 @@ else devfsenable="true" fi -if [ -f "$__object/parameter/devfs-ruleset" ]; then - devfsruleset="$(cat "$__object/parameter/devfs-ruleset")" -else - devfsruleset="jailrules" -fi +devfsruleset="$(cat "$__object/parameter/devfs-ruleset")" # devfs_ruleset being defined without devfs_enable being true # is pointless. Treat this as an error. @@ -84,14 +80,11 @@ if [ -f "$__object/parameter/onboot" ]; then onboot="true" fi -if [ -f "$__object/parameter/jaildir" ]; then - jaildir="$(cat "$__object/parameter/jaildir")" -else - jaildir="/usr/jail" -fi +jaildir="$(cat "$__object/parameter/jaildir")" present="$(cat "$__object/explorer/present")" status="$(cat "$__object/explorer/status")" + # Handle ip="iface|addr, iface|addr" format if [ $(expr "${ip}" : ".*|.*") -gt "0" ]; then # If we have multiple IPs defined, $interface doesn't make sense because ip="iface|addr, iface|addr" implies it diff --git a/cdist/conf/type/__jail/manifest b/cdist/conf/type/__jail/manifest index cf5b7938..6a953241 100755 --- a/cdist/conf/type/__jail/manifest +++ b/cdist/conf/type/__jail/manifest @@ -33,11 +33,7 @@ if [ ! "$os" = "freebsd" ]; then exit 1 fi -if [ -f "$__object/parameter/jaildir" ]; then - jaildir="$(cat "$__object/parameter/jaildir")" -else - jaildir="/usr/jail" -fi +jaildir="$(cat "$__object/parameter/jaildir")" __directory ${jaildir} --parents diff --git a/cdist/conf/type/__jail/parameter/default/devfs-ruleset b/cdist/conf/type/__jail/parameter/default/devfs-ruleset new file mode 100644 index 00000000..f602aa0a --- /dev/null +++ b/cdist/conf/type/__jail/parameter/default/devfs-ruleset @@ -0,0 +1 @@ +jailrules diff --git a/cdist/conf/type/__jail/parameter/default/jailbase b/cdist/conf/type/__jail/parameter/default/jailbase new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__jail/parameter/default/jailbase @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__jail/parameter/default/jaildir b/cdist/conf/type/__jail/parameter/default/jaildir new file mode 100644 index 00000000..ec7d86c6 --- /dev/null +++ b/cdist/conf/type/__jail/parameter/default/jaildir @@ -0,0 +1 @@ +/usr/jail diff --git a/cdist/conf/type/__package_yum/gencode-remote b/cdist/conf/type/__package_yum/gencode-remote index 9c98c257..5f0e8ac8 100755 --- a/cdist/conf/type/__package_yum/gencode-remote +++ b/cdist/conf/type/__package_yum/gencode-remote @@ -27,11 +27,7 @@ else name="$__object_id" fi -if [ -f "$__object/parameter/state" ]; then - state_should="$(cat "$__object/parameter/state")" -else - state_should="present" -fi +state_should="$(cat "$__object/parameter/state")" if grep -q -E "(centos|redhat|amazon)" "$__global/explorer/os"; then opts="-y --quiet" diff --git a/cdist/conf/type/__package_yum/parameter/default/state b/cdist/conf/type/__package_yum/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__package_yum/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__package_zypper/gencode-remote b/cdist/conf/type/__package_zypper/gencode-remote index 51713590..d9f16f8d 100644 --- a/cdist/conf/type/__package_zypper/gencode-remote +++ b/cdist/conf/type/__package_zypper/gencode-remote @@ -34,17 +34,8 @@ else name="$__object_id" fi -if [ -f "$__object/parameter/state" ]; then - state_should="$(cat "$__object/parameter/state")" -else - state_should="present" -fi - -if [ -f "$__object/parameter/ptype" ]; then - ptype="$(cat "$__object/parameter/ptype")" -else - ptype="package" -fi +state_should="$(cat "$__object/parameter/state")" +ptype="$(cat "$__object/parameter/ptype")" if [ -f "$__object/parameter/version" ]; then version_should="$(cat "$__object/parameter/version")" diff --git a/cdist/conf/type/__package_zypper/parameter/default/state b/cdist/conf/type/__package_zypper/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__package_zypper/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__user_groups/gencode-remote b/cdist/conf/type/__user_groups/gencode-remote index c5e4a35e..9f11dd16 100755 --- a/cdist/conf/type/__user_groups/gencode-remote +++ b/cdist/conf/type/__user_groups/gencode-remote @@ -19,7 +19,7 @@ # user="$(cat "$__object/parameter/user" 2>/dev/null || echo "$__object_id")" -state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")" +state_should="$(cat "$__object/parameter/state")" mkdir "$__object/files" # file has to be sorted for comparison with `comm` diff --git a/cdist/conf/type/__user_groups/parameter/default/state b/cdist/conf/type/__user_groups/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__user_groups/parameter/default/state @@ -0,0 +1 @@ +present From 294285c164fdb212ea2fc6277c97fc877e889cb2 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 6 Feb 2014 00:08:40 +0100 Subject: [PATCH 04/16] import __ccollect_source type Signed-off-by: Nico Schottelius --- .../type/__ccollect_source/explorer/cksum | 34 +++++++ .../conf/type/__ccollect_source/explorer/stat | 47 ++++++++++ .../conf/type/__ccollect_source/explorer/type | 33 +++++++ .../type/__ccollect_source/gencode-remote | 93 +++++++++++++++++++ cdist/conf/type/__ccollect_source/man.text | 64 +++++++++++++ cdist/conf/type/__ccollect_source/manifest | 53 +++++++++++ .../type/__ccollect_source/parameter/boolean | 1 + .../parameter/default/ccollectconf | 1 + .../__ccollect_source/parameter/default/state | 1 + .../type/__ccollect_source/parameter/optional | 2 + .../parameter/optional_multiple | 1 + .../type/__ccollect_source/parameter/required | 2 + 12 files changed, 332 insertions(+) create mode 100755 cdist/conf/type/__ccollect_source/explorer/cksum create mode 100755 cdist/conf/type/__ccollect_source/explorer/stat create mode 100755 cdist/conf/type/__ccollect_source/explorer/type create mode 100755 cdist/conf/type/__ccollect_source/gencode-remote create mode 100644 cdist/conf/type/__ccollect_source/man.text create mode 100755 cdist/conf/type/__ccollect_source/manifest create mode 100644 cdist/conf/type/__ccollect_source/parameter/boolean create mode 100644 cdist/conf/type/__ccollect_source/parameter/default/ccollectconf create mode 100644 cdist/conf/type/__ccollect_source/parameter/default/state create mode 100644 cdist/conf/type/__ccollect_source/parameter/optional create mode 100644 cdist/conf/type/__ccollect_source/parameter/optional_multiple create mode 100644 cdist/conf/type/__ccollect_source/parameter/required diff --git a/cdist/conf/type/__ccollect_source/explorer/cksum b/cdist/conf/type/__ccollect_source/explorer/cksum new file mode 100755 index 00000000..335e4e7a --- /dev/null +++ b/cdist/conf/type/__ccollect_source/explorer/cksum @@ -0,0 +1,34 @@ +#!/bin/sh +# +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) +# +# 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 . +# +# +# Retrieve the md5sum of a file to be created, if it is already existing. +# + +destination="/$__object_id" + +if [ -e "$destination" ]; then + if [ -f "$destination" ]; then + cksum < "$destination" + else + echo "NO REGULAR FILE" + fi +else + echo "NO FILE FOUND, NO CHECKSUM CALCULATED." +fi diff --git a/cdist/conf/type/__ccollect_source/explorer/stat b/cdist/conf/type/__ccollect_source/explorer/stat new file mode 100755 index 00000000..298221b7 --- /dev/null +++ b/cdist/conf/type/__ccollect_source/explorer/stat @@ -0,0 +1,47 @@ +#!/bin/sh +# +# 2013 Steven Armstrong (steven-cdist armstrong.cc) +# +# 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 . +# + +destination="/$__object_id" + +# nothing to work with, nothing we could do +[ -e "$destination" ] || exit 0 + +os=$("$__explorer/os") +case "$os" in + "freebsd") + # FIXME: should be something like this based on man page, but can not test + stat -f "type: %ST +owner: %Du %Su +group: %Dg %Sg +mode: %Op %Sp +size: %Dz +links: %Dl +" "$destination" + ;; + *) + stat --printf="type: %F +owner: %u %U +group: %g %G +mode: %a %A +size: %s +links: %h +" "$destination" + ;; +esac diff --git a/cdist/conf/type/__ccollect_source/explorer/type b/cdist/conf/type/__ccollect_source/explorer/type new file mode 100755 index 00000000..e723047c --- /dev/null +++ b/cdist/conf/type/__ccollect_source/explorer/type @@ -0,0 +1,33 @@ +#!/bin/sh +# +# 2013 Steven Armstrong (steven-cdist armstrong.cc) +# +# 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 . +# + +destination="/$__object_id" + +if [ ! -e "$destination" ]; then + echo none +elif [ -h "$destination" ]; then + echo symlink +elif [ -f "$destination" ]; then + echo file +elif [ -d "$destination" ]; then + echo directory +else + echo unknown +fi diff --git a/cdist/conf/type/__ccollect_source/gencode-remote b/cdist/conf/type/__ccollect_source/gencode-remote new file mode 100755 index 00000000..c41b5179 --- /dev/null +++ b/cdist/conf/type/__ccollect_source/gencode-remote @@ -0,0 +1,93 @@ +#!/bin/sh +# +# 2014 Nico Schottelius (nico-cdist at schottelius.org) +# +# 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 . +# + +destination="/$__object_id" +state_should="$(cat "$__object/parameter/state")" +type="$(cat "$__object/explorer/type")" +stat_file="$__object/explorer/stat" + + +get_current_value() { + if [ -s "$stat_file" ]; then + _name="$1" + _value="$2" + case "$_value" in + [0-9]*) + _index=2 + ;; + *) + _index=3 + ;; + esac + awk '/'"$_name"':/ { print $'$_index' }' "$stat_file" + unset _name _value _index + fi +} + +set_group() { + echo chgrp \"$1\" \"$destination\" + echo chgrp $1 >> "$__messages_out" +} + +set_owner() { + echo chown \"$1\" \"$destination\" + echo chown $1 >> "$__messages_out" +} + +set_mode() { + echo chmod \"$1\" \"$destination\" + echo chmod $1 >> "$__messages_out" +} + +set_attributes= +case "$state_should" in + present|exists) + # Note: Mode - needs to happen last as a chown/chgrp can alter mode by + # clearing S_ISUID and S_ISGID bits (see chown(2)) + for attribute in group owner mode; do + if [ -f "$__object/parameter/$attribute" ]; then + value_should="$(cat "$__object/parameter/$attribute")" + + # change 0xxx format to xxx format => same as stat returns + if [ "$attribute" = mode ]; then + value_should="$(echo $value_should | sed 's/^0\(...\)/\1/')" + fi + + value_is="$(get_current_value "$attribute" "$value_should")" + if [ -f "$__object/files/set-attributes" -o "$value_should" != "$value_is" ]; then + "set_$attribute" "$value_should" + fi + fi + done + + ;; + + absent) + if [ "$type" = "file" ]; then + echo rm -f \"$destination\" + echo remove >> "$__messages_out" + fi + ;; + + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__ccollect_source/man.text b/cdist/conf/type/__ccollect_source/man.text new file mode 100644 index 00000000..32a7467e --- /dev/null +++ b/cdist/conf/type/__ccollect_source/man.text @@ -0,0 +1,64 @@ +cdist-type__ccollect_source(7) +============================== +Nico Schottelius + + +NAME +---- +cdist-type__ccollect_source - Manage ccollect sources + + +DESCRIPTION +----------- +This cdist type allows you to create or delete ccollect sources. + +REQUIRED PARAMETERS +------------------- +source:: + The source from which to backup +destination:: + The destination directory + + +OPTIONAL PARAMETERS +------------------- +state:: + 'present' or 'absent', defaults to 'present' +ccollectconf:: + The CCOLLECT_CONF directory. Defaults to /etc/ccollect. + + +OPTIONAL MULTIPLE PARAMETERS +---------------------------- +exclude:: + Paths to exclude of backup + +BOOLEAN PARAMETERS +------------------ +verbose:: + Whether to report backup verbosely + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__ccollect_source doc.ungleich.ch \ + --source doc.ungleich.ch:/ \ + --destination /backup/doc.ungleich.ch \ + --exclude '/proc/*' --exclude '/sys/*' \ + --verbose + +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- ccollect(1) +- http://www.nico.schottelius.org/software/ccollect/ + + +COPYING +------- +Copyright \(C) 2014 Nico Schottelius. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__ccollect_source/manifest b/cdist/conf/type/__ccollect_source/manifest new file mode 100755 index 00000000..89c2ef2b --- /dev/null +++ b/cdist/conf/type/__ccollect_source/manifest @@ -0,0 +1,53 @@ +#!/bin/sh +# +# 2014 Nico Schottelius (nico-cdist at schottelius.org) +# +# 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 . +# + +name="$__object_id" +state="$(cat "$__object/parameter/state")" +source="$(cat "$__object/parameter/source")" +destination="$(cat "$__object/parameter/destination")" +ccollectconf="$(cat "$__object/parameter/ccollectconf" | sed 's,/$,,')" + +sourcedir="$ccollectconf/sources" +basedir="$sourcedir/$name" + +destination_file="$basedir/destination" +source_file="$basedir/source" +exclude_file="$basedir/exclude" +verbose_file="$basedir/verbose" + +__directory "$basedir" --state "$state" + +export require="__directory$basedir" +echo "$destination" | __file "$destination_file" --source - --state "$state" +echo "$source" | __file "$source_file" --source - --state "$state" + +################################################################################ +# Booleans +if [ -f "$__object/parameter/verbose" ]; then + verbosestate="present" +else + verbosestate="absent" +fi +__file "$verbose_file" --state "$verbosestate" + +if [ -f "$__object/parameter/exclude" ]; then + __file "$exclude_file" --source - --state "$state" \ + < "$__object/parameter/exclude" +fi diff --git a/cdist/conf/type/__ccollect_source/parameter/boolean b/cdist/conf/type/__ccollect_source/parameter/boolean new file mode 100644 index 00000000..c00ee94a --- /dev/null +++ b/cdist/conf/type/__ccollect_source/parameter/boolean @@ -0,0 +1 @@ +verbose diff --git a/cdist/conf/type/__ccollect_source/parameter/default/ccollectconf b/cdist/conf/type/__ccollect_source/parameter/default/ccollectconf new file mode 100644 index 00000000..a9fda009 --- /dev/null +++ b/cdist/conf/type/__ccollect_source/parameter/default/ccollectconf @@ -0,0 +1 @@ +/etc/ccollect diff --git a/cdist/conf/type/__ccollect_source/parameter/default/state b/cdist/conf/type/__ccollect_source/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__ccollect_source/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__ccollect_source/parameter/optional b/cdist/conf/type/__ccollect_source/parameter/optional new file mode 100644 index 00000000..0249d11e --- /dev/null +++ b/cdist/conf/type/__ccollect_source/parameter/optional @@ -0,0 +1,2 @@ +ccollectconf +state diff --git a/cdist/conf/type/__ccollect_source/parameter/optional_multiple b/cdist/conf/type/__ccollect_source/parameter/optional_multiple new file mode 100644 index 00000000..9ba870ea --- /dev/null +++ b/cdist/conf/type/__ccollect_source/parameter/optional_multiple @@ -0,0 +1 @@ +exclude diff --git a/cdist/conf/type/__ccollect_source/parameter/required b/cdist/conf/type/__ccollect_source/parameter/required new file mode 100644 index 00000000..9239646e --- /dev/null +++ b/cdist/conf/type/__ccollect_source/parameter/required @@ -0,0 +1,2 @@ +source +destination From c1d2ceefc2ed2d294927f18335f47ab14ef6b154 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 6 Feb 2014 00:10:02 +0100 Subject: [PATCH 05/16] ++changes Signed-off-by: Nico Schottelius --- docs/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog b/docs/changelog index 9c222384..7d693496 100644 --- a/docs/changelog +++ b/docs/changelog @@ -10,6 +10,7 @@ Changelog * New Type: __apt_key_uri (Steven Armstrong) * New Type: __apt_norecommends (Steven Armstrong) * New Type: __apt_source (Steven Armstrong) + * New Type: __ccollect_source 3.0.5: 2014-02-05 From 98e7b7644cd9ae031b89c6ed604ac589e2adc0cd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 6 Feb 2014 11:35:45 +0100 Subject: [PATCH 06/16] release 3.0.6 Signed-off-by: Nico Schottelius --- docs/changelog | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index 7d693496..e07f14ff 100644 --- a/docs/changelog +++ b/docs/changelog @@ -5,12 +5,17 @@ Changelog * Exception: No braces means author == Nico Schottelius -3.0.6: +3.0.6: 2014-02-06 * New Type: __apt_key (Steven Armstrong) * New Type: __apt_key_uri (Steven Armstrong) * New Type: __apt_norecommends (Steven Armstrong) * New Type: __apt_source (Steven Armstrong) * New Type: __ccollect_source + * Type __git: Use default parameters (Daniel Heule) + * Type __jail: Use default parameters (Daniel Heule) + * Type __package_yum: Use default parameters (Daniel Heule) + * Type __package_zypper: Use default parameters (Daniel Heule) + * Type __user_groups: Use default parameters (Daniel Heule) 3.0.5: 2014-02-05 From 51afca5336464dc65ed183bf83c21e718d167db0 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 6 Feb 2014 15:26:17 +0100 Subject: [PATCH 07/16] Implement lastest suggestions from nico, rename ENV Variable to CDIST_ORDER_DEPENDENCY --- cdist/emulator.py | 5 ++--- docs/man/man7/cdist-manifest.text | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cdist/emulator.py b/cdist/emulator.py index 2c3c12a4..203c97e5 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -189,9 +189,8 @@ class Emulator(object): def record_requirements(self): """record requirements""" - #from pudb import set_trace; set_trace(); - if "EXECUTE_TYPES_IN_CREATION_ORDER" in self.env and self.env['EXECUTE_TYPES_IN_CREATION_ORDER'] == 'true': + if "CDIST_ORDER_DEPENDENCY" in self.env: # load object name created bevor this one from typeorder file ... with open(self.typeorder_path, 'r') as typecreationfile: typecreationorder = typecreationfile.readlines() @@ -202,7 +201,7 @@ class Emulator(object): self.env['require'] += " " + lastcreatedtype else: self.env['require'] = lastcreatedtype - self.log.debug("Injecting require for EXECUTE_TYPES_IN_CREATION_ORDER: %s for %s", lastcreatedtype, self.cdist_object.name) + self.log.debug("Injecting require for CDIST_ORDER_DEPENDENCY: %s for %s", lastcreatedtype, self.cdist_object.name) except IndexError: # if no second last line, we are on the first type, so do not set a requirement pass diff --git a/docs/man/man7/cdist-manifest.text b/docs/man/man7/cdist-manifest.text index 8ae8f966..66a4cd2a 100644 --- a/docs/man/man7/cdist-manifest.text +++ b/docs/man/man7/cdist-manifest.text @@ -142,19 +142,19 @@ into an undefined situation. THIS IS A BETA FEATURE AND MAY BE REMOVED AT ANY TIME. -EXECUTE_TYPES_IN_CREATION_ORDER is a EXPERIMENTAL FEATURE ! +CDIST_ORDER_DEPENDENCY is a EXPERIMENTAL FEATURE ! You can tell cdist to execute all types in the order in which they are created -in the manifest by exporting EXECUTE_TYPES_IN_CREATION_ORDER with the value true. +in the manifest by exporting CDIST_ORDER_DEPENDENCY. -------------------------------------------------------------------------------- # Tells cdist to execute all types in the order in which they are created ... -export EXECUTE_TYPES_IN_CREATION_ORDER=true +export CDIST_ORDER_DEPENDENCY=on __sample_type 1 require="__some_type_somewhere/id" __sample_type 2 __example_type 23 # Now this types are executed in the creation order until the variable is unset -unset EXECUTE_TYPES_IN_CREATION_ORDER +unset CDIST_ORDER_DEPENDENCY # all now following types cdist makes the order .. __not_in_order_type 42 From 724385fcf38a0ee94009250e434c02dc941530d4 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 6 Feb 2014 15:55:41 +0100 Subject: [PATCH 08/16] update manifest document for in order execution Signed-off-by: Nico Schottelius --- docs/man/man7/cdist-manifest.text | 67 ++++++++++++++++++------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/docs/man/man7/cdist-manifest.text b/docs/man/man7/cdist-manifest.text index 66a4cd2a..fbdab849 100644 --- a/docs/man/man7/cdist-manifest.text +++ b/docs/man/man7/cdist-manifest.text @@ -128,6 +128,19 @@ All objects that are created in a type manifest are automatically required from the type that is calling them. This is called "autorequirement" in cdist jargon. +CREATE DEPENDENCIES FROM EXECUTION ORDER +----------------------------------------- +You can tell cdist to execute all types in the order in which they are created +in the manifest by setting up the variable CDIST_ORDER_DEPENDENCY. +When cdist sees that this variable is setup, the current created object +automatically depends on the previously created object. + +It essentially helps you to build up blocks of code that build upon each other +(like first creating the directory xyz than the file below the directory). + +THIS IS A BETA FEATURE AND MAY BE REMOVED OR CHANGED AT ANY TIME. + + OVERRIDES --------- In some special cases, you would like to create an already defined object @@ -139,33 +152,7 @@ ATTENTION: Only use this feature if you are 100% sure in which order cdist encounter the affected objects, otherwhise this results into an undefined situation. -THIS IS A BETA FEATURE AND MAY BE REMOVED AT ANY TIME. - - -CDIST_ORDER_DEPENDENCY is a EXPERIMENTAL FEATURE ! -You can tell cdist to execute all types in the order in which they are created -in the manifest by exporting CDIST_ORDER_DEPENDENCY. - --------------------------------------------------------------------------------- - -# Tells cdist to execute all types in the order in which they are created ... -export CDIST_ORDER_DEPENDENCY=on -__sample_type 1 -require="__some_type_somewhere/id" __sample_type 2 -__example_type 23 -# Now this types are executed in the creation order until the variable is unset -unset CDIST_ORDER_DEPENDENCY -# all now following types cdist makes the order .. -__not_in_order_type 42 - -# how it works : -# this lines above are translated to: -__sample_type 1 -require="__some_type_somewhere/id __sample_type/1" __sample_type 2 -require="__sample_type/2" __example_type 23 -__not_in_order_type 42 - --------------------------------------------------------------------------------- +THIS IS A BETA FEATURE AND MAY BE REMOVED OR CHANGED AT ANY TIME. @@ -223,6 +210,30 @@ CDIST_ALLOW_OVERRIDE=yes __user foobar --password 'some_other_hash' # and stay at the original value of /home/foobarexample -------------------------------------------------------------------------------- +Dependencies defined by execution order work as following: + +-------------------------------------------------------------------------------- + +# Tells cdist to execute all types in the order in which they are created ... +export CDIST_ORDER_DEPENDENCY=on +__sample_type 1 +require="__some_type_somewhere/id" __sample_type 2 +__example_type 23 +# Now this types are executed in the creation order until the variable is unset +unset CDIST_ORDER_DEPENDENCY +# all now following types cdist makes the order .. +__not_in_order_type 42 + +# how it works : +# this lines above are translated to: +__sample_type 1 +require="__some_type_somewhere/id __sample_type/1" __sample_type 2 +require="__sample_type/2" __example_type 23 +__not_in_order_type 42 + +-------------------------------------------------------------------------------- + + SEE ALSO -------- @@ -232,5 +243,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2010-2012 Nico Schottelius. Free use of this software is +Copyright \(C) 2010-2014 Nico Schottelius. Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3). From 49764ae5c77953273e801b928bdb126b01320eec Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 6 Feb 2014 15:58:25 +0100 Subject: [PATCH 09/16] ++changes Signed-off-by: Nico Schottelius --- docs/changelog | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/changelog b/docs/changelog index e07f14ff..120d8e87 100644 --- a/docs/changelog +++ b/docs/changelog @@ -5,6 +5,9 @@ Changelog * Exception: No braces means author == Nico Schottelius +3.0.7: + * Core: Add support for in order execution (Daniel Heule) + 3.0.6: 2014-02-06 * New Type: __apt_key (Steven Armstrong) * New Type: __apt_key_uri (Steven Armstrong) @@ -17,13 +20,11 @@ Changelog * Type __package_zypper: Use default parameters (Daniel Heule) * Type __user_groups: Use default parameters (Daniel Heule) - 3.0.5: 2014-02-05 * Core: Introduce override concept (Daniel Heule) * Type __process: Make --state absent work (Steven Armstrong) * Documentation: Update documentation for environment variables - 3.0.4: 2014-01-29 * Core: Ignore install types in config mode * Documentation: Update reference (files path in object space) @@ -32,7 +33,6 @@ Changelog * Type __debconf_set_selections: Support --file - to read from stdin * Type __jail: Fix jaildir parameter handling (Jake Guffey) - 3.0.3: 2014-01-22 * Core: Enhance error message when requirement is missing object id * Core: Add environment variable to select shell for executing scripts (Daniel Heule) @@ -45,7 +45,6 @@ Changelog * Type __zypper_repo: Use default paremeters (Daniel Heule) * Type __zypper_service: Use default paremeters (Daniel Heule) - 3.0.2: 2014-01-19 * Documentation: Document all messages sent by types (Daniel Heule) * New Type: __block (Steven Armstrong) @@ -53,7 +52,6 @@ Changelog * Type __cron: Replace existing entry when changing it (Daniel Heule) * Type __ssh_authorized_keys: Use new type __block (Steven Armstrong) - 3.0.1: 2014-01-14 * Core: Copy only files, not directories (Steven Armstrong) * Core: Allow hostnames to start with / From 52e2017d8feedfd035838a6c186c119fa713cf88 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 6 Feb 2014 16:03:07 +0100 Subject: [PATCH 10/16] CDIST_ALLOW_OVERRIDE -> CDIST_OVERRIDE as requested by nico --- cdist/emulator.py | 4 ++-- docs/man/man7/cdist-manifest.text | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cdist/emulator.py b/cdist/emulator.py index 4f91cd8e..1e8701cf 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -145,14 +145,14 @@ class Emulator(object): if value is not None: self.parameters[key] = value - if self.cdist_object.exists and not 'CDIST_ALLOW_OVERRIDE' in os.environ: + if self.cdist_object.exists and not 'CDIST_OVERRIDE' in os.environ: if self.cdist_object.parameters != self.parameters: raise cdist.Error("Object %s already exists with conflicting parameters:\n%s: %s\n%s: %s" % (self.cdist_object.name, " ".join(self.cdist_object.source), self.cdist_object.parameters, self.object_source, self.parameters) ) else: if self.cdist_object.exists: - self.log.debug('Object %s override forced with CDIST_ALLOW_OVERRIDE',self.cdist_object.name) + self.log.debug('Object %s override forced with CDIST_OVERRIDE',self.cdist_object.name) self.cdist_object.create(True) else: self.cdist_object.create() diff --git a/docs/man/man7/cdist-manifest.text b/docs/man/man7/cdist-manifest.text index 7f1b95dc..cfbd8bea 100644 --- a/docs/man/man7/cdist-manifest.text +++ b/docs/man/man7/cdist-manifest.text @@ -133,7 +133,7 @@ OVERRIDES --------- In some special cases, you would like to create an already defined object with different parameters. In normal situations this leads to an error in cdist. -If you whish, you can setup the environment variable CDIST_ALLOW_OVERRIDE +If you whish, you can setup the environment variable CDIST_OVERRIDE (any value or even empty is ok) to tell cdist, that this object override is wanted and should be accepted. ATTENTION: Only use this feature if you are 100% sure in which order @@ -190,7 +190,7 @@ __user foobar --password 'some_fancy_hash' --home /home/foobarexample __user foobar --password 'some_other_hash' # this tells cdist, that you know that this is an override and should be accepted -CDIST_ALLOW_OVERRIDE=yes __user foobar --password 'some_other_hash' +CDIST_OVERRIDE=yes __user foobar --password 'some_other_hash' # its only an override, means the parameter --home is not touched # and stay at the original value of /home/foobarexample -------------------------------------------------------------------------------- From 2fa174f6ead4c4fb81af2b8618f9c668723f2789 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 6 Feb 2014 17:02:14 +0100 Subject: [PATCH 11/16] update link to ungleich Signed-off-by: Nico Schottelius --- docs/web/cdist/support.mdwn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/web/cdist/support.mdwn b/docs/web/cdist/support.mdwn index 7515070d..39388c5a 100644 --- a/docs/web/cdist/support.mdwn +++ b/docs/web/cdist/support.mdwn @@ -20,6 +20,6 @@ you can join the ### Commercial support You can request commercial support for cdist from -[my company](http://firma.schottelius.org/english/). +[my company](http://www.ungleich.ch/english/). [[!tag cdist unix]] From 717e21da6c6a93fa77c3da65641b217718d464bd Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Fri, 7 Feb 2014 00:28:02 +0100 Subject: [PATCH 12/16] initial update for override unittests --- cdist/test/emulator/__init__.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index 8c2dcd72..d2bf4cf2 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -100,6 +100,7 @@ class EmulatorTestCase(test.CdistTestCase): argv = ['__file', '/tmp/foobar'] self.env['require'] = '__file/etc/*' emu = emulator.Emulator(argv, env=self.env) + emu.run() # if we get here all is fine @@ -129,6 +130,33 @@ class AutoRequireEmulatorTestCase(test.CdistTestCase): expected = ['__planet/Saturn', '__moon/Prometheus'] self.assertEqual(sorted(cdist_object.autorequire), sorted(expected)) +class OverrideTestCase(test.CdistTestCase): + + def setUp(self): + self.temp_dir = self.mkdtemp() + handle, self.script = self.mkstemp(dir=self.temp_dir) + os.close(handle) + base_path = self.temp_dir + + self.local = local.Local( + target_host=self.target_host, + base_path=base_path, + exec_path=test.cdist_exec_path, + add_conf_dirs=[conf_dir]) + self.local.create_files_dirs() + + self.manifest = core.Manifest(self.target_host, self.local) + self.env = self.manifest.env_initial_manifest(self.script) + + def tearDown(self): + shutil.rmtree(self.temp_dir) + + def test_override(self): + argv = ['__file', '/tmp/foobar'] + self.env['require'] = '__file/etc/*' + emu = emulator.Emulator(argv, env=self.env) + # if we get here all is fine + class ArgumentsTestCase(test.CdistTestCase): @@ -182,7 +210,7 @@ class ArgumentsTestCase(test.CdistTestCase): object_id = 'some-id' value = 'some value' argv = [type_name, object_id, '--required1', value, '--required2', value] - print(self.env) +# print(self.env) os.environ.update(self.env) emu = emulator.Emulator(argv) emu.run() From f163b327205949f584cb90730be1276e0f1d2265 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Fri, 7 Feb 2014 13:28:22 +0100 Subject: [PATCH 13/16] first try of a test --- cdist/test/emulator/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index d2bf4cf2..57874f9d 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -100,7 +100,6 @@ class EmulatorTestCase(test.CdistTestCase): argv = ['__file', '/tmp/foobar'] self.env['require'] = '__file/etc/*' emu = emulator.Emulator(argv, env=self.env) - emu.run() # if we get here all is fine @@ -155,6 +154,11 @@ class OverrideTestCase(test.CdistTestCase): argv = ['__file', '/tmp/foobar'] self.env['require'] = '__file/etc/*' emu = emulator.Emulator(argv, env=self.env) + emu.run() + argv = ['__file', '/tmp/foobar'] + self.env['require'] = '__file/etc/*' + emu = emulator.Emulator(argv, env=self.env) + emu.run() # if we get here all is fine From 60c53e213c6961ea7d19731df2a0309095d5897c Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Fri, 7 Feb 2014 14:24:12 +0100 Subject: [PATCH 14/16] testcases emulator.OverrideTestCase, with some minor bugfixes to make test work as expected ... --- cdist/emulator.py | 3 +-- cdist/test/cdist_object/__init__.py | 4 ++-- cdist/test/cdist_type/__init__.py | 4 ++-- cdist/test/emulator/__init__.py | 15 +++++++++++---- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cdist/emulator.py b/cdist/emulator.py index 7fd89110..c910531c 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -130,7 +130,6 @@ class Emulator(object): self.args = parser.parse_args(self.argv[1:]) self.log.debug('Args: %s' % self.args) - def setup_object(self): # Setup object_id - FIXME: unset / do not setup anymore! if not self.cdist_type.is_singleton: @@ -146,7 +145,7 @@ class Emulator(object): if value is not None: self.parameters[key] = value - if self.cdist_object.exists and not 'CDIST_OVERRIDE' in os.environ: + if self.cdist_object.exists and not 'CDIST_OVERRIDE' in self.env: if self.cdist_object.parameters != self.parameters: raise cdist.Error("Object %s already exists with conflicting parameters:\n%s: %s\n%s: %s" % (self.cdist_object.name, " ".join(self.cdist_object.source), self.cdist_object.parameters, self.object_source, self.parameters) diff --git a/cdist/test/cdist_object/__init__.py b/cdist/test/cdist_object/__init__.py index 54ecf637..0e2da103 100644 --- a/cdist/test/cdist_object/__init__.py +++ b/cdist/test/cdist_object/__init__.py @@ -58,10 +58,10 @@ class ObjectClassTestCase(test.CdistTestCase): def test_list_type_names(self): type_names = list(cdist.core.CdistObject.list_type_names(object_base_path)) - self.assertEqual(type_names, ['__first', '__second', '__third']) + self.assertEqual(sorted(type_names), ['__first', '__second', '__third']) def test_list_objects(self): - found_objects = list(core.CdistObject.list_objects(object_base_path, type_base_path)) + found_objects = sorted(list(core.CdistObject.list_objects(object_base_path, type_base_path))) self.assertEqual(found_objects, self.expected_objects) def test_create_singleton(self): diff --git a/cdist/test/cdist_type/__init__.py b/cdist/test/cdist_type/__init__.py index 79f824d3..36a524b4 100644 --- a/cdist/test/cdist_type/__init__.py +++ b/cdist/test/cdist_type/__init__.py @@ -34,7 +34,7 @@ class TypeTestCase(test.CdistTestCase): def test_list_type_names(self): base_path = op.join(fixtures, 'list_types') type_names = core.CdistType.list_type_names(base_path) - self.assertEqual(type_names, ['__first', '__second', '__third']) + self.assertEqual(sorted(type_names), ['__first', '__second', '__third']) def test_list_types(self): base_path = op.join(fixtures, 'list_types') @@ -44,7 +44,7 @@ class TypeTestCase(test.CdistTestCase): core.CdistType(base_path, '__second'), core.CdistType(base_path, '__third'), ] - self.assertEqual(types, types_expected) + self.assertEqual(sorted(types), types_expected) def test_only_one_instance(self): base_path = fixtures diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index 57874f9d..95c189d6 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -2,6 +2,7 @@ # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) # 2012-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2014 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. # @@ -150,16 +151,22 @@ class OverrideTestCase(test.CdistTestCase): def tearDown(self): shutil.rmtree(self.temp_dir) - def test_override(self): + def test_override_negative(self): argv = ['__file', '/tmp/foobar'] - self.env['require'] = '__file/etc/*' emu = emulator.Emulator(argv, env=self.env) emu.run() + argv = ['__file', '/tmp/foobar','--mode','404'] + emu = emulator.Emulator(argv, env=self.env) + self.assertRaises(cdist.Error, emu.run) + + def test_override_feature(self): argv = ['__file', '/tmp/foobar'] - self.env['require'] = '__file/etc/*' emu = emulator.Emulator(argv, env=self.env) emu.run() - # if we get here all is fine + argv = ['__file', '/tmp/foobar','--mode','404'] + self.env['CDIST_OVERRIDE'] = 'on' + emu = emulator.Emulator(argv, env=self.env) + emu.run() class ArgumentsTestCase(test.CdistTestCase): From f87fc63a7960a7efe42d354d64c3cfaf97c47942 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 8 Feb 2014 00:13:33 +0100 Subject: [PATCH 15/16] cdist 3.0.7 Signed-off-by: Nico Schottelius --- docs/changelog | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/changelog b/docs/changelog index 120d8e87..2bbe4edf 100644 --- a/docs/changelog +++ b/docs/changelog @@ -5,8 +5,9 @@ Changelog * Exception: No braces means author == Nico Schottelius -3.0.7: - * Core: Add support for in order execution (Daniel Heule) +3.0.7: 2014-02-08 + * Core: Allow dependencies to be created based execution order (Daniel Heule) + * Core: Add tests for override (Daniel Heule) 3.0.6: 2014-02-06 * New Type: __apt_key (Steven Armstrong) From 77df0ae324c95874f543bba213a54723771d2271 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 8 Feb 2014 00:14:42 +0100 Subject: [PATCH 16/16] update reference Signed-off-by: Nico Schottelius --- docs/man/cdist-reference.text.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/man/cdist-reference.text.sh b/docs/man/cdist-reference.text.sh index 5de59eab..88a002df 100755 --- a/docs/man/cdist-reference.text.sh +++ b/docs/man/cdist-reference.text.sh @@ -239,6 +239,9 @@ require:: CDIST_ALLOW_OVERRIDE:: Allow overwriting type parameters (see cdist-manifest(7)) +CDIST_ORDER_DEPENDENCY:: + Create dependencies based on the execution order (see cdist-manifest(7)) + SEE ALSO -------- - cdist(1) @@ -246,6 +249,6 @@ SEE ALSO COPYING ------- -Copyright \(C) 2011-2013 Nico Schottelius. Free use of this software is +Copyright \(C) 2011-2014 Nico Schottelius. Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3). eof