From 66224f5bdc5b94595708c8c1c7fb95753c03b791 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 25 Oct 2012 23:51:45 +0200 Subject: [PATCH 01/95] add some urls Signed-off-by: Nico Schottelius --- doc/dev/logs/2012-05-23.urls | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 doc/dev/logs/2012-05-23.urls diff --git a/doc/dev/logs/2012-05-23.urls b/doc/dev/logs/2012-05-23.urls new file mode 100644 index 00000000..e37407b3 --- /dev/null +++ b/doc/dev/logs/2012-05-23.urls @@ -0,0 +1,5 @@ +http://nu-ex.com/cv.html + +https://lists.metalab.at/pipermail/devops/2012-January/000089.html + +http://www.ir0nik.com/wordpress/?p=121 From 081d3aea37ab23fad42bc64d83e9ac23cb64ae60 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 11:09:45 +0100 Subject: [PATCH 02/95] remove manifests, which are not needed anymore (in production without them for some months) Signed-off-by: Nico Schottelius --- cdist/conf/type/__rvm_gem/manifest | 38 ------------ cdist/conf/type/__rvm_gemset/manifest | 36 ------------ cdist/conf/type/__rvm_ruby/manifest | 83 --------------------------- 3 files changed, 157 deletions(-) delete mode 100755 cdist/conf/type/__rvm_gem/manifest delete mode 100755 cdist/conf/type/__rvm_gemset/manifest delete mode 100755 cdist/conf/type/__rvm_ruby/manifest diff --git a/cdist/conf/type/__rvm_gem/manifest b/cdist/conf/type/__rvm_gem/manifest deleted file mode 100755 index a551472d..00000000 --- a/cdist/conf/type/__rvm_gem/manifest +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# -# 2012 Evax Software -# -# 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 . -# - -gem="$__object_id" -gemset="$(cat "$__object/parameter/gemset")" -ruby="$(echo "$gemset" | cut -d '@' -f 1)" -gemsetname="$(echo "$gemset" | cut -d '@' -f 2)" -user="$(cat "$__object/parameter/user")" -state="$(cat "$__object/explorer/state")" -if [ -f "$__object/parameter/default" ]; then - default="$(cat "$__object/parameter/default")" -else - default="no" - echo $default > "$__object/parameter/default" -fi - -__rvm "$user" --state present -require="__rvm/$user" \ - __rvm_ruby $ruby --user "$user" --state present --default $default -require="__rvm_ruby/$ruby" \ - __rvm_gemset $gemset --user "$user" --state present --default $default diff --git a/cdist/conf/type/__rvm_gemset/manifest b/cdist/conf/type/__rvm_gemset/manifest deleted file mode 100755 index b69395ea..00000000 --- a/cdist/conf/type/__rvm_gemset/manifest +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# -# 2012 Evax Software -# -# 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 . -# - -gemset="$__object_id" -ruby="$(echo "$gemset" | cut -d '@' -f 1)" -gemsetname="$(echo "$gemset" | cut -d '@' -f 2)" -user="$(cat "$__object/parameter/user")" -state="$(cat "$__object/explorer/state")" -if [ -f "$__object/parameter/default" ]; then - default="$(cat "$__object/parameter/default")" -else - default="no" - echo $default > "$__object/parameter/default" -fi - -__rvm "$user" --state present -require="__rvm/$user" \ - __rvm_ruby $ruby --user "$user" --state present --default $default - diff --git a/cdist/conf/type/__rvm_ruby/manifest b/cdist/conf/type/__rvm_ruby/manifest deleted file mode 100755 index 581e98a8..00000000 --- a/cdist/conf/type/__rvm_ruby/manifest +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/sh -# -# 2012 Evax Software -# -# 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/default" ]; then - default="$(cat "$__object/parameter/default")" -else - default="no" - echo "$default" > "$__object/parameter/default" -fi - -ruby="$__object_id" -user="$(cat "$__object/parameter/user")" -state="$(cat "$__object/explorer/state")" - -apt_ruby="build-essential openssl libreadline6 libreadline6-dev curl git-core -zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 -libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison -subversion" -apt_jruby="curl g++ openjdk-6-jre-headless" -apt_jruby_head="ant openjdk-6-jdk" -apt_ironruby="curl mono-2.0-devel" - -emerge_ruby="libiconv readline zlib openssl curl git libyaml sqlite libxslt -libtool gcc autoconf automake bison m4" -emerge_jruby="dev-java/sun-jdk dev-java/sun-jre-bin" -emerge_ironruby="dev-lang/mono" - -pacman_ruby="gcc patch curl zlib readline libxml2 libxslt git autoconf -diffutils make libtool bison subversion" -pacman_jruby="jdk jre curl" -pacman_ironruby="mono" - -yum_ruby="gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel -libffi-devel openssl-devel make bzip2 autoconf automake libtool bison -iconv-devel" -yum_jruby="java" - -os="$(cat "$__global/explorer/os")" -case "$os" in - archlinux) type="pacman" ;; - debian|ubuntu) type="apt" ;; - gentoo) type="emerge" ;; - fedora|redhat|centos) type="yum" ;; - *);; -esac -case "$ruby" in - ruby-head*) - deps_list="${type}_ruby_head" - ;; - ruby*) - deps_list="${type}_ruby" - ;; - jruby-head*) - deps_list="${type}_jruby_head" - ;; - jruby*) - deps_list="${type}_jruby" - ;; - ironruby*) - deps_list="${type}_ironruby" - ;; -esac -deps=$(eval echo \$$deps_list) -for p in $deps; do __package_${type} $p --state present; done - -__rvm "$user" --state present From 6771a13758820813af402e47f5c4ace4be854d65 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 13:30:45 +0100 Subject: [PATCH 03/95] pass exec_path from context to local, making it obsolete to manually add the argument to the _link_types_for_emulator Signed-off-by: Nico Schottelius --- cdist/config_install.py | 1 - cdist/context.py | 2 +- cdist/exec/local.py | 15 +++++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cdist/config_install.py b/cdist/config_install.py index b7804a10..2c1edc44 100644 --- a/cdist/config_install.py +++ b/cdist/config_install.py @@ -79,7 +79,6 @@ class ConfigInstall(object): def stage_prepare(self): """Do everything for a deploy, minus the actual code stage""" - self.local.link_emulator(self.context.exec_path) self.explorer.run_global_explorers(self.local.global_explorer_out_path) self.manifest.run_initial_manifest(self.context.initial_manifest) diff --git a/cdist/context.py b/cdist/context.py index 5fec530f..d3e30dec 100644 --- a/cdist/context.py +++ b/cdist/context.py @@ -59,7 +59,7 @@ class Context(object): self.temp_dir = tempfile.mkdtemp() self.out_path = os.path.join(self.temp_dir, "out") - self.local = local.Local(self.target_host, conf_dirs, self.out_path) + self.local = local.Local(self.target_host, conf_dirs, self.out_path, self.exec_path) self.initial_manifest = (initial_manifest or os.path.join(self.local.manifest_path, "init")) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index d0ff1765..d75917f5 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -37,11 +37,13 @@ class Local(object): Directly accessing the local side from python code is a bug. """ - def __init__(self, target_host, conf_dirs, out_path, cache_dir=None): + def __init__(self, target_host, conf_dirs, out_path, exec_path, cache_dir=None): self.target_host = target_host - self.add_conf_dirs = conf_dirs self.out_path = out_path + self.exec_path = exec_path + + self._add_conf_dirs = conf_dirs self._init_log() self._init_permissions() @@ -88,8 +90,8 @@ class Local(object): self.conf_dirs.append(user_conf_dir) # Add user supplied directories - if self.add_conf_dirs: - self.conf_dirs.extend(self.add_conf_dirs) + if self._add_conf_dirs: + self.conf_dirs.extend(self._add_conf_dirs) def _init_cache_dir(self, cache_dir): if cache_dir: @@ -146,6 +148,7 @@ class Local(object): def create_files_dirs(self): self._create_context_dirs() self._create_conf_path_and_link_conf_dirs() + self._link_types_for_emulator() def _create_context_dirs(self): self.mkdir(self.out_path) @@ -185,9 +188,9 @@ class Local(object): except OSError as e: raise cdist.Error("Linking %s %s to %s failed: %s" % (sub_dir, src, dst, e.__str__())) - def link_emulator(self, exec_path): + def _link_types_for_emulator(self): """Link emulator to types""" - src = os.path.abspath(exec_path) + src = os.path.abspath(self.exec_path) for cdist_type in core.CdistType.list_types(self.type_path): dst = os.path.join(self.bin_path, cdist_type.name) self.log.debug("Linking emulator: %s to %s", src, dst) From 4946fe26541a91b815bc553344adf82b970d0786 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 13:34:48 +0100 Subject: [PATCH 04/95] adjust paths in test --- cdist/test/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cdist/test/__init__.py b/cdist/test/__init__.py index faa9dc2d..f8e71287 100644 --- a/cdist/test/__init__.py +++ b/cdist/test/__init__.py @@ -24,9 +24,9 @@ import unittest import tempfile cdist_base_path = os.path.abspath( - os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../../")) + os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../../../")) -cdist_exec_path = os.path.join(cdist_base_path, "bin/cdist") +cdist_exec_path = os.path.join(cdist_base_path, "scripts/cdist") class CdistTestCase(unittest.TestCase): From 32a94a0f89e0ba8002ff0135e66e425d4fd93c96 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 13:35:52 +0100 Subject: [PATCH 05/95] adjust emulator test to pass exec_path to local Signed-off-by: Nico Schottelius --- cdist/test/emulator/__init__.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index ff18fe87..679fd149 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -45,8 +45,8 @@ class EmulatorTestCase(test.CdistTestCase): os.close(handle) self.target_host = 'localhost' out_path = self.temp_dir - self.local = local.Local(self.target_host, local_base_path, out_path) - self.local.create_directories() + self.local = local.Local(self.target_host, local_base_path, out_path, test.cdist_exec_path) + self.local.create_files_dirs() self.env = { 'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']), '__target_host': self.target_host, @@ -113,9 +113,8 @@ class AutoRequireEmulatorTestCase(test.CdistTestCase): self.target_host = 'localhost' out_path = self.temp_dir _local_base_path = fixtures - self.local = local.Local(self.target_host, _local_base_path, out_path) - self.local.create_directories() - self.local.link_emulator(cdist.test.cdist_exec_path) + self.local = local.Local(self.target_host, _local_base_path, out_path, test.cdist_exec_path) + self.local.create_files_dirs() self.manifest = core.Manifest(self.target_host, self.local) def tearDown(self): @@ -140,9 +139,8 @@ class ArgumentsTestCase(test.CdistTestCase): handle, self.script = self.mkstemp(dir=self.temp_dir) os.close(handle) _local_base_path = fixtures - self.local = local.Local(self.target_host, _local_base_path, out_path) - self.local.create_directories() - self.local.link_emulator(test.cdist_exec_path) + self.local = local.Local(self.target_host, _local_base_path, out_path, test.cdist_exec_path) + self.local.create_files_dirs() self.env = { 'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']), '__target_host': self.target_host, From 6eddaaf09057b26157c27fe3ef3f1606b89d7ef5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 13:46:01 +0100 Subject: [PATCH 06/95] rename parameter correctly to add_conf_dirs Signed-off-by: Nico Schottelius --- cdist/exec/local.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index d75917f5..2406c8d5 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -37,13 +37,13 @@ class Local(object): Directly accessing the local side from python code is a bug. """ - def __init__(self, target_host, conf_dirs, out_path, exec_path, cache_dir=None): + def __init__(self, target_host, out_path, exec_path, add_conf_dirs=[], cache_dir=None): self.target_host = target_host self.out_path = out_path self.exec_path = exec_path - self._add_conf_dirs = conf_dirs + self._add_conf_dirs = add_conf_dirs self._init_log() self._init_permissions() From d944f2ac19985dd76c8bdca0b3be34536a5db51a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 14:13:52 +0100 Subject: [PATCH 07/95] add pythonpath for testing --- build | 1 + 1 file changed, 1 insertion(+) diff --git a/build b/build index 9d7284d7..57dc275b 100755 --- a/build +++ b/build @@ -302,6 +302,7 @@ eof test) shift # skip t + export PYTHONPATH="$(pwd -P)" if [ $# -lt 1 ]; then python3 -m cdist.test From 6ecfb28d9346830c8c643b0b36aac3597cfacb7a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 14:14:52 +0100 Subject: [PATCH 08/95] name parameter correctly add_conf_dirs Signed-off-by: Nico Schottelius --- cdist/context.py | 4 ++-- scripts/cdist | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cdist/context.py b/cdist/context.py index d3e30dec..92e683a3 100644 --- a/cdist/context.py +++ b/cdist/context.py @@ -38,7 +38,7 @@ class Context(object): remote_copy, remote_exec, initial_manifest=False, - conf_dirs=[], + add_conf_dirs=[], exec_path=sys.argv[0], debug=False): @@ -59,7 +59,7 @@ class Context(object): self.temp_dir = tempfile.mkdtemp() self.out_path = os.path.join(self.temp_dir, "out") - self.local = local.Local(self.target_host, conf_dirs, self.out_path, self.exec_path) + self.local = local.Local(self.target_host, self.out_path, self.exec_path, add_conf_dirs=add_conf_dirs) self.initial_manifest = (initial_manifest or os.path.join(self.local.manifest_path, "init")) diff --git a/scripts/cdist b/scripts/cdist index d5ea06d0..00ebbf18 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -172,7 +172,7 @@ def configinstall_onehost(host, args, mode, parallel): remote_copy=args.remote_copy, remote_exec=args.remote_exec, initial_manifest=args.manifest, - conf_dirs=args.conf_dir, + add_conf_dirs=args.conf_dir, exec_path=sys.argv[0], debug=args.debug) From 1177286d4e678547bc1df228e4e97008fe12551f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 14:42:55 +0100 Subject: [PATCH 09/95] cleanups of tests (especially exec.local) Signed-off-by: Nico Schottelius --- cdist/test/exec/local.py | 29 +++++++++++++++-------------- cdist/test/manifest/__init__.py | 3 +-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cdist/test/exec/local.py b/cdist/test/exec/local.py index e6f2c2b0..ebfc64af 100644 --- a/cdist/test/exec/local.py +++ b/cdist/test/exec/local.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -25,9 +26,6 @@ import shutil import string import random -#import logging -#logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(message)s') - import cdist from cdist import test from cdist.exec import local @@ -35,17 +33,22 @@ from cdist.exec import local import os.path as op my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') -local_base_path = fixtures - class LocalTestCase(test.CdistTestCase): def setUp(self): - self.temp_dir = self.mkdtemp() + target_host = 'localhost' + self.temp_dir = self.mkdtemp() self.out_path = self.temp_dir - self.base_path = local_base_path - self.local = local.Local(target_host, self.base_path, self.out_path) + + self.local = local.Local( + target_host=target_host, + out_path=self.out_path, + exec_path=test.cdist_exec_path + ) + + self.home_dir = os.path.join(os.environ['HOME'], ".cdist") def tearDown(self): shutil.rmtree(self.temp_dir) @@ -53,10 +56,7 @@ class LocalTestCase(test.CdistTestCase): ### test api def test_cache_path(self): - self.assertEqual(self.local.cache_path, os.path.join(self.base_path, "cache")) - - def test_conf_path(self): - self.assertEqual(self.local.conf_path, os.path.join(self.base_path, "conf")) + self.assertEqual(self.local.cache_path, os.path.join(self.home_dir, "cache")) def test_global_explorer_path(self): self.assertEqual(self.local.global_explorer_path, os.path.join(self.base_path, "conf", "explorer")) @@ -117,7 +117,8 @@ class LocalTestCase(test.CdistTestCase): self.local.rmdir(temp_dir) self.assertFalse(os.path.isdir(temp_dir)) - def test_create_directories(self): - self.local.create_directories() + def test_create_files_dirs(self): + self.local.create_files_dirs() self.assertTrue(os.path.isdir(self.local.out_path)) self.assertTrue(os.path.isdir(self.local.bin_path)) + self.assertTrue(os.path.isdir(self.local.conf_path)) diff --git a/cdist/test/manifest/__init__.py b/cdist/test/manifest/__init__.py index a9846b1d..61a815a9 100644 --- a/cdist/test/manifest/__init__.py +++ b/cdist/test/manifest/__init__.py @@ -49,8 +49,7 @@ class ManifestTestCase(test.CdistTestCase): self.target_host = 'localhost' out_path = self.temp_dir self.local = local.Local(self.target_host, local_base_path, out_path) - self.local.create_directories() - self.local.link_emulator(cdist.test.cdist_exec_path) + self.local.create_files_dirs() self.manifest = manifest.Manifest(self.target_host, self.local) self.log = logging.getLogger(self.target_host) From 69a38443328c93d6ae30ed8f50433f9b3694f35a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 14:48:51 +0100 Subject: [PATCH 10/95] fix some tests and fix home_dir lookup Signed-off-by: Nico Schottelius --- cdist/exec/local.py | 2 +- cdist/test/exec/local.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index 2406c8d5..4a9660ef 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -54,7 +54,7 @@ class Local(object): def _init_home_dir(self): if 'HOME' in os.environ: - self.home_dir = os.environ['HOME'] + self.home_dir = os.path.join(os.environ['HOME'], ".cdist") else: self.home_dir = None diff --git a/cdist/test/exec/local.py b/cdist/test/exec/local.py index ebfc64af..f74302df 100644 --- a/cdist/test/exec/local.py +++ b/cdist/test/exec/local.py @@ -58,14 +58,8 @@ class LocalTestCase(test.CdistTestCase): def test_cache_path(self): self.assertEqual(self.local.cache_path, os.path.join(self.home_dir, "cache")) - def test_global_explorer_path(self): - self.assertEqual(self.local.global_explorer_path, os.path.join(self.base_path, "conf", "explorer")) - - def test_manifest_path(self): - self.assertEqual(self.local.manifest_path, os.path.join(self.base_path, "conf", "manifest")) - - def test_type_path(self): - self.assertEqual(self.local.type_path, os.path.join(self.base_path, "conf", "type")) + def test_conf_path(self): + self.assertEqual(self.local.conf_path, os.path.join(self.out_path, "conf")) def test_out_path(self): self.assertEqual(self.local.out_path, self.out_path) @@ -81,6 +75,18 @@ class LocalTestCase(test.CdistTestCase): ### /test api + ### test internal implementation + + def test_global_explorer_path(self): + self.assertEqual(self.local.global_explorer_path, os.path.join(self.out_path, "conf", "explorer")) + + def test_manifest_path(self): + self.assertEqual(self.local.manifest_path, os.path.join(self.out_path, "conf", "manifest")) + + def test_type_path(self): + self.assertEqual(self.local.type_path, os.path.join(self.out_path, "conf", "type")) + + ### other tests def test_run_success(self): self.local.run(['/bin/true']) @@ -98,7 +104,7 @@ class LocalTestCase(test.CdistTestCase): handle, script = self.mkstemp(dir=self.temp_dir) with os.fdopen(handle, "w") as fd: fd.writelines(["#!/bin/sh\n", "/bin/false"]) - self.assertRaises(local.LocalScriptError, self.local.run_script, script) + self.assertRaises(cdist.Error, self.local.run_script, script) def test_run_script_get_output(self): handle, script = self.mkstemp(dir=self.temp_dir) From af241653670318d514212d903b995ec9202a64f8 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 15:17:46 +0100 Subject: [PATCH 11/95] introduce home_dir as a property Signed-off-by: Nico Schottelius --- cdist/exec/local.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index 4a9660ef..2f870033 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -47,16 +47,20 @@ class Local(object): self._init_log() self._init_permissions() - self._init_home_dir() self._init_paths() self._init_cache_dir(cache_dir) self._init_conf_dirs() - def _init_home_dir(self): + @property + def dist_conf_dir(self): + return os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf")) + + @property + def home_dir(self): if 'HOME' in os.environ: - self.home_dir = os.path.join(os.environ['HOME'], ".cdist") + return os.path.join(os.environ['HOME'], ".cdist") else: - self.home_dir = None + return = None def _init_log(self): self.log = logging.getLogger(self.target_host) @@ -81,13 +85,12 @@ class Local(object): self.conf_dirs = [] # Comes with the distribution - system_conf_dir = os.path.join(os.path.dirname(cdist.__file__), "conf") + system_conf_dir = os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf")) self.conf_dirs.append(system_conf_dir) # Is the default place for user created explorer, type and manifest if self.home_dir: - user_conf_dir = os.path.join(self.home_dir, ".cdist") - self.conf_dirs.append(user_conf_dir) + self.conf_dirs.append(self.home_dir) # Add user supplied directories if self._add_conf_dirs: @@ -152,13 +155,12 @@ class Local(object): def _create_context_dirs(self): self.mkdir(self.out_path) + self.mkdir(self.conf_path) self.mkdir(self.global_explorer_out_path) self.mkdir(self.bin_path) def _create_conf_path_and_link_conf_dirs(self): - self.mkdir(self.conf_path) - # Link destination directories for sub_dir in [ "explorer", "manifest", "type" ]: self.mkdir(os.path.join(self.conf_path, sub_dir)) From 528901bdeee3f963d42e30e0408edeb459b56732 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 15:20:10 +0100 Subject: [PATCH 12/95] update a lot of tests for new exec.local Signed-off-by: Nico Schottelius --- cdist/core/cdist_type.py | 1 - cdist/exec/local.py | 2 +- cdist/test/autorequire/__init__.py | 6 +++-- cdist/test/code/__init__.py | 2 +- cdist/test/emulator/__init__.py | 23 +++++++++++-------- cdist/test/exec/local.py | 36 ++++++++++++++++++++++++++++++ cdist/test/explorer/__init__.py | 2 +- 7 files changed, 57 insertions(+), 15 deletions(-) diff --git a/cdist/core/cdist_type.py b/cdist/core/cdist_type.py index 86f3ced1..44e192fc 100644 --- a/cdist/core/cdist_type.py +++ b/cdist/core/cdist_type.py @@ -24,7 +24,6 @@ import os import cdist - class NoSuchTypeError(cdist.Error): def __init__(self, type_path, type_absolute_path): self.type_path = type_path diff --git a/cdist/exec/local.py b/cdist/exec/local.py index 2f870033..7ef11458 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -60,7 +60,7 @@ class Local(object): if 'HOME' in os.environ: return os.path.join(os.environ['HOME'], ".cdist") else: - return = None + return None def _init_log(self): self.log = logging.getLogger(self.target_host) diff --git a/cdist/test/autorequire/__init__.py b/cdist/test/autorequire/__init__.py index 2263cbf9..bd763fd3 100644 --- a/cdist/test/autorequire/__init__.py +++ b/cdist/test/autorequire/__init__.py @@ -34,7 +34,7 @@ import cdist.context import os.path as op my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') -local_base_path = fixtures +add_conf_dir = op.join(fixtures, 'conf') class AutorequireTestCase(test.CdistTestCase): @@ -48,7 +48,9 @@ class AutorequireTestCase(test.CdistTestCase): self.context = cdist.context.Context( target_host=self.target_host, - base_path=local_base_path, + remote_copy='/bin/true', + remote_exec='/bin/true', + add_conf_dirs=add_conf_dir, exec_path=test.cdist_exec_path, debug=False) self.config = config.Config(self.context) diff --git a/cdist/test/code/__init__.py b/cdist/test/code/__init__.py index 8a8583d7..8bc937b0 100644 --- a/cdist/test/code/__init__.py +++ b/cdist/test/code/__init__.py @@ -44,7 +44,7 @@ class CodeTestCase(test.CdistTestCase): self.local_base_path = local_base_path self.out_path = self.mkdtemp() self.local = local.Local(self.target_host, self.local_base_path, self.out_path) - self.local.create_directories() + self.local.create_files_dirs() self.remote_base_path = self.mkdtemp() self.user = getpass.getuser() diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index 679fd149..1b77bdb6 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -33,8 +33,6 @@ from cdist import core from cdist import config import cdist.context -local_base_path = test.cdist_base_path - class EmulatorTestCase(test.CdistTestCase): def setUp(self): @@ -45,7 +43,10 @@ class EmulatorTestCase(test.CdistTestCase): os.close(handle) self.target_host = 'localhost' out_path = self.temp_dir - self.local = local.Local(self.target_host, local_base_path, out_path, test.cdist_exec_path) + self.local = local.Local( + target_host=self.target_host, + out_path=out_path, + exec_path=test.cdist_exec_path) self.local.create_files_dirs() self.env = { 'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']), @@ -112,8 +113,10 @@ class AutoRequireEmulatorTestCase(test.CdistTestCase): self.temp_dir = self.mkdtemp() self.target_host = 'localhost' out_path = self.temp_dir - _local_base_path = fixtures - self.local = local.Local(self.target_host, _local_base_path, out_path, test.cdist_exec_path) + self.local = local.Local( + target_host=self.target_host, + out_path=out_path, + exec_path=test.cdist_exec_path) self.local.create_files_dirs() self.manifest = core.Manifest(self.target_host, self.local) @@ -138,9 +141,13 @@ class ArgumentsTestCase(test.CdistTestCase): out_path = self.temp_dir handle, self.script = self.mkstemp(dir=self.temp_dir) os.close(handle) - _local_base_path = fixtures - self.local = local.Local(self.target_host, _local_base_path, out_path, test.cdist_exec_path) + + self.local = local.Local( + target_host=self.target_host, + out_path=out_path, + exec_path=test.cdist_exec_path) self.local.create_files_dirs() + self.env = { 'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']), '__target_host': self.target_host, @@ -228,13 +235,11 @@ class StdinTestCase(test.CdistTestCase): self.target_host = 'localhost' self.temp_dir = self.mkdtemp() os.environ['__cdist_out_dir'] = self.temp_dir - local_base_path = fixtures self.context = cdist.context.Context( target_host=self.target_host, remote_copy='scp -o User=root -q', remote_exec='ssh -o User=root -q', - base_path=local_base_path, exec_path=test.cdist_exec_path, debug=False) self.config = config.Config(self.context) diff --git a/cdist/test/exec/local.py b/cdist/test/exec/local.py index f74302df..687c13a5 100644 --- a/cdist/test/exec/local.py +++ b/cdist/test/exec/local.py @@ -33,6 +33,7 @@ from cdist.exec import local import os.path as op my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') +conf_dir = op.join(fixtures, "conf") class LocalTestCase(test.CdistTestCase): @@ -86,6 +87,41 @@ class LocalTestCase(test.CdistTestCase): def test_type_path(self): self.assertEqual(self.local.type_path, os.path.join(self.out_path, "conf", "type")) + def test_dist_conf_dir_linking(self): + """Ensure that links are correctly created for types included in distribution""" + + test_type="__file" + + link_test_local = local.Local( + target_host='localhost', + out_path=self.out_path, + exec_path=test.cdist_exec_path, + ) + + link_test_local._create_conf_path_and_link_conf_dirs() + + our_type_dir = os.path.join(link_test_local.type_path, test_type) + + self.assertTrue(os.path.isdir(our_type_dir)) + + def test_added_conf_dir_linking(self): + """Ensure that links are correctly created for types in added conf directories""" + + test_type="__cdist_test_type" + + link_test_local = local.Local( + target_host='localhost', + out_path=self.out_path, + exec_path=test.cdist_exec_path, + add_conf_dirs=[conf_dir] + ) + + link_test_local._create_conf_path_and_link_conf_dirs() + + our_type_dir = os.path.join(link_test_local.type_path, test_type) + + self.assertTrue(os.path.isdir(our_type_dir)) + ### other tests def test_run_success(self): diff --git a/cdist/test/explorer/__init__.py b/cdist/test/explorer/__init__.py index 257ad8a9..528cb786 100644 --- a/cdist/test/explorer/__init__.py +++ b/cdist/test/explorer/__init__.py @@ -45,7 +45,7 @@ class ExplorerClassTestCase(test.CdistTestCase): self.local_base_path = local_base_path self.out_path = self.mkdtemp() self.local = local.Local(self.target_host, self.local_base_path, self.out_path) - self.local.create_directories() + self.local.create_files_dirs() self.remote_base_path = self.mkdtemp() self.user = getpass.getuser() From 0dd4942d96e6636bdfd05f3d70c78d960dbdc169 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 15:25:57 +0100 Subject: [PATCH 13/95] pre5 updates Signed-off-by: Nico Schottelius --- docs/changelog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog b/docs/changelog index d76f65bb..db6dbe59 100644 --- a/docs/changelog +++ b/docs/changelog @@ -5,6 +5,9 @@ Changelog * Exception: No braces means author == Nico Schottelius +2.1.0pre5: 2012-11-01 + * Core: First round of tests updated to work with multiple configuration directories + 2.1.0pre4: 2012-10-31 * Dist: PyPi: Moved cdist.py to script/cdist to avoid double import * Core: Added support for multiple configuration directories (no documentation) From 8a40ba789a13ee55b8879aa18a1c5f7a66af3996 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 15:39:36 +0100 Subject: [PATCH 14/95] include freecode dist into dist process Signed-off-by: Nico Schottelius --- build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build b/build index 57dc275b..0dca69c9 100755 --- a/build +++ b/build @@ -108,6 +108,8 @@ case "$1" in $0 pub + $0 dist-freecode + $0 dist-post ;; @@ -214,7 +216,7 @@ eof printf "Press enter to submit to freecode> " read dummy - cat << eof | cfreecode-api release cdist + cat << eof | cfreecode-api release-add cdist { "auth_code": "$api_token", "release": { From f264cf9f6cfb1678377c57d7ee7d9e5ce464a1fe Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 17:45:34 +0100 Subject: [PATCH 15/95] insert the actual data into the release process for freecode Signed-off-by: Nico Schottelius --- build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build b/build index 0dca69c9..def72470 100755 --- a/build +++ b/build @@ -220,9 +220,9 @@ eof { "auth_code": "$api_token", "release": { - "tag_list": "REPLACEME", + "tag_list": "$taglist", "version": "$version", - "changelog": "REPLACEMETOO", + "changelog": "$changelog", "hidden_from_frontpage": false } } From 5ec586f7641f22a0d4fa565e48dd3eb3a9519a25 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 18:21:56 +0100 Subject: [PATCH 16/95] begin to cleanup explorer test case Signed-off-by: Nico Schottelius --- cdist/test/__init__.py | 4 ++++ cdist/test/explorer/__init__.py | 40 ++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/cdist/test/__init__.py b/cdist/test/__init__.py index f8e71287..3d9b1a2e 100644 --- a/cdist/test/__init__.py +++ b/cdist/test/__init__.py @@ -28,9 +28,13 @@ cdist_base_path = os.path.abspath( cdist_exec_path = os.path.join(cdist_base_path, "scripts/cdist") +global_fixtures_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "fixtures")) class CdistTestCase(unittest.TestCase): + remote_exec = os.path.join(global_fixtures_dir, "remote", "exec") + remote_copy = os.path.join(global_fixtures_dir, "remote", "copy") + def mkdtemp(self, **kwargs): return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) diff --git a/cdist/test/explorer/__init__.py b/cdist/test/explorer/__init__.py index 528cb786..7801df5d 100644 --- a/cdist/test/explorer/__init__.py +++ b/cdist/test/explorer/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -35,35 +35,45 @@ from cdist.core import explorer import os.path as op my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') -local_base_path = fixtures +conf_dir = op.join(fixtures, "conf") class ExplorerClassTestCase(test.CdistTestCase): def setUp(self): self.target_host = 'localhost' - self.local_base_path = local_base_path - self.out_path = self.mkdtemp() - self.local = local.Local(self.target_host, self.local_base_path, self.out_path) + self.temp_dir = self.mkdtemp() + self.out_path = os.path.join(self.temp_dir, "out") + self.remote_base_path = os.path.join(self.temp_dir, "remote") + + self.local = local.Local( + target_host=self.target_host, + out_path=self.out_path, + exec_path=test.cdist_exec_path, + add_conf_dirs=[conf_dir]) + self.local.create_files_dirs() - self.remote_base_path = self.mkdtemp() - self.user = getpass.getuser() - remote_exec = "ssh -o User=%s -q" % self.user - remote_copy = "scp -o User=%s -q" % self.user - self.remote = remote.Remote(self.target_host, self.remote_base_path, remote_exec, remote_copy) + self.remote = remote.Remote( + self.target_host, + self.remote_base_path, + self.remote_exec, + self.remote_copy) - self.explorer = explorer.Explorer(self.target_host, self.local, self.remote) + self.explorer = explorer.Explorer( + self.target_host, + self.local, + self.remote) self.log = logging.getLogger(self.target_host) def tearDown(self): - shutil.rmtree(self.out_path) - shutil.rmtree(self.remote_base_path) + shutil.rmtree(self.temp_dir) def test_list_global_explorer_names(self): - expected = ['foobar', 'global'] - self.assertEqual(self.explorer.list_global_explorer_names(), expected) + names = self.explorer.list_global_explorer_names() + self.assertIn("foobar", names) + self.assertIn("global", names) def test_transfer_global_explorers(self): self.explorer.transfer_global_explorers() From 09fd8090324f0e706a11fb2ae9c091ec977dd42d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 18:22:52 +0100 Subject: [PATCH 17/95] add new remote handler which turns remote into local ;-) Signed-off-by: Nico Schottelius --- cdist/test/fixtures/remote/copy | 28 ++++++++++++++++++++++++++++ cdist/test/fixtures/remote/exec | 29 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100755 cdist/test/fixtures/remote/copy create mode 100755 cdist/test/fixtures/remote/exec diff --git a/cdist/test/fixtures/remote/copy b/cdist/test/fixtures/remote/copy new file mode 100755 index 00000000..475155da --- /dev/null +++ b/cdist/test/fixtures/remote/copy @@ -0,0 +1,28 @@ +#!/bin/sh +# +# 2012 Nico Schottelius (nico-cdist 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 . +# +# + +recursive=$1; shift +src=$1; shift +dst=$1; shift + +dst=$(echo $dst | sed "s/^${__target_host}://") + +cp "$recursive" "$src" "$dst" diff --git a/cdist/test/fixtures/remote/exec b/cdist/test/fixtures/remote/exec new file mode 100755 index 00000000..ac658313 --- /dev/null +++ b/cdist/test/fixtures/remote/exec @@ -0,0 +1,29 @@ +#!/bin/sh +# +# 2012 Nico Schottelius (nico-cdist 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 . +# +# +# same as cdist default +# +# Usage: +# cdist config --remote-exec "/path/to/this/script" target_host +# + +target_host=$1; shift +# echo "Executing $@ (for $target_host)" +/bin/sh -c "$@" From 184e2bd9c56a751bfc6fa6ed300618fac36f6719 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 1 Nov 2012 18:25:29 +0100 Subject: [PATCH 18/95] add new remote that does local calls Signed-off-by: Nico Schottelius --- cdist/test/fixtures/remote | 1 + docs/changelog | 3 +++ other/examples/remote/local/README | 3 +++ .../test/fixtures/remote => other/examples/remote/local}/copy | 0 .../test/fixtures/remote => other/examples/remote/local}/exec | 0 5 files changed, 7 insertions(+) create mode 120000 cdist/test/fixtures/remote create mode 100644 other/examples/remote/local/README rename {cdist/test/fixtures/remote => other/examples/remote/local}/copy (100%) rename {cdist/test/fixtures/remote => other/examples/remote/local}/exec (100%) diff --git a/cdist/test/fixtures/remote b/cdist/test/fixtures/remote new file mode 120000 index 00000000..c5db6358 --- /dev/null +++ b/cdist/test/fixtures/remote @@ -0,0 +1 @@ +../../../other/examples/remote/local \ No newline at end of file diff --git a/docs/changelog b/docs/changelog index db6dbe59..2cdf6cbf 100644 --- a/docs/changelog +++ b/docs/changelog @@ -5,6 +5,9 @@ Changelog * Exception: No braces means author == Nico Schottelius +2.1.0pre6: + * New Example: Turn remote calls into local calls (used for unittesting) + 2.1.0pre5: 2012-11-01 * Core: First round of tests updated to work with multiple configuration directories diff --git a/other/examples/remote/local/README b/other/examples/remote/local/README new file mode 100644 index 00000000..cfd350f9 --- /dev/null +++ b/other/examples/remote/local/README @@ -0,0 +1,3 @@ +This effectively turns remote calling into local calling. + +Probably most useful for the unittesting. diff --git a/cdist/test/fixtures/remote/copy b/other/examples/remote/local/copy similarity index 100% rename from cdist/test/fixtures/remote/copy rename to other/examples/remote/local/copy diff --git a/cdist/test/fixtures/remote/exec b/other/examples/remote/local/exec similarity index 100% rename from cdist/test/fixtures/remote/exec rename to other/examples/remote/local/exec From 90fad0fe83176dd5a07fc690f527c97dba34c32b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 14:15:14 +0100 Subject: [PATCH 19/95] create remote base in test - needed? Signed-off-by: Nico Schottelius --- cdist/test/explorer/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/test/explorer/__init__.py b/cdist/test/explorer/__init__.py index 7801df5d..bb39d006 100644 --- a/cdist/test/explorer/__init__.py +++ b/cdist/test/explorer/__init__.py @@ -45,6 +45,7 @@ class ExplorerClassTestCase(test.CdistTestCase): self.temp_dir = self.mkdtemp() self.out_path = os.path.join(self.temp_dir, "out") self.remote_base_path = os.path.join(self.temp_dir, "remote") + os.makedirs(self.remote_base_path) self.local = local.Local( target_host=self.target_host, From ccb3c8780f1091d3ed889b5e63ffe900e8f26c0c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 14:16:27 +0100 Subject: [PATCH 20/95] ++release date Signed-off-by: Nico Schottelius --- doc/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changelog b/doc/changelog index 05d6d96b..e5abb6b5 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.15: +2.0.15: 2012-11-02 * Core: Make variable __object_name available in type explorers (Steven Armtrong) * New Type: __qemu_img * New Type: __line From afa5f884c5bd73ec3c07b5920145fe50c67f6fe7 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 14:25:55 +0100 Subject: [PATCH 21/95] rought migration document Signed-off-by: Nico Schottelius --- docs/dev/logs/2012-11-02.migration_to_2.1 | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 docs/dev/logs/2012-11-02.migration_to_2.1 diff --git a/docs/dev/logs/2012-11-02.migration_to_2.1 b/docs/dev/logs/2012-11-02.migration_to_2.1 new file mode 100644 index 00000000..2ef8df22 --- /dev/null +++ b/docs/dev/logs/2012-11-02.migration_to_2.1 @@ -0,0 +1,40 @@ +create a new branch to ensure nothing breaks + + % git checkout -b 2.1_merge + +fetch latest upstream changes (change origin if you use another +remote name for upstream cdist) + + % git fetch -v origin + +Now try to merge upstream into the new branch. + + + % git merge origin/2.1 + +fix any conflicts that may have been occurred due to local changes +and then **git add** and *git commit** those changes. + +As the types have a new location, **cdist/conf/** now, you have to move +your own types there as well: + + % git mv conf/type/* cdist/conf/ + +The manifest location also changed, so move this one as well: + + % git mv conf/manifest/* cdist/conf/manifest/ + +Use **git status** to review the changes and ensure they +are in the git database: + + % git commit -m "Move types and manifests for 2.1 migration" + +This should be everything necessary for a 2.1 migration. Test the result +by running cdist on one of your staging hosts: + + % ./bin/cdist config -v staging-host + + +You can now cleanup the empty conf/ directory: + + % rmdir conf/* && rmdir conf From 6e107fa92c121482be9f9804b57b154116fc697b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 16:27:28 +0100 Subject: [PATCH 22/95] Export PYTHONPATH so it's available for the emulator Signed-off-by: Nico Schottelius --- bin/cdist | 6 +++++- docs/changelog | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/cdist b/bin/cdist index 5a6ce92f..dfe4fa00 100755 --- a/bin/cdist +++ b/bin/cdist @@ -26,4 +26,8 @@ dir=${0%/*} # Ensure version is present - the bundled/shipped version contains a static version, # the git version contains a dynamic version "$dir/../build" version -PYTHONPATH="${dir}/../" "$dir/../scripts/cdist" "$@" + +libdir=$(cd "${dir}/../" && pwd -P) +export PYTHONPATH="${libdir}" + +"$dir/../scripts/cdist" "$@" diff --git a/docs/changelog b/docs/changelog index 9b6a391f..3062d44b 100644 --- a/docs/changelog +++ b/docs/changelog @@ -6,6 +6,7 @@ Changelog 2.1.0pre6: * New Example: Turn remote calls into local calls (used for unittesting) + * Core: Export PYTHONPATH, it's also needed by emulator 2.1.0pre5: 2012-11-01 * Core: First round of tests updated to work with multiple configuration directories From 384a20ffbca66330279837cccc742fb9e7459ede Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 16:58:52 +0100 Subject: [PATCH 23/95] building ruby requires bzip2 to be present to extract the tar.bz2 Signed-off-by: Nico Schottelius --- cdist/conf/type/__rvm_ruby/manifest | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 cdist/conf/type/__rvm_ruby/manifest diff --git a/cdist/conf/type/__rvm_ruby/manifest b/cdist/conf/type/__rvm_ruby/manifest new file mode 100755 index 00000000..65cf80a1 --- /dev/null +++ b/cdist/conf/type/__rvm_ruby/manifest @@ -0,0 +1,25 @@ +#!/bin/sh +# +# 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 . +# +# + +# Required packages for building ruby +for package in bzip2; do + __package --state present +done From 5eac7512a5fd613e99586a422e8d68d6106f3af5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 17:04:00 +0100 Subject: [PATCH 24/95] fix dependencies for __rvm_ruby Signed-off-by: Nico Schottelius --- cdist/conf/type/__rvm_ruby/manifest | 2 +- docs/changelog | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__rvm_ruby/manifest b/cdist/conf/type/__rvm_ruby/manifest index 65cf80a1..6d5f4977 100755 --- a/cdist/conf/type/__rvm_ruby/manifest +++ b/cdist/conf/type/__rvm_ruby/manifest @@ -20,6 +20,6 @@ # # Required packages for building ruby -for package in bzip2; do +for package in bzip2 gcc make; do __package --state present done diff --git a/docs/changelog b/docs/changelog index 3062d44b..f848d83c 100644 --- a/docs/changelog +++ b/docs/changelog @@ -7,6 +7,7 @@ Changelog 2.1.0pre6: * New Example: Turn remote calls into local calls (used for unittesting) * Core: Export PYTHONPATH, it's also needed by emulator + * Type __rvm_ruby: Add clean package dependencies 2.1.0pre5: 2012-11-01 * Core: First round of tests updated to work with multiple configuration directories From 13fc5aa8f5b1a3a92b59fe00c6e7d53bd6158c8f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 17:15:16 +0100 Subject: [PATCH 25/95] use shortcut version to exit if nothing is to be done Signed-off-by: Nico Schottelius --- cdist/conf/type/__rvm_gem/gencode-remote | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/cdist/conf/type/__rvm_gem/gencode-remote b/cdist/conf/type/__rvm_gem/gencode-remote index 34a69624..0b855fc0 100755 --- a/cdist/conf/type/__rvm_gem/gencode-remote +++ b/cdist/conf/type/__rvm_gem/gencode-remote @@ -1,6 +1,7 @@ #!/bin/sh # # 2012 Evax Software +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -25,19 +26,20 @@ gemsetname="$(echo "$gemset" | cut -d '@' -f 2)" state_is="$(cat "$__object/explorer/state")" user="$(cat "$__object/parameter/user")" state_should="$(cat "$__object/parameter/state")" -if [ "$state_is" != "$state_should" ]; then - case "$state_should" in - present) - cat << DONE + +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + cat << DONE su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\" rvm use $gemset; gem install $gem" DONE - ;; - absent) - cat << DONE + ;; + absent) + cat << DONE su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\" rvm use $gemset; gem uninstall $gem" DONE - ;; - esac -fi + ;; +esac From d97f6794d0cf65a839c22dcb71c781ee79ef6ba4 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 17:16:25 +0100 Subject: [PATCH 26/95] run rvm as user, not as root Signed-off-by: Nico Schottelius --- cdist/conf/type/__rvm_gem/gencode-remote | 6 ++---- docs/changelog | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cdist/conf/type/__rvm_gem/gencode-remote b/cdist/conf/type/__rvm_gem/gencode-remote index 0b855fc0..3aef45ef 100755 --- a/cdist/conf/type/__rvm_gem/gencode-remote +++ b/cdist/conf/type/__rvm_gem/gencode-remote @@ -32,14 +32,12 @@ state_should="$(cat "$__object/parameter/state")" case "$state_should" in present) cat << DONE -su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\" -rvm use $gemset; gem install $gem" +su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm; rvm use $gemset; gem install $gem"\" DONE ;; absent) cat << DONE -su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\" -rvm use $gemset; gem uninstall $gem" +su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm; rvm use $gemset; gem uninstall $gem"\" DONE ;; esac diff --git a/docs/changelog b/docs/changelog index f848d83c..a2c78210 100644 --- a/docs/changelog +++ b/docs/changelog @@ -7,7 +7,8 @@ Changelog 2.1.0pre6: * New Example: Turn remote calls into local calls (used for unittesting) * Core: Export PYTHONPATH, it's also needed by emulator - * Type __rvm_ruby: Add clean package dependencies + * Bugfix Type __rvm_ruby: Add clean package dependencies + * Bugfix Type __rvm_gem: Run rvm as user, not as root 2.1.0pre5: 2012-11-01 * Core: First round of tests updated to work with multiple configuration directories From c779e16fe23c6e3bf340ecde633bae4972893058 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 17:18:57 +0100 Subject: [PATCH 27/95] __rvm: use shortcut version Signed-off-by: Nico Schottelius --- cdist/conf/type/__rvm/gencode-remote | 23 ++++++++++++----------- docs/changelog | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cdist/conf/type/__rvm/gencode-remote b/cdist/conf/type/__rvm/gencode-remote index aa6ef647..dbc6ba60 100755 --- a/cdist/conf/type/__rvm/gencode-remote +++ b/cdist/conf/type/__rvm/gencode-remote @@ -1,6 +1,7 @@ #!/bin/sh # # 2012 Evax Software +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -21,20 +22,20 @@ user="$__object_id" state_is="$(cat "$__object/explorer/state")" state_should="$(cat "$__object/parameter/state")" -if [ "$state_is" != "$state_should" ]; then - case "$state_should" in - present) - cat << DONE + +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + cat << DONE su - $user -c "unset rvm_path; unset rvm_bin_path; unset rvm_prefix; unset rvm_version; curl -L get.rvm.io | bash -s stable" DONE - ;; - absent) - cat << DONE + ;; + absent) + cat << DONE su - $user -c "rm -Rf \"\\\$HOME/.rvm\"; sed '/rvm\/scripts\/rvm/d' \"\\\$HOME/.bashrc\" > \"\\\$HOME/.bashrc.cdist-tmp\" mv \"\\\$HOME/.bashrc.cdist-tmp\" \"\\\$HOME/.bashrc\"" - DONE - ;; - esac -fi + ;; +esac diff --git a/docs/changelog b/docs/changelog index a2c78210..e9423925 100644 --- a/docs/changelog +++ b/docs/changelog @@ -9,6 +9,7 @@ Changelog * Core: Export PYTHONPATH, it's also needed by emulator * Bugfix Type __rvm_ruby: Add clean package dependencies * Bugfix Type __rvm_gem: Run rvm as user, not as root + * Cleanup Type __rvm: Use shortcut version 2.1.0pre5: 2012-11-01 * Core: First round of tests updated to work with multiple configuration directories From d5955bbb4d0f0e341cd3be258d7c1ac59b0c4ea9 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 17:19:30 +0100 Subject: [PATCH 28/95] reference dependency package as well Signed-off-by: Nico Schottelius --- cdist/conf/type/__rvm_ruby/manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__rvm_ruby/manifest b/cdist/conf/type/__rvm_ruby/manifest index 6d5f4977..db8fd830 100755 --- a/cdist/conf/type/__rvm_ruby/manifest +++ b/cdist/conf/type/__rvm_ruby/manifest @@ -21,5 +21,5 @@ # Required packages for building ruby for package in bzip2 gcc make; do - __package --state present + __package "$package" --state present done From df88d98ea05565fa64452c9eb7ab816454849e3a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 17:35:13 +0100 Subject: [PATCH 29/95] many cleanups to __rvm* types Signed-off-by: Nico Schottelius --- cdist/conf/type/__rvm_gem/gencode-remote | 7 ++-- cdist/conf/type/__rvm_gemset/explorer/state | 6 ++-- cdist/conf/type/__rvm_gemset/gencode-remote | 37 ++++++++++----------- docs/changelog | 2 +- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/cdist/conf/type/__rvm_gem/gencode-remote b/cdist/conf/type/__rvm_gem/gencode-remote index 3aef45ef..1fe6e78e 100755 --- a/cdist/conf/type/__rvm_gem/gencode-remote +++ b/cdist/conf/type/__rvm_gem/gencode-remote @@ -1,5 +1,4 @@ -#!/bin/sh -# +#!/bin/sh # # 2012 Evax Software # 2012 Nico Schottelius (nico-cdist at schottelius.org) # @@ -32,12 +31,12 @@ state_should="$(cat "$__object/parameter/state")" case "$state_should" in present) cat << DONE -su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm; rvm use $gemset; gem install $gem"\" +su - "$user" -c 'source ~/.rvm/scripts/rvm; rvm use "$gemset"; gem install "$gem"' DONE ;; absent) cat << DONE -su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm; rvm use $gemset; gem uninstall $gem"\" +su - "$user" -c 'source ~/.rvm/scripts/rvm; rvm use "$gemset"; gem uninstall "$gem"' DONE ;; esac diff --git a/cdist/conf/type/__rvm_gemset/explorer/state b/cdist/conf/type/__rvm_gemset/explorer/state index fbf11830..c8d573b5 100755 --- a/cdist/conf/type/__rvm_gemset/explorer/state +++ b/cdist/conf/type/__rvm_gemset/explorer/state @@ -22,13 +22,13 @@ gemset="$__object_id" ruby="$(echo "$gemset" | cut -d '@' -f 1)" gemsetname="$(echo "$gemset" | cut -d '@' -f2)" user="$(cat "$__object/parameter/user")" -if su - "$user" -c "[ ! -d \"\$HOME/.rvm\" ]" ; then +if su - "$user" -c "[ ! -d ~/.rvm ]" ; then echo "absent" exit 0 fi -if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\" +if su - "$user" -c "source ~/.rvm/scripts/rvm rvm list | grep -q $ruby"; then - if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\" + if su - "$user" -c "source ~/.rvm/scripts/rvm rvm use $ruby > /dev/null; rvm gemset list | grep -q $gemsetname"; then echo "present" exit 0 diff --git a/cdist/conf/type/__rvm_gemset/gencode-remote b/cdist/conf/type/__rvm_gemset/gencode-remote index 1604538d..1fd14061 100755 --- a/cdist/conf/type/__rvm_gemset/gencode-remote +++ b/cdist/conf/type/__rvm_gemset/gencode-remote @@ -1,6 +1,7 @@ #!/bin/sh # # 2012 Evax Software +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -25,29 +26,27 @@ state_is="$(cat "$__object/explorer/state")" user="$(cat "$__object/parameter/user")" default="$(cat "$__object/parameter/default" 2>/dev/null || true)" state_should="$(cat "$__object/parameter/state")" -if [ "$state_is" != "$state_should" ]; then - case "$state_should" in - present) - cat << DONE -su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\" -rvm $gemset --create" + +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + cat << DONE +su - "$user" -c "source ~/.rvm/scripts/rvm; rvm $gemset --create" DONE - case "$default" in + case "$default" in no) ;; *) - cat << DONE -su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\" -rvm use --default $gemset" + cat << DONE +su - "$user" -c "source ~/.rvm/scripts/rvm; rvm use --default $gemset" DONE ;; - esac - ;; - absent) - cat << DONE -su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\" -rvm use $ruby; rvm --force gemset delete $gemsetname" + esac + ;; + absent) + cat << DONE +su - "$user" -c "source ~/.rvm/scripts/rvm; rvm use $ruby; rvm --force gemset delete $gemsetname" DONE - ;; - esac -fi + ;; +esac diff --git a/docs/changelog b/docs/changelog index e9423925..b91b01c7 100644 --- a/docs/changelog +++ b/docs/changelog @@ -9,7 +9,7 @@ Changelog * Core: Export PYTHONPATH, it's also needed by emulator * Bugfix Type __rvm_ruby: Add clean package dependencies * Bugfix Type __rvm_gem: Run rvm as user, not as root - * Cleanup Type __rvm: Use shortcut version + * Cleanup Type __rvm, __rvm_gemset: Use shortcut version 2.1.0pre5: 2012-11-01 * Core: First round of tests updated to work with multiple configuration directories From 0eac132b83fe4ea44517fe9f051412cbd1552c8d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 21:46:08 +0100 Subject: [PATCH 30/95] adjust gemset explorer to work with new rvm version (fixes #108) See https://github.com/wayneeseguin/rvm/issues/1285 Signed-off-by: Nico Schottelius --- cdist/conf/type/__rvm_gemset/explorer/state | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cdist/conf/type/__rvm_gemset/explorer/state b/cdist/conf/type/__rvm_gemset/explorer/state index c8d573b5..fa643a6e 100755 --- a/cdist/conf/type/__rvm_gemset/explorer/state +++ b/cdist/conf/type/__rvm_gemset/explorer/state @@ -22,14 +22,14 @@ gemset="$__object_id" ruby="$(echo "$gemset" | cut -d '@' -f 1)" gemsetname="$(echo "$gemset" | cut -d '@' -f2)" user="$(cat "$__object/parameter/user")" -if su - "$user" -c "[ ! -d ~/.rvm ]" ; then + +if [ ! -e "~$user/.rvm/scripts/rvm" ] ; then echo "absent" exit 0 fi -if su - "$user" -c "source ~/.rvm/scripts/rvm -rvm list | grep -q $ruby"; then - if su - "$user" -c "source ~/.rvm/scripts/rvm -rvm use $ruby > /dev/null; rvm gemset list | grep -q $gemsetname"; then + +if su - "$user" -c 'source ~/.rvm/scripts/rvm; rvm list strings | grep -q "^$ruby\$"'; then + if su - "$user" -c 'source ~/.rvm/scripts/rvm; rvm use "$ruby" > /dev/null; rvm gemset list strings | cut -f 1 -d " " | grep -q "^$gemsetname\$"'; then echo "present" exit 0 fi From 5308d2cfe7363414be071b889ef6e93a9e800776 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 22:35:52 +0100 Subject: [PATCH 31/95] link to role from database Signed-off-by: Nico Schottelius --- cdist/conf/type/__postgres_database/man.text | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/conf/type/__postgres_database/man.text b/cdist/conf/type/__postgres_database/man.text index 06cb736f..d01ca8f6 100644 --- a/cdist/conf/type/__postgres_database/man.text +++ b/cdist/conf/type/__postgres_database/man.text @@ -36,6 +36,7 @@ __postgres_database mydbname --state present --owner mydbusername SEE ALSO -------- - cdist-type(7) +- cdist-type__postgres_role(7) COPYING From 03d224c74c7578f555562480026437d8a7d72401 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 22:43:19 +0100 Subject: [PATCH 32/95] add hint to db from role Signed-off-by: Nico Schottelius --- cdist/conf/type/__postgres_role/man.text | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/conf/type/__postgres_role/man.text b/cdist/conf/type/__postgres_role/man.text index bcc7b5d7..9b917060 100644 --- a/cdist/conf/type/__postgres_role/man.text +++ b/cdist/conf/type/__postgres_role/man.text @@ -49,6 +49,7 @@ __postgres_role dbcustomer --state present --password 'bla' --createdb true SEE ALSO -------- - cdist-type(7) +- cdist-type__postgres_database(7) - http://www.postgresql.org/docs/current/static/sql-createrole.html From b6f61a632f0d49e8f90f8adafb25afda149b0167 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 22:56:45 +0100 Subject: [PATCH 33/95] __postgres_role: switch to boolean, use shortcut version Signed-off-by: Nico Schottelius --- .../conf/type/__postgres_role/gencode-remote | 45 +++++++++---------- cdist/conf/type/__postgres_role/man.text | 13 ++++-- .../type/__postgres_role/parameter/boolean | 5 +++ .../type/__postgres_role/parameter/optional | 5 --- docs/changelog | 4 ++ 5 files changed, 38 insertions(+), 34 deletions(-) create mode 100644 cdist/conf/type/__postgres_role/parameter/boolean diff --git a/cdist/conf/type/__postgres_role/gencode-remote b/cdist/conf/type/__postgres_role/gencode-remote index a3280c09..c9de4707 100755 --- a/cdist/conf/type/__postgres_role/gencode-remote +++ b/cdist/conf/type/__postgres_role/gencode-remote @@ -22,33 +22,28 @@ name="$__object_id" state_is="$(cat "$__object/explorer/state")" state_should="$(cat "$__object/parameter/state")" -if [ "$state_is" != "$state_should" ]; then - case "$state_should" in - present) - optional="password - login - createdb - createrole - superuser" - for parameter in $optional; do - if [ -f "$__object/parameter/$parameter" ]; then - value="$(cat "$__object/parameter/$parameter")" - eval $parameter=$value +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + if [ -f "$__object/parameter/password" ]; then + password="$(cat "$__object/parameter/$parameter")" + fi + booleans="" + for boolean in login createdb createrole superuser; do + if [ ! -f "$__object/parameter/$boolean" ]; then + boolean="no${boolean}" fi - done + upper=$(echo $boolean | tr '[a-z]' '[A-Z]') + booleans="$booleans $upper" + done [ -n "$password" ] && password="PASSWORD '$password'" - [ "$login" = "true" ] && login="LOGIN" || login="NOLOGIN" - [ "$createdb" = "true" ] && createdb="CREATEDB" || createdb="NOCREATEDB" - [ "$createrole" = "true" ] && createrole="CREATEROLE" || createrole="NOCREATEROLE" - [ "$superuser" = "true" ] && superuser="SUPERUSER" || superuser="NOSUPERUSER" - [ "$inherit" = "true" ] && inherit="INHERIT" || inherit="NOINHERIT" - cmd="CREATE ROLE $name WITH $password $login $createdb $createrole $superuser $inherit" + cmd="CREATE ROLE $name WITH $password $booleans" echo "su - postgres -c \"psql -c \\\"$cmd\\\"\"" - ;; - absent) - echo "su - postgres -c \"dropuser \\\"$name\\\"\"" - ;; - esac -fi + ;; + absent) + echo "su - postgres -c \"dropuser \\\"$name\\\"\"" + ;; +esac diff --git a/cdist/conf/type/__postgres_role/man.text b/cdist/conf/type/__postgres_role/man.text index 9b917060..4f13fa53 100644 --- a/cdist/conf/type/__postgres_role/man.text +++ b/cdist/conf/type/__postgres_role/man.text @@ -21,17 +21,22 @@ state:: OPTIONAL PARAMETERS ------------------- -All optional parameter map directly to the corresponding postgres createrole +All parameter map directly to the corresponding postgres createrole parameters. password:: + +BOOLEAN PARAMETERS +------------------ +All parameter map directly to the corresponding postgres createrole +parameters. + login:: createdb:: createrole:: superuser:: inherit:: - EXAMPLES -------- @@ -40,9 +45,9 @@ __postgres_role myrole --state present __postgres_role myrole --state present --password 'secret' -__postgres_role admin --state present --password 'very-secret' --superuser true +__postgres_role admin --state present --password 'very-secret' --superuser -__postgres_role dbcustomer --state present --password 'bla' --createdb true +__postgres_role dbcustomer --state present --password 'bla' --createdb -------------------------------------------------------------------------------- diff --git a/cdist/conf/type/__postgres_role/parameter/boolean b/cdist/conf/type/__postgres_role/parameter/boolean new file mode 100644 index 00000000..a581b3fd --- /dev/null +++ b/cdist/conf/type/__postgres_role/parameter/boolean @@ -0,0 +1,5 @@ +login +createdb +createrole +superuser +inherit diff --git a/cdist/conf/type/__postgres_role/parameter/optional b/cdist/conf/type/__postgres_role/parameter/optional index c5abb57f..f3097ab1 100644 --- a/cdist/conf/type/__postgres_role/parameter/optional +++ b/cdist/conf/type/__postgres_role/parameter/optional @@ -1,6 +1 @@ password -login -createdb -createrole -superuser -inherit diff --git a/docs/changelog b/docs/changelog index b91b01c7..56750722 100644 --- a/docs/changelog +++ b/docs/changelog @@ -10,6 +10,10 @@ Changelog * Bugfix Type __rvm_ruby: Add clean package dependencies * Bugfix Type __rvm_gem: Run rvm as user, not as root * Cleanup Type __rvm, __rvm_gemset: Use shortcut version + * Bugfix __rvm_gemset: Correctly check for gemsets + * Cleanup Type __postgres_database, __postgres_role: Reference each other + in documentation + * Cleanp Type __postgres_role: Use boolean parameters where appropriate 2.1.0pre5: 2012-11-01 * Core: First round of tests updated to work with multiple configuration directories From 2d69eb07c198e46ece48cda8c0142d6002d5dfcb Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Nov 2012 22:57:23 +0100 Subject: [PATCH 34/95] ++changes Signed-off-by: Nico Schottelius --- docs/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog b/docs/changelog index 56750722..1df72293 100644 --- a/docs/changelog +++ b/docs/changelog @@ -14,6 +14,7 @@ Changelog * Cleanup Type __postgres_database, __postgres_role: Reference each other in documentation * Cleanp Type __postgres_role: Use boolean parameters where appropriate + * Cleanp Type __postgres_role: Use shortcut version 2.1.0pre5: 2012-11-01 * Core: First round of tests updated to work with multiple configuration directories From 1db1168c9ab09919efe49e37dc0cac3b1a6a04dd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 5 Nov 2012 21:42:39 +0100 Subject: [PATCH 35/95] move doc into new location Signed-off-by: Nico Schottelius --- {doc => docs}/dev/logs/2012-05-23.urls | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {doc => docs}/dev/logs/2012-05-23.urls (100%) diff --git a/doc/dev/logs/2012-05-23.urls b/docs/dev/logs/2012-05-23.urls similarity index 100% rename from doc/dev/logs/2012-05-23.urls rename to docs/dev/logs/2012-05-23.urls From 43061dc1b3068ab239f6eee78b8ea3ebc23895b7 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 5 Nov 2012 22:44:20 +0100 Subject: [PATCH 36/95] +releasedate Signed-off-by: Nico Schottelius --- docs/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index 1df72293..6a3e29ba 100644 --- a/docs/changelog +++ b/docs/changelog @@ -4,7 +4,7 @@ Changelog * Changes are always commented with their author in (braces) * Exception: No braces means author == Nico Schottelius -2.1.0pre6: +2.1.0pre6: 2012-11-05 * New Example: Turn remote calls into local calls (used for unittesting) * Core: Export PYTHONPATH, it's also needed by emulator * Bugfix Type __rvm_ruby: Add clean package dependencies From 9bdb715b7d3b75b733db15a4198576a96d936719 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Nov 2012 16:42:18 +0100 Subject: [PATCH 37/95] ensure all parameters for exec are executed Signed-off-by: Nico Schottelius --- other/examples/remote/local/copy | 1 - other/examples/remote/local/exec | 8 +------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/other/examples/remote/local/copy b/other/examples/remote/local/copy index 475155da..644fee15 100755 --- a/other/examples/remote/local/copy +++ b/other/examples/remote/local/copy @@ -24,5 +24,4 @@ src=$1; shift dst=$1; shift dst=$(echo $dst | sed "s/^${__target_host}://") - cp "$recursive" "$src" "$dst" diff --git a/other/examples/remote/local/exec b/other/examples/remote/local/exec index ac658313..838513a9 100755 --- a/other/examples/remote/local/exec +++ b/other/examples/remote/local/exec @@ -18,12 +18,6 @@ # along with cdist. If not, see . # # -# same as cdist default -# -# Usage: -# cdist config --remote-exec "/path/to/this/script" target_host -# target_host=$1; shift -# echo "Executing $@ (for $target_host)" -/bin/sh -c "$@" +echo "$@" | /bin/sh From 4a67d768d5655f9c7bdc1df0ac0a31685d38fd63 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Nov 2012 16:47:51 +0100 Subject: [PATCH 38/95] fix all explorer test cases Signed-off-by: Nico Schottelius --- cdist/test/explorer/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cdist/test/explorer/__init__.py b/cdist/test/explorer/__init__.py index bb39d006..266a1073 100644 --- a/cdist/test/explorer/__init__.py +++ b/cdist/test/explorer/__init__.py @@ -60,6 +60,7 @@ class ExplorerClassTestCase(test.CdistTestCase): self.remote_base_path, self.remote_exec, self.remote_copy) + self.remote.create_files_dirs() self.explorer = explorer.Explorer( self.target_host, @@ -83,14 +84,20 @@ class ExplorerClassTestCase(test.CdistTestCase): self.assertEqual(sorted(os.listdir(source)), sorted(os.listdir(destination))) def test_run_global_explorer(self): + """Checkt that running ONE global explorer works""" self.explorer.transfer_global_explorers() output = self.explorer.run_global_explorer('global') self.assertEqual(output, 'global\n') def test_run_global_explorers(self): + """Ensure output is created for every global explorer""" out_path = self.mkdtemp() + self.explorer.run_global_explorers(out_path) - self.assertEqual(sorted(os.listdir(out_path)), sorted(['foobar', 'global'])) + names = sorted(self.explorer.list_global_explorer_names()) + output = sorted(os.listdir(out_path)) + + self.assertEqual(names, output) shutil.rmtree(out_path) def test_list_type_explorer_names(self): From 04bd5d88c36482b82f50adad7928cb3409137df4 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Nov 2012 16:58:30 +0100 Subject: [PATCH 39/95] Fix tests for code Signed-off-by: Nico Schottelius --- cdist/exec/remote.py | 2 +- cdist/test/code/__init__.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cdist/exec/remote.py b/cdist/exec/remote.py index 07c6614b..d4d2cb2b 100644 --- a/cdist/exec/remote.py +++ b/cdist/exec/remote.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # diff --git a/cdist/test/code/__init__.py b/cdist/test/code/__init__.py index 8bc937b0..473c4b39 100644 --- a/cdist/test/code/__init__.py +++ b/cdist/test/code/__init__.py @@ -34,23 +34,27 @@ from cdist.core import code import os.path as op my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') -local_base_path = fixtures +conf_dir = op.join(fixtures, 'conf') class CodeTestCase(test.CdistTestCase): def setUp(self): self.target_host = 'localhost' - self.local_base_path = local_base_path self.out_path = self.mkdtemp() - self.local = local.Local(self.target_host, self.local_base_path, self.out_path) + + self.local = local.Local( + target_host=self.target_host, + out_path = self.out_path, + exec_path = cdist.test.cdist_exec_path, + add_conf_dirs=[conf_dir]) self.local.create_files_dirs() self.remote_base_path = self.mkdtemp() - self.user = getpass.getuser() - remote_exec = "ssh -o User=%s -q" % self.user - remote_copy = "scp -o User=%s -q" % self.user + remote_exec = self.remote_exec + remote_copy = self.remote_copy self.remote = remote.Remote(self.target_host, self.remote_base_path, remote_exec, remote_copy) + self.remote.create_files_dirs() self.code = code.Code(self.target_host, self.local, self.remote) From 8dfbb4a9dd7bad57566c7d9021524244b16cbb8f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Nov 2012 16:59:21 +0100 Subject: [PATCH 40/95] ++changes for next version Signed-off-by: Nico Schottelius --- docs/changelog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog b/docs/changelog index 6a3e29ba..16e6e25d 100644 --- a/docs/changelog +++ b/docs/changelog @@ -4,6 +4,9 @@ Changelog * Changes are always commented with their author in (braces) * Exception: No braces means author == Nico Schottelius +2.1.0pre7: + * Core: Tests for "cdist.code" work again + 2.1.0pre6: 2012-11-05 * New Example: Turn remote calls into local calls (used for unittesting) * Core: Export PYTHONPATH, it's also needed by emulator From bb1a8d8e661eb04f3d972451e279521b520b8ea6 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Nov 2012 17:01:20 +0100 Subject: [PATCH 41/95] fixup manifest tests Signed-off-by: Nico Schottelius --- cdist/test/code/__init__.py | 1 + cdist/test/manifest/__init__.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cdist/test/code/__init__.py b/cdist/test/code/__init__.py index 473c4b39..f5d445ab 100644 --- a/cdist/test/code/__init__.py +++ b/cdist/test/code/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # diff --git a/cdist/test/manifest/__init__.py b/cdist/test/manifest/__init__.py index 61a815a9..0de04743 100644 --- a/cdist/test/manifest/__init__.py +++ b/cdist/test/manifest/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -37,8 +38,7 @@ from cdist.core import manifest import os.path as op my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') -local_base_path = fixtures - +conf_dir = op.join(fixtures, 'conf') class ManifestTestCase(test.CdistTestCase): @@ -48,8 +48,13 @@ class ManifestTestCase(test.CdistTestCase): self.temp_dir = self.mkdtemp() self.target_host = 'localhost' out_path = self.temp_dir - self.local = local.Local(self.target_host, local_base_path, out_path) + self.local = local.Local( + target_host=self.target_host, + out_path=out_path, + exec_path = cdist.test.cdist_exec_path, + add_conf_dirs=[conf_dir]) self.local.create_files_dirs() + self.manifest = manifest.Manifest(self.target_host, self.local) self.log = logging.getLogger(self.target_host) From 474d901fdad4bc319b08a3bdc49e19e396d52b50 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Nov 2012 17:02:05 +0100 Subject: [PATCH 42/95] ++changes next version Signed-off-by: Nico Schottelius --- docs/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index 16e6e25d..3f1dec49 100644 --- a/docs/changelog +++ b/docs/changelog @@ -5,7 +5,7 @@ Changelog * Exception: No braces means author == Nico Schottelius 2.1.0pre7: - * Core: Tests for "cdist.code" work again + * Core: Tests for "test.code", "test.manifest" work again 2.1.0pre6: 2012-11-05 * New Example: Turn remote calls into local calls (used for unittesting) From c47d0fae1c67f576e810304eb4b004ce807f03d8 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Nov 2012 17:28:26 +0100 Subject: [PATCH 43/95] fix autorequire test case and fix cdist_base_path test assignment Signed-off-by: Nico Schottelius --- cdist/context.py | 2 +- cdist/test/__init__.py | 4 ++-- cdist/test/autorequire/__init__.py | 16 +++++++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cdist/context.py b/cdist/context.py index 92e683a3..2855f228 100644 --- a/cdist/context.py +++ b/cdist/context.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # -# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2010-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # diff --git a/cdist/test/__init__.py b/cdist/test/__init__.py index 3d9b1a2e..a8c6103b 100644 --- a/cdist/test/__init__.py +++ b/cdist/test/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -24,7 +24,7 @@ import unittest import tempfile cdist_base_path = os.path.abspath( - os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../../../")) + os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../")) cdist_exec_path = os.path.join(cdist_base_path, "scripts/cdist") diff --git a/cdist/test/autorequire/__init__.py b/cdist/test/autorequire/__init__.py index bd763fd3..4b47b06b 100644 --- a/cdist/test/autorequire/__init__.py +++ b/cdist/test/autorequire/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -36,7 +37,6 @@ my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') add_conf_dir = op.join(fixtures, 'conf') - class AutorequireTestCase(test.CdistTestCase): def setUp(self): @@ -44,15 +44,21 @@ class AutorequireTestCase(test.CdistTestCase): os.environ = os.environ.copy() self.target_host = 'localhost' self.temp_dir = self.mkdtemp() - os.environ['__cdist_out_dir'] = self.temp_dir + + self.out_dir = os.path.join(self.temp_dir, "out") + self.remote_out_dir = os.path.join(self.temp_dir, "remote") + + os.environ['__cdist_out_dir'] = self.out_dir + os.environ['__cdist_remote_out_dir'] = self.remote_out_dir self.context = cdist.context.Context( target_host=self.target_host, - remote_copy='/bin/true', - remote_exec='/bin/true', - add_conf_dirs=add_conf_dir, + remote_copy=self.remote_copy, + remote_exec=self.remote_exec, + add_conf_dirs=[add_conf_dir], exec_path=test.cdist_exec_path, debug=False) + self.config = config.Config(self.context) def tearDown(self): From e4024736689b2695f11ae20327c4794644e2ad77 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Nov 2012 21:32:20 +0100 Subject: [PATCH 44/95] ++changes Signed-off-by: Nico Schottelius --- docs/changelog | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index 3f1dec49..93c3cf69 100644 --- a/docs/changelog +++ b/docs/changelog @@ -5,7 +5,8 @@ Changelog * Exception: No braces means author == Nico Schottelius 2.1.0pre7: - * Core: Tests for "test.code", "test.manifest" work again + * Core: Tests for autorequire, code, manifest work again + * Core: Print error message on missing initial manifest 2.1.0pre6: 2012-11-05 * New Example: Turn remote calls into local calls (used for unittesting) From a22e729a3cf7ddab5465b311be602ee36eb095ce Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Nov 2012 21:32:37 +0100 Subject: [PATCH 45/95] raise special error on missing manifest Signed-off-by: Nico Schottelius --- cdist/core/manifest.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cdist/core/manifest.py b/cdist/core/manifest.py index 5faeccd1..ecc4a490 100644 --- a/cdist/core/manifest.py +++ b/cdist/core/manifest.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -25,6 +25,20 @@ import os import cdist +class NoInitialManifestError(cdist.Error): + """ + Display missing initial manifest + """ + + def __init__(self, manifest_path): + if os.path.islink(manifest_path): + self.message = "%s -> %s" (manifest_path, os.path.realpath(manifest_path)) + else: + self.message = manifest_path + + def __str__(self): + return "Initial manifest missing: %s" % self.message + ''' common: runs only locally, does not need remote @@ -84,6 +98,11 @@ class Manifest(object): env['__manifest'] = self.local.manifest_path env['__cdist_manifest'] = script self.log.info("Running initial manifest " + self.local.manifest_path) + + if not os.path.isfile(self.local.manifest_path): + print("fooooobar") + raise NoInitialManifestError(self.local.manifest_path) + self.local.run_script(script, env=env) def run_type_manifest(self, cdist_object): From 866f23ea2cc1d4f6b9961f5c892efcae2e2caddf Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Nov 2012 21:32:54 +0100 Subject: [PATCH 46/95] inject conf_dir for emulator test Signed-off-by: Nico Schottelius --- cdist/test/emulator/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index 1b77bdb6..871083f8 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -33,6 +34,12 @@ from cdist import core from cdist import config import cdist.context +import os.path as op +my_dir = op.abspath(op.dirname(__file__)) +fixtures = op.join(my_dir, 'fixtures') +conf_dir = op.join(fixtures, 'conf') + + class EmulatorTestCase(test.CdistTestCase): def setUp(self): @@ -46,7 +53,8 @@ class EmulatorTestCase(test.CdistTestCase): self.local = local.Local( target_host=self.target_host, out_path=out_path, - exec_path=test.cdist_exec_path) + exec_path=test.cdist_exec_path, + add_conf_dirs=[conf_dir]) self.local.create_files_dirs() self.env = { 'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']), From aedb3669c74e786c312fd261d74182077b51ecd4 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Nov 2012 21:46:02 +0100 Subject: [PATCH 47/95] print hint if initial manifest is missing Signed-off-by: Nico Schottelius --- cdist/context.py | 2 +- cdist/core/manifest.py | 17 +---------------- scripts/cdist | 2 +- 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/cdist/context.py b/cdist/context.py index 2855f228..767b17a8 100644 --- a/cdist/context.py +++ b/cdist/context.py @@ -87,6 +87,6 @@ class Context(object): def filter(self, record): """Add hostname to logs via logging Filter""" - record.msg = self.target_host + ": " + record.msg + record.msg = self.target_host + ": " + str(record.msg) return True diff --git a/cdist/core/manifest.py b/cdist/core/manifest.py index ecc4a490..61d92992 100644 --- a/cdist/core/manifest.py +++ b/cdist/core/manifest.py @@ -25,20 +25,6 @@ import os import cdist -class NoInitialManifestError(cdist.Error): - """ - Display missing initial manifest - """ - - def __init__(self, manifest_path): - if os.path.islink(manifest_path): - self.message = "%s -> %s" (manifest_path, os.path.realpath(manifest_path)) - else: - self.message = manifest_path - - def __str__(self): - return "Initial manifest missing: %s" % self.message - ''' common: runs only locally, does not need remote @@ -100,8 +86,7 @@ class Manifest(object): self.log.info("Running initial manifest " + self.local.manifest_path) if not os.path.isfile(self.local.manifest_path): - print("fooooobar") - raise NoInitialManifestError(self.local.manifest_path) + raise cdist.Error("Initial manifest is missing") self.local.run_script(script, env=env) diff --git a/scripts/cdist b/scripts/cdist index 00ebbf18..fd18933a 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -181,9 +181,9 @@ def configinstall_onehost(host, args, mode, parallel): context.cleanup() except cdist.Error as e: + context.log.error(e) # We are running in our own process here, need to sys.exit! if parallel: - log.error(e) sys.exit(1) else: raise From 28bf0c3ed8f8bcee36caa07839b8163986d29872 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Nov 2012 21:52:11 +0100 Subject: [PATCH 48/95] setup target_host for tests in test main class Signed-off-by: Nico Schottelius --- cdist/test/__init__.py | 2 ++ cdist/test/emulator/__init__.py | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cdist/test/__init__.py b/cdist/test/__init__.py index a8c6103b..ab767699 100644 --- a/cdist/test/__init__.py +++ b/cdist/test/__init__.py @@ -35,6 +35,8 @@ class CdistTestCase(unittest.TestCase): remote_exec = os.path.join(global_fixtures_dir, "remote", "exec") remote_copy = os.path.join(global_fixtures_dir, "remote", "copy") + target_host = 'cdisttesthost' + def mkdtemp(self, **kwargs): return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index 871083f8..f9743e16 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -39,7 +39,6 @@ my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') conf_dir = op.join(fixtures, 'conf') - class EmulatorTestCase(test.CdistTestCase): def setUp(self): @@ -48,7 +47,6 @@ class EmulatorTestCase(test.CdistTestCase): self.temp_dir = self.mkdtemp() handle, self.script = self.mkstemp(dir=self.temp_dir) os.close(handle) - self.target_host = 'localhost' out_path = self.temp_dir self.local = local.Local( target_host=self.target_host, From 6482863c5d1bc7c75e6b0babe05524ff9bd6cbf0 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Nov 2012 22:32:18 +0100 Subject: [PATCH 49/95] allow manifest to return env for usage from external Signed-off-by: Nico Schottelius --- cdist/core/manifest.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/cdist/core/manifest.py b/cdist/core/manifest.py index 61d92992..324374c3 100644 --- a/cdist/core/manifest.py +++ b/cdist/core/manifest.py @@ -78,29 +78,37 @@ class Manifest(object): self.env.update({'__cdist_debug': "yes" }) - def run_initial_manifest(self, script): + def env_initial_manifest(self, script): env = os.environ.copy() env.update(self.env) env['__manifest'] = self.local.manifest_path env['__cdist_manifest'] = script + + return env + + def run_initial_manifest(self, script): self.log.info("Running initial manifest " + self.local.manifest_path) if not os.path.isfile(self.local.manifest_path): raise cdist.Error("Initial manifest is missing") - self.local.run_script(script, env=env) + self.local.run_script(script, env=self.env_initial_manifest(script)) + + def env_type_manifest(self, cdist_object): + env = os.environ.copy() + env.update(self.env) + env.update({ + '__manifest': self.local.manifest_path, + '__object': cdist_object.absolute_path, + '__object_id': cdist_object.object_id, + '__object_name': cdist_object.name, + '__type': cdist_object.cdist_type.absolute_path, + '__cdist_manifest': script, + }) + + return env def run_type_manifest(self, cdist_object): script = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path) if os.path.isfile(script): - env = os.environ.copy() - env.update(self.env) - env.update({ - '__manifest': self.local.manifest_path, - '__object': cdist_object.absolute_path, - '__object_id': cdist_object.object_id, - '__object_name': cdist_object.name, - '__type': cdist_object.cdist_type.absolute_path, - '__cdist_manifest': script, - }) - self.local.run_script(script, env=env) + self.local.run_script(script, env=self.env_type_manifest(cdist_object)) From 9cf80f5fdfb2bced3dc58178b7b3f4e3d6871da5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 6 Nov 2012 22:39:25 +0100 Subject: [PATCH 50/95] make use of env provided by manifest Signed-off-by: Nico Schottelius --- cdist/test/emulator/__init__.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index f9743e16..26530f44 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -39,6 +39,7 @@ my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') conf_dir = op.join(fixtures, 'conf') +import logging class EmulatorTestCase(test.CdistTestCase): def setUp(self): @@ -48,20 +49,17 @@ class EmulatorTestCase(test.CdistTestCase): handle, self.script = self.mkstemp(dir=self.temp_dir) os.close(handle) out_path = self.temp_dir + self.local = local.Local( target_host=self.target_host, out_path=out_path, exec_path=test.cdist_exec_path, add_conf_dirs=[conf_dir]) + logging.root.setLevel(logging.DEBUG) self.local.create_files_dirs() - self.env = { - 'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']), - '__target_host': self.target_host, - '__global': self.local.out_path, - '__cdist_type_base_path': self.local.type_path, # for use in type emulator - '__manifest': self.local.manifest_path, - '__cdist_manifest': self.script, - } + + self.manifest = core.Manifest(self.target_host, self.local) + self.env = self.manifest.env_initial_manifest(self.script) def tearDown(self): os.environ = self.orig_environ From e785092935b710fa48e1b9ca2d673ed69d5ea2a3 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 09:07:18 +0100 Subject: [PATCH 51/95] allow Manifest to differentiate between supplied and implicit found initial manifest Signed-off-by: Nico Schottelius --- cdist/core/manifest.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/cdist/core/manifest.py b/cdist/core/manifest.py index 324374c3..74d45947 100644 --- a/cdist/core/manifest.py +++ b/cdist/core/manifest.py @@ -86,15 +86,19 @@ class Manifest(object): return env - def run_initial_manifest(self, script): - self.log.info("Running initial manifest " + self.local.manifest_path) + def run_initial_manifest(self, initial_manifest=None): + if not initial_manifest: + initial_manifest = self.local.initial_manifest - if not os.path.isfile(self.local.manifest_path): - raise cdist.Error("Initial manifest is missing") + self.log.info("Running initial manifest " + initial_manifest) - self.local.run_script(script, env=self.env_initial_manifest(script)) + if not os.path.isfile(initial_manifest): + raise cdist.Error("Initial manifest is missing: %s" % initial_manifest) + + self.local.run_script(script, env=self.env_initial_manifest(initial_manifest)) def env_type_manifest(self, cdist_object): + type_manifest = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path) env = os.environ.copy() env.update(self.env) env.update({ @@ -103,12 +107,12 @@ class Manifest(object): '__object_id': cdist_object.object_id, '__object_name': cdist_object.name, '__type': cdist_object.cdist_type.absolute_path, - '__cdist_manifest': script, + '__cdist_manifest': type_manifest, }) return env def run_type_manifest(self, cdist_object): - script = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path) - if os.path.isfile(script): - self.local.run_script(script, env=self.env_type_manifest(cdist_object)) + type_manifest = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path) + if os.path.isfile(type_manifest): + self.local.run_script(type_manifest, env=self.env_type_manifest(cdist_object)) From 7b51e22922d2d118737594d65e111c8bef3348ee Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 09:58:47 +0100 Subject: [PATCH 52/95] allow to read stdin from different handle than sys.stdin in emulator Signed-off-by: Nico Schottelius --- cdist/emulator.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cdist/emulator.py b/cdist/emulator.py index dedb52ed..2d344f09 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -29,8 +29,9 @@ import cdist from cdist import core class Emulator(object): - def __init__(self, argv): + def __init__(self, argv, stdin=sys.stdin): self.argv = argv + self.stdin = stdin self.object_id = False self.global_path = os.environ['__global'] @@ -148,13 +149,13 @@ class Emulator(object): chunk_size = 8192 def _read_stdin(self): - return sys.stdin.buffer.read(self.chunk_size) + return self.stdin.buffer.read(self.chunk_size) def save_stdin(self): """If something is written to stdin, save it in the object as $__object/stdin so it can be accessed in manifest and gencode-* scripts. """ - if not sys.stdin.isatty(): + if not self.stdin.isatty(): try: # go directly to file instead of using CdistObject's api # as that does not support streaming From a32d3abd338937e1b7d9331204a477eb93746d80 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 10:25:47 +0100 Subject: [PATCH 53/95] allow to pass in environment into emulator Signed-off-by: Nico Schottelius --- cdist/emulator.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cdist/emulator.py b/cdist/emulator.py index 2d344f09..f65c9bec 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -29,17 +29,17 @@ import cdist from cdist import core class Emulator(object): - def __init__(self, argv, stdin=sys.stdin): + def __init__(self, argv, stdin=sys.stdin, env=os.environ): self.argv = argv self.stdin = stdin self.object_id = False - self.global_path = os.environ['__global'] - self.target_host = os.environ['__target_host'] + self.global_path = self.env['__global'] + self.target_host = self.env['__target_host'] # Internally only - self.object_source = os.environ['__cdist_manifest'] - self.type_base_path = os.environ['__cdist_type_base_path'] + self.object_source = self.env['__cdist_manifest'] + self.type_base_path = self.env['__cdist_type_base_path'] self.object_base_path = os.path.join(self.global_path, "object") @@ -63,7 +63,7 @@ class Emulator(object): def run(self): """Emulate type commands (i.e. __file and co)""" - if '__install' in os.environ: + if '__install' in self.env: if not self.cdist_type.is_install: self.log.debug("Running in install mode, ignoring non install type") return True @@ -80,7 +80,7 @@ class Emulator(object): logformat = '%(levelname)s: %(message)s' logging.basicConfig(format=logformat) - if '__cdist_debug' in os.environ: + if '__cdist_debug' in self.env: logging.root.setLevel(logging.DEBUG) else: logging.root.setLevel(logging.INFO) @@ -171,8 +171,8 @@ class Emulator(object): def record_requirements(self): """record requirements""" - if "require" in os.environ: - requirements = os.environ['require'] + if "require" in self.env: + requirements = self.env['require'] self.log.debug("reqs = " + requirements) for requirement in requirements.split(" "): # Ignore empty fields - probably the only field anyway @@ -192,7 +192,7 @@ class Emulator(object): """An object shall automatically depend on all objects that it defined in it's type manifest. """ # __object_name is the name of the object whose type manifest is currently executed - __object_name = os.environ.get('__object_name', None) + __object_name = self.env.get('__object_name', None) if __object_name: # The object whose type manifest is currently run parent = self.cdist_object.object_from_name(__object_name) From 1e4833781efb3bb38109a0348470597bed941113 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 10:48:30 +0100 Subject: [PATCH 54/95] distinguish between user supplied and derived manifest on error printing Signed-off-by: Nico Schottelius --- cdist/core/manifest.py | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/cdist/core/manifest.py b/cdist/core/manifest.py index 74d45947..1e34afbf 100644 --- a/cdist/core/manifest.py +++ b/cdist/core/manifest.py @@ -57,6 +57,29 @@ type manifeste is: creates: new objects through type emulator ''' +class NoInitialManifestError(cdist.Error): + """ + Display missing initial manifest: + - Display path if user given + - try to resolve link if it is a link + - Omit path if default (is a linked path in temp directory without + much help) + """ + + def __init__(self, manifest_path, user_supplied): + msg_header = "Initial manifest missing" + + if user_supplied: + if os.path.islink(manifest_path): + self.message = "%s: %s -> %s" (msg_header, manifest_path, os.path.realpath(manifest_path)) + else: + self.message = "%s: %s" (msg_header, manifest_path) + else: + self.message = "%s" (msg_header) + + def __str__(self): + return repr(self.message) + class Manifest(object): """Executes cdist manifests. @@ -70,44 +93,47 @@ class Manifest(object): self.env = { 'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']), - '__target_host': self.target_host, - '__global': self.local.out_path, '__cdist_type_base_path': self.local.type_path, # for use in type emulator + '__global': self.local.out_path, + '__target_host': self.target_host, } if self.log.getEffectiveLevel() == logging.DEBUG: self.env.update({'__cdist_debug': "yes" }) - def env_initial_manifest(self, script): + def env_initial_manifest(self, initial_manifest): env = os.environ.copy() env.update(self.env) + env['__cdist_manifest'] = initial_manifest env['__manifest'] = self.local.manifest_path - env['__cdist_manifest'] = script return env def run_initial_manifest(self, initial_manifest=None): if not initial_manifest: initial_manifest = self.local.initial_manifest + user_supplied = False + else: + user_supplied = True self.log.info("Running initial manifest " + initial_manifest) if not os.path.isfile(initial_manifest): - raise cdist.Error("Initial manifest is missing: %s" % initial_manifest) + raise NoInitialManifestError(initial_manifest, user_supplied) - self.local.run_script(script, env=self.env_initial_manifest(initial_manifest)) + self.local.run_script(initial_manifest, env=self.env_initial_manifest(initial_manifest)) def env_type_manifest(self, cdist_object): type_manifest = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path) env = os.environ.copy() env.update(self.env) env.update({ + '__cdist_manifest': type_manifest, '__manifest': self.local.manifest_path, '__object': cdist_object.absolute_path, '__object_id': cdist_object.object_id, '__object_name': cdist_object.name, '__type': cdist_object.cdist_type.absolute_path, - '__cdist_manifest': type_manifest, }) return env From 45d5e4719a83185670b4b57a469f166494c387e3 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 10:49:11 +0100 Subject: [PATCH 55/95] read from stdin using read, not buffer.read() to be compatible with other IO streams Signed-off-by: Nico Schottelius --- cdist/emulator.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cdist/emulator.py b/cdist/emulator.py index f65c9bec..53c6914d 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -32,6 +32,8 @@ class Emulator(object): def __init__(self, argv, stdin=sys.stdin, env=os.environ): self.argv = argv self.stdin = stdin + self.env = env + self.object_id = False self.global_path = self.env['__global'] @@ -147,9 +149,8 @@ class Emulator(object): # Record / Append source self.cdist_object.source.append(self.object_source) - chunk_size = 8192 def _read_stdin(self): - return self.stdin.buffer.read(self.chunk_size) + return self.stdin.read() def save_stdin(self): """If something is written to stdin, save it in the object as $__object/stdin so it can be accessed in manifest and gencode-* From 217d2bcb23516b3cfe5fa733928db91a6b8fdbca Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 10:49:51 +0100 Subject: [PATCH 56/95] Fix test: StdinTestCase Signed-off-by: Nico Schottelius --- cdist/test/autorequire/__init__.py | 1 - cdist/test/emulator/__init__.py | 69 ++++++++++++------- cdist/test/emulator/fixtures/conf/type/__file | 1 - 3 files changed, 45 insertions(+), 26 deletions(-) delete mode 120000 cdist/test/emulator/fixtures/conf/type/__file diff --git a/cdist/test/autorequire/__init__.py b/cdist/test/autorequire/__init__.py index 4b47b06b..2a647954 100644 --- a/cdist/test/autorequire/__init__.py +++ b/cdist/test/autorequire/__init__.py @@ -42,7 +42,6 @@ class AutorequireTestCase(test.CdistTestCase): def setUp(self): self.orig_environ = os.environ os.environ = os.environ.copy() - self.target_host = 'localhost' self.temp_dir = self.mkdtemp() self.out_dir = os.path.join(self.temp_dir, "out") diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index 26530f44..ec254a21 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -20,6 +20,7 @@ # # +import io import os import shutil import string @@ -141,7 +142,6 @@ class ArgumentsTestCase(test.CdistTestCase): def setUp(self): self.temp_dir = self.mkdtemp() - self.target_host = 'localhost' out_path = self.temp_dir handle, self.script = self.mkstemp(dir=self.temp_dir) os.close(handle) @@ -236,38 +236,59 @@ class StdinTestCase(test.CdistTestCase): def setUp(self): self.orig_environ = os.environ os.environ = os.environ.copy() - self.target_host = 'localhost' + self.temp_dir = self.mkdtemp() - os.environ['__cdist_out_dir'] = self.temp_dir + out_path = os.path.join(self.temp_dir, "out") - self.context = cdist.context.Context( + self.local = local.Local( target_host=self.target_host, - remote_copy='scp -o User=root -q', - remote_exec='ssh -o User=root -q', + out_path=out_path, exec_path=test.cdist_exec_path, - debug=False) - self.config = config.Config(self.context) + add_conf_dirs=[conf_dir]) + self.local.create_files_dirs() + + self.manifest = core.Manifest( + target_host=self.target_host, + local = self.local) + def tearDown(self): os.environ = self.orig_environ shutil.rmtree(self.temp_dir) def test_file_from_stdin(self): - handle, destination = self.mkstemp(dir=self.temp_dir) - os.close(handle) - source_handle, source = self.mkstemp(dir=self.temp_dir) - candidates = string.ascii_letters+string.digits - with os.fdopen(source_handle, 'w') as fd: - for x in range(100): - fd.write(''.join(random.sample(candidates, len(candidates)))) + """ + Test whether reading from stdin works + """ - handle, initial_manifest = self.mkstemp(dir=self.temp_dir) - with os.fdopen(handle, 'w') as fd: - fd.write('__file_from_stdin %s --source %s\n' % (destination, source)) - self.context.initial_manifest = initial_manifest - self.config.stage_prepare() + ###################################################################### + # Create string with random content + random_string = str(random.sample(range(1000), 800)) + random_buffer = io.BytesIO(bytes(random_string, 'utf-8')) - cdist_type = core.CdistType(self.config.local.type_path, '__file') - cdist_object = core.CdistObject(cdist_type, self.config.local.object_path, destination) - # Test weither stdin has been stored correctly - self.assertTrue(filecmp.cmp(source, os.path.join(cdist_object.absolute_path, 'stdin'))) + ###################################################################### + # Prepare required args and environment for emulator + type_name = '__file' + object_id = "cdist-test-id" + argv = [type_name, object_id] + + initial_manifest_path = "/cdist-test/path/that/does/not/exist" + env = self.manifest.env_initial_manifest(initial_manifest_path) + + ###################################################################### + # Create path where stdin should reside at + cdist_type = core.CdistType(self.local.type_path, type_name) + cdist_object = core.CdistObject(cdist_type, self.local.object_path, object_id) + stdin_out_path = os.path.join(cdist_object.absolute_path, 'stdin') + + ###################################################################### + # Run emulator + emu = emulator.Emulator(argv, stdin=random_buffer, env=env) + emu.run() + + ###################################################################### + # Read where emulator should have placed stdin + with open(stdin_out_path, 'r') as fd: + stdin_saved_by_emulator = fd.read() + + self.assertEqual(random_string, stdin_saved_by_emulator) diff --git a/cdist/test/emulator/fixtures/conf/type/__file b/cdist/test/emulator/fixtures/conf/type/__file deleted file mode 120000 index 1ed684b9..00000000 --- a/cdist/test/emulator/fixtures/conf/type/__file +++ /dev/null @@ -1 +0,0 @@ -../../../../../conf/type/__file \ No newline at end of file From 4dd0f61934cb2123eafefe9a16d65b9b86406040 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 10:51:13 +0100 Subject: [PATCH 57/95] --whitespace Signed-off-by: Nico Schottelius --- cdist/test/emulator/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index ec254a21..ecbb97a3 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -212,7 +212,7 @@ class ArgumentsTestCase(test.CdistTestCase): # 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): @@ -251,7 +251,7 @@ class StdinTestCase(test.CdistTestCase): self.manifest = core.Manifest( target_host=self.target_host, local = self.local) - + def tearDown(self): os.environ = self.orig_environ shutil.rmtree(self.temp_dir) From e2e1d0bb67cfb4578177c0b2cd3ce86fbda5e76c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 11:05:29 +0100 Subject: [PATCH 58/95] include % Signed-off-by: Nico Schottelius --- cdist/core/manifest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cdist/core/manifest.py b/cdist/core/manifest.py index 1e34afbf..19639618 100644 --- a/cdist/core/manifest.py +++ b/cdist/core/manifest.py @@ -71,11 +71,11 @@ class NoInitialManifestError(cdist.Error): if user_supplied: if os.path.islink(manifest_path): - self.message = "%s: %s -> %s" (msg_header, manifest_path, os.path.realpath(manifest_path)) + self.message = "%s: %s -> %s" % (msg_header, manifest_path, os.path.realpath(manifest_path)) else: - self.message = "%s: %s" (msg_header, manifest_path) + self.message = "%s: %s" % (msg_header, manifest_path) else: - self.message = "%s" (msg_header) + self.message = "%s" % (msg_header) def __str__(self): return repr(self.message) From 7d57d1df79a6e91efbe50eeddfe501085f96496e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 11:05:40 +0100 Subject: [PATCH 59/95] update emulator tests to work again Signed-off-by: Nico Schottelius --- cdist/test/emulator/__init__.py | 57 +++++++++++---------------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index ecbb97a3..fc0b6695 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -40,12 +40,9 @@ my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') conf_dir = op.join(fixtures, 'conf') -import logging class EmulatorTestCase(test.CdistTestCase): def setUp(self): - self.orig_environ = os.environ - os.environ = os.environ.copy() self.temp_dir = self.mkdtemp() handle, self.script = self.mkstemp(dir=self.temp_dir) os.close(handle) @@ -56,72 +53,61 @@ class EmulatorTestCase(test.CdistTestCase): out_path=out_path, exec_path=test.cdist_exec_path, add_conf_dirs=[conf_dir]) - logging.root.setLevel(logging.DEBUG) 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): - os.environ = self.orig_environ shutil.rmtree(self.temp_dir) def test_nonexistent_type_exec(self): argv = ['__does-not-exist'] - os.environ.update(self.env) - self.assertRaises(core.NoSuchTypeError, emulator.Emulator, argv) + self.assertRaises(core.NoSuchTypeError, emulator.Emulator, argv, env=self.env) def test_nonexistent_type_requirement(self): argv = ['__file', '/tmp/foobar'] - os.environ.update(self.env) - os.environ['require'] = '__does-not-exist/some-id' - emu = emulator.Emulator(argv) + self.env['require'] = '__does-not-exist/some-id' + emu = emulator.Emulator(argv, env=self.env) self.assertRaises(core.NoSuchTypeError, emu.run) def test_illegal_object_id_requirement(self): argv = ['__file', '/tmp/foobar'] - os.environ.update(self.env) - os.environ['require'] = '__file/bad/id/with/.cdist/inside' - emu = emulator.Emulator(argv) + self.env['require'] = '__file/bad/id/with/.cdist/inside' + emu = emulator.Emulator(argv, env=self.env) self.assertRaises(core.IllegalObjectIdError, emu.run) def test_missing_object_id_requirement(self): argv = ['__file', '/tmp/foobar'] - os.environ.update(self.env) - os.environ['require'] = '__file' - emu = emulator.Emulator(argv) + self.env['require'] = '__file' + emu = emulator.Emulator(argv, env=self.env) self.assertRaises(core.IllegalObjectIdError, emu.run) def test_singleton_object_requirement(self): argv = ['__file', '/tmp/foobar'] - os.environ.update(self.env) - os.environ['require'] = '__issue' - emu = emulator.Emulator(argv) + self.env['require'] = '__issue' + emu = emulator.Emulator(argv, env=self.env) emu.run() # if we get here all is fine def test_requirement_pattern(self): argv = ['__file', '/tmp/foobar'] - os.environ.update(self.env) - os.environ['require'] = '__file/etc/*' - emu = emulator.Emulator(argv) + self.env['require'] = '__file/etc/*' + emu = emulator.Emulator(argv, env=self.env) # if we get here all is fine -import os.path as op -my_dir = op.abspath(op.dirname(__file__)) -fixtures = op.join(my_dir, 'fixtures') - class AutoRequireEmulatorTestCase(test.CdistTestCase): def setUp(self): self.temp_dir = self.mkdtemp() - self.target_host = 'localhost' - out_path = self.temp_dir + out_path = os.path.join(self.temp_dir, "out") + self.local = local.Local( target_host=self.target_host, out_path=out_path, - exec_path=test.cdist_exec_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) @@ -149,17 +135,12 @@ class ArgumentsTestCase(test.CdistTestCase): self.local = local.Local( target_host=self.target_host, out_path=out_path, - exec_path=test.cdist_exec_path) + exec_path=test.cdist_exec_path, + add_conf_dirs=[conf_dir]) self.local.create_files_dirs() - self.env = { - 'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']), - '__target_host': self.target_host, - '__global': self.local.out_path, - '__cdist_type_base_path': self.local.type_path, # for use in type emulator - '__manifest': self.local.manifest_path, - '__cdist_manifest': self.script, - } + 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) From 1bb3c82d729a1c0b721f10000e2012218812d467 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 11:47:26 +0100 Subject: [PATCH 60/95] cleanup some logging stuff Signed-off-by: Nico Schottelius --- cdist/test/code/__init__.py | 5 +---- cdist/test/explorer/__init__.py | 3 --- cdist/test/manifest/__init__.py | 2 ++ 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/cdist/test/code/__init__.py b/cdist/test/code/__init__.py index f5d445ab..284ef9c0 100644 --- a/cdist/test/code/__init__.py +++ b/cdist/test/code/__init__.py @@ -20,10 +20,9 @@ # # +import getpass import os import shutil -import getpass -import logging import cdist from cdist import core @@ -63,8 +62,6 @@ class CodeTestCase(test.CdistTestCase): self.cdist_object = core.CdistObject(self.cdist_type, self.local.object_path, 'whatever') self.cdist_object.create() - self.log = logging.getLogger("cdist") - def tearDown(self): shutil.rmtree(self.out_path) shutil.rmtree(self.remote_base_path) diff --git a/cdist/test/explorer/__init__.py b/cdist/test/explorer/__init__.py index 266a1073..a97b538a 100644 --- a/cdist/test/explorer/__init__.py +++ b/cdist/test/explorer/__init__.py @@ -23,7 +23,6 @@ import os import shutil import getpass -import logging import cdist from cdist import core @@ -67,8 +66,6 @@ class ExplorerClassTestCase(test.CdistTestCase): self.local, self.remote) - self.log = logging.getLogger(self.target_host) - def tearDown(self): shutil.rmtree(self.temp_dir) diff --git a/cdist/test/manifest/__init__.py b/cdist/test/manifest/__init__.py index 0de04743..727017e7 100644 --- a/cdist/test/manifest/__init__.py +++ b/cdist/test/manifest/__init__.py @@ -107,6 +107,8 @@ class ManifestTestCase(test.CdistTestCase): self.assertEqual(output_dict['__object_name'], cdist_object.name) def test_debug_env_setup(self): + current_level = self.log.getEffectiveLevel() self.log.setLevel(logging.DEBUG) manifest = cdist.core.manifest.Manifest(self.target_host, self.local) self.assertTrue("__cdist_debug" in manifest.env) + self.log.setLevel(current_level) From 37ea64d23b00e6f70e288ebb266950ac8d755f93 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 12:12:26 +0100 Subject: [PATCH 61/95] automate blog & ml Signed-off-by: Nico Schottelius --- build | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 5 deletions(-) diff --git a/build b/build index def72470..776da03f 100755 --- a/build +++ b/build @@ -35,6 +35,7 @@ A2XH="a2x -f xhtml --no-xmllint -a encoding=UTF-8" # Developer webbase WEBDIR=$HOME/niconetz +WEBBLOG=$WEBDIR/blog WEBBASE=$WEBDIR/software/cdist WEBMAN=$WEBBASE/man/$version WEBPAGE=${WEBBASE}.mdwn @@ -108,9 +109,14 @@ case "$1" in $0 pub + $0 dist-blog $0 dist-freecode + $0 dist-ml + $0 dist-manual + ;; - $0 dist-post + changelog-changes) + awk -F: 'BEGIN { start=0 } { if ($0 ~ /^[[:digit:]]/) { if(start == 0) {start = 1 } else { exit } } else { if(start==1) {print $0 }} }' "$basedir/docs/changelog" ;; changelog-version) @@ -144,15 +150,78 @@ case "$1" in ;; - dist-post) + blog) + version=$($0 changelog-version) + blogfile=$WEBBLOG/cdist-${version}-released.mdwn + cat << eof > "$blogfile" +[[!meta title="Cdist $version released"]] + +Here's a short overview about the changes found in this release: + +eof + + $0 changelog-changes >> "$blogfile" + + cat << eof >> "$blogfile" +For more information visit the [[cdist homepage|software/cdist]]. + +[[!tag cdist config unix]] +eof + ;; + + dist-blog) + $0 blog + version=$($0 changelog-version) + file=cdist-${version}-released.mdwn + cd $WEBBBLOG + git add "$file" + git commit -m "New cdist version (blogentry): $version" "$file" + git push + ;; + + dist-ml) + $0 blog + version=$($0 changelog-version) + to_a=cdist + to_d=l.schottelius.org + to=${to_a}@${to_d} + + from_a=nico-cdist + from_d=schottelius.org + from=${from_a}@${from_d} + + ( + cat << eof +From: Nico -telmich- Schottelius <$from> +To: cdist mailing list <$to> +Subject: [cdist] cdist $version released + +Hello .*, + +cdist $version has been released with the following changes: + +eof + + "$0" changelog-changes + cat << eof + +Cheers, + +Nico + +-- +Automatisation at its best level. With cdist. +eof + ) | /usr/sbin/sendmail -f "$from" "$to" + ;; + + + dist-manual) cat << notes To be done manually... - - freecode release - - blog entry - linkedin entry - - mailinglist update notes ;; From c53d1807524c30ee497782dae347e1026a595329 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 12:12:33 +0100 Subject: [PATCH 62/95] release 2.1.0pre7 Signed-off-by: Nico Schottelius --- docs/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/changelog b/docs/changelog index 93c3cf69..f8030609 100644 --- a/docs/changelog +++ b/docs/changelog @@ -4,8 +4,8 @@ Changelog * Changes are always commented with their author in (braces) * Exception: No braces means author == Nico Schottelius -2.1.0pre7: - * Core: Tests for autorequire, code, manifest work again +2.1.0pre7: 2012-11-07 + * Core: All unit tests restored back to working * Core: Print error message on missing initial manifest 2.1.0pre6: 2012-11-05 From e786803daec2d598bcc2853469dccb297e0d6cfc Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 12:13:06 +0100 Subject: [PATCH 63/95] strip prefix away Signed-off-by: Nico Schottelius --- build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build b/build index 776da03f..34775a31 100755 --- a/build +++ b/build @@ -194,7 +194,7 @@ eof cat << eof From: Nico -telmich- Schottelius <$from> To: cdist mailing list <$to> -Subject: [cdist] cdist $version released +Subject: cdist $version released Hello .*, From 7a1f81dc7b15defa8ae41fdf9f227dd8213fead1 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 7 Nov 2012 16:54:34 +0100 Subject: [PATCH 64/95] remove install types Signed-off-by: Steven Armstrong --- cdist/conf/type/__mkfs/gencode-remote | 38 ----- cdist/conf/type/__mkfs/install | 0 cdist/conf/type/__mkfs/man.text | 57 -------- cdist/conf/type/__mkfs/manifest | 31 ---- cdist/conf/type/__mkfs/parameter/optional | 3 - cdist/conf/type/__mkfs/parameter/required | 1 - cdist/conf/type/__partition_msdos/install | 0 cdist/conf/type/__partition_msdos/man.text | 62 -------- cdist/conf/type/__partition_msdos/manifest | 41 ------ .../type/__partition_msdos/parameter/optional | 3 - .../type/__partition_msdos/parameter/required | 1 - .../explorer/partitions | 3 - .../type/__partition_msdos_apply/files/lib.sh | 61 -------- .../__partition_msdos_apply/gencode-remote | 138 ------------------ .../conf/type/__partition_msdos_apply/install | 0 .../type/__partition_msdos_apply/man.text | 42 ------ .../type/__partition_msdos_apply/singleton | 0 17 files changed, 481 deletions(-) delete mode 100755 cdist/conf/type/__mkfs/gencode-remote delete mode 100644 cdist/conf/type/__mkfs/install delete mode 100644 cdist/conf/type/__mkfs/man.text delete mode 100755 cdist/conf/type/__mkfs/manifest delete mode 100644 cdist/conf/type/__mkfs/parameter/optional delete mode 100644 cdist/conf/type/__mkfs/parameter/required delete mode 100644 cdist/conf/type/__partition_msdos/install delete mode 100644 cdist/conf/type/__partition_msdos/man.text delete mode 100755 cdist/conf/type/__partition_msdos/manifest delete mode 100644 cdist/conf/type/__partition_msdos/parameter/optional delete mode 100644 cdist/conf/type/__partition_msdos/parameter/required delete mode 100755 cdist/conf/type/__partition_msdos_apply/explorer/partitions delete mode 100644 cdist/conf/type/__partition_msdos_apply/files/lib.sh delete mode 100755 cdist/conf/type/__partition_msdos_apply/gencode-remote delete mode 100644 cdist/conf/type/__partition_msdos_apply/install delete mode 100644 cdist/conf/type/__partition_msdos_apply/man.text delete mode 100644 cdist/conf/type/__partition_msdos_apply/singleton diff --git a/cdist/conf/type/__mkfs/gencode-remote b/cdist/conf/type/__mkfs/gencode-remote deleted file mode 100755 index b3561bad..00000000 --- a/cdist/conf/type/__mkfs/gencode-remote +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# -# 2011 Steven Armstrong (steven-cdist at 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 . -# - -device="$(cat "$__object/parameter/device")" -type="$(cat "$__object/parameter/type")" - -if [ "$type" = "swap" ]; then - echo "mkswap $device" -else - command="mkfs -t $type -q" - if [ -f "$__object/parameter/options" ]; then - options="$(cat "$__object/parameter/options")" - command="$command $options" - fi - command="$command $device" - if [ -f "$__object/parameter/blocks" ]; then - blocks="$(cat "$__object/parameter/blocks")" - command="$command $blocks" - fi - echo "$command" -fi diff --git a/cdist/conf/type/__mkfs/install b/cdist/conf/type/__mkfs/install deleted file mode 100644 index e69de29b..00000000 diff --git a/cdist/conf/type/__mkfs/man.text b/cdist/conf/type/__mkfs/man.text deleted file mode 100644 index 4320c639..00000000 --- a/cdist/conf/type/__mkfs/man.text +++ /dev/null @@ -1,57 +0,0 @@ -cdist-type__mkfs(7) -=================== -Steven Armstrong - - -NAME ----- -cdist-type__mkfs - build a linux file system - - -DESCRIPTION ------------ -This cdist type is a wrapper for the mkfs command. - - -REQUIRED PARAMETERS -------------------- -type:: - The filesystem type to use. Same as mkfs -t. - - -OPTIONAL PARAMETERS -------------------- -device:: - defaults to object_id - -options:: - file system-specific options to be passed to the mkfs command - -blocks:: - the number of blocks to be used for the file system - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# reiserfs /dev/sda5 -__mkfs /dev/sda5 --type reiserfs -# same thing with explicit device -__mkfs whatever --device /dev/sda5 --type reiserfs - -# jfs with journal on /dev/sda2 -__mkfs /dev/sda1 --type jfs --options "-j /dev/sda2" --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) -- mkfs(8) - - -COPYING -------- -Copyright \(C) 2011 Steven Armstrong. 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/__mkfs/manifest b/cdist/conf/type/__mkfs/manifest deleted file mode 100755 index e9d275a4..00000000 --- a/cdist/conf/type/__mkfs/manifest +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh -# -# 2011 Steven Armstrong (steven-cdist at 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 . -# - -# set defaults -if [ -f "$__object/parameter/device" ]; then - device="(cat "$__object/parameter/device")" -else - device="/$__object_id" - echo "$device" > "$__object/parameter/device" -fi - -type="(cat "$__object/parameter/type")" - -options="(cat "$__object/parameter/options")" diff --git a/cdist/conf/type/__mkfs/parameter/optional b/cdist/conf/type/__mkfs/parameter/optional deleted file mode 100644 index 86aeae30..00000000 --- a/cdist/conf/type/__mkfs/parameter/optional +++ /dev/null @@ -1,3 +0,0 @@ -device -options -blocks diff --git a/cdist/conf/type/__mkfs/parameter/required b/cdist/conf/type/__mkfs/parameter/required deleted file mode 100644 index aa80e646..00000000 --- a/cdist/conf/type/__mkfs/parameter/required +++ /dev/null @@ -1 +0,0 @@ -type diff --git a/cdist/conf/type/__partition_msdos/install b/cdist/conf/type/__partition_msdos/install deleted file mode 100644 index e69de29b..00000000 diff --git a/cdist/conf/type/__partition_msdos/man.text b/cdist/conf/type/__partition_msdos/man.text deleted file mode 100644 index 78220ee0..00000000 --- a/cdist/conf/type/__partition_msdos/man.text +++ /dev/null @@ -1,62 +0,0 @@ -cdist-type__partition_msdos(7) -============================== -Steven Armstrong - - -NAME ----- -cdist-type__partition_msdos - creates msdos partitions - - -DESCRIPTION ------------ -This cdist type allows you to create msdos paritions. - - -REQUIRED PARAMETERS -------------------- -type:: - the partition type used in fdisk (such as 82 or 83) or "extended" - - -OPTIONAL PARAMETERS -------------------- -partition:: - defaults to object_id -bootable:: - mark partition as bootable, true or false, defaults to false -size:: - the size of the partition (such as 32M or 15G, whole numbers - only), '+' for remaining space, or 'n%' for percentage of remaining - (these should only be used after all specific partition sizes are - specified). Defaults to +. - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# 128MB, linux, bootable -__partition_msdos /dev/sda1 --type 83 --size 128M --bootable true -# 512MB, swap -__partition_msdos /dev/sda2 --type 82 --size 512M -# 100GB, extended -__partition_msdos /dev/sda3 --type extended --size 100G -# 10GB, linux -__partition_msdos /dev/sda5 --type 83 --size 10G -# 50% of the free space of the extended partition, linux -__partition_msdos /dev/sda6 --type 83 --size 50% -# rest of the extended partition, linux -__partition_msdos /dev/sda7 --type 83 --size + --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) - - -COPYING -------- -Copyright \(C) 2011 Steven Armstrong. 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/__partition_msdos/manifest b/cdist/conf/type/__partition_msdos/manifest deleted file mode 100755 index 21e43856..00000000 --- a/cdist/conf/type/__partition_msdos/manifest +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh -# -# 2011 Steven Armstrong (steven-cdist at 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 . -# - -# set defaults -if [ -f "$__object/parameter/partition" ]; then - partition="(cat "$__object/parameter/partition")" -else - partition="/$__object_id" - echo "$partition" > "$__object/parameter/partition" -fi -device="$(echo "$partition" | sed 's/[0-9]//g')" -echo "$device" > "$__object/parameter/device" -minor="$(echo "$partition" | sed 's/[^0-9]//g')" -echo "$minor" > "$__object/parameter/minor" - -if [ ! -f "$__object/parameter/bootable" ]; then - echo "false" > "$__object/parameter/bootable" -fi -if [ ! -f "$__object/parameter/size" ]; then - echo "+" > "$__object/parameter/size" -fi - -# pull in the type that actually does something with the above parameters -require="$__object_name" __partition_msdos_apply diff --git a/cdist/conf/type/__partition_msdos/parameter/optional b/cdist/conf/type/__partition_msdos/parameter/optional deleted file mode 100644 index b2b0a4c2..00000000 --- a/cdist/conf/type/__partition_msdos/parameter/optional +++ /dev/null @@ -1,3 +0,0 @@ -partition -bootable -size diff --git a/cdist/conf/type/__partition_msdos/parameter/required b/cdist/conf/type/__partition_msdos/parameter/required deleted file mode 100644 index aa80e646..00000000 --- a/cdist/conf/type/__partition_msdos/parameter/required +++ /dev/null @@ -1 +0,0 @@ -type diff --git a/cdist/conf/type/__partition_msdos_apply/explorer/partitions b/cdist/conf/type/__partition_msdos_apply/explorer/partitions deleted file mode 100755 index 6be61af4..00000000 --- a/cdist/conf/type/__partition_msdos_apply/explorer/partitions +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -cat /proc/partitions diff --git a/cdist/conf/type/__partition_msdos_apply/files/lib.sh b/cdist/conf/type/__partition_msdos_apply/files/lib.sh deleted file mode 100644 index 5767ea43..00000000 --- a/cdist/conf/type/__partition_msdos_apply/files/lib.sh +++ /dev/null @@ -1,61 +0,0 @@ -die() { - echo "[__partition_msdos_apply] $@" >&2 - exit 1 -} -debug() { - #echo "[__partition_msdos_apply] $@" >&2 - : -} - -fdisk_command() { - local device="$1" - local cmd="$2" - - debug fdisk_command "running fdisk command '${cmd}' on device ${device}" - printf "${cmd}\nw\n" | fdisk -c -u "$device" - # give disk some time - sleep 1 - return $? -} - -create_disklabel() { - local device=$1 - - debug create_disklabel "creating new msdos disklabel" - fdisk_command ${device} "o" - return $? -} - -create_partition() { - local device="$1" - local minor="$2" - local size="$3" - local type="$4" - local primary_count="$5" - - if [ "$type" = "extended" -o "$type" = "5" ]; then - # Extended partition - primary_extended="e\n" - first_minor="${minor}\n" - [ "${minor}" = "4" ] && first_minor="" - type_minor="${minor}\n" - [ "${minor}" = "1" ] && type_minor="" - type="5" - elif [ "${minor}" -lt "5" ]; then - primary_extended="p\n" - first_minor="${minor}\n" - [ "${minor}" = "4" ] && first_minor="" - type_minor="${minor}\n" - [ "${minor}" = "1" ] && type_minor="" - else - # Logical partitions - first_minor="${minor}\n" - type_minor="${minor}\n" - primary_extended="l\n" - [ "$primary_count" -gt "3" ] && primary_extended="" - fi - [ -n "${size}" ] && size="+${size}M" - fdisk_command ${device} "n\n${primary_extended}${first_minor}\n${size}\nt\n${type_minor}${type}\n" - return $? -} - diff --git a/cdist/conf/type/__partition_msdos_apply/gencode-remote b/cdist/conf/type/__partition_msdos_apply/gencode-remote deleted file mode 100755 index 5dab7070..00000000 --- a/cdist/conf/type/__partition_msdos_apply/gencode-remote +++ /dev/null @@ -1,138 +0,0 @@ -#!/bin/sh -# -# 2011 Steven Armstrong (steven-cdist at 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 . -# - -die() { - echo "[__partition_msdos_apply] $@" >&2 - exit 1 -} -debug() { - #echo "[__partition_msdos_apply] $@" >&2 - : -} - -# Convert a size specifier 1G 100M or 50% into the corresponding numeric MB. -size_to_mb() { - local size=$1 - local available_size="$2" - - local number_suffix="$(echo ${size} | sed -e 's:\.[0-9]\+::' -e 's:\([0-9]\+\)\([MmGg%]\)[Bb]\?:\1|\2:')" - local number="$(echo ${number_suffix} | cut -d '|' -f1)" - local suffix="$(echo ${number_suffix} | cut -d '|' -f2)" - - case "$suffix" in - M|m) - size="$number" - ;; - G|g) - size="$(( $number * 1024 ))" - ;; - %) - size="$(( $available_size * $number / 100 ))" - ;; - *) - size="-1" - esac - echo "$size" -} - -# include function library for use on target -cat "$__type/files/lib.sh" - -partitions="$__object/explorer/partitions" -objects=$(find "$__global/object/__partition_msdos" -path "*.cdist") -current_device="" -available_device_size= -available_extended_size= -available_size= -primary_count=0 -for object in $objects; do - device="$(cat "$object/parameter/device")" - if [ "$current_device" != "$device" ]; then - echo "create_disklabel \"$device\" || die 'Failed to create disklabel for $device'" - current_device="$device" - device_name=$(echo ${device} | sed -e 's:^/dev/::;s:/:\\/:g') - available_device_size=$(( $(awk "/${device_name}\$/ { print \$3; }" "$partitions") / 1024)) - # make sure we don't go past the end of the drive - available_device_size=$((available_device_size - 2)) - available_extended_size=0 - primary_count=0 - debug "----- $device" - debug "current_device=$current_device" - debug "available_device_size=$available_device_size" - fi - - type="$(cat "$object/parameter/type")" - partition="$(cat "$object/parameter/partition")" - minor="$(cat "$object/parameter/minor")" - - bootable="$(cat "$object/parameter/bootable")" - size="$(cat "$object/parameter/size")" - - - if [ "${minor}" -lt "5" ]; then - # Primary partitions - primary_count=$(( $primary_count + 1 )) - available_size=$available_device_size - else - # Logical partitions - available_size=$available_extended_size - fi - - if [ "$size" = "+" ]; then - # use rest of device - partition_size="" - available_size=0 - else - partition_size=$(size_to_mb "$size" "$available_size") - available_size="$(( $available_size - $partition_size ))" - fi - - if [ "${minor}" -lt "5" ]; then - # Primary partitions - available_device_size=$available_size - if [ "$type" = "extended" -o "$type" = "5" ]; then - # Extended partition - available_extended_size=$partition_size - fi - else - # Logical paritions - available_extended_size=$available_size - fi - - [ "$partition_size" = "-1" ] && die "could not translate size '$size' to a usable value" - debug "----- $partition" - debug "primary_count=$primary_count" - debug "current_device=$current_device" - debug "device=$device" - debug "type=$type" - debug "partition=$partition" - debug "minor=$minor" - debug "bootable=$bootable" - debug "size=$size" - debug "partition_size=$partition_size" - debug "available_size=$available_size" - debug "available_device_size=$available_device_size" - debug "available_extended_size=$available_extended_size" - debug "----------" - - echo "create_partition '$device' '$minor' '$partition_size' '$type' '$primary_count' \ - || die 'Failed to create partition: $partition'" -done - diff --git a/cdist/conf/type/__partition_msdos_apply/install b/cdist/conf/type/__partition_msdos_apply/install deleted file mode 100644 index e69de29b..00000000 diff --git a/cdist/conf/type/__partition_msdos_apply/man.text b/cdist/conf/type/__partition_msdos_apply/man.text deleted file mode 100644 index 6cc53b77..00000000 --- a/cdist/conf/type/__partition_msdos_apply/man.text +++ /dev/null @@ -1,42 +0,0 @@ -cdist-type__partition_msdos_apply(7) -==================================== -Steven Armstrong - - -NAME ----- -cdist-type__partition_msdos_apply - Apply dos partition settings - - -DESCRIPTION ------------ -Create the partitions defined with __partition_msdos - - -REQUIRED PARAMETERS -------------------- -None - - -OPTIONAL PARAMETERS -------------------- -None. - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -__partition_msdos_apply --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) -- cdist-type__partition_msdos_apply(7) - -COPYING -------- -Copyright \(C) 2011 Steven Armstrong. 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/__partition_msdos_apply/singleton b/cdist/conf/type/__partition_msdos_apply/singleton deleted file mode 100644 index e69de29b..00000000 From 03cc2a63b163fabd2654843acbabba5d00301d1b Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 7 Nov 2012 14:28:30 +0100 Subject: [PATCH 65/95] types to handle autofs maps Signed-off-by: Steven Armstrong --- cdist/conf/type/__autofs/man.text | 42 +++++++++ .../gencode-local => __autofs/manifest} | 26 ++++-- .../{__autofs_master => __autofs}/singleton | 0 cdist/conf/type/__autofs_map/explorer/entry | 50 ++++++++++ cdist/conf/type/__autofs_map/gencode-remote | 93 +++++++++++++++++++ cdist/conf/type/__autofs_map/man.text | 20 +++- cdist/conf/type/__autofs_map/manifest | 45 +++++---- .../conf/type/__autofs_map/parameter/boolean | 1 + .../__autofs_master/files/auto.master.header | 3 - .../type/__autofs_master/parameter/optional | 1 - .../gencode-remote} | 24 +++-- .../man.text | 23 ++--- cdist/conf/type/__autofs_reload/singleton | 0 13 files changed, 273 insertions(+), 55 deletions(-) create mode 100644 cdist/conf/type/__autofs/man.text rename cdist/conf/type/{__autofs_master/gencode-local => __autofs/manifest} (59%) rename cdist/conf/type/{__autofs_master => __autofs}/singleton (100%) create mode 100755 cdist/conf/type/__autofs_map/explorer/entry create mode 100755 cdist/conf/type/__autofs_map/gencode-remote create mode 100644 cdist/conf/type/__autofs_map/parameter/boolean delete mode 100644 cdist/conf/type/__autofs_master/files/auto.master.header delete mode 100644 cdist/conf/type/__autofs_master/parameter/optional rename cdist/conf/type/{__autofs_master/manifest => __autofs_reload/gencode-remote} (62%) rename cdist/conf/type/{__autofs_master => __autofs_reload}/man.text (51%) create mode 100644 cdist/conf/type/__autofs_reload/singleton diff --git a/cdist/conf/type/__autofs/man.text b/cdist/conf/type/__autofs/man.text new file mode 100644 index 00000000..9b343309 --- /dev/null +++ b/cdist/conf/type/__autofs/man.text @@ -0,0 +1,42 @@ +cdist-type__autofs(7) +===================== +Steven Armstrong + + +NAME +---- +cdist-type__autofs - install and start autofs + + +DESCRIPTION +----------- +This space intentionally left blank. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +None. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__autofs +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2012 Steven Armstrong. 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/__autofs_master/gencode-local b/cdist/conf/type/__autofs/manifest similarity index 59% rename from cdist/conf/type/__autofs_master/gencode-local rename to cdist/conf/type/__autofs/manifest index 701f97a8..31844415 100755 --- a/cdist/conf/type/__autofs_master/gencode-local +++ b/cdist/conf/type/__autofs/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -17,10 +17,22 @@ # You should have received a copy of the GNU General Public License # along with cdist. If not, see . # -# -# Generate auto.master config based on all defined __autofs_map ojbects. -# -auto_master="$__object/files/auto.master" -cat "$(cat "$__object/parameter/header")" > "$auto_master" -find "$__global/object/__autofs_map" -path "*.cdist/parameter/entry" | xargs cat >> "$auto_master" + +os=$(cat "$__global/explorer/os") + +not_supported() { + echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 +} + +case "$os" in + ubuntu|debian|archlinux) + __package autofs --state present + __start_on_boot autofs --state present + ;; + *) + not_supported + ;; +esac diff --git a/cdist/conf/type/__autofs_master/singleton b/cdist/conf/type/__autofs/singleton similarity index 100% rename from cdist/conf/type/__autofs_master/singleton rename to cdist/conf/type/__autofs/singleton diff --git a/cdist/conf/type/__autofs_map/explorer/entry b/cdist/conf/type/__autofs_map/explorer/entry new file mode 100755 index 00000000..7aa26518 --- /dev/null +++ b/cdist/conf/type/__autofs_map/explorer/entry @@ -0,0 +1,50 @@ +#!/bin/sh +# +# 2011 - 2012 Steven Armstrong (steven-cdist at 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 . +# + +candidates="/etc/auto.master /etc/autofs/auto.master" +find_auto_master() { + # get the path of the auto.master file + for candidate in $candidates; do + if [ -f "$candidate" ]; then + echo "$candidate" + return + fi + done +} + +auto_master="$(find_auto_master)" + +# no auto.master, nothing we could do +[ -f "$auto_master" ] || exit 0 + +# NOTE: keep variables in sync in manifest/explorer/gencode-* +prefix="#cdist:$__object_name" +suffix="#/cdist:$__object_name" +awk -v prefix="$prefix" -v suffix="$suffix" '{ + if (index($0,prefix)) { + triggered=1 + } + if (triggered) { + if (index($0,suffix)) { + triggered=0 + } + print + } +}' "$auto_master" diff --git a/cdist/conf/type/__autofs_map/gencode-remote b/cdist/conf/type/__autofs_map/gencode-remote new file mode 100755 index 00000000..fa6acffb --- /dev/null +++ b/cdist/conf/type/__autofs_map/gencode-remote @@ -0,0 +1,93 @@ +#!/bin/sh +# +# 2011 - 2012 Steven Armstrong (steven-cdist at 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 . +# + +entry="$__object/files/entry" +state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo present)" +if [ ! -s "$__object/explorer/entry" ]; then + state_is='absent' +else + state_is=$(diff -q "$entry" "$__object/explorer/entry" >/dev/null \ + && echo present \ + || echo changed + ) +fi + +if [ "$state_should" = "$state_is" ]; then + # Nothing to do, move along + exit 0 +fi + +cat << DONE +candidates="/etc/auto.master /etc/autofs/auto.master" +find_auto_master() { + # get the path of the auto.master file + for candidate in \$candidates; do + if [ -f "\$candidate" ]; then + echo "\$candidate" + return + fi + done +} + +auto_master="\$(find_auto_master)" + +if [ ! -f "\$auto_master" ]; then + echo "Could not determine auto.master location, tried: \$candidates" >&2 + exit 1 +fi +DONE + +remove_entry() { + # NOTE: keep variables in sync in manifest/explorer/gencode-* + prefix="#cdist:$__object_name" + suffix="#/cdist:$__object_name" + cat << DONE +awk -v prefix="$prefix" -v suffix="$suffix" ' +{ + if (index(\$0,prefix)) { + triggered=1 + } + if (triggered) { + if (index(\$0,suffix)) { + triggered=0 + } + } else { + print + } +}' "\$auto_master" > "\$auto_master"+ +mv -f "\$auto_master"+ "\$auto_master" +DONE +} + +case "$state_should" in + present) + if [ "$state_is" = "changed" ]; then + remove_entry + fi + cat << DONE +cat >> "\$auto_master" << EOC +$(cat "$entry") +EOC +DONE + ;; + absent) + remove_entry + ;; +esac diff --git a/cdist/conf/type/__autofs_map/man.text b/cdist/conf/type/__autofs_map/man.text index 941e22da..50ce2fa8 100644 --- a/cdist/conf/type/__autofs_map/man.text +++ b/cdist/conf/type/__autofs_map/man.text @@ -36,25 +36,35 @@ comment:: auto.master. +BOOLEAN PARAMETERS +------------------ +noreload:: + don't reload autofs after the entry has been changed + + EXAMPLES -------- -------------------------------------------------------------------------------- -# Add auto mounter at /net +# Add auto mounter at /net and reload __autofs_map /net --map /etc/auto.net --type program -# Add auto mounter at /pub -__autofs_map /pub --map /etc/auto.pub \ - --type file --options nosuid,rw,bg,hard,intr --ghost +# Add auto mounter at /pub and don't reload +__autofs_map /pub \ + --map /etc/auto.pub \ + --type file \ + --options "nosuid,rw,bg,hard,intr --ghost" \ + --noreload -------------------------------------------------------------------------------- SEE ALSO -------- - cdist-type(7) +- cdist-type__autofs_reload(7) COPYING ------- -Copyright \(C) 2011 Steven Armstrong. Free use of this software is +Copyright \(C) 2012 Steven Armstrong. 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/__autofs_map/manifest b/cdist/conf/type/__autofs_map/manifest index d86ea799..58dc0f98 100755 --- a/cdist/conf/type/__autofs_map/manifest +++ b/cdist/conf/type/__autofs_map/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011 - 2012 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -20,23 +20,36 @@ name="/$__object_id" map="$(cat "$__object/parameter/map")" +type="$(cat "$__object/parameter/type" 2>/dev/null || echo "file")" +options="$(cat "$__object/parameter/options" 2>/dev/null || true)" -if [ -f "$__object/parameter/type" ]; then - type="$(cat "$__object/parameter/type")" -else - type="file" - echo "$type" > "$__object/parameter/type" -fi +# NOTE: keep variables in sync in manifest/explorer/gencode-* +prefix="#cdist:$__object_name" +suffix="#/cdist:$__object_name" -# Generate entry for use in auto.master -entry="${name} ${type}:${map}" -if [ -f "$__object/parameter/options" ]; then - entry="$entry $(cat "$__object/parameter/options")" -fi +mkdir "$__object/files" + +# Generate entry for inclusion in auto.master +entry="$__object/files/entry" +echo "$prefix" > "$entry" if [ -f "$__object/parameter/comment" ]; then - echo "# $(cat "$__object/parameter/comment")" > "$__object/parameter/entry" + echo "# $(cat "$__object/parameter/comment")" >> "$entry" fi -echo "$entry" >> "$__object/parameter/entry" - -require="$__object_name" __autofs_master +echo "$name $type:$map $options" >> $entry +echo "$suffix" >> "$entry" +# Reload autofs after changes if the user wishes this +if [ ! -f "$__object/parameter/noreload" ]; then + state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo present)" + if [ ! -s "$__object/explorer/entry" ]; then + state_is='absent' + else + state_is=$(diff -q "$entry" "$__object/explorer/entry" >/dev/null \ + && echo present \ + || echo changed + ) + fi + if [ "$state_is" != "$state_should" ]; then + require="$__object_name" __autofs_reload + fi +fi diff --git a/cdist/conf/type/__autofs_map/parameter/boolean b/cdist/conf/type/__autofs_map/parameter/boolean new file mode 100644 index 00000000..862edc87 --- /dev/null +++ b/cdist/conf/type/__autofs_map/parameter/boolean @@ -0,0 +1 @@ +noreload diff --git a/cdist/conf/type/__autofs_master/files/auto.master.header b/cdist/conf/type/__autofs_master/files/auto.master.header deleted file mode 100644 index 53590257..00000000 --- a/cdist/conf/type/__autofs_master/files/auto.master.header +++ /dev/null @@ -1,3 +0,0 @@ -# Generated from cdist __autofs_master -# Do not change this file. Changes will be overwritten. - diff --git a/cdist/conf/type/__autofs_master/parameter/optional b/cdist/conf/type/__autofs_master/parameter/optional deleted file mode 100644 index 8e83f898..00000000 --- a/cdist/conf/type/__autofs_master/parameter/optional +++ /dev/null @@ -1 +0,0 @@ -header diff --git a/cdist/conf/type/__autofs_master/manifest b/cdist/conf/type/__autofs_reload/gencode-remote similarity index 62% rename from cdist/conf/type/__autofs_master/manifest rename to cdist/conf/type/__autofs_reload/gencode-remote index e429842e..883602e2 100755 --- a/cdist/conf/type/__autofs_master/manifest +++ b/cdist/conf/type/__autofs_reload/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -19,13 +19,19 @@ # -if [ ! -f "$__object/parameter/header" ]; then - echo "$__type/files/auto.master.header" > "$__object/parameter/header" -fi +os=$(cat "$__global/explorer/os") -[ -d "$__object/files" ] || mkdir "$__object/files" -require="$__object_name" __file /etc/auto.master --source "$__object/files/auto.master" \ - --mode 644 \ - --owner root \ - --group root +not_supported() { + echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 +} +case "$os" in + ubuntu|debian|archlinux) + echo "pkill -HUP automount" + ;; + *) + not_supported + ;; +esac diff --git a/cdist/conf/type/__autofs_master/man.text b/cdist/conf/type/__autofs_reload/man.text similarity index 51% rename from cdist/conf/type/__autofs_master/man.text rename to cdist/conf/type/__autofs_reload/man.text index 641c8393..d2085a98 100644 --- a/cdist/conf/type/__autofs_master/man.text +++ b/cdist/conf/type/__autofs_reload/man.text @@ -1,38 +1,33 @@ -cdist-type__autofs_master(7) +cdist-type__autofs_reload(7) ============================ Steven Armstrong NAME ---- -cdist-type__autofs_master - Generate the auto.master file +cdist-type__autofs_reload - tell automounter to reload config file DESCRIPTION ----------- -This cdist type generates a auto.master configuration from given __autofs_map -definitions. See cdist-type__auto_map(7). +This space intentionally left blank. REQUIRED PARAMETERS ------------------- -None +None. + OPTIONAL PARAMETERS ------------------- -header:: - Absolute path to a file used as the header for the generated auto.master - file. +None. + EXAMPLES -------- -------------------------------------------------------------------------------- -# auto.master with default header -__autofs_master - -# auto.master with custom header -__autofs_master --header /path/to/header +__autofs_reload -------------------------------------------------------------------------------- @@ -43,5 +38,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2011 Steven Armstrong. Free use of this software is +Copyright \(C) 2012 Steven Armstrong. 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/__autofs_reload/singleton b/cdist/conf/type/__autofs_reload/singleton new file mode 100644 index 00000000..e69de29b From 7e951fd4d184a2948c808039e0ed92a83ef07974 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 7 Nov 2012 15:16:04 +0100 Subject: [PATCH 66/95] __apt_ppa: /installed/present/ Signed-off-by: Steven Armstrong --- cdist/conf/type/__apt_ppa/manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__apt_ppa/manifest b/cdist/conf/type/__apt_ppa/manifest index 04c66ce0..e7ad0c26 100755 --- a/cdist/conf/type/__apt_ppa/manifest +++ b/cdist/conf/type/__apt_ppa/manifest @@ -20,7 +20,7 @@ name="$__object_id" -__package python-software-properties --state installed +__package python-software-properties --state present require="__package/python-software-properties" \ __file /usr/local/bin/remove-apt-repository \ From 8f525fbc8345997b3a4cb93f88afb32968c3f7fd Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 7 Nov 2012 15:46:25 +0100 Subject: [PATCH 67/95] __apt_update_index: ignore top level directory Signed-off-by: Steven Armstrong --- cdist/conf/type/__apt_update_index/gencode-remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__apt_update_index/gencode-remote b/cdist/conf/type/__apt_update_index/gencode-remote index e66ff7a3..61ce11a9 100755 --- a/cdist/conf/type/__apt_update_index/gencode-remote +++ b/cdist/conf/type/__apt_update_index/gencode-remote @@ -20,7 +20,7 @@ # run 'apt-get update' if anything in /etc/apt is newer then /var/lib/apt/lists cat << DONE -if find /etc/apt -cnewer /var/lib/apt/lists | grep . > /dev/null; then +if find /etc/apt -mindepth 1 -cnewer /var/lib/apt/lists | grep . > /dev/null; then apt-get update || apt-get update fi DONE From f769b395c27a8eaf5ebdda518d2c9a201d9a5d46 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 7 Nov 2012 16:28:21 +0100 Subject: [PATCH 68/95] __file: implement --state exists Signed-off-by: Steven Armstrong --- cdist/conf/type/__file/gencode-local | 2 +- cdist/conf/type/__file/gencode-remote | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__file/gencode-local b/cdist/conf/type/__file/gencode-local index b74893fb..a6c55abf 100755 --- a/cdist/conf/type/__file/gencode-local +++ b/cdist/conf/type/__file/gencode-local @@ -27,7 +27,7 @@ exists="$(cat "$__object/explorer/exists")" [ "$state_should" = "exists" -a "$exists" = "yes" ] && exit 0 # nothing to do -if [ "$state_should" = "present" ]; then +if [ "$state_should" = "present" -o "$state_should" = "exists" ]; then if [ -f "$__object/parameter/source" ]; then source="$(cat "$__object/parameter/source")" if [ "$source" = "-" ]; then diff --git a/cdist/conf/type/__file/gencode-remote b/cdist/conf/type/__file/gencode-remote index 2b4c7e45..04a1ea78 100755 --- a/cdist/conf/type/__file/gencode-remote +++ b/cdist/conf/type/__file/gencode-remote @@ -26,7 +26,7 @@ state_should="$(cat "$__object/parameter/state")" exists="$(cat "$__object/explorer/exists")" case "$state_should" in - present) + present|exists) # No source? Create empty file if [ ! -f "$__object/parameter/source" ]; then if [ "$exists" = "no" ]; then From 324a88c435b89395c1c67b800588ef7ef0aa10db Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 7 Nov 2012 16:49:55 +0100 Subject: [PATCH 69/95] __timezone: set timezone in /etc/timezone on debuntu Signed-off-by: Steven Armstrong --- cdist/conf/type/__timezone/gencode-remote | 30 +++++++++++++++++++++++ cdist/conf/type/__timezone/manifest | 21 +++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100755 cdist/conf/type/__timezone/gencode-remote diff --git a/cdist/conf/type/__timezone/gencode-remote b/cdist/conf/type/__timezone/gencode-remote new file mode 100755 index 00000000..b4782d4b --- /dev/null +++ b/cdist/conf/type/__timezone/gencode-remote @@ -0,0 +1,30 @@ +#!/bin/sh +# +# 2012 Steven Armstrong (steven-cdist at 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 . +# +# +# This type allows to configure the desired localtime timezone. + +timezone="$__object_id" +os=$(cat "$__global/explorer/os") + +case "$os" in + ubuntu|debian) + echo "echo \"$timezone\" > /etc/timezone" + ;; +esac diff --git a/cdist/conf/type/__timezone/manifest b/cdist/conf/type/__timezone/manifest index b0bae209..7583c9c9 100755 --- a/cdist/conf/type/__timezone/manifest +++ b/cdist/conf/type/__timezone/manifest @@ -1,6 +1,7 @@ #!/bin/sh # # 2011 Ramon Salvadó (rsalvado at gnuine dot com) +# 2012 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -22,7 +23,25 @@ timezone="$__object_id" -__package tzdata --state installed +os=$(cat "$__global/explorer/os") + +not_supported() { + echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 +} + +case "$os" in + ubuntu|debian|archlinux) + : + ;; + *) + not_supported + ;; +esac + +# same for all supported os's +__package tzdata --state present require="__package/tzdata" __link /etc/localtime \ --source "/usr/share/zoneinfo/${timezone}" \ --type symbolic From 6adb20b8292851b67a7357ee28ed4ab7eb321dc3 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Wed, 7 Nov 2012 16:52:44 +0100 Subject: [PATCH 70/95] __ssh_authorized_key: /installed/present/ Signed-off-by: Steven Armstrong --- cdist/conf/type/__ssh_authorized_key/manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__ssh_authorized_key/manifest b/cdist/conf/type/__ssh_authorized_key/manifest index d9db9c78..8984d5d4 100755 --- a/cdist/conf/type/__ssh_authorized_key/manifest +++ b/cdist/conf/type/__ssh_authorized_key/manifest @@ -21,7 +21,7 @@ # This type allows to send a public ssh key from a user to the # authorized_keys of another # -#require="__package openssh-server --state installed" +#require="__package openssh-server --state present" # Get option srcuser if defined if [ -f "$__object/parameter/srcuser" ]; then srcuser=`cat "$__object/parameter/srcuser"` From 489fa2a8be06260c241ec2c71f535c63577cadac Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 17:21:22 +0100 Subject: [PATCH 71/95] +quotes Signed-off-by: Nico Schottelius --- build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build b/build index 34775a31..baad93be 100755 --- a/build +++ b/build @@ -173,7 +173,7 @@ eof $0 blog version=$($0 changelog-version) file=cdist-${version}-released.mdwn - cd $WEBBBLOG + cd "$WEBBLOG" git add "$file" git commit -m "New cdist version (blogentry): $version" "$file" git push From ace897de258ade3f0597f81f7850de745a3cd149 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 17:28:27 +0100 Subject: [PATCH 72/95] simplify timezone manifest Signed-off-by: Nico Schottelius --- cdist/conf/type/__timezone/manifest | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/cdist/conf/type/__timezone/manifest b/cdist/conf/type/__timezone/manifest index 7583c9c9..76fa5c97 100755 --- a/cdist/conf/type/__timezone/manifest +++ b/cdist/conf/type/__timezone/manifest @@ -2,6 +2,7 @@ # # 2011 Ramon Salvadó (rsalvado at gnuine dot com) # 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -22,26 +23,16 @@ # This type allows to configure the desired localtime timezone. timezone="$__object_id" - os=$(cat "$__global/explorer/os") -not_supported() { - echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 - echo "Please contribute an implementation for it if you can." >&2 - exit 1 -} - case "$os" in - ubuntu|debian|archlinux) - : - ;; - *) - not_supported - ;; + archlinux|debian|ubuntu) + __package tzdata --state present + require="__package/tzdata" __link /etc/localtime \ + --source "/usr/share/zoneinfo/${timezone}" \ + --type symbolic + ;; + *) + echo "Unsupported OS $os" >&2 + ;; esac - -# same for all supported os's -__package tzdata --state present -require="__package/tzdata" __link /etc/localtime \ - --source "/usr/share/zoneinfo/${timezone}" \ - --type symbolic From a4b2e2ce9556ef82f02126080a1c531ed2dbaf46 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 17:34:21 +0100 Subject: [PATCH 73/95] ++changes(next version) Signed-off-by: Nico Schottelius --- docs/changelog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/changelog b/docs/changelog index f8030609..863f6db3 100644 --- a/docs/changelog +++ b/docs/changelog @@ -4,6 +4,10 @@ Changelog * Changes are always commented with their author in (braces) * Exception: No braces means author == Nico Schottelius +2.1.0pre8: + * Type cleanup: __apt_ppa, __apt_ppa_update_index, __file, + __ssh_authorized_key, __timezone, all install types (Steven Armstrong) + 2.1.0pre7: 2012-11-07 * Core: All unit tests restored back to working * Core: Print error message on missing initial manifest From 265d1af56a8a1d59080b63bff8aa24c8db4df42b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 17:40:39 +0100 Subject: [PATCH 74/95] rename vm to diskimage, ensure state is setup Signed-off-by: Nico Schottelius --- cdist/conf/type/__qemu_img/gencode-remote | 7 ++++--- cdist/conf/type/__qemu_img/manifest | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cdist/conf/type/__qemu_img/gencode-remote b/cdist/conf/type/__qemu_img/gencode-remote index acadcef0..e5ff1b4f 100644 --- a/cdist/conf/type/__qemu_img/gencode-remote +++ b/cdist/conf/type/__qemu_img/gencode-remote @@ -2,7 +2,8 @@ # State: absent is handled by manifest - we need only to do stuff if image is # not existing and state != absent # -[ -f "$__object/parameter/state" ] && state="$(cat "$__object/parameter/state")" +state="present" +[ -f "$__object/parameter/state" ] state="$(cat "$__object/parameter/state")" [ "$state" = "absent" ] && exit 0 exists="$(cat "$__object/explorer/exists")" @@ -15,6 +16,6 @@ exists="$(cat "$__object/explorer/exists")" format=qcow2 [ -f "$__object/parameter/format" ] && format="$(cat "$__object/parameter/format")" size="$(cat "$__object/parameter/size")" -vm="/$__object_id" +diskimage="/$__object_id" -echo qemu-img create -f \"$format\" \"$vm\" \"$size\" +echo qemu-img create -f \"$format\" \"$diskimage\" \"$size\" diff --git a/cdist/conf/type/__qemu_img/manifest b/cdist/conf/type/__qemu_img/manifest index d343e188..b835301d 100644 --- a/cdist/conf/type/__qemu_img/manifest +++ b/cdist/conf/type/__qemu_img/manifest @@ -3,12 +3,13 @@ # format=qcow2 +state=present [ -f "$__object/parameter/format" ] && format="$(cat "$__object/parameter/format")" [ -f "$__object/parameter/state" ] && state="$(cat "$__object/parameter/state")" -vm="/$__object_id" +diskimage="/$__object_id" # Absent is ensured by __file, present by gencode-remote if [ "$state" = "absent" ]; then - __file "$vm" --state absent + __file "$diskimage" --state absent fi From a0add17cf804696f634b85b31bcab4329d4b0903 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 17:44:54 +0100 Subject: [PATCH 75/95] ++exit 1 Signed-off-by: Nico Schottelius --- cdist/conf/type/__timezone/manifest | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/conf/type/__timezone/manifest b/cdist/conf/type/__timezone/manifest index 76fa5c97..81de0217 100755 --- a/cdist/conf/type/__timezone/manifest +++ b/cdist/conf/type/__timezone/manifest @@ -34,5 +34,6 @@ case "$os" in ;; *) echo "Unsupported OS $os" >&2 + exit 1 ;; esac From 7a44f3057412b2a600c91b7feabe59f32a95571f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 17:47:55 +0100 Subject: [PATCH 76/95] simplify manifest Signed-off-by: Nico Schottelius --- cdist/conf/type/__autofs/manifest | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/cdist/conf/type/__autofs/manifest b/cdist/conf/type/__autofs/manifest index 31844415..4a726c0a 100755 --- a/cdist/conf/type/__autofs/manifest +++ b/cdist/conf/type/__autofs/manifest @@ -1,6 +1,7 @@ #!/bin/sh # # 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -21,18 +22,13 @@ os=$(cat "$__global/explorer/os") -not_supported() { - echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 - echo "Please contribute an implementation for it if you can." >&2 - exit 1 -} - case "$os" in - ubuntu|debian|archlinux) - __package autofs --state present - __start_on_boot autofs --state present - ;; - *) - not_supported - ;; + ubuntu|debian|archlinux) + __package autofs --state present + __start_on_boot autofs --state present + ;; + *) + echo "Unsupported OS: $os" >&2 + exit 1 + ;; esac From 8ab408f890970a92d88ccf39c770a37c10d58fa9 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 17:52:05 +0100 Subject: [PATCH 77/95] remove parameter change code Signed-off-by: Nico Schottelius --- cdist/conf/type/__file/gencode-local | 5 +++-- cdist/conf/type/__file/gencode-remote | 5 +++-- cdist/conf/type/__file/manifest | 24 ------------------------ 3 files changed, 6 insertions(+), 28 deletions(-) delete mode 100755 cdist/conf/type/__file/manifest diff --git a/cdist/conf/type/__file/gencode-local b/cdist/conf/type/__file/gencode-local index a6c55abf..087011c4 100755 --- a/cdist/conf/type/__file/gencode-local +++ b/cdist/conf/type/__file/gencode-local @@ -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. # @@ -22,7 +22,8 @@ # destination="/$__object_id" -state_should="$(cat "$__object/parameter/state")" +state_should=present +[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" exists="$(cat "$__object/explorer/exists")" [ "$state_should" = "exists" -a "$exists" = "yes" ] && exit 0 # nothing to do diff --git a/cdist/conf/type/__file/gencode-remote b/cdist/conf/type/__file/gencode-remote index 04a1ea78..8b03e919 100755 --- a/cdist/conf/type/__file/gencode-remote +++ b/cdist/conf/type/__file/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. # @@ -22,7 +22,8 @@ # destination="/$__object_id" -state_should="$(cat "$__object/parameter/state")" +state_should=present +[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" exists="$(cat "$__object/explorer/exists")" case "$state_should" in diff --git a/cdist/conf/type/__file/manifest b/cdist/conf/type/__file/manifest deleted file mode 100755 index 6b5e1ca7..00000000 --- a/cdist/conf/type/__file/manifest +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -# -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 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 . -# - -# set default: present, if not setup -statefile="$__object/parameter/state" -[ -f "$statefile" ] || echo present > "$statefile" From 2cfa046cdd373df9248375fc52498786b6a1778e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 17:57:47 +0100 Subject: [PATCH 78/95] indentions, whitespace Signed-off-by: Nico Schottelius --- cdist/conf/type/__issue/manifest | 21 +++++++++---------- cdist/conf/type/__ssh_authorized_key/manifest | 1 - 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cdist/conf/type/__issue/manifest b/cdist/conf/type/__issue/manifest index eff6b808..d2720f2d 100755 --- a/cdist/conf/type/__issue/manifest +++ b/cdist/conf/type/__issue/manifest @@ -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. # @@ -24,17 +24,16 @@ destination=/etc/issue os="$(cat "$__global/explorer/os")" if [ -f "$__object/parameter/source" ]; then - source="$(cat "$__object/parameter/source")" - echo using $source + source="$(cat "$__object/parameter/source")" else - case "$os" in - archlinux|redhat) - source="$__type/files/$os" - ;; - *) - source="$__type/files/default" - ;; - esac + case "$os" in + archlinux|redhat) + source="$__type/files/$os" + ;; + *) + source="$__type/files/default" + ;; + esac fi __file "$destination" --source "$source" diff --git a/cdist/conf/type/__ssh_authorized_key/manifest b/cdist/conf/type/__ssh_authorized_key/manifest index 8984d5d4..86c58740 100755 --- a/cdist/conf/type/__ssh_authorized_key/manifest +++ b/cdist/conf/type/__ssh_authorized_key/manifest @@ -64,4 +64,3 @@ require="__directory${sshpath}" \ # the line added depends on authorized_keys existence require="__file${sshpath}/authorized_keys" __addifnosuchline sshkey --file \ "$sshpath/authorized_keys" --line "$rsa" - From 7814ece7b7745b0bb97140d23c2f65fe98e70d0e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 18:01:30 +0100 Subject: [PATCH 79/95] remove parameter changing code Signed-off-by: Nico Schottelius --- cdist/conf/type/__link/gencode-remote | 50 +++++++++++++-------------- cdist/conf/type/__link/manifest | 24 ------------- 2 files changed, 24 insertions(+), 50 deletions(-) delete mode 100755 cdist/conf/type/__link/manifest diff --git a/cdist/conf/type/__link/gencode-remote b/cdist/conf/type/__link/gencode-remote index 8d4cc3d5..2975ef69 100755 --- a/cdist/conf/type/__link/gencode-remote +++ b/cdist/conf/type/__link/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. # @@ -27,35 +27,33 @@ type="$(cat "$__object/parameter/type")" source="$(cat "$__object/parameter/source")" case "$type" in - symbolic) - lnopt="-s" - ;; - hard) - lnopt="" - ;; - *) - echo "Unknown type: $type" >&2 - exit 1 - ;; + symbolic) + lnopt="-s" + ;; + hard) + lnopt="" + ;; + *) + echo "Unknown link type: $type" >&2 + exit 1 + ;; esac state_is="$(cat "$__object/explorer/state")" -state_should="$(cat "$__object/parameter/state")" +state_should=present +[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" -if [ "$state_should" = "$state_is" ]; then - # nothing to do - exit 0 -fi +[ "$state_should" = "$state_is" ] && exit 0 case "$state_should" in - present) - echo ln ${lnopt} -f \"$source\" \"$destination\" - ;; - absent) - echo rm -f \"$destination\" - ;; - *) - echo "Unknown state: $state_should" >&2 - exit 1 - ;; + present) + echo ln ${lnopt} -f \"$source\" \"$destination\" + ;; + absent) + echo rm -f \"$destination\" + ;; + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; esac diff --git a/cdist/conf/type/__link/manifest b/cdist/conf/type/__link/manifest deleted file mode 100755 index 6b5e1ca7..00000000 --- a/cdist/conf/type/__link/manifest +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -# -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 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 . -# - -# set default: present, if not setup -statefile="$__object/parameter/state" -[ -f "$statefile" ] || echo present > "$statefile" From 82830f191dc040e1e4087604260c10f20de44a7e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 18:04:49 +0100 Subject: [PATCH 80/95] link __process to __start_on_boot and vice versa Signed-off-by: Nico Schottelius --- cdist/conf/type/__process/man.text | 3 +-- cdist/conf/type/__start_on_boot/man.text | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__process/man.text b/cdist/conf/type/__process/man.text index 961a7f9a..929ba6a0 100644 --- a/cdist/conf/type/__process/man.text +++ b/cdist/conf/type/__process/man.text @@ -17,8 +17,6 @@ REQUIRED PARAMETERS ------------------- state:: 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 @@ -66,6 +64,7 @@ __process rpcstatd --state present --start "/etc/init.d/statd start" \ SEE ALSO -------- - cdist-type(7) +- cdist-type__start_on_boot(7) COPYING diff --git a/cdist/conf/type/__start_on_boot/man.text b/cdist/conf/type/__start_on_boot/man.text index 0e75c9ab..58a68d65 100644 --- a/cdist/conf/type/__start_on_boot/man.text +++ b/cdist/conf/type/__start_on_boot/man.text @@ -45,6 +45,7 @@ __start_on_boot puppet --state absent SEE ALSO -------- - cdist-type(7) +- cdist-type__process(7) COPYING From aeff2bcb0f0523f4a02698910fbc3295baeb9b23 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 18:06:11 +0100 Subject: [PATCH 81/95] indention Signed-off-by: Nico Schottelius --- cdist/conf/type/__process/explorer/runs | 6 +++--- cdist/conf/type/__process/gencode-remote | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cdist/conf/type/__process/explorer/runs b/cdist/conf/type/__process/explorer/runs index 240ebef9..561e2fe9 100755 --- a/cdist/conf/type/__process/explorer/runs +++ b/cdist/conf/type/__process/explorer/runs @@ -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. # @@ -22,9 +22,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 pgrep -x -f "$name" || true diff --git a/cdist/conf/type/__process/gencode-remote b/cdist/conf/type/__process/gencode-remote index e4519f3c..fdb6033a 100755 --- a/cdist/conf/type/__process/gencode-remote +++ b/cdist/conf/type/__process/gencode-remote @@ -20,9 +20,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")" From 347c620eedd1385aea2492884bbc799372311293 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 18:08:03 +0100 Subject: [PATCH 82/95] indent Signed-off-by: Nico Schottelius --- cdist/conf/type/__file/explorer/cksum | 14 +++++++------- cdist/conf/type/__file/explorer/exists | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cdist/conf/type/__file/explorer/cksum b/cdist/conf/type/__file/explorer/cksum index dcad99ba..335e4e7a 100755 --- a/cdist/conf/type/__file/explorer/cksum +++ b/cdist/conf/type/__file/explorer/cksum @@ -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. # @@ -24,11 +24,11 @@ destination="/$__object_id" if [ -e "$destination" ]; then - if [ -f "$destination" ]; then - cksum < "$destination" - else - echo "NO REGULAR FILE" - fi + if [ -f "$destination" ]; then + cksum < "$destination" + else + echo "NO REGULAR FILE" + fi else - echo "NO FILE FOUND, NO CHECKSUM CALCULATED." + echo "NO FILE FOUND, NO CHECKSUM CALCULATED." fi diff --git a/cdist/conf/type/__file/explorer/exists b/cdist/conf/type/__file/explorer/exists index f8b85671..c319cb5d 100755 --- a/cdist/conf/type/__file/explorer/exists +++ b/cdist/conf/type/__file/explorer/exists @@ -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. # @@ -24,7 +24,7 @@ destination="/$__object_id" if [ -e "$destination" ]; then - echo yes + echo yes else - echo no + echo no fi From 13d6644966ca8319eef99c49cedd1a8e518a2b1c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 18:10:15 +0100 Subject: [PATCH 83/95] do not report errors on missing gemset Signed-off-by: Nico Schottelius --- cdist/conf/type/__rvm_gem/explorer/state | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__rvm_gem/explorer/state b/cdist/conf/type/__rvm_gem/explorer/state index 09509a2e..4146d666 100755 --- a/cdist/conf/type/__rvm_gem/explorer/state +++ b/cdist/conf/type/__rvm_gem/explorer/state @@ -1,6 +1,7 @@ #!/bin/sh # # 2012 Evax Software +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -30,8 +31,8 @@ fi if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\" rvm list | grep -q $ruby"; then if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\" -rvm use $ruby > /dev/null; rvm gemset list | grep -q $gemsetname && -rvm use $gemset > /dev/null && gem list | grep -q $gem"; then +rvm use $ruby > /dev/null 2>&1; rvm gemset list | grep -q $gemsetname && +rvm use $gemset > /dev/null 2>&1 && gem list | grep -q $gem"; then echo "present" exit 0 fi From 47424bf200c7e0fb2361f0b710c892e48153d1f7 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 18:15:15 +0100 Subject: [PATCH 84/95] update __package* manpages Signed-off-by: Nico Schottelius --- cdist/conf/type/__package/man.text | 2 +- cdist/conf/type/__package_pip/man.text | 2 +- cdist/conf/type/__package_pkg_freebsd/man.text | 10 +++++----- cdist/conf/type/__package_pkg_openbsd/man.text | 2 +- cdist/conf/type/__package_rubygem/man.text | 2 +- cdist/conf/type/__package_yum/man.text | 3 +-- cdist/conf/type/__package_zypper/man.text | 2 +- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cdist/conf/type/__package/man.text b/cdist/conf/type/__package/man.text index 69ecf0ad..229ccf92 100644 --- a/cdist/conf/type/__package/man.text +++ b/cdist/conf/type/__package/man.text @@ -34,7 +34,7 @@ type:: __package_emerge for Gentoo state:: - The state the package should be in, either "present" or "absent" + either "present" or "absent", defaults to "present" EXAMPLES diff --git a/cdist/conf/type/__package_pip/man.text b/cdist/conf/type/__package_pip/man.text index 21d4f9fd..8cb7d80a 100644 --- a/cdist/conf/type/__package_pip/man.text +++ b/cdist/conf/type/__package_pip/man.text @@ -28,7 +28,7 @@ pip:: Instead of using pip from PATH, use the specific pip path. state:: - Either "present" or "absent". + Either "present" or "absent", defaults to "present" EXAMPLES diff --git a/cdist/conf/type/__package_pkg_freebsd/man.text b/cdist/conf/type/__package_pkg_freebsd/man.text index f1589037..71387148 100644 --- a/cdist/conf/type/__package_pkg_freebsd/man.text +++ b/cdist/conf/type/__package_pkg_freebsd/man.text @@ -21,19 +21,19 @@ None 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. version:: - If supplied, use to install a specific version of the package named. + If supplied, use to install a specific version of the package named. pkgsite:: - If supplied, use to install from a specific package repository. + If supplied, use to install from a specific package repository. state:: - Either "present" or "absent". + Either "present" or "absent", defaults to "present" EXAMPLES diff --git a/cdist/conf/type/__package_pkg_openbsd/man.text b/cdist/conf/type/__package_pkg_openbsd/man.text index 8fcc3216..f523a892 100644 --- a/cdist/conf/type/__package_pkg_openbsd/man.text +++ b/cdist/conf/type/__package_pkg_openbsd/man.text @@ -27,7 +27,7 @@ flavor:: If supplied, use to avoid ambiguity. state:: - The state the package should be in, either "present" or "absent" + Either "present" or "absent", defaults to "present" EXAMPLES diff --git a/cdist/conf/type/__package_rubygem/man.text b/cdist/conf/type/__package_rubygem/man.text index feefe699..a808c2aa 100644 --- a/cdist/conf/type/__package_rubygem/man.text +++ b/cdist/conf/type/__package_rubygem/man.text @@ -24,7 +24,7 @@ name:: If supplied, use the name and not the object id as the package name. state:: - The state the package should be in, either "present" or "absent" + Either "present" or "absent", defaults to "present" EXAMPLES diff --git a/cdist/conf/type/__package_yum/man.text b/cdist/conf/type/__package_yum/man.text index 9aabf7fb..d958dd1e 100644 --- a/cdist/conf/type/__package_yum/man.text +++ b/cdist/conf/type/__package_yum/man.text @@ -26,8 +26,7 @@ name:: If supplied, use the name and not the object id as the package name. state:: - The state the package should be in, either "present" or "absent" - (the old values "installed" or "removed" will be removed in cdist 2.1). + Either "present" or "absent", defaults to "present" EXAMPLES diff --git a/cdist/conf/type/__package_zypper/man.text b/cdist/conf/type/__package_zypper/man.text index 702d51e5..e2261d33 100644 --- a/cdist/conf/type/__package_zypper/man.text +++ b/cdist/conf/type/__package_zypper/man.text @@ -24,7 +24,7 @@ name:: If supplied, use the name and not the object id as the package name. state:: - The state the package should be in, either "present" or "absent" + Either "present" or "absent", defaults to "present" EXAMPLES From 344e08dddae8c2a03b4ac135a3feb72c02a6ff27 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 18:22:25 +0100 Subject: [PATCH 85/95] Archive __autofs types (fixes #116) Signed-off-by: Nico Schottelius --- other/archived_types/.README.unmaintained | 1 + other/archived_types/README | 3 +++ other/archived_types/__autofs/README | 1 + {cdist/conf/type => other/archived_types}/__autofs/man.text | 0 {cdist/conf/type => other/archived_types}/__autofs/manifest | 0 {cdist/conf/type => other/archived_types}/__autofs/singleton | 0 other/archived_types/__autofs_map/README | 1 + .../type => other/archived_types}/__autofs_map/explorer/entry | 0 .../type => other/archived_types}/__autofs_map/gencode-remote | 0 .../conf/type => other/archived_types}/__autofs_map/man.text | 0 .../conf/type => other/archived_types}/__autofs_map/manifest | 0 .../archived_types}/__autofs_map/parameter/boolean | 0 .../archived_types}/__autofs_map/parameter/optional | 0 .../archived_types}/__autofs_map/parameter/required | 0 other/archived_types/__autofs_reload/README | 1 + .../archived_types}/__autofs_reload/gencode-remote | 0 .../type => other/archived_types}/__autofs_reload/man.text | 0 .../type => other/archived_types}/__autofs_reload/singleton | 0 18 files changed, 7 insertions(+) create mode 100644 other/archived_types/.README.unmaintained create mode 100644 other/archived_types/README create mode 120000 other/archived_types/__autofs/README rename {cdist/conf/type => other/archived_types}/__autofs/man.text (100%) rename {cdist/conf/type => other/archived_types}/__autofs/manifest (100%) rename {cdist/conf/type => other/archived_types}/__autofs/singleton (100%) create mode 120000 other/archived_types/__autofs_map/README rename {cdist/conf/type => other/archived_types}/__autofs_map/explorer/entry (100%) rename {cdist/conf/type => other/archived_types}/__autofs_map/gencode-remote (100%) rename {cdist/conf/type => other/archived_types}/__autofs_map/man.text (100%) rename {cdist/conf/type => other/archived_types}/__autofs_map/manifest (100%) rename {cdist/conf/type => other/archived_types}/__autofs_map/parameter/boolean (100%) rename {cdist/conf/type => other/archived_types}/__autofs_map/parameter/optional (100%) rename {cdist/conf/type => other/archived_types}/__autofs_map/parameter/required (100%) create mode 120000 other/archived_types/__autofs_reload/README rename {cdist/conf/type => other/archived_types}/__autofs_reload/gencode-remote (100%) rename {cdist/conf/type => other/archived_types}/__autofs_reload/man.text (100%) rename {cdist/conf/type => other/archived_types}/__autofs_reload/singleton (100%) diff --git a/other/archived_types/.README.unmaintained b/other/archived_types/.README.unmaintained new file mode 100644 index 00000000..e9795911 --- /dev/null +++ b/other/archived_types/.README.unmaintained @@ -0,0 +1 @@ +This type is not maintained by anymore and has thus been removed from cdist. diff --git a/other/archived_types/README b/other/archived_types/README new file mode 100644 index 00000000..32cd1f3d --- /dev/null +++ b/other/archived_types/README @@ -0,0 +1,3 @@ +This directory contains types that used to be included with +cdist, but are not in use anymore. Have a look at the README +file in each type, to find out why it was removed. diff --git a/other/archived_types/__autofs/README b/other/archived_types/__autofs/README new file mode 120000 index 00000000..7495e43b --- /dev/null +++ b/other/archived_types/__autofs/README @@ -0,0 +1 @@ +../.README.unmaintained \ No newline at end of file diff --git a/cdist/conf/type/__autofs/man.text b/other/archived_types/__autofs/man.text similarity index 100% rename from cdist/conf/type/__autofs/man.text rename to other/archived_types/__autofs/man.text diff --git a/cdist/conf/type/__autofs/manifest b/other/archived_types/__autofs/manifest similarity index 100% rename from cdist/conf/type/__autofs/manifest rename to other/archived_types/__autofs/manifest diff --git a/cdist/conf/type/__autofs/singleton b/other/archived_types/__autofs/singleton similarity index 100% rename from cdist/conf/type/__autofs/singleton rename to other/archived_types/__autofs/singleton diff --git a/other/archived_types/__autofs_map/README b/other/archived_types/__autofs_map/README new file mode 120000 index 00000000..7495e43b --- /dev/null +++ b/other/archived_types/__autofs_map/README @@ -0,0 +1 @@ +../.README.unmaintained \ No newline at end of file diff --git a/cdist/conf/type/__autofs_map/explorer/entry b/other/archived_types/__autofs_map/explorer/entry similarity index 100% rename from cdist/conf/type/__autofs_map/explorer/entry rename to other/archived_types/__autofs_map/explorer/entry diff --git a/cdist/conf/type/__autofs_map/gencode-remote b/other/archived_types/__autofs_map/gencode-remote similarity index 100% rename from cdist/conf/type/__autofs_map/gencode-remote rename to other/archived_types/__autofs_map/gencode-remote diff --git a/cdist/conf/type/__autofs_map/man.text b/other/archived_types/__autofs_map/man.text similarity index 100% rename from cdist/conf/type/__autofs_map/man.text rename to other/archived_types/__autofs_map/man.text diff --git a/cdist/conf/type/__autofs_map/manifest b/other/archived_types/__autofs_map/manifest similarity index 100% rename from cdist/conf/type/__autofs_map/manifest rename to other/archived_types/__autofs_map/manifest diff --git a/cdist/conf/type/__autofs_map/parameter/boolean b/other/archived_types/__autofs_map/parameter/boolean similarity index 100% rename from cdist/conf/type/__autofs_map/parameter/boolean rename to other/archived_types/__autofs_map/parameter/boolean diff --git a/cdist/conf/type/__autofs_map/parameter/optional b/other/archived_types/__autofs_map/parameter/optional similarity index 100% rename from cdist/conf/type/__autofs_map/parameter/optional rename to other/archived_types/__autofs_map/parameter/optional diff --git a/cdist/conf/type/__autofs_map/parameter/required b/other/archived_types/__autofs_map/parameter/required similarity index 100% rename from cdist/conf/type/__autofs_map/parameter/required rename to other/archived_types/__autofs_map/parameter/required diff --git a/other/archived_types/__autofs_reload/README b/other/archived_types/__autofs_reload/README new file mode 120000 index 00000000..7495e43b --- /dev/null +++ b/other/archived_types/__autofs_reload/README @@ -0,0 +1 @@ +../.README.unmaintained \ No newline at end of file diff --git a/cdist/conf/type/__autofs_reload/gencode-remote b/other/archived_types/__autofs_reload/gencode-remote similarity index 100% rename from cdist/conf/type/__autofs_reload/gencode-remote rename to other/archived_types/__autofs_reload/gencode-remote diff --git a/cdist/conf/type/__autofs_reload/man.text b/other/archived_types/__autofs_reload/man.text similarity index 100% rename from cdist/conf/type/__autofs_reload/man.text rename to other/archived_types/__autofs_reload/man.text diff --git a/cdist/conf/type/__autofs_reload/singleton b/other/archived_types/__autofs_reload/singleton similarity index 100% rename from cdist/conf/type/__autofs_reload/singleton rename to other/archived_types/__autofs_reload/singleton From 0eda57986fd205a7a64abbfd12a0e9103ff9d72e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 18:28:58 +0100 Subject: [PATCH 86/95] remove parameter changing code in __key_value (fixes #114,#36) Signed-off-by: Nico Schottelius --- cdist/conf/type/__key_value/gencode-remote | 61 +++++++++++----------- cdist/conf/type/__key_value/manifest | 10 ++-- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/cdist/conf/type/__key_value/gencode-remote b/cdist/conf/type/__key_value/gencode-remote index b3ffeb46..5fa24d5b 100755 --- a/cdist/conf/type/__key_value/gencode-remote +++ b/cdist/conf/type/__key_value/gencode-remote @@ -1,6 +1,7 @@ #!/bin/sh # # 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -18,42 +19,42 @@ # along with cdist. If not, see . # -key="$(cat "$__object/parameter/key")" +key="$__object_id" +[ -f "$__object/parameter/key" ] && key="$(cat "$__object/parameter/key")" +state_should=present +[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" + file="$(cat "$__object/parameter/file")" delimiter="$(cat "$__object/parameter/delimiter")" value="$(cat "$__object/parameter/value")" state_is="$(cat "$__object/explorer/state")" -state_should="$(cat "$__object/parameter/state")" -if [ "$state_is" = "$state_should" ]; then - # nothing to do - exit 0 -fi +[ "$state_is" = "$state_should" ] && exit 0 case "$state_should" in - absent) - # remove lines starting with key - echo "sed '/^$key\($delimiter\+\)/d' \"$file\" > \"$file.cdist-tmp\"" - echo "mv \"$file.cdist-tmp\" \"$file\"" - ;; - present) - case "$state_is" in - absent) - # add new key and value - echo "echo \"${key}${delimiter}${value}\" >> \"$file\"" - ;; - wrongvalue) - # change exisiting value - echo "sed \"s|^$key\($delimiter\+\).*|$key\1$value|\" \"$file\" > \"$file.cdist-tmp\"" - echo "mv \"$file.cdist-tmp\" \"$file\"" - ;; - *) - echo "Unknown explorer state: $state_is" >&2 - exit 1 - esac - ;; - *) - echo "Unknown state: $state_should" >&2 - exit 1 + absent) + # remove lines starting with key + echo "sed '/^$key\($delimiter\+\)/d' \"$file\" > \"$file.cdist-tmp\"" + echo "mv \"$file.cdist-tmp\" \"$file\"" + ;; + present) + case "$state_is" in + absent) + # add new key and value + echo "echo \"${key}${delimiter}${value}\" >> \"$file\"" + ;; + wrongvalue) + # change exisiting value + echo "sed \"s|^$key\($delimiter\+\).*|$key\1$value|\" \"$file\" > \"$file.cdist-tmp\"" + echo "mv \"$file.cdist-tmp\" \"$file\"" + ;; + *) + echo "Unknown explorer state: $state_is" >&2 + exit 1 + esac + ;; + *) + echo "Unknown state: $state_should" >&2 + exit 1 esac diff --git a/cdist/conf/type/__key_value/manifest b/cdist/conf/type/__key_value/manifest index 2e75e175..8ed9cc9c 100755 --- a/cdist/conf/type/__key_value/manifest +++ b/cdist/conf/type/__key_value/manifest @@ -1,6 +1,7 @@ #!/bin/sh # # 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -18,13 +19,10 @@ # along with cdist. If not, see . # -# set defaults -key="$(cat "$__object/parameter/key" 2>/dev/null \ - || echo "$__object_id" | tee "$__object/parameter/key")" -state="$(cat "$__object/parameter/state" 2>/dev/null \ - || echo "present" | tee "$__object/parameter/state")" +state_should=present +[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" -if [ "$state" = "present" -a ! -f "$__object/parameter/value" ]; then +if [ "$state_should" = "present" -a ! -f "$__object/parameter/value" ]; then echo "Missing required parameter 'value'" >&2 exit 1 fi From 91eccc892056172bdac3db0d34219ba72f1fe0e1 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 18:57:52 +0100 Subject: [PATCH 87/95] ++changes(next_version) Signed-off-by: Nico Schottelius --- docs/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog b/docs/changelog index 863f6db3..5d3c1698 100644 --- a/docs/changelog +++ b/docs/changelog @@ -7,6 +7,7 @@ Changelog 2.1.0pre8: * Type cleanup: __apt_ppa, __apt_ppa_update_index, __file, __ssh_authorized_key, __timezone, all install types (Steven Armstrong) + * Types: Remove all parameter changing code 2.1.0pre7: 2012-11-07 * Core: All unit tests restored back to working From 3d4bb3837f073d820c833267e19a0ffd3f25d20b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 19:22:02 +0100 Subject: [PATCH 88/95] documentation cleanups Signed-off-by: Nico Schottelius --- cdist/conf/type/__package/man.text | 2 +- cdist/conf/type/__package_apt/man.text | 2 +- cdist/conf/type/__package_luarocks/man.text | 2 +- cdist/conf/type/__package_opkg/man.text | 2 +- cdist/conf/type/__package_pacman/man.text | 5 ++--- cdist/conf/type/__package_pip/man.text | 2 +- cdist/conf/type/__pf_ruleset/man.text | 1 + cdist/conf/type/__postgres_role/man.text | 2 +- cdist/conf/type/__process/man.text | 14 +++++++------- cdist/conf/type/__qemu_img/man.text | 3 +-- cdist/conf/type/__rvm/man.text | 2 +- cdist/conf/type/__rvm_gem/man.text | 8 ++++---- cdist/conf/type/__rvm_gemset/man.text | 6 +++--- cdist/conf/type/__rvm_ruby/man.text | 10 +++++----- cdist/conf/type/__start_on_boot/man.text | 2 +- 15 files changed, 31 insertions(+), 32 deletions(-) diff --git a/cdist/conf/type/__package/man.text b/cdist/conf/type/__package/man.text index 229ccf92..b656c890 100644 --- a/cdist/conf/type/__package/man.text +++ b/cdist/conf/type/__package/man.text @@ -34,7 +34,7 @@ type:: __package_emerge for Gentoo state:: - either "present" or "absent", defaults to "present" + Either "present" or "absent", defaults to "present" EXAMPLES diff --git a/cdist/conf/type/__package_apt/man.text b/cdist/conf/type/__package_apt/man.text index 35c34d33..5d4656c1 100644 --- a/cdist/conf/type/__package_apt/man.text +++ b/cdist/conf/type/__package_apt/man.text @@ -25,7 +25,7 @@ name:: If supplied, use the name and not the object id as the package name. state:: - The state the package should be in, either "present" or "absent" + Either "present" or "absent", defaults to "present" EXAMPLES diff --git a/cdist/conf/type/__package_luarocks/man.text b/cdist/conf/type/__package_luarocks/man.text index 18a80a79..657f68e5 100644 --- a/cdist/conf/type/__package_luarocks/man.text +++ b/cdist/conf/type/__package_luarocks/man.text @@ -24,7 +24,7 @@ name:: If supplied, use the name and not the object id as the package name. state:: - The state the package should be in, either "present" or "absent" + Either "present" or "absent", defaults to "present" EXAMPLES diff --git a/cdist/conf/type/__package_opkg/man.text b/cdist/conf/type/__package_opkg/man.text index 3d02d1ce..aeb0a1c5 100644 --- a/cdist/conf/type/__package_opkg/man.text +++ b/cdist/conf/type/__package_opkg/man.text @@ -24,7 +24,7 @@ name:: If supplied, use the name and not the object id as the package name. state:: - The state the package should be in, either "present" or "absent" + Either "present" or "absent", defaults to "present" EXAMPLES diff --git a/cdist/conf/type/__package_pacman/man.text b/cdist/conf/type/__package_pacman/man.text index 17c2037a..2e24ecd9 100644 --- a/cdist/conf/type/__package_pacman/man.text +++ b/cdist/conf/type/__package_pacman/man.text @@ -10,8 +10,7 @@ cdist-type__package_pacman - Manage packages with pacman DESCRIPTION ----------- -Pacman is usually used on the Archlinux distribution to manage -packages. +Pacman is usually used on the Archlinux distribution to manage packages. REQUIRED PARAMETERS @@ -25,7 +24,7 @@ name:: If supplied, use the name and not the object id as the package name. state:: - The state the package should be in, either "present" or "absent" + Either "present" or "absent", defaults to "present" EXAMPLES diff --git a/cdist/conf/type/__package_pip/man.text b/cdist/conf/type/__package_pip/man.text index 8cb7d80a..5f619871 100644 --- a/cdist/conf/type/__package_pip/man.text +++ b/cdist/conf/type/__package_pip/man.text @@ -28,7 +28,7 @@ pip:: Instead of using pip from PATH, use the specific pip path. state:: - Either "present" or "absent", defaults to "present" + Either "present" or "absent", defaults to "present" EXAMPLES diff --git a/cdist/conf/type/__pf_ruleset/man.text b/cdist/conf/type/__pf_ruleset/man.text index 5c368e77..0dc07f71 100644 --- a/cdist/conf/type/__pf_ruleset/man.text +++ b/cdist/conf/type/__pf_ruleset/man.text @@ -26,6 +26,7 @@ source:: Note that this type is almost useless without a ruleset defined, but it's technically not needed, e.g. for the case of disabling the firewall temporarily. + EXAMPLES -------- diff --git a/cdist/conf/type/__postgres_role/man.text b/cdist/conf/type/__postgres_role/man.text index 4f13fa53..904f0831 100644 --- a/cdist/conf/type/__postgres_role/man.text +++ b/cdist/conf/type/__postgres_role/man.text @@ -16,7 +16,7 @@ This cdist type allows you to create or drop postgres roles. REQUIRED PARAMETERS ------------------- state:: - either 'present' or 'absent' + Either "present" or "absent", defaults to "present" OPTIONAL PARAMETERS diff --git a/cdist/conf/type/__process/man.text b/cdist/conf/type/__process/man.text index 929ba6a0..0d457ead 100644 --- a/cdist/conf/type/__process/man.text +++ b/cdist/conf/type/__process/man.text @@ -16,23 +16,23 @@ This cdist type allows you to define the state of a process. REQUIRED PARAMETERS ------------------- state:: - State of the process: Either present or absent + Either "present" or "absent", defaults to "present" OPTIONAL PARAMETERS ------------------- name:: - Process name to match on when using pgrep -f -x. + Process name to match on when using pgrep -f -x. - This is useful, if the name starts with a "/", - because the leading slash is stripped away from - the object id by cdist. + This is useful, if the name starts with a "/", + because the leading slash is stripped away from + the object id by cdist. stop:: - Executable to use for stopping the process. + Executable to use for stopping the process. start:: - Executable to use for starting the process. + Executable to use for starting the process. EXAMPLES diff --git a/cdist/conf/type/__qemu_img/man.text b/cdist/conf/type/__qemu_img/man.text index 3e16f957..39188ab0 100644 --- a/cdist/conf/type/__qemu_img/man.text +++ b/cdist/conf/type/__qemu_img/man.text @@ -24,8 +24,7 @@ size:: OPTIONAL PARAMETERS ------------------- state:: - The state of the image file: either "present" or "absent". - Defaults to "present". + Either "present" or "absent", defaults to "present" EXAMPLES diff --git a/cdist/conf/type/__rvm/man.text b/cdist/conf/type/__rvm/man.text index 0a355dc6..c1f83e60 100644 --- a/cdist/conf/type/__rvm/man.text +++ b/cdist/conf/type/__rvm/man.text @@ -16,7 +16,7 @@ RVM is the Ruby enVironment Manager for the Ruby programming language. REQUIRED PARAMETERS ------------------- state:: - Either "present" or "absent". + Either "present" or "absent". EXAMPLES diff --git a/cdist/conf/type/__rvm_gem/man.text b/cdist/conf/type/__rvm_gem/man.text index 85b52d65..fbf9a622 100644 --- a/cdist/conf/type/__rvm_gem/man.text +++ b/cdist/conf/type/__rvm_gem/man.text @@ -16,16 +16,16 @@ RVM is the Ruby enVironment Manager for the Ruby programming language. REQUIRED PARAMETERS ------------------- user:: - The remote user account to use + The remote user account to use gemset:: - The gemset to use + The gemset to use state:: - Either "present" or "absent". + Either "present" or "absent" OPTIONAL PARAMETERS ------------------- default:: - Make the selected gemset the default + Make the selected gemset the default EXAMPLES -------- diff --git a/cdist/conf/type/__rvm_gemset/man.text b/cdist/conf/type/__rvm_gemset/man.text index 10b6b411..26e866ba 100644 --- a/cdist/conf/type/__rvm_gemset/man.text +++ b/cdist/conf/type/__rvm_gemset/man.text @@ -16,14 +16,14 @@ RVM is the Ruby enVironment Manager for the Ruby programming language. REQUIRED PARAMETERS ------------------- user:: - The remote user account to use + The remote user account to use state:: - Either "present" or "absent". + Either "present" or "absent". OPTIONAL PARAMETERS ------------------- default:: - If set to anything but "no" (the default), set the given gemset as default. + If set to anything but "no" (the default), set the given gemset as default. EXAMPLES -------- diff --git a/cdist/conf/type/__rvm_ruby/man.text b/cdist/conf/type/__rvm_ruby/man.text index c558cfe3..90a7b654 100644 --- a/cdist/conf/type/__rvm_ruby/man.text +++ b/cdist/conf/type/__rvm_ruby/man.text @@ -16,14 +16,14 @@ RVM is the Ruby enVironment Manager for the Ruby programming language. REQUIRED PARAMETERS ------------------- user:: - The remote user account to use + The remote user account to use state:: - Either "present" or "absent". + Either "present" or "absent". -OPTIONAL PARAMETERS -------------------- +BOOLEAN PARAMETERS +------------------ default: - If set to anything but "no" (the default), set the given version as default + If set to anything but "no" (the default), set the given version as default EXAMPLES -------- diff --git a/cdist/conf/type/__start_on_boot/man.text b/cdist/conf/type/__start_on_boot/man.text index 58a68d65..6d804884 100644 --- a/cdist/conf/type/__start_on_boot/man.text +++ b/cdist/conf/type/__start_on_boot/man.text @@ -24,7 +24,7 @@ None. OPTIONAL PARAMETERS ------------------- state:: - 'present' or 'absent', defaults to 'present' + Either "present" or "absent", defaults to "present" EXAMPLES From 482ec3c5d8bcd0d9dc4b7ba7df8bdfe39870f001 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 19:27:17 +0100 Subject: [PATCH 89/95] make --default boolean in type __rvm_ruby Signed-off-by: Nico Schottelius --- cdist/conf/type/__rvm_ruby/gencode-remote | 41 ++++++++++--------- cdist/conf/type/__rvm_ruby/man.text | 4 +- .../parameter/{optional => boolean} | 0 3 files changed, 23 insertions(+), 22 deletions(-) rename cdist/conf/type/__rvm_ruby/parameter/{optional => boolean} (100%) diff --git a/cdist/conf/type/__rvm_ruby/gencode-remote b/cdist/conf/type/__rvm_ruby/gencode-remote index 0003cfe7..f1de3906 100755 --- a/cdist/conf/type/__rvm_ruby/gencode-remote +++ b/cdist/conf/type/__rvm_ruby/gencode-remote @@ -24,23 +24,24 @@ user="$(cat "$__object/parameter/user")" default="$(cat "$__object/parameter/default" 2>/dev/null || true)" state_should="$(cat "$__object/parameter/state")" -if [ "$state_is" != "$state_should" ]; then - case "$state_should" in - present) - echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\ - "rvm install $ruby\"" - case "$default" in - no) - ;; - *) - echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\ - "rvm use --default $ruby\"" - ;; - esac - ;; - absent) - echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\ - "rvm remove $ruby\"" - ;; - esac -fi +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\ + "rvm install $ruby\"" + if [ -f "$__object/parameter/default" ]; then + echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\ + "rvm use --default $ruby\"" + fi + ;; + absent) + echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\ + "rvm remove $ruby\"" + ;; + + *) + echo "Unknown state $state_should" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__rvm_ruby/man.text b/cdist/conf/type/__rvm_ruby/man.text index 90a7b654..dbbab85e 100644 --- a/cdist/conf/type/__rvm_ruby/man.text +++ b/cdist/conf/type/__rvm_ruby/man.text @@ -23,7 +23,7 @@ state:: BOOLEAN PARAMETERS ------------------ default: - If set to anything but "no" (the default), set the given version as default + Set the given version as default EXAMPLES -------- @@ -33,7 +33,7 @@ EXAMPLES __rvm_ruby ruby-1.9.3-p0 --user thelonious --state present # Install ruby 1.9.3 through rvm for user ornette and make it the default -__rvm_ruby ruby-1.9.3-p0 --user ornette --state present --default yes +__rvm_ruby ruby-1.9.3-p0 --user ornette --state present --default # Remove ruby 1.9.3 for user john __rvm_ruby ruby-1.9.3-p0 --user john --state absent diff --git a/cdist/conf/type/__rvm_ruby/parameter/optional b/cdist/conf/type/__rvm_ruby/parameter/boolean similarity index 100% rename from cdist/conf/type/__rvm_ruby/parameter/optional rename to cdist/conf/type/__rvm_ruby/parameter/boolean From fc7564c829db210c888fcbabc58f1019f03cc685 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Nov 2012 19:28:24 +0100 Subject: [PATCH 90/95] ++changes(next_version) Signed-off-by: Nico Schottelius --- docs/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog b/docs/changelog index 5d3c1698..df5c1b2b 100644 --- a/docs/changelog +++ b/docs/changelog @@ -8,6 +8,7 @@ Changelog * Type cleanup: __apt_ppa, __apt_ppa_update_index, __file, __ssh_authorized_key, __timezone, all install types (Steven Armstrong) * Types: Remove all parameter changing code + * Type __rvm_ruby: Change parameter "default" to be boolean 2.1.0pre7: 2012-11-07 * Core: All unit tests restored back to working From bbea7123f3422519bdabb41f760a1a5e77ad88c7 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 11 Nov 2012 13:09:46 +0100 Subject: [PATCH 91/95] cdist prefix required Signed-off-by: Nico Schottelius --- docs/man/man7/cdist-quickstart.text | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/man/man7/cdist-quickstart.text b/docs/man/man7/cdist-quickstart.text index 51943d41..b718da64 100644 --- a/docs/man/man7/cdist-quickstart.text +++ b/docs/man/man7/cdist-quickstart.text @@ -77,7 +77,7 @@ git clone git://git.schottelius.org/cdist # Create manifest (maps configuration to host(s) cd cdist -echo '__file /etc/cdist-configured' > conf/manifest/init +echo '__file /etc/cdist-configured' > cdist/conf/manifest/init # Configure localhost in verbose mode ./bin/cdist config -v localhost From 03ec09c771f0f89fae4b7f54c37476f04b435a4b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 14 Nov 2012 20:51:52 +0100 Subject: [PATCH 92/95] ++changes 2.1 documentation Signed-off-by: Nico Schottelius --- docs/dev/logs/2012-11-02.migration_to_2.1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/dev/logs/2012-11-02.migration_to_2.1 b/docs/dev/logs/2012-11-02.migration_to_2.1 index 2ef8df22..6c736a5c 100644 --- a/docs/dev/logs/2012-11-02.migration_to_2.1 +++ b/docs/dev/logs/2012-11-02.migration_to_2.1 @@ -38,3 +38,10 @@ by running cdist on one of your staging hosts: You can now cleanup the empty conf/ directory: % rmdir conf/* && rmdir conf + + + +-------------------------------------------------------------------------------- + +Boolean parameter introduced: + __directory /path/to --parents yes => __directory /path/to --parents From a498330bd3122b6abd150c543b89f22af85065bc Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 15 Nov 2012 09:32:44 +0100 Subject: [PATCH 93/95] remove _read_stdin and open stdin file in non-binary mode Signed-off-by: Nico Schottelius --- cdist/emulator.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/cdist/emulator.py b/cdist/emulator.py index 53c6914d..b6ee5166 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -149,8 +149,6 @@ class Emulator(object): # Record / Append source self.cdist_object.source.append(self.object_source) - def _read_stdin(self): - return self.stdin.read() def save_stdin(self): """If something is written to stdin, save it in the object as $__object/stdin so it can be accessed in manifest and gencode-* @@ -160,12 +158,10 @@ class Emulator(object): try: # go directly to file instead of using CdistObject's api # as that does not support streaming + # FIXME: no streaming needed anymore path = os.path.join(self.cdist_object.absolute_path, 'stdin') - with open(path, 'wb') as fd: - chunk = self._read_stdin() - while chunk: - fd.write(chunk) - chunk = self._read_stdin() + with open(path, 'w') as fd: + fd.write(self.stdin.read()) except EnvironmentError as e: raise cdist.Error('Failed to read from stdin: %s' % e) From 2fca87eda855449734b6e5588d3da60f94e1a7e5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 15 Nov 2012 09:34:19 +0100 Subject: [PATCH 94/95] ++comment Signed-off-by: Nico Schottelius --- cdist/emulator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/emulator.py b/cdist/emulator.py index b6ee5166..e54bd0dc 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -158,7 +158,7 @@ class Emulator(object): try: # go directly to file instead of using CdistObject's api # as that does not support streaming - # FIXME: no streaming needed anymore + # FIXME: no streaming needed anymore - use a raw file (not yet there?) path = os.path.join(self.cdist_object.absolute_path, 'stdin') with open(path, 'w') as fd: fd.write(self.stdin.read()) From 80c6592ec8676c1963573d54e3aa80008b7d100b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 15 Nov 2012 09:49:37 +0100 Subject: [PATCH 95/95] add hints to related manpages Signed-off-by: Nico Schottelius --- cdist/conf/type/__user/man.text | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/conf/type/__user/man.text b/cdist/conf/type/__user/man.text index e571c7c5..7be2c2f2 100644 --- a/cdist/conf/type/__user/man.text +++ b/cdist/conf/type/__user/man.text @@ -54,6 +54,7 @@ __user foobar --uid 1001 --shell /bin/zsh --home /home/foobar SEE ALSO -------- - cdist-type(7) +- usermod(8) or pw(8) COPYING