Merge branch 'preos' into 4.0-pre-not-stable

This commit is contained in:
Nico Schottelius 2014-02-08 00:32:39 +01:00
commit 03f99a0e55
27 changed files with 154 additions and 75 deletions

View file

@ -23,22 +23,17 @@ state_is="$(cat "$__object/explorer/state")"
owner_is="$(cat "$__object/explorer/owner")" owner_is="$(cat "$__object/explorer/owner")"
group_is="$(cat "$__object/explorer/group")" group_is="$(cat "$__object/explorer/group")"
state_should=present state_should="$(cat "$__object/parameter/state")"
[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
branch=master branch="$(cat "$__object/parameter/branch")"
[ -f "$__object/parameter/branch" ] && branch="$(cat "$__object/parameter/branch")"
source="$(cat "$__object/parameter/source")" source="$(cat "$__object/parameter/source")"
destination="/$__object_id" destination="/$__object_id"
owner="" owner="$(cat "$__object/parameter/owner")"
[ -f "$__object/parameter/owner" ] && owner="$(cat "$__object/parameter/owner")" group="$(cat "$__object/parameter/group")"
group="" mode="$(cat "$__object/parameter/mode")"
[ -f "$__object/parameter/group" ] && group="$(cat "$__object/parameter/group")"
mode=""
[ -f "$__object/parameter/mode" ] && mode="$(cat "$__object/parameter/mode")"
[ "$state_should" = "$state_is" -a \ [ "$state_should" = "$state_is" -a \
"$owner" = "$owner_is" -a \ "$owner" = "$owner_is" -a \

View file

@ -23,8 +23,7 @@
__package git --state present __package git --state present
state_should=present state_should="$(cat "$__object/parameter/state")"
[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
# Let __directory handle removal of git repos # Let __directory handle removal of git repos

View file

@ -0,0 +1 @@
master

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@
present

View file

@ -22,17 +22,9 @@
# virtual machines. # virtual machines.
# #
if [ -f "$__object/parameter/jaildir" ]; then
jaildir="$(cat "$__object/parameter/jaildir")" jaildir="$(cat "$__object/parameter/jaildir")"
else
jaildir="/usr/jail"
fi
if [ -f "$__object/parameter/jailbase" ]; then
jailbase="$(cat "$__object/parameter/jailbase")" jailbase="$(cat "$__object/parameter/jailbase")"
else
jailbase=""
fi
state="$(cat "$__object/parameter/state")" state="$(cat "$__object/parameter/state")"

View file

@ -66,11 +66,7 @@ else
devfsenable="true" devfsenable="true"
fi fi
if [ -f "$__object/parameter/devfs-ruleset" ]; then
devfsruleset="$(cat "$__object/parameter/devfs-ruleset")" devfsruleset="$(cat "$__object/parameter/devfs-ruleset")"
else
devfsruleset="jailrules"
fi
# devfs_ruleset being defined without devfs_enable being true # devfs_ruleset being defined without devfs_enable being true
# is pointless. Treat this as an error. # is pointless. Treat this as an error.
@ -84,14 +80,11 @@ if [ -f "$__object/parameter/onboot" ]; then
onboot="true" onboot="true"
fi fi
if [ -f "$__object/parameter/jaildir" ]; then
jaildir="$(cat "$__object/parameter/jaildir")" jaildir="$(cat "$__object/parameter/jaildir")"
else
jaildir="/usr/jail"
fi
present="$(cat "$__object/explorer/present")" present="$(cat "$__object/explorer/present")"
status="$(cat "$__object/explorer/status")" status="$(cat "$__object/explorer/status")"
# Handle ip="iface|addr, iface|addr" format # Handle ip="iface|addr, iface|addr" format
if [ $(expr "${ip}" : ".*|.*") -gt "0" ]; then if [ $(expr "${ip}" : ".*|.*") -gt "0" ]; then
# If we have multiple IPs defined, $interface doesn't make sense because ip="iface|addr, iface|addr" implies it # If we have multiple IPs defined, $interface doesn't make sense because ip="iface|addr, iface|addr" implies it

View file

@ -33,11 +33,7 @@ if [ ! "$os" = "freebsd" ]; then
exit 1 exit 1
fi fi
if [ -f "$__object/parameter/jaildir" ]; then
jaildir="$(cat "$__object/parameter/jaildir")" jaildir="$(cat "$__object/parameter/jaildir")"
else
jaildir="/usr/jail"
fi
__directory ${jaildir} --parents __directory ${jaildir} --parents

View file

@ -0,0 +1 @@
jailrules

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@
/usr/jail

View file

@ -27,11 +27,7 @@ else
name="$__object_id" name="$__object_id"
fi fi
if [ -f "$__object/parameter/state" ]; then
state_should="$(cat "$__object/parameter/state")" state_should="$(cat "$__object/parameter/state")"
else
state_should="present"
fi
if grep -q -E "(centos|redhat|amazon)" "$__global/explorer/os"; then if grep -q -E "(centos|redhat|amazon)" "$__global/explorer/os"; then
opts="-y --quiet" opts="-y --quiet"

View file

@ -0,0 +1 @@
present

View file

@ -34,17 +34,8 @@ else
name="$__object_id" name="$__object_id"
fi fi
if [ -f "$__object/parameter/state" ]; then
state_should="$(cat "$__object/parameter/state")" state_should="$(cat "$__object/parameter/state")"
else
state_should="present"
fi
if [ -f "$__object/parameter/ptype" ]; then
ptype="$(cat "$__object/parameter/ptype")" ptype="$(cat "$__object/parameter/ptype")"
else
ptype="package"
fi
if [ -f "$__object/parameter/version" ]; then if [ -f "$__object/parameter/version" ]; then
version_should="$(cat "$__object/parameter/version")" version_should="$(cat "$__object/parameter/version")"

View file

@ -0,0 +1 @@
present

View file

@ -19,7 +19,7 @@
# #
user="$(cat "$__object/parameter/user" 2>/dev/null || echo "$__object_id")" user="$(cat "$__object/parameter/user" 2>/dev/null || echo "$__object_id")"
state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")" state_should="$(cat "$__object/parameter/state")"
mkdir "$__object/files" mkdir "$__object/files"
# file has to be sorted for comparison with `comm` # file has to be sorted for comparison with `comm`

View file

@ -0,0 +1 @@
present

View file

@ -72,6 +72,7 @@ class Emulator(object):
raise MissingRequiredEnvironmentVariableError(e.args[0]) raise MissingRequiredEnvironmentVariableError(e.args[0])
self.object_base_path = os.path.join(self.global_path, "object") self.object_base_path = os.path.join(self.global_path, "object")
self.typeorder_path = os.path.join(self.global_path, "typeorder")
self.type_name = os.path.basename(argv[0]) self.type_name = os.path.basename(argv[0])
self.cdist_type = core.CdistType(self.type_base_path, self.type_name) self.cdist_type = core.CdistType(self.type_base_path, self.type_name)
@ -129,7 +130,6 @@ class Emulator(object):
self.args = parser.parse_args(self.argv[1:]) self.args = parser.parse_args(self.argv[1:])
self.log.debug('Args: %s' % self.args) self.log.debug('Args: %s' % self.args)
def setup_object(self): def setup_object(self):
# Setup object_id - FIXME: unset / do not setup anymore! # Setup object_id - FIXME: unset / do not setup anymore!
if not self.cdist_type.is_singleton: if not self.cdist_type.is_singleton:
@ -145,18 +145,21 @@ class Emulator(object):
if value is not None: if value is not None:
self.parameters[key] = value self.parameters[key] = value
if self.cdist_object.exists and not 'CDIST_ALLOW_OVERRIDE' in os.environ: if self.cdist_object.exists and not 'CDIST_OVERRIDE' in self.env:
if self.cdist_object.parameters != self.parameters: if self.cdist_object.parameters != self.parameters:
raise cdist.Error("Object %s already exists with conflicting parameters:\n%s: %s\n%s: %s" raise cdist.Error("Object %s already exists with conflicting parameters:\n%s: %s\n%s: %s"
% (self.cdist_object.name, " ".join(self.cdist_object.source), self.cdist_object.parameters, self.object_source, self.parameters) % (self.cdist_object.name, " ".join(self.cdist_object.source), self.cdist_object.parameters, self.object_source, self.parameters)
) )
else: else:
if self.cdist_object.exists: if self.cdist_object.exists:
self.log.debug('Object %s override forced with CDIST_ALLOW_OVERRIDE',self.cdist_object.name) self.log.debug('Object %s override forced with CDIST_OVERRIDE',self.cdist_object.name)
self.cdist_object.create(True) self.cdist_object.create(True)
else: else:
self.cdist_object.create() self.cdist_object.create()
self.cdist_object.parameters = self.parameters self.cdist_object.parameters = self.parameters
# record the created object in typeorder file
with open(self.typeorder_path, 'a') as typeorderfile:
print(self.cdist_object.name, file=typeorderfile)
# Record / Append source # Record / Append source
self.cdist_object.source.append(self.object_source) self.cdist_object.source.append(self.object_source)
@ -186,6 +189,23 @@ class Emulator(object):
def record_requirements(self): def record_requirements(self):
"""record requirements""" """record requirements"""
if "CDIST_ORDER_DEPENDENCY" in self.env:
# load object name created bevor this one from typeorder file ...
with open(self.typeorder_path, 'r') as typecreationfile:
typecreationorder = typecreationfile.readlines()
# get the type created bevore this one ...
try:
lastcreatedtype = typecreationorder[-2].strip()
if 'require' in self.env:
self.env['require'] += " " + lastcreatedtype
else:
self.env['require'] = lastcreatedtype
self.log.debug("Injecting require for CDIST_ORDER_DEPENDENCY: %s for %s", lastcreatedtype, self.cdist_object.name)
except IndexError:
# if no second last line, we are on the first type, so do not set a requirement
pass
if "require" in self.env: if "require" in self.env:
requirements = self.env['require'] requirements = self.env['require']
self.log.debug("reqs = " + requirements) self.log.debug("reqs = " + requirements)
@ -203,7 +223,7 @@ class Emulator(object):
self.log.error("%s requires object %s without object id. Defined at %s" % (self.cdist_object.name, requirement, self.object_source)) self.log.error("%s requires object %s without object id. Defined at %s" % (self.cdist_object.name, requirement, self.object_source))
raise raise
self.log.debug("Recording requirement: " + requirement) self.log.debug("Recording requirement: %s", requirement)
# Save the sanitised version, not the user supplied one # Save the sanitised version, not the user supplied one
# (__file//bar => __file/bar) # (__file//bar => __file/bar)

View file

@ -58,10 +58,10 @@ class ObjectClassTestCase(test.CdistTestCase):
def test_list_type_names(self): def test_list_type_names(self):
type_names = list(cdist.core.CdistObject.list_type_names(object_base_path)) type_names = list(cdist.core.CdistObject.list_type_names(object_base_path))
self.assertEqual(type_names, ['__first', '__second', '__third']) self.assertEqual(sorted(type_names), ['__first', '__second', '__third'])
def test_list_objects(self): def test_list_objects(self):
found_objects = list(core.CdistObject.list_objects(object_base_path, type_base_path)) found_objects = sorted(list(core.CdistObject.list_objects(object_base_path, type_base_path)))
self.assertEqual(found_objects, self.expected_objects) self.assertEqual(found_objects, self.expected_objects)
def test_create_singleton(self): def test_create_singleton(self):

View file

@ -34,7 +34,7 @@ class TypeTestCase(test.CdistTestCase):
def test_list_type_names(self): def test_list_type_names(self):
base_path = op.join(fixtures, 'list_types') base_path = op.join(fixtures, 'list_types')
type_names = core.CdistType.list_type_names(base_path) type_names = core.CdistType.list_type_names(base_path)
self.assertEqual(type_names, ['__first', '__second', '__third']) self.assertEqual(sorted(type_names), ['__first', '__second', '__third'])
def test_list_types(self): def test_list_types(self):
base_path = op.join(fixtures, 'list_types') base_path = op.join(fixtures, 'list_types')
@ -44,7 +44,7 @@ class TypeTestCase(test.CdistTestCase):
core.CdistType(base_path, '__second'), core.CdistType(base_path, '__second'),
core.CdistType(base_path, '__third'), core.CdistType(base_path, '__third'),
] ]
self.assertEqual(types, types_expected) self.assertEqual(sorted(types), types_expected)
def test_only_one_instance(self): def test_only_one_instance(self):
base_path = fixtures base_path = fixtures

View file

@ -2,6 +2,7 @@
# #
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2012-2013 Nico Schottelius (nico-cdist at schottelius.org) # 2012-2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2014 Daniel Heule (hda at sfs.biz)
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -129,6 +130,44 @@ class AutoRequireEmulatorTestCase(test.CdistTestCase):
expected = ['__planet/Saturn', '__moon/Prometheus'] expected = ['__planet/Saturn', '__moon/Prometheus']
self.assertEqual(sorted(cdist_object.autorequire), sorted(expected)) self.assertEqual(sorted(cdist_object.autorequire), sorted(expected))
class OverrideTestCase(test.CdistTestCase):
def setUp(self):
self.temp_dir = self.mkdtemp()
handle, self.script = self.mkstemp(dir=self.temp_dir)
os.close(handle)
base_path = self.temp_dir
self.local = local.Local(
target_host=self.target_host,
base_path=base_path,
exec_path=test.cdist_exec_path,
add_conf_dirs=[conf_dir])
self.local.create_files_dirs()
self.manifest = core.Manifest(self.target_host, self.local)
self.env = self.manifest.env_initial_manifest(self.script)
def tearDown(self):
shutil.rmtree(self.temp_dir)
def test_override_negative(self):
argv = ['__file', '/tmp/foobar']
emu = emulator.Emulator(argv, env=self.env)
emu.run()
argv = ['__file', '/tmp/foobar','--mode','404']
emu = emulator.Emulator(argv, env=self.env)
self.assertRaises(cdist.Error, emu.run)
def test_override_feature(self):
argv = ['__file', '/tmp/foobar']
emu = emulator.Emulator(argv, env=self.env)
emu.run()
argv = ['__file', '/tmp/foobar','--mode','404']
self.env['CDIST_OVERRIDE'] = 'on'
emu = emulator.Emulator(argv, env=self.env)
emu.run()
class ArgumentsTestCase(test.CdistTestCase): class ArgumentsTestCase(test.CdistTestCase):
@ -182,7 +221,7 @@ class ArgumentsTestCase(test.CdistTestCase):
object_id = 'some-id' object_id = 'some-id'
value = 'some value' value = 'some value'
argv = [type_name, object_id, '--required1', value, '--required2', value] argv = [type_name, object_id, '--required1', value, '--required2', value]
print(self.env) # print(self.env)
os.environ.update(self.env) os.environ.update(self.env)
emu = emulator.Emulator(argv) emu = emulator.Emulator(argv)
emu.run() emu.run()

View file

@ -9,19 +9,27 @@ Changelog
* Core: Integrate initial preos support * Core: Integrate initial preos support
3.0.6: 3.0.7: 2014-02-08
* Core: Allow dependencies to be created based execution order (Daniel Heule)
* Core: Add tests for override (Daniel Heule)
3.0.6: 2014-02-06
* New Type: __apt_key (Steven Armstrong) * New Type: __apt_key (Steven Armstrong)
* New Type: __apt_key_uri (Steven Armstrong) * New Type: __apt_key_uri (Steven Armstrong)
* New Type: __apt_norecommends (Steven Armstrong) * New Type: __apt_norecommends (Steven Armstrong)
* New Type: __apt_source (Steven Armstrong) * New Type: __apt_source (Steven Armstrong)
* New Type: __ccollect_source
* Type __git: Use default parameters (Daniel Heule)
* Type __jail: Use default parameters (Daniel Heule)
* Type __package_yum: Use default parameters (Daniel Heule)
* Type __package_zypper: Use default parameters (Daniel Heule)
* Type __user_groups: Use default parameters (Daniel Heule)
3.0.5: 2014-02-05 3.0.5: 2014-02-05
* Core: Introduce override concept (Daniel Heule) * Core: Introduce override concept (Daniel Heule)
* Type __process: Make --state absent work (Steven Armstrong) * Type __process: Make --state absent work (Steven Armstrong)
* Documentation: Update documentation for environment variables * Documentation: Update documentation for environment variables
3.0.4: 2014-01-29 3.0.4: 2014-01-29
* Core: Ignore install types in config mode * Core: Ignore install types in config mode
* Documentation: Update reference (files path in object space) * Documentation: Update reference (files path in object space)
@ -31,7 +39,6 @@ Changelog
* Type __debconf_set_selections: Support --file - to read from stdin * Type __debconf_set_selections: Support --file - to read from stdin
* Type __jail: Fix jaildir parameter handling (Jake Guffey) * Type __jail: Fix jaildir parameter handling (Jake Guffey)
3.0.3: 2014-01-22 3.0.3: 2014-01-22
* Core: Enhance error message when requirement is missing object id * Core: Enhance error message when requirement is missing object id
* Core: Add environment variable to select shell for executing scripts (Daniel Heule) * Core: Add environment variable to select shell for executing scripts (Daniel Heule)
@ -44,7 +51,6 @@ Changelog
* Type __zypper_repo: Use default paremeters (Daniel Heule) * Type __zypper_repo: Use default paremeters (Daniel Heule)
* Type __zypper_service: Use default paremeters (Daniel Heule) * Type __zypper_service: Use default paremeters (Daniel Heule)
3.0.2: 2014-01-19 3.0.2: 2014-01-19
* Documentation: Document all messages sent by types (Daniel Heule) * Documentation: Document all messages sent by types (Daniel Heule)
* New Type: __block (Steven Armstrong) * New Type: __block (Steven Armstrong)
@ -52,7 +58,6 @@ Changelog
* Type __cron: Replace existing entry when changing it (Daniel Heule) * Type __cron: Replace existing entry when changing it (Daniel Heule)
* Type __ssh_authorized_keys: Use new type __block (Steven Armstrong) * Type __ssh_authorized_keys: Use new type __block (Steven Armstrong)
3.0.1: 2014-01-14 3.0.1: 2014-01-14
* Core: Copy only files, not directories (Steven Armstrong) * Core: Copy only files, not directories (Steven Armstrong)
* Core: Allow hostnames to start with / * Core: Allow hostnames to start with /

View file

@ -239,6 +239,9 @@ require::
CDIST_ALLOW_OVERRIDE:: CDIST_ALLOW_OVERRIDE::
Allow overwriting type parameters (see cdist-manifest(7)) Allow overwriting type parameters (see cdist-manifest(7))
CDIST_ORDER_DEPENDENCY::
Create dependencies based on the execution order (see cdist-manifest(7))
SEE ALSO SEE ALSO
-------- --------
- cdist(1) - cdist(1)
@ -246,6 +249,6 @@ SEE ALSO
COPYING COPYING
------- -------
Copyright \(C) 2011-2013 Nico Schottelius. Free use of this software is Copyright \(C) 2011-2014 Nico Schottelius. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3). granted under the terms of the GNU General Public License version 3 (GPLv3).
eof eof

View file

@ -128,19 +128,34 @@ All objects that are created in a type manifest are automatically required
from the type that is calling them. This is called "autorequirement" in from the type that is calling them. This is called "autorequirement" in
cdist jargon. cdist jargon.
CREATE DEPENDENCIES FROM EXECUTION ORDER
-----------------------------------------
You can tell cdist to execute all types in the order in which they are created
in the manifest by setting up the variable CDIST_ORDER_DEPENDENCY.
When cdist sees that this variable is setup, the current created object
automatically depends on the previously created object.
It essentially helps you to build up blocks of code that build upon each other
(like first creating the directory xyz than the file below the directory).
THIS IS A BETA FEATURE AND MAY BE REMOVED OR CHANGED AT ANY TIME.
OVERRIDES OVERRIDES
--------- ---------
In some special cases, you would like to create an already defined object In some special cases, you would like to create an already defined object
with different parameters. In normal situations this leads to an error in cdist. with different parameters. In normal situations this leads to an error in cdist.
If you whish, you can setup the environment variable CDIST_ALLOW_OVERRIDE If you whish, you can setup the environment variable CDIST_OVERRIDE
(any value or even empty is ok) to tell cdist, that this object override is (any value or even empty is ok) to tell cdist, that this object override is
wanted and should be accepted. wanted and should be accepted.
ATTENTION: Only use this feature if you are 100% sure in which order ATTENTION: Only use this feature if you are 100% sure in which order
cdist encounter the affected objects, otherwhise this results cdist encounter the affected objects, otherwhise this results
into an undefined situation. into an undefined situation.
THIS IS A BETA FEATURE AND MAY BE REMOVED AT ANY TIME. THIS IS A BETA FEATURE AND MAY BE REMOVED OR CHANGED AT ANY TIME.
EXAMPLES EXAMPLES
-------- --------
@ -190,11 +205,35 @@ __user foobar --password 'some_fancy_hash' --home /home/foobarexample
__user foobar --password 'some_other_hash' __user foobar --password 'some_other_hash'
# this tells cdist, that you know that this is an override and should be accepted # this tells cdist, that you know that this is an override and should be accepted
CDIST_ALLOW_OVERRIDE=yes __user foobar --password 'some_other_hash' CDIST_OVERRIDE=yes __user foobar --password 'some_other_hash'
# its only an override, means the parameter --home is not touched # its only an override, means the parameter --home is not touched
# and stay at the original value of /home/foobarexample # and stay at the original value of /home/foobarexample
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
Dependencies defined by execution order work as following:
--------------------------------------------------------------------------------
# Tells cdist to execute all types in the order in which they are created ...
export CDIST_ORDER_DEPENDENCY=on
__sample_type 1
require="__some_type_somewhere/id" __sample_type 2
__example_type 23
# Now this types are executed in the creation order until the variable is unset
unset CDIST_ORDER_DEPENDENCY
# all now following types cdist makes the order ..
__not_in_order_type 42
# how it works :
# this lines above are translated to:
__sample_type 1
require="__some_type_somewhere/id __sample_type/1" __sample_type 2
require="__sample_type/2" __example_type 23
__not_in_order_type 42
--------------------------------------------------------------------------------
SEE ALSO SEE ALSO
-------- --------
@ -204,5 +243,5 @@ SEE ALSO
COPYING COPYING
------- -------
Copyright \(C) 2010-2012 Nico Schottelius. Free use of this software is Copyright \(C) 2010-2014 Nico Schottelius. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3). granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -20,6 +20,6 @@ you can join the
### Commercial support ### Commercial support
You can request commercial support for cdist from You can request commercial support for cdist from
[my company](http://firma.schottelius.org/english/). [my company](http://www.ungleich.ch/english/).
[[!tag cdist unix]] [[!tag cdist unix]]