forked from ungleich-public/cdist
various cleanups
Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
parent
442dc767dd
commit
958d2d336f
3 changed files with 45 additions and 86 deletions
|
@ -56,6 +56,21 @@ class CdistObject(object):
|
|||
STATE_RUNNING = "running"
|
||||
STATE_DONE = "done"
|
||||
|
||||
def __init__(self, cdist_type, base_path, object_id=None):
|
||||
self.cdist_type = cdist_type # instance of Type
|
||||
self.base_path = base_path
|
||||
self.object_id = object_id
|
||||
|
||||
self.validate_object_id()
|
||||
self.sanitise_object_id()
|
||||
|
||||
self.name = self.join_name(self.cdist_type.name, self.object_id)
|
||||
self.path = os.path.join(self.cdist_type.path, self.object_id, OBJECT_MARKER)
|
||||
self.absolute_path = os.path.join(self.base_path, self.path)
|
||||
self.code_local_path = os.path.join(self.path, "code-local")
|
||||
self.code_remote_path = os.path.join(self.path, "code-remote")
|
||||
self.parameter_path = os.path.join(self.path, "parameter")
|
||||
|
||||
@classmethod
|
||||
def list_objects(cls, object_base_path, type_base_path):
|
||||
"""Return a list of object instances"""
|
||||
|
@ -112,21 +127,6 @@ class CdistObject(object):
|
|||
raise IllegalObjectIdError(self.object_id,
|
||||
"Missing object_id and type is not a singleton.")
|
||||
|
||||
def __init__(self, cdist_type, base_path, object_id=None):
|
||||
self.cdist_type = cdist_type # instance of Type
|
||||
self.base_path = base_path
|
||||
self.object_id = object_id
|
||||
|
||||
self.validate_object_id()
|
||||
self.sanitise_object_id()
|
||||
|
||||
self.name = self.join_name(self.cdist_type.name, self.object_id)
|
||||
self.path = os.path.join(self.cdist_type.path, self.object_id, OBJECT_MARKER)
|
||||
self.absolute_path = os.path.join(self.base_path, self.path)
|
||||
self.code_local_path = os.path.join(self.path, "code-local")
|
||||
self.code_remote_path = os.path.join(self.path, "code-remote")
|
||||
self.parameter_path = os.path.join(self.path, "parameter")
|
||||
|
||||
def object_from_name(self, object_name):
|
||||
"""Convenience method for creating an object instance from an object name.
|
||||
|
||||
|
@ -232,7 +232,7 @@ class CdistObject(object):
|
|||
[<Object __type/object_id>, <Object __other_type/any>, <Object __other_type/match>]
|
||||
"""
|
||||
|
||||
object_names = self.list_object_namess(self.base_path)
|
||||
object_names = self.list_object_names(self.base_path)
|
||||
for pattern in requirements:
|
||||
found = False
|
||||
for requirement in fnmatch.filter(object_names, pattern):
|
||||
|
@ -274,6 +274,3 @@ class RequirementNotFoundError(cdist.Error):
|
|||
|
||||
def __str__(self):
|
||||
return 'Requirement could not be found: %s' % self.requirement
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -42,6 +42,26 @@ class CdistType(object):
|
|||
|
||||
"""
|
||||
|
||||
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):
|
||||
raise NoSuchTypeError(self.path, self.absolute_path)
|
||||
self.manifest_path = os.path.join(self.name, "manifest")
|
||||
self.explorer_path = os.path.join(self.name, "explorer")
|
||||
self.gencode_local_path = os.path.join(self.name, "gencode-local")
|
||||
self.gencode_remote_path = os.path.join(self.name, "gencode-remote")
|
||||
self.manifest_path = os.path.join(self.name, "manifest")
|
||||
|
||||
self.__explorers = None
|
||||
self.__required_parameters = None
|
||||
self.__required_multiple_parameters = None
|
||||
self.__optional_parameters = None
|
||||
self.__optional_multiple_parameters = None
|
||||
self.__boolean_parameters = None
|
||||
|
||||
@classmethod
|
||||
def list_types(cls, base_path):
|
||||
"""Return a list of type instances"""
|
||||
|
@ -65,26 +85,6 @@ class CdistType(object):
|
|||
# return instance so __init__ is called
|
||||
return cls._instances[name]
|
||||
|
||||
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):
|
||||
raise NoSuchTypeError(self.path, self.absolute_path)
|
||||
self.manifest_path = os.path.join(self.name, "manifest")
|
||||
self.explorer_path = os.path.join(self.name, "explorer")
|
||||
self.gencode_local_path = os.path.join(self.name, "gencode-local")
|
||||
self.gencode_remote_path = os.path.join(self.name, "gencode-remote")
|
||||
self.manifest_path = os.path.join(self.name, "manifest")
|
||||
|
||||
self.__explorers = None
|
||||
self.__required_parameters = None
|
||||
self.__required_multiple_parameters = None
|
||||
self.__optional_parameters = None
|
||||
self.__optional_multiple_parameters = None
|
||||
self.__boolean_parameters = None
|
||||
|
||||
def __repr__(self):
|
||||
return '<CdistType %s>' % self.name
|
||||
|
||||
|
|
|
@ -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.
|
||||
#
|
||||
|
@ -202,56 +203,24 @@ class ObjectTestCase(test.CdistTestCase):
|
|||
self.assertEqual(other_object.object_id, 'man')
|
||||
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# 2010-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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
import cdist
|
||||
from cdist import test
|
||||
from cdist import core
|
||||
|
||||
import os.path as op
|
||||
my_dir = op.abspath(op.dirname(__file__))
|
||||
fixtures = op.join(my_dir, 'fixtures')
|
||||
object_base_path = op.join(fixtures, 'object')
|
||||
type_base_path = op.join(fixtures, 'type')
|
||||
|
||||
|
||||
class ResolverTestCase(test.CdistTestCase):
|
||||
class ObjectResolveRequirementsTestCase(test.CdistTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.objects = list(core.CdistObject.list_objects(object_base_path, type_base_path))
|
||||
self.object_index = dict((o.name, o) for o in self.objects)
|
||||
|
||||
# Create a test object with requirements
|
||||
self.test_object = core.CdistObject(cdist_type, base_path, object_id=None)
|
||||
self.cdist_type = core.CdistType(type_base_path, '__third')
|
||||
self.cdist_object = core.CdistObject(self.cdist_type, object_base_path, 'moon')
|
||||
|
||||
def tearDown(self):
|
||||
for o in self.objects:
|
||||
o.requirements = []
|
||||
|
||||
def test_find_requirements_by_name_string(self):
|
||||
"""Check that resolving requirements by name works"""
|
||||
requirements = ['__first/man', '__second/on-the', '__third/moon']
|
||||
|
||||
required_objects = [self.object_index[name] for name in requirements]
|
||||
self.assertEqual(sorted(list(self.dependency_resolver.find_requirements_by_name(requirements))),
|
||||
sorted(required_objects))
|
||||
|
@ -278,16 +247,9 @@ class ResolverTestCase(test.CdistTestCase):
|
|||
[third_moon, second_on_the, first_man]
|
||||
)
|
||||
|
||||
def test_circular_reference(self):
|
||||
first_man = self.object_index['__first/man']
|
||||
first_woman = self.object_index['__first/woman']
|
||||
first_man.requirements = [first_woman.name]
|
||||
first_woman.requirements = [first_man.name]
|
||||
with self.assertRaises(resolver.CircularReferenceError):
|
||||
self.dependency_resolver.dependencies
|
||||
|
||||
def test_requirement_not_found(self):
|
||||
first_man = self.object_index['__first/man']
|
||||
first_man.requirements = ['__does/not/exist']
|
||||
with self.assertRaises(cdist.Error):
|
||||
self.dependency_resolver.dependencies
|
||||
with self.assertRaises(core.cdist_object.RequirementNotFoundError):
|
||||
first_man.find_requirements_by_name(first_man.requirements)
|
||||
|
||||
|
|
Loading…
Reference in a new issue