コード例 #1
0
ファイル: BaseEntityTest.py プロジェクト: cea-hpc/milkcheck
 def test_resolve_all(self):
     """resolve_all() resolves all BaseEntity properties"""
     entity = BaseEntity('entity')
     entity.add_var('TGT', 'localhost')
     entity.add_var('NBR1', 1)
     entity.add_var('NBR2', 2)
     entity.add_var('NBR3', 3)
     entity.add_var('NBR4', 4)
     entity.add_var('NBR5', 5)
     entity.add_var('NBR6', 6)
     entity.add_var('KEYWORD', 'delegate')
     entity.add_var('TXT', 'I am the entity')
     entity.fromdict({
                      'target': "%TGT",
                      'timeout': "%NBR1",
                      'retry': "%NBR2",
                      'fanout': "%NBR3",
                      'delay': "%NBR4",
                      'warnings': "%NBR5",
                      'errors': "%NBR6",
                      'desc': "%TXT",
                      'mode': "%KEYWORD"
                     })
     entity.resolve_all()
     self.assertEqual(entity.desc, "I am the entity")
     self.assertEqual(entity.target, NodeSet('localhost'))
     self.assertEqual(entity.timeout, 1)
     self.assertEqual(entity.maxretry, 2)
     self.assertEqual(entity.fanout, 3)
     self.assertEqual(entity.delay, 4)
     self.assertEqual(entity.errors, 6)
     self.assertEqual(entity.warnings, 5)
     self.assertEqual(entity.mode, 'delegate')
コード例 #2
0
ファイル: BaseEntityTest.py プロジェクト: fihuer/milkcheck
 def test_resolve_all(self):
     """resolve_all() resolves all BaseEntity properties"""
     entity = BaseEntity('entity')
     entity.add_var('TGT', 'localhost')
     entity.add_var('NBR1', 1)
     entity.add_var('NBR2', 2)
     entity.add_var('NBR3', 3)
     entity.add_var('NBR4', 4)
     entity.add_var('NBR5', 5)
     entity.add_var('NBR6', 6)
     entity.add_var('KEYWORD', 'delegate')
     entity.add_var('TXT', 'I am the entity')
     entity.fromdict({
         'target': "%TGT",
         'timeout': "%NBR1",
         'retry': "%NBR2",
         'fanout': "%NBR3",
         'delay': "%NBR4",
         'warnings': "%NBR5",
         'errors': "%NBR6",
         'desc': "%TXT",
         'mode': "%KEYWORD"
     })
     entity.resolve_all()
     self.assertEqual(entity.desc, "I am the entity")
     self.assertEqual(entity.target, NodeSet('localhost'))
     self.assertEqual(entity.timeout, 1)
     self.assertEqual(entity.maxretry, 2)
     self.assertEqual(entity.fanout, 3)
     self.assertEqual(entity.delay, 4)
     self.assertEqual(entity.errors, 6)
     self.assertEqual(entity.warnings, 5)
     self.assertEqual(entity.mode, 'delegate')
コード例 #3
0
ファイル: ServiceGroup.py プロジェクト: mdlx/milkcheck
    def fromdict(self, grpdict):
        """Populate group attributes from dict."""
        BaseEntity.fromdict(self, grpdict)

        if 'services' in grpdict:
            dep_mapping = {}

            # Wrap dependencies from YAML and build the service
            for names, props in grpdict['services'].items():
                for subservice in NodeSet(names):

                    # Parsing dependencies
                    wrap = DepWrapper()
                    for prop in ('require', 'require_weak',
                                 'before', 'after', 'check'):
                        if prop in props:
                            if prop in ('before', 'after'):
                                props['require_weak'] = props[prop]
                                prop = 'require_weak'
                            wrap.deps[prop] = props[prop]

                    # Get subservices which might be Service or ServiceGroup
                    service = None
                    if 'services' in props:
                        service = ServiceGroup(subservice)
                        service.fromdict(props)
                    else:
                        service = Service(subservice)
                        service.fromdict(props)

                    # Link the group and its new subservice together
                    self._subservices[subservice] = service
                    service.parent = self

                    wrap.source = service
                    dep_mapping[subservice] = wrap

            # Generate dependency links of the service
            for wrap in dep_mapping.values():
                # Not any dependencies so just attach
                for dtype in wrap.deps:
                    for dep in wrap.deps[dtype]:
                        if dep not in self._subservices:
                            raise UnknownDependencyError(dep)
                        wrap.source.add_dep(self._subservices[dep],
                                                         sgth=dtype.upper())

            # Bind subgraph to the service group
            for service in self.iter_subservices():
                if not service.children:
                    service.add_dep(self._source, parent=False)
                if not service.parents:
                    service.add_dep(self._sink)

        for subser in self.iter_subservices():
            subser.inherits_from(self)
コード例 #4
0
ファイル: BaseEntityTest.py プロジェクト: cea-hpc/milkcheck
 def test_resolve_all_variables(self):
     """resolve_all() resolves variables only once"""
     entity = BaseEntity('entity')
     entity.add_var('foo', 'cool')
     entity.add_var('bar', '%foo')
     entity.add_var('baz', '%foo')
     entity.fromdict({'desc': 'New %bar'})
     entity.resolve_all()
     self.assertEqual(entity.variables['foo'], entity.variables['bar'])
     self.assertEqual(entity.variables['foo'], entity.variables['baz'])
     self.assertEqual(entity.desc, 'New cool')
コード例 #5
0
ファイル: BaseEntityTest.py プロジェクト: fihuer/milkcheck
 def test_resolve_all_variables(self):
     """resolve_all() resolves variables only once"""
     entity = BaseEntity('entity')
     entity.add_var('foo', 'cool')
     entity.add_var('bar', '%foo')
     entity.add_var('baz', '%foo')
     entity.fromdict({'desc': 'New %bar'})
     entity.resolve_all()
     self.assertEqual(entity.variables['foo'], entity.variables['bar'])
     self.assertEqual(entity.variables['foo'], entity.variables['baz'])
     self.assertEqual(entity.desc, 'New cool')
コード例 #6
0
ファイル: Service.py プロジェクト: fihuer/milkcheck
    def fromdict(self, svcdict):
        """Populate service attributes from dict."""
        BaseEntity.fromdict(self, svcdict)

        if 'actions' in svcdict:
            dependencies = {}
            for names, props in svcdict['actions'].items():
                for name in NodeSet(names):
                    action = Action(name)
                    self.add_action(action)
                    action.fromdict(props)

                    dependencies[name] = props.get('check', [])

            for action in self._actions.values():
                for dep in dependencies[action.name]:
                    action.add_dep(self._actions[dep])

        # Inherits properies between service and actions
        for action in self.iter_actions():
            action.inherits_from(self)
コード例 #7
0
ファイル: Service.py プロジェクト: pombredanne/milkcheck
    def fromdict(self, svcdict):
        """Populate service attributes from dict."""
        BaseEntity.fromdict(self, svcdict)

        if "actions" in svcdict:
            dependencies = {}
            actions = {}
            for names, props in svcdict["actions"].items():
                for name in NodeSet(names):
                    action = Action(name)
                    action.fromdict(props)

                    actions[name] = action
                    dependencies[name] = props.get("check", [])

            for action in actions.values():
                for dep in dependencies[action.name]:
                    action.add_dep(actions[dep])
                self.add_action(action)

        # Inherits properies between service and actions
        for action in self.iter_actions():
            action.inherits_from(self)
コード例 #8
0
ファイル: Action.py プロジェクト: mdlx/milkcheck
    def fromdict(self, actdict):
        """Populate action attributes from dict."""
        BaseEntity.fromdict(self, actdict)

        if 'cmd' in actdict:
            self.command = actdict['cmd']
コード例 #9
0
ファイル: Action.py プロジェクト: fihuer/milkcheck
    def fromdict(self, actdict):
        """Populate action attributes from dict."""
        BaseEntity.fromdict(self, actdict)

        if 'cmd' in actdict:
            self.command = actdict['cmd']