forked from ungleich-public/cdist
		
	Warn about invalid type and continue instead of error.
This commit is contained in:
		
					parent
					
						
							
								e6c5563a16
							
						
					
				
			
			
				commit
				
					
						c14f3b68f4
					
				
			
		
					 3 changed files with 12 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -21,7 +21,7 @@
 | 
			
		|||
#
 | 
			
		||||
 | 
			
		||||
from cdist.core.cdist_type import CdistType
 | 
			
		||||
from cdist.core.cdist_type import NoSuchTypeError, InvalidTypeError
 | 
			
		||||
from cdist.core.cdist_type import InvalidTypeError
 | 
			
		||||
from cdist.core.cdist_object import CdistObject
 | 
			
		||||
from cdist.core.cdist_object import IllegalObjectIdError
 | 
			
		||||
from cdist.core.explorer import Explorer
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,20 +23,15 @@
 | 
			
		|||
import os
 | 
			
		||||
import cdist
 | 
			
		||||
import cdist.core
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class NoSuchTypeError(cdist.Error):
 | 
			
		||||
class InvalidTypeError(cdist.Error):
 | 
			
		||||
    def __init__(self, name, type_path, type_absolute_path):
 | 
			
		||||
        self.name = name
 | 
			
		||||
        self.type_path = type_path
 | 
			
		||||
        self.type_absolute_path = type_absolute_path
 | 
			
		||||
 | 
			
		||||
    def __str__(self):
 | 
			
		||||
        return "Type '%s' does not exist at '%s'" % (
 | 
			
		||||
                self.type_path, self.type_absolute_path)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class InvalidTypeError(NoSuchTypeError):
 | 
			
		||||
    def __str__(self):
 | 
			
		||||
        return "Invalid type '%s' at '%s' defined at '%s'" % (
 | 
			
		||||
                self.type_path, self.type_absolute_path,
 | 
			
		||||
| 
						 | 
				
			
			@ -52,12 +47,15 @@ class CdistType(object):
 | 
			
		|||
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    log = logging.getLogger("cdist")
 | 
			
		||||
 | 
			
		||||
    def __init__(self, base_path, name):
 | 
			
		||||
        self.base_path = base_path
 | 
			
		||||
        self.name = name
 | 
			
		||||
        self.path = self.name
 | 
			
		||||
        self.absolute_path = os.path.join(self.base_path, self.path)
 | 
			
		||||
        if not os.path.isdir(self.absolute_path):
 | 
			
		||||
            os.remove(self.absolute_path)
 | 
			
		||||
            raise InvalidTypeError(self.name, self.path, self.absolute_path)
 | 
			
		||||
        self.manifest_path = os.path.join(self.name, "manifest")
 | 
			
		||||
        self.explorer_path = os.path.join(self.name, "explorer")
 | 
			
		||||
| 
						 | 
				
			
			@ -80,7 +78,11 @@ class CdistType(object):
 | 
			
		|||
    def list_types(cls, base_path):
 | 
			
		||||
        """Return a list of type instances"""
 | 
			
		||||
        for name in cls.list_type_names(base_path):
 | 
			
		||||
            yield cls(base_path, name)
 | 
			
		||||
            try:
 | 
			
		||||
                yield cls(base_path, name)
 | 
			
		||||
            except InvalidTypeError as e:
 | 
			
		||||
                # ignore invalid type, log warning and continue
 | 
			
		||||
                cls.log.warning(e)
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def list_type_names(cls, base_path):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,7 @@ next:
 | 
			
		|||
	* Type __ccollect_source: Add create destination parameter (Dominique Roux)
 | 
			
		||||
	* Type __ssh_authorized_key: Add messaging (Thomas Eckert)
 | 
			
		||||
	* New type: __letsencrypt_cert (Nico Schottelius, Kamila Součková)
 | 
			
		||||
	* Core: Warn about invalid type in conf dir and continue instead of error (Darko Poljak)
 | 
			
		||||
 | 
			
		||||
4.7.2: 2017-10-22
 | 
			
		||||
	* Type __hostname: Add support for CoreOS (Ľubomír Kučera)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue