Merge branch 'master' into type__jail_boolean

This commit is contained in:
Nico Schottelius 2012-11-19 13:40:59 +01:00
commit bb19902581
8 changed files with 53 additions and 13 deletions

View file

@ -26,7 +26,7 @@ name="$__object_id"
. /etc/lsb-release
repo_name="${name#ppa:}"
repo_file_name="$(echo "$repo_name" | sed "s:\/:\-:")-${DISTRIB_CODENAME}.list"
repo_file_name="$(echo "$repo_name" | sed -e "s|[/:]|-|" -e "s|\.|_|")-${DISTRIB_CODENAME}.list"
[ -s "/etc/apt/sources.list.d/${repo_file_name}" ] \
&& echo present || echo absent

View file

@ -36,7 +36,7 @@ __rvm_gemset rails --gemset ruby-1.9.3-p0@myset --user bill --state present
# Do the same and also make ruby-1.9.3-p0@myset the default gemset
__rvm_gemset rails --gemset ruby-1.9.3-p0@myset --user bill \
--state present --default yes
--state present --default
# Remove it
__rvm_ruby rails --gemset ruby-1.9.3-p0@myset --user bill --state absent

View file

@ -186,6 +186,8 @@ class CdistObject(object):
return os.path.join(self.path, "explorer")
requirements = fsproperty.FileListProperty(lambda obj: os.path.join(obj.absolute_path, 'require'))
before = fsproperty.FileListProperty(lambda obj: os.path.join(obj.absolute_path, 'before'))
after = fsproperty.FileListProperty(lambda obj: os.path.join(obj.absolute_path, 'after'))
autorequire = fsproperty.FileListProperty(lambda obj: os.path.join(obj.absolute_path, 'autorequire'))
parameters = fsproperty.DirectoryDictProperty(lambda obj: os.path.join(obj.base_path, obj.parameter_path))
explorers = fsproperty.DirectoryDictProperty(lambda obj: os.path.join(obj.base_path, obj.explorer_path))

View file

@ -23,13 +23,14 @@
import argparse
import logging
import os
import warnings
import sys
import cdist
from cdist import core
class Emulator(object):
def __init__(self, argv, stdin=sys.stdin, env=os.environ):
def __init__(self, argv, stdin=sys.stdin.buffer, env=os.environ):
self.argv = argv
self.stdin = stdin
self.env = env
@ -92,8 +93,12 @@ class Emulator(object):
def commandline(self):
"""Parse command line"""
self.meta_parameters = dict.fromkeys(('after', 'before'))
meta_parser = argparse.ArgumentParser(add_help=False)
for meta_parameter in self.meta_parameters.keys():
meta_parser.add_argument('--%s' % meta_parameter, action='append', required=False)
parser = argparse.ArgumentParser(add_help=False, argument_default=argparse.SUPPRESS)
parser = argparse.ArgumentParser(add_help=False, parents=[meta_parser], argument_default=argparse.SUPPRESS)
for parameter in self.cdist_type.required_parameters:
argument = "--" + parameter
@ -119,6 +124,11 @@ class Emulator(object):
self.args = parser.parse_args(self.argv[1:])
self.log.debug('Args: %s' % self.args)
# Handle meta parameters
for meta_parameter in self.meta_parameters.keys():
if meta_parameter in self.args:
self.meta_parameters[meta_parameter] = getattr(self.args, meta_parameter)
delattr(self.args, meta_parameter)
def setup_object(self):
# Setup object_id - FIXME: unset / do not setup anymore!
@ -151,6 +161,10 @@ class Emulator(object):
# Record / Append source
self.cdist_object.source.append(self.object_source)
chunk_size = 65536
def _read_stdin(self):
return self.stdin.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-*
@ -160,19 +174,29 @@ 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 - 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())
with open(path, 'wb') as fd:
chunk = self._read_stdin()
while chunk:
fd.write(chunk)
chunk = self._read_stdin()
except EnvironmentError as e:
raise cdist.Error('Failed to read from stdin: %s' % e)
def record_requirements(self):
"""record requirements"""
for key in ('before', 'after'):
if key in self.meta_parameters and self.meta_parameters[key]:
for value in self.meta_parameters[key]:
self.log.debug("Recording requirement: %s %s %s", self.cdist_object.name, key, value)
dependency_list = getattr(self.cdist_object, key)
# append to the object.after or object.before lists
dependency_list.append(value)
if "require" in self.env:
warnings.warn("The 'require' envrionment variable is deprecated. Use the --before and --after meta parameters to define dependencies.", category=PendingDeprecationWarning, stacklevel=2)
requirements = self.env['require']
self.log.debug("reqs = " + requirements)
for requirement in requirements.split(" "):
# Ignore empty fields - probably the only field anyway
if len(requirement) == 0: continue
@ -181,11 +205,10 @@ class Emulator(object):
cdist_object = self.cdist_object.object_from_name(requirement)
self.log.debug("Recording requirement: " + requirement)
# Save the sanitised version, not the user supplied one
# (__file//bar => __file/bar)
# This ensures pattern matching is done against sanitised list
self.cdist_object.requirements.append(cdist_object.name)
self.cdist_object.after.append(cdist_object.name)
def record_auto_requirements(self):
"""An object shall automatically depend on all objects that it defined in it's type manifest.

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011-2012 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
@ -109,10 +109,21 @@ class DependencyResolver(object):
raise RequirementNotFoundError(pattern)
def _preprocess_requirements(self):
"""Find all autorequire dependencies and merge them to be just requirements
for further processing.
"""Find all before, after and autorequire dependencies and merge them
to be just requirements for further processing.
"""
for cdist_object in self.objects.values():
if cdist_object.after:
cdist_object.requirements.extend(cdist_object.after)
# As we changed the object on disc, we have to ensure it is not
# preprocessed again if someone would call us multiple times.
cdist_object.after = []
if cdist_object.before:
for other_object in self.find_requirements_by_name(cdist_object.before):
other_object.requirements.append(cdist_object.name)
# As we changed the object on disc, we have to ensure it is not
# preprocessed again if someone would call us multiple times.
cdist_object.before = []
if cdist_object.autorequire:
# The objects (children) that this cdist_object (parent) defined
# in it's type manifest shall inherit all explicit requirements

View file

@ -87,6 +87,7 @@ class ObjectTestCase(test.CdistTestCase):
self.cdist_object.code_local = ''
self.cdist_object.code_remote = ''
self.cdist_object.state = ''
self.cdist_object.requirements = []
def test_name(self):
self.assertEqual(self.cdist_object.name, '__third/moon')

View file

@ -9,6 +9,8 @@ next:
* Type __rvm_gemset: Change parameter "default" to be boolean
* New Type: __user_groups (Steven Armstrong)
* Type __user: Remove --groups support (now provided by __user_groups)
* Type __apt_ppa: Bugfix: Installeded ppa detection (Steven Armstrong)
* Core: Support for --after and --before parameters
2.1.0pre8: 2012-11-15
* Type cleanup: __apt_ppa, __apt_ppa_update_index, __file,

View file

@ -42,6 +42,7 @@ To upgrade to the lastet version do
* The types **\_\_autofs**, **\_\_autofs_map** and **\_\_autofs_reload** have been removed
(no maintainer, no users)
* Type **\_\_user**: Parameter --groups removed (use the new \_\_user_groups type)
* require="" is deprecated: Use --after and --before as parameters instead
### Updating from 1.7 to 2.0