From d0123acc2a6f7f2db05f25b4e63abce2f22a8649 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 3 Nov 2011 15:44:51 +0100 Subject: [PATCH] implement singleton as requirement Signed-off-by: Steven Armstrong --- lib/cdist/emulator.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/cdist/emulator.py b/lib/cdist/emulator.py index 4880c6e6..7ae89294 100644 --- a/lib/cdist/emulator.py +++ b/lib/cdist/emulator.py @@ -156,19 +156,22 @@ class Emulator(object): self.log.debug("Recording requirement: " + requirement) requirement_parts = requirement.split(os.sep, 1) requirement_type_name = requirement_parts[0] - requirement_object_id = requirement_parts[1] - - # FIXME: Add support for omitted object id == singleton - #if len(requirement_parts) == 1: - #except IndexError: - # # no object id, must be singleton - # requirement_object_id = 'singleton' - - # Remove / if existent in object id + try: + requirement_object_id = requirement_parts[1] + except IndexError: + # no object id, assume singleton + requirement_object_id = 'singleton' + + # Remove leading / from object id requirement_object_id = requirement_object_id.lstrip('/') # Instantiate type which fails if type does not exist requirement_type = core.Type(self.type_base_path, requirement_type_name) + + if requirement_object_id == 'singleton' \ + and not requirement_type.is_singleton: + raise IllegalRequirementError(requirement, "Missing object_id and type is not a singleton.") + # Instantiate object which fails if the object_id is illegal requirement_object = core.Object(requirement_type, self.object_base_path, requirement_object_id)