コード例 #1
0
    def setUp(self):
        '''
        Set up the graph of services within the service manager

        Graph
                                _ start
                   -- service1 /
                 -'             _ start
                  '-- service2 /
        '''

        CLICommon.setUp(self)

        # Service
        service1 = Service('service1')
        service1.desc = 'I am the service 1'
        service2 = Service('service2')
        service2.desc = 'I am the service 2'
        # Actions
        action = Action('start', command='/bin/true')
        action.inherits_from(service1)
        service1.add_action(action)

        service2.add_dep(target=service1)

        action = Action('start', command='/bin/true')
        action.inherits_from(service2)
        service2.add_action(action)

        # Register services within the manager
        self.manager.register_services(service1, service2)
コード例 #2
0
    def test_prepare_group_subservices(self):
        '''Test prepare group with multiple internal dependencies.'''
        group = ServiceGroup('GROUP')
        ac_suc1 = Action('start', command='/bin/true')
        ac_suc2 = Action('start', command='/bin/true')
        ac_suc3 = Action('start', command='/bin/true')

        subserv_a = Service('SUB1')
        subserv_b = Service('SUB2')
        subserv_c = Service('SUB3')

        subserv_a.add_action(ac_suc1)
        subserv_b.add_action(ac_suc2)
        subserv_c.add_action(ac_suc3)

        group.add_inter_dep(target=subserv_a)
        group.add_inter_dep(target=subserv_b)
        group.add_inter_dep(base=subserv_a, target=subserv_c)
        group.add_inter_dep(base=subserv_b, target=subserv_c)

        group.run('start')
        self.assertEqual(group.status, DONE)
        self.assertEqual(subserv_a.status, DONE)
        self.assertEqual(subserv_b.status, DONE)
        self.assertEqual(subserv_c.status, DONE)
コード例 #3
0
 def test_remove_inter_dep(self):
     '''Test ability to remove a dependency in a subgraph'''
     group = ServiceGroup('GROUP')
     s1 = Service('alpha')
     s2 = Service('beta')
     s3 = Service('lambda')
     group.add_inter_dep(target=s1)
     group.add_inter_dep(target=s2)
     group.add_inter_dep(target=s3)
     group.add_inter_dep(base=s1, target=s3)
     group.add_inter_dep(base=s2, target=s3)
     group.remove_inter_dep('lambda')
     self.assertTrue(s1.has_parent_dep('sink'))
     self.assertTrue(s2.has_parent_dep('sink'))
     self.assertTrue(s1.has_child_dep('source'))
     self.assertTrue(s2.has_child_dep('source'))
     self.assertFalse(s1.has_parent_dep('lambda'))
     self.assertFalse(s2.has_parent_dep('lambda'))
     group.remove_inter_dep('alpha')
     self.assertFalse(group._source.has_parent_dep('alpha'))
     self.assertTrue(group._source.has_parent_dep('beta'))
     self.assertFalse(group._sink.has_child_dep('alpha'))
     self.assertTrue(group._sink.has_child_dep('beta'))
     group.remove_inter_dep('beta')
     self.assertFalse(group._source.parents)
     self.assertFalse(group._sink.children)
コード例 #4
0
    def test_missing_action(self):
        """Test prepare with service with missing action is ok"""

        # Graph leaf has no 'status' action
        s1 = Service("1")
        s1.add_action(Action('start', command='/bin/true'))
        s1.add_action(Action('status', command='/bin/true'))
        s2 = Service("2")
        s2.add_action(Action('start', command='/bin/true'))
        s2.add_dep(s1)
        s2.run('status')
        self.assertEqual(s1.status, DONE)
        self.assertEqual(s2.status, MISSING)

        s1.reset()
        s2.reset()
        self.assertEqual(s1.status, NO_STATUS)
        self.assertEqual(s2.status, NO_STATUS)

        # 'status' action is propagated to leaf even if '2' has not the
        # requested action.
        s3 = Service("3")
        s3.add_action(Action('start', command='/bin/true'))
        s3.add_action(Action('status', command='/bin/true'))
        s3.add_dep(s2)
        s3.run('status')
        self.assertEqual(s1.status, DONE)
        self.assertEqual(s2.status, MISSING)
        self.assertEqual(s3.status, DONE)
コード例 #5
0
 def test_prepare_multiple_delay(self):
     '''Test prepare with dependencies and multiple delays'''
     serv = Service('BASE_DELAYED')
     serv_a = Service('A_NOT_DELAYED')
     serv_b = Service('B_DELAYED')
     serv_c = Service('C_DELAYED')
     act_a = Action(name='start', command='/bin/true')
     act_serv = Action(name='start', command='/bin/true', delay=0.3)
     act_b = Action(name='start', command='/bin/true', delay=0.3)
     act_c = Action(name='start', command='/bin/true', delay=0.5)
     serv.add_action(act_serv)
     serv_a.add_action(act_a)
     serv_b.add_action(act_b)
     serv_c.add_action(act_c)
     serv.add_dep(serv_a)
     serv.add_dep(serv_b)
     serv_a.add_dep(serv_c)
     serv_b.add_dep(serv_c)
     serv.run('start')
     self.assertEqual(serv.status, DONE)
     self.assert_near(0.3, 0.2, act_serv.duration)
     self.assertEqual(serv_a.status, DONE)
     self.assert_near(0.0, 0.2, act_a.duration)
     self.assertEqual(serv_b.status, DONE)
     self.assert_near(0.3, 0.2, act_b.duration)
     self.assertEqual(serv_c.status, DONE)
     self.assert_near(0.5, 0.2, act_c.duration)
コード例 #6
0
    def test_prepare_with_multiple_require_errors(self):
        """Test multiple require dependencies errors at different levels."""
        serv_base_error = Service('A')
        serv_ok_warnings = Service('B')
        serv_error = Service('C')
        serv_timeout = Service('D')

        ac_suc = Action(name='start', command='/bin/true')
        ac_suc2 = Action(name='start', command='/bin/true')
        ac_suc3 = Action(name='start', command='/bin/true')
        ac_tim = Action(name='start', command='sleep 3', timeout=0.3)

        serv_base_error.add_action(ac_suc)
        serv_ok_warnings.add_action(ac_suc2)
        serv_error.add_action(ac_suc3)
        serv_timeout.add_action(ac_tim)

        serv_base_error.add_dep(serv_ok_warnings)
        serv_base_error.add_dep(serv_error)
        serv_ok_warnings.add_dep(serv_timeout, REQUIRE_WEAK)
        serv_error.add_dep(serv_timeout)

        serv_base_error.run('start')

        self.assertEqual(serv_base_error.status, DEP_ERROR)
        self.assertEqual(serv_ok_warnings.status, DONE)
        self.assertEqual(serv_error.status, DEP_ERROR)
        self.assertEqual(serv_timeout.status, TIMEOUT)
コード例 #7
0
    def test_prepare_errors_same_level(self):
        """Test prepare behaviour with two errors at the same level"""
        serv = Service('BASE')
        serv_a = Service('DEP_A')
        serv_b = Service('DEP_B')
        serv_c = Service('DEP_C')

        ac_suc = Action(name='start', command='/bin/true')
        ac_suc2 = Action(name='start', command='/bin/true')
        ac_err = Action(name='start', command='/bin/false')
        ac_err2 = Action(name='start', command='dlvlfvlf')

        serv.add_action(ac_suc)
        serv_a.add_action(ac_suc2)
        serv_b.add_action(ac_err)
        serv_c.add_action(ac_err2)

        serv.add_dep(serv_a)
        serv_a.add_dep(serv_b)
        serv_a.add_dep(serv_c)

        serv.run('start')

        self.assertEqual(serv.status, DEP_ERROR)
        self.assertEqual(serv_a.status, DEP_ERROR)
        self.assertEqual(serv_b.status, ERROR)
        self.assertEqual(serv_c.status, ERROR)
コード例 #8
0
 def test_add_bad_inter_dep(self):
     """Adding a subservice on a bad base raises an Exception"""
     grp = ServiceGroup('grp')
     srv1 = Service('foo1')
     srv2 = Service('foo2')
     self.assertRaises(ServiceNotFoundError,
                       grp.add_inter_dep,
                       target=srv2,
                       base=srv1)
コード例 #9
0
    def setUp(self):
        '''
        Set up the graph of services within the service manager

        Graph
                __ S2                    __ I1
            S1 /         -- G1 -- (src) /    ^  -- (sink)
               `-- S3 --/               `-- I2

        Each node has an action start and an action stop
        '''
        CLICommon.setUp(self)

        svc1 = Service('S1')
        svc1.desc = 'I am the service S1'
        self.svc2 = svc2 = Service('S2')
        svc2.desc = 'I am the service S2'
        svc3 = Service('S3')
        svc3.desc = 'I am the service S3'
        group1 = ServiceGroup('G1')
        inter1 = Service('I1')
        inter1.desc = 'I am the service I1'
        inter2 = Service('I2')
        inter2.desc = 'I am the service I2'

        # Actions S1
        start_svc1 = Action('start', HOSTNAME + ', BADNODE', '/bin/true')
        start_svc1.delay = 1
        stop_svc1 = Action('stop', HOSTNAME + ',BADNODE', '/bin/true')
        stop_svc1.delay = 1
        svc1.add_actions(start_svc1, stop_svc1)
        # Actions S2
        svc2.add_action(Action('start', HOSTNAME + ',BADNODE', '/bin/true'))
        svc2.add_action(Action('stop', HOSTNAME + ',BADNODE', '/bin/true'))
        # Actions S3
        svc3.add_action(Action('start', HOSTNAME + ',BADNODE', '/bin/false'))
        svc3.add_action(Action('stop', HOSTNAME + ',BADNODE', '/bin/false'))
        # Actions I1
        inter1.add_action(Action('start', HOSTNAME, 'echo ok'))
        inter1.add_action(Action('stop', HOSTNAME, 'echo ok'))
        # Actions I2
        inter2.add_action(Action('start', HOSTNAME + ',BADNODE', '/bin/true'))
        inter2.add_action(Action('stop', HOSTNAME + ',BADNODE', '/bin/true'))

        # Build graph
        svc1.add_dep(target=svc2)
        svc1.add_dep(target=svc3)
        svc3.add_dep(target=group1)
        inter2.add_dep(inter1)
        group1.add_inter_dep(target=inter1)
        group1.add_inter_dep(target=inter2)

        # Register services within the manager
        self.manager.register_services(svc1, svc2, svc3, group1)
コード例 #10
0
 def test_eval_deps_status_error(self):
     '''Test the method eval_deps_status DEP_ERROR'''
     group = ServiceGroup('group')
     e1 = Service('E1')
     e2 = Service('E2')
     e1.status = DEP_ERROR
     group.add_dep(target=e1)
     group.add_dep(target=e2)
     group.add_inter_dep(target=Service('I1'))
     self.assertEqual(group.eval_deps_status(), DEP_ERROR)
     self.assertEqual(group.eval_deps_status(), DEP_ERROR)
コード例 #11
0
 def test_inheritance(self):
     '''Test inheritance between action and services'''
     ser1 = Service('parent')
     ser1.target = '127.0.0.1'
     ser2 = Service('inherited')
     ser2.add_action(Action('start'))
     ser2.add_action(Action('stop', "foo"))
     ser2.inherits_from(ser1)
     self.assertEqual(ser2.target, NodeSet('127.0.0.1'))
     self.assertEqual(ser2._actions['start'].target, NodeSet('127.0.0.1'))
     self.assertEqual(ser2._actions['stop'].target, NodeSet("foo"))
コード例 #12
0
ファイル: ServiceGroup.py プロジェクト: mdlx/milkcheck
 def __init__(self, name, target=None):
     Service.__init__(self, name, target)
     # Entry point of the group
     self._source = Service('source')
     self._source.simulate = True
     self._source.add_dep(target=self, parent=False)
     del self.parents['source']
     self._sink = Service('sink')
     self._sink.simulate = True
     # subservices
     self._subservices = {}
コード例 #13
0
 def test_skipped_group(self):
     """A group with only SKIPPED services should be SKIPPED"""
     grp = ServiceGroup('group')
     svc1 = Service('svc1')
     svc1.add_action(Action('start', target="@NOTHING", command=':'))
     svc2 = Service('svc2')
     svc2.add_action(Action('start', target="@NOTHING", command=':'))
     grp.add_inter_dep(target=svc1)
     grp.add_inter_dep(target=svc2)
     grp.run('start')
     self.assertEqual(grp.status, SKIPPED)
コード例 #14
0
 def test_eval_deps_status_done(self):
     '''Test the method eval_deps_status NO_STATUS'''
     group = ServiceGroup('group')
     e1 = Service('E1')
     e2 = Service('E2')
     group.add_dep(target=e1)
     group.add_dep(target=e2)
     group.add_inter_dep(target=Service('I1'))
     self.assertEqual(group.eval_deps_status(), NO_STATUS)
     e1.status = DONE
     e2.status = DONE
     self.assertEqual(group.eval_deps_status(), NO_STATUS)
コード例 #15
0
 def test_service_registration(self):
     '''Test the resgistration of a service within the manager'''
     manager = service_manager_self()
     srvtest = Service('test')
     manager.register_service(srvtest)
     self.assertTrue(manager.has_service(srvtest))
     self.assertRaises(ServiceAlreadyReferencedError,
         manager.register_service, Service('test'))
     srva = Service('A')
     srvb = Service('B')
     manager.register_services(srva, srvb)
     self.assertTrue(manager.has_service(srva))
     self.assertTrue(manager.has_service(srvb))
コード例 #16
0
 def test_eval_deps_status_ws(self):
     '''Test the method eval_deps_status WAITING_STATUS'''
     group = ServiceGroup('group')
     ext1 = Service('E1')
     ext2 = Service('E2')
     ext1.status = DONE
     ext2.status = WARNING
     group.add_dep(target=ext1)
     group.add_dep(target=ext2)
     int1 = Service('E1')
     group.add_inter_dep(target=int1)
     int1.status = WAITING_STATUS
     self.assertEqual(group.eval_deps_status(), WAITING_STATUS)
コード例 #17
0
 def test_call_services_reversed(self):
     '''Test service_manager with custom reversed actions'''
     manager = service_manager_self()
     s1 = Service('S1')
     s2 = Service('S2')
     s1.add_action(Action('wait', command='/bin/true'))
     s2.add_action(Action('wait', command='/bin/true'))
     s1.add_dep(s2)
     manager.register_services(s1, s2)
     manager.call_services(['S1'], 'wait',
                     conf={"reverse_actions": ['wait']})
     self.assertTrue(s1._algo_reversed)
     self.assertTrue(s2._algo_reversed)
コード例 #18
0
    def test_filter_mix_no_target(self):
        """service without target do not filter service with target"""
        svc1 = Service('top')
        svc1.add_action(Action('start', command='false'))

        svc2 = Service('bottom')
        svc2.add_action(Action('start', command='true', target='localhost'))
        svc2.add_dep(svc1, sgth=FILTER)

        svc2.run('start')

        self.assertEqual(svc1.status, ERROR)
        self.assertEqual(svc2.status, DONE)
コード例 #19
0
    def test_filter_dep_one_error(self):
        """error nodes are propagated along 'filter' dependencies"""
        svc1 = Service('first')
        svc1.add_action(Action('start', command='false', target=HOSTNAME))

        svc2 = Service('second')
        svc2.add_action(Action('start', command='true', target=HOSTNAME))
        svc2.add_dep(svc1, sgth=FILTER)

        svc2.run('start')

        self.assertEqual(svc1.status, ERROR)
        self.assertEqual(svc2.status, SKIPPED)
コード例 #20
0
    def test_filter_dep_no_error(self):
        """test FILTER dependency without error"""
        svc1 = Service('first')
        svc1.add_action(Action('start', command='/bin/true', target=HOSTNAME))

        svc2 = Service('second')
        svc2.add_action(Action('start', command='/bin/true', target=HOSTNAME))
        svc2.add_dep(svc1, sgth=FILTER)

        svc2.run('start')

        self.assertEqual(svc1.status, DONE)
        self.assertEqual(svc2.status, DONE)
コード例 #21
0
    def test_filter_dep_error_propagation(self):
        """error nodes are propagated along 'filter' dependencies (one node)"""
        svc1 = Service('first')
        tgt = '%s,fakenode' % HOSTNAME
        svc1.add_action(Action('start', command='true', target=tgt))

        svc2 = Service('second')
        svc2.add_action(Action('start', command='true', target=HOSTNAME))
        svc2.add_dep(svc1, sgth=FILTER)

        svc2.run('start')

        self.assertEqual(svc1.status, ERROR)
        self.assertEqual(svc2.status, DONE)
コード例 #22
0
    def test_filter_dep_timeout(self):
        """timeout nodes are propagated along 'filter' dependencies"""
        svc1 = Service('first')
        svc1.add_action(
            Action('start', command='sleep 1', target=HOSTNAME, timeout=0.1))

        svc2 = Service('second')
        svc2.add_action(Action('start', command='true', target=HOSTNAME))
        svc2.add_dep(svc1, sgth=FILTER)

        svc2.run('start')

        self.assertEqual(svc1.status, TIMEOUT)
        self.assertEqual(svc2.status, SKIPPED)
コード例 #23
0
    def test_group_with_weak_dep_error(self):
        """A group with a weak dep error runs fine (add_inter_dep())."""

        dep1 = Service('dep1')
        dep1.add_action(Action('stop', command='/bin/false'))

        grp = ServiceGroup('group')
        svc = Service('svc')
        svc.add_action(Action('stop', command='/bin/true'))
        grp.add_inter_dep(svc)
        grp.add_dep(dep1, sgth=REQUIRE_WEAK)
        grp.run('stop')

        self.assertEqual(grp.status, DONE)
コード例 #24
0
ファイル: CoreTests.py プロジェクト: mdlx/milkcheck
    def test_core_behaviour_reverse(self):
        '''Test ability of the core to solve a large graph in reverse mode'''
        # Define Group 1
        grp1 = ServiceGroup('GRP1')
        grp1.algo_reversed = True
        grp1_i1 = Service('I1')
        grp1_i1.algo_reversed = True
        grp1_i2 = Service('I2')
        grp1_i2.algo_reversed = True
        grp1_i3 = Service('I3')
        grp1_i3.algo_reversed = True
        grp1_i1.add_action(Action('stop', command='/bin/true'))
        grp1_i2.add_action(Action('stop', command='/bin/true'))
        grp1_i3.add_action(Action('stop', command='/bin/true'))
        grp1.add_inter_dep(target=grp1_i1)
        grp1.add_inter_dep(base=grp1_i1, target=grp1_i2)
        grp1.add_inter_dep(target=grp1_i3)

        # Define Group 2
        grp2 = ServiceGroup('GRP2')
        grp2.algo_reversed = True
        grp2_i1 = Service('I1')
        grp2_i1.algo_reversed = True
        grp2_i2 = Service('I2')
        grp2_i2.algo_reversed = True
        grp2_i1.add_action(Action('stop', command='/bin/true'))
        grp2_i2.add_action(Action('stop', command='/bin/true'))
        grp2.add_inter_dep(target=grp2_i1)
        grp2.add_inter_dep(base=grp2_i1, target=grp2_i2)

        # Define Group init
        svc1 = Service('S1')
        svc1.algo_reversed = True
        svc1.add_action(Action('stop', command='/bin/true'))
        svc2 = Service('S2')
        svc2.algo_reversed = True
        svc2.add_action(Action('stop', command='/bin/true'))
        svc3 = Service('S3')
        svc3.algo_reversed = True
        svc3.add_action(Action('stop', command='/bin/true'))
        group_init = ServiceGroup('GROUP_INIT')
        group_init.algo_reversed = True
        group_init.add_inter_dep(target=svc1)
        group_init.add_inter_dep(base=svc1, target=svc2, sgth=REQUIRE_WEAK)
        group_init.add_inter_dep(base=svc1, target=grp1)
        group_init.add_inter_dep(base=svc2, target=svc3)
        group_init.add_inter_dep(base=grp1, target=svc3)
        group_init.add_inter_dep(base=svc3, target=grp2)

        # Solve the graph
        group_init.run('stop')

        # Assertions
        self.assertEqual(grp2.status, DONE)
        self.assertEqual(svc3.status, DONE)
        self.assertEqual(svc2.status, DONE)
        self.assertEqual(grp1.status, DONE)
        self.assertEqual(svc1.status, DONE)
        self.assertEqual(group_init.status, DONE)
コード例 #25
0
    def test_filter_error_no_action(self):
        """
        propagation along 'filter' dependencies works if action names mismatch
        """
        svc1 = Service('first')
        svc1.add_action(Action('start', command='false', target=HOSTNAME))

        svc2 = Service('second')
        svc2.add_action(Action('other', command='true', target=HOSTNAME))
        svc2.add_dep(svc1, sgth=FILTER)

        svc2.run('start')

        self.assertEqual(svc1.status, ERROR)
        self.assertEqual(svc2.status, MISSING)
コード例 #26
0
 def test_run_reverse_with_dependencies(self):
     ser = Service('REVERSE_BASE')
     ser_dep = Service('REVERSE_DEP')
     ser.algo_reversed = True
     ser_dep.algo_reversed = True
     stop1 = Action('stop', command='/bin/true')
     stop2 = Action('stop', command='/bin/true')
     ser.add_action(stop1)
     ser_dep.add_action(stop2)
     ser.add_dep(ser_dep)
     ser_dep.run('stop')
     self.assertEqual(ser.status, DONE)
     self.assertTrue(stop1.duration)
     self.assertEqual(ser_dep.status, DONE)
     self.assertTrue(stop2.duration)
コード例 #27
0
ファイル: ActionTest.py プロジェクト: fihuer/milkcheck
    def test_desc(self):
        """Test action inherits 'desc'"""
        # No service description, no action description
        action1 = Action('status', command='/bin/true')
        service = Service('TEST')
        service.add_actions(action1)
        self.assertEqual(action1.desc, None)

        # Service description, actions inherits the description
        action2 = Action('status', command='/bin/true')
        service2 = Service('TEST2')
        service2.desc = "Service TEST"
        service2.add_actions(action2)
        action2.inherits_from(service2)
        self.assertEqual(action2.desc, "Service TEST")
コード例 #28
0
ファイル: ActionTest.py プロジェクト: fihuer/milkcheck
    def test_skipped_action_overload(self):
        """Test action is not skipped if they overload target."""
        # A dep on ERROR
        dep = Service('dep')
        dep.add_action(Action('start', command='/bin/false'))
        # A service running on empty nodeset...
        svc = Service('foo', target='@NOTEXIST')
        # ... with an action overloading the empty nodeset
        svc.add_action(Action('start', target=HOSTNAME, command=':'))

        svc.add_dep(dep)
        svc.run('start')

        self.assertEqual(dep.status, ERROR)
        self.assertEqual(svc.status, DEP_ERROR)
コード例 #29
0
 def test_run_stop_on_group(self):
     '''Test stop algorithm on a group'''
     group = ServiceGroup('G1')
     i1 = Service('I1')
     i1.add_action(Action('stop', command='/bin/true'))
     group.add_inter_dep(target=i1)
     s1 = Service('S1')
     s1.add_action(Action('stop', command='/bin/true'))
     s1.add_dep(target=group)
     s1.algo_reversed = True
     group.algo_reversed = True
     group.run('stop')
     self.assertEqual(s1.status, DONE)
     self.assertEqual(i1.status, DONE)
     self.assertEqual(group.status, DONE)
コード例 #30
0
 def test_fromdict2(self):
     '''
     Test instanciate a service from a dictionnary with dependant actions
     '''
     ser = Service('S1')
     ser.fromdict({
         'desc': 'I am the service S1',
         'target': 'localhost',
         'actions': {
             'start': {
                 'check': ['status'],
                 'cmd': '/bin/True'
             },
             'stop': {
                 'cmd': '/bin/True'
             },
             'status': {
                 'cmd': '/bin/True'
             }
         }
     })
     self.assertTrue(ser)
     self.assertEqual(len(ser._actions), 3)
     self.assertTrue('start' in ser._actions)
     self.assertTrue('stop' in ser._actions)
     self.assertTrue('status' in ser._actions)
     self.assertTrue(ser._actions['start'].has_parent_dep('status'))