コード例 #1
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)
コード例 #2
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
    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)
コード例 #3
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)
コード例 #4
0
ファイル: CliTest.py プロジェクト: cea-hpc/milkcheck
    def test_command_output_warning(self):
        '''Test command line output with warning'''
        svc_warn = Service('service_failled')
        svc_warn.desc = 'I am the failled service'
        svc_ok = Service('service_ok')
        svc_ok.desc = 'I am the ok service'
        # Actions
        action = Action('warning', command='/bin/false')
        action.inherits_from(svc_warn)
        svc_warn.add_action(action)
        action = Action('warning', command='/bin/true')
        action.inherits_from(svc_ok)
        svc_ok.add_action(action)

        # Register services within the manager
        svc_ok.add_dep(target=svc_warn, sgth=REQUIRE_WEAK)
        self.manager.add_service(svc_warn)
        self.manager.add_service(svc_ok)

        self._output_check(['service_ok', 'warning'], RC_OK,
"""warning service_failled ran in 0.00 s
 > localhost exited with 1
service_failled - I am the failled service                        [  ERROR  ]
service_ok - I am the ok service                                  [    OK   ]
""")
コード例 #5
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
    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)
コード例 #6
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)
コード例 #7
0
ファイル: CliTest.py プロジェクト: cea-hpc/milkcheck
class CommandLineStderrOutputTests(CLICommon):
    '''Tests cases of the command line output on stderr'''

    def setUp(self):
        '''
        Set up the graph of services within the service manager

        Graph
                                _ start
                   -- service1 /
                 -'             _ start
                  '-- service2 /
        '''
        CLICommon.setUp(self)

        # Service
        self.service1 = Service('service1')
        self.service2 = Service('service2')
        # Actions
        action = Action('start', command='/bin/true')
        action.inherits_from(self.service1)
        self.service1.add_action(action)

        self.service2.add_dep(target=self.service1)

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

        # Register services within the manager
        self.manager.add_service(self.service1)
        self.manager.add_service(self.service2)

    def test_stderr_too_large_svc_name(self):
        '''Test stderr output with too large service name is truncated'''
        self.service1.name = "S" * 100
        self.service2.name = "s" * 100
        self._output_check(['start'], RC_OK,
                           "%s...  [    OK   ]\n%s...  [    OK   ]\n"
                               % (61 * 'S', 61 * 's'),
                           "[%s...]\r[%s...]\r" % (72 * 'S', 72 * 's'))

    def test_too_large_svc_name_wide_terminal(self):
        '''
        Test output with too large service name is truncated with wide terminal
        '''
        self.service1.name = "S" * 200
        self.service2.name = "s" * 200
        self._output_check(['start'], RC_OK,
                           "%s...  [    OK   ]  \n%s...  [    OK   ]  \n"
                                % (104 * 'S', 104 * 's'),
                           "[%s...]\r[%s...]\r" % (117 * 'S', 117 * 's'),
                           term_width=MAXTERMWIDTH + 2)
コード例 #8
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
    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)
コード例 #9
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)
コード例 #10
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)
コード例 #11
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)
コード例 #12
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
    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)
コード例 #13
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)
コード例 #14
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
    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)
コード例 #15
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
    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)
コード例 #16
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
    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)
コード例 #17
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)
コード例 #18
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
    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)
コード例 #19
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)
コード例 #20
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)
コード例 #21
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
 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)
コード例 #22
0
ファイル: ServiceGroupTest.py プロジェクト: cea-hpc/milkcheck
 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)
コード例 #23
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)
コード例 #24
0
ファイル: ActionTest.py プロジェクト: cea-hpc/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)
コード例 #25
0
ファイル: ActionTest.py プロジェクト: mdlx/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)
コード例 #26
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)
コード例 #27
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)
コード例 #28
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)
コード例 #29
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
    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)
コード例 #30
0
 def test_call_services_retcode_weak(self):
     '''Test call_services return 0 (OK) even with require_weak'''
     manager = service_manager_self()
     s1 = Service('S1')
     s2 = Service('S2')
     s3 = Service('S3')
     s4 = Service('S4')
     s1.add_action(Action('start', command='/bin/true'))
     s2.add_action(Action('start', command='/bin/false'))
     s3.add_action(Action('start', command='/bin/true'))
     s4.add_action(Action('start', command='/bin/true'))
     s1.add_dep(target=s2, sgth=REQUIRE_WEAK)
     s2.add_dep(target=s3)
     s2.add_dep(target=s4)
     manager.register_services(s1, s2, s3, s4)
     manager.call_services([], 'start')
     self.assertEqual(manager.source.status, DONE)
コード例 #31
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
    def test_prepare_one_dependency(self):
        """Test prepare with one dependency."""
        # Define the main service
        serv_test = Service('test_service')
        start = Action(name='start', command='/bin/true')
        start2 = Action(name='start', command='/bin/true')
        serv_test.add_action(start)

        # Define the single dependency of the main service
        serv_dep = Service('dependency')
        serv_dep.add_action(start2)
        serv_test.add_dep(serv_dep)

        # Start preparing of the base service
        serv_test.run('start')
        self.assertEqual(serv_test.status, DONE)
        self.assertEqual(serv_dep.status, DONE)
コード例 #32
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
    def test_run_with_locked_service(self):
        '''Test run services with locked dependencies'''
        s1 = Service('S1')
        s2 = Service('S2')
        s3 = Service('S3')
        s4 = Service('S4')
        s5 = Service('S5')

        # Actions S1
        start_s1 = Action('start', command='/bin/true')
        stop_s1 = Action('stop', command='/bin/true')
        s1.add_actions(start_s1, stop_s1)
        # Actions S2
        start_s2 = Action('start', command='/bin/true')
        stop_s2 = Action('stop', command='/bin/true')
        s2.add_actions(start_s2, stop_s2)
        # Actions S3
        start_s3 = Action('start', command='/bin/false')
        stop_s3 = Action('stop', command='/bin/false')
        s3.add_actions(start_s3, stop_s3)
        # Actions S4
        start_s4 = Action('start', command='/bin/true')
        stop_s4 = Action('stop', command='/bin/true')
        s4.add_actions(start_s4, stop_s4)
        # Actions I1
        start_s5 = Action('start', command='/bin/true')
        stop_s5 = Action('stop', command='/bin/true')
        s5.add_actions(start_s5, stop_s5)

        # Locked services
        s3.status = LOCKED

        # Build graph
        s1.add_dep(target=s2)
        s1.add_dep(target=s3)
        s3.add_dep(target=s4)
        s3.add_dep(target=s5)
        
        # Run service S1
        s1.run('start')

        self.assertEqual(s1.status, DONE)
        self.assertEqual(s2.status, DONE)
        self.assertEqual(s3.status, LOCKED)
        self.assertEqual(s4.status, NO_STATUS)
        self.assertEqual(s5.status, NO_STATUS)
コード例 #33
0
    def test_run_with_locked_service(self):
        '''Test run services with locked dependencies'''
        s1 = Service('S1')
        s2 = Service('S2')
        s3 = Service('S3')
        s4 = Service('S4')
        s5 = Service('S5')

        # Actions S1
        start_s1 = Action('start', command='/bin/true')
        stop_s1 = Action('stop', command='/bin/true')
        s1.add_actions(start_s1, stop_s1)
        # Actions S2
        start_s2 = Action('start', command='/bin/true')
        stop_s2 = Action('stop', command='/bin/true')
        s2.add_actions(start_s2, stop_s2)
        # Actions S3
        start_s3 = Action('start', command='/bin/false')
        stop_s3 = Action('stop', command='/bin/false')
        s3.add_actions(start_s3, stop_s3)
        # Actions S4
        start_s4 = Action('start', command='/bin/true')
        stop_s4 = Action('stop', command='/bin/true')
        s4.add_actions(start_s4, stop_s4)
        # Actions I1
        start_s5 = Action('start', command='/bin/true')
        stop_s5 = Action('stop', command='/bin/true')
        s5.add_actions(start_s5, stop_s5)

        # Locked services
        s3.status = LOCKED

        # Build graph
        s1.add_dep(target=s2)
        s1.add_dep(target=s3)
        s3.add_dep(target=s4)
        s3.add_dep(target=s5)

        # Run service S1
        s1.run('start')

        self.assertEqual(s1.status, DONE)
        self.assertEqual(s2.status, DONE)
        self.assertEqual(s3.status, LOCKED)
        self.assertEqual(s4.status, NO_STATUS)
        self.assertEqual(s5.status, NO_STATUS)
コード例 #34
0
 def test_call_services_retcode6(self):
     '''Test call_services return 6 whether source is DEP_ERROR'''
     manager = service_manager_self()
     s1 = Service('S1')
     s2 = Service('S2')
     s3 = Service('S3')
     s4 = Service('S4')
     s1.add_action(Action('start', command='/bin/true'))
     s2.add_action(Action('start', command='/bin/false'))
     s3.add_action(Action('start', command='/bin/true'))
     s4.add_action(Action('start', command='/bin/true'))
     s1.add_dep(target=s2)
     s2.add_dep(target=s3)
     s2.add_dep(target=s4)
     manager.register_services(s1, s2, s3, s4)
     manager.call_services([], 'start')
     self.assertTrue(manager.source.status in (ERROR, DEP_ERROR))
コード例 #35
0
    def test_prepare_one_dependency(self):
        """Test prepare with one dependency."""
        # Define the main service
        serv_test = Service('test_service')
        start = Action(name='start', command='/bin/true')
        start2 = Action(name='start', command='/bin/true')
        serv_test.add_action(start)

        # Define the single dependency of the main service
        serv_dep = Service('dependency')
        serv_dep.add_action(start2)
        serv_test.add_dep(serv_dep)

        # Start preparing of the base service
        serv_test.run('start')
        self.assertEqual(serv_test.status, DONE)
        self.assertEqual(serv_dep.status, DONE)
コード例 #36
0
ファイル: ServiceGroupTest.py プロジェクト: cea-hpc/milkcheck
 def test_run_partial_deps(self):
     '''Test start algorithm as soon as the calling point is done.'''
     serv = Service('NOT_CALLED')
     serv_a = ServiceGroup('CALLING_GROUP')
     serv_b = Service('SERV_1')
     serv_c = Service('SERV_2')
     act_suc1 = Action('start', command='/bin/true')
     act_suc2 = Action('start', command='/bin/true')
     serv_b.add_action(act_suc1)
     serv_c.add_action(act_suc2)
     serv.add_dep(serv_a)
     serv_a.add_dep(target=serv_b)
     serv_a.add_inter_dep(target=serv_c)
     serv_a.run('start')
     self.assertEqual(serv.status, NO_STATUS)
     self.assertEqual(serv_a.status, DONE)
     self.assertEqual(serv_b.status, DONE)
     self.assertEqual(serv_c.status, DONE)
コード例 #37
0
 def test_run_partial_deps(self):
     '''Test start algorithm as soon as the calling point is done.'''
     serv = Service('NOT_CALLED')
     serv_a = ServiceGroup('CALLING_GROUP')
     serv_b = Service('SERV_1')
     serv_c = Service('SERV_2')
     act_suc1 = Action('start', command='/bin/true')
     act_suc2 = Action('start', command='/bin/true')
     serv_b.add_action(act_suc1)
     serv_c.add_action(act_suc2)
     serv.add_dep(serv_a)
     serv_a.add_dep(target=serv_b)
     serv_a.add_inter_dep(target=serv_c)
     serv_a.run('start')
     self.assertEqual(serv.status, NO_STATUS)
     self.assertEqual(serv_a.status, DONE)
     self.assertEqual(serv_b.status, DONE)
     self.assertEqual(serv_c.status, DONE)
コード例 #38
0
 def test_call_services_retcode0(self):
     '''Test call_services return 0 whether source is DONE'''
     manager = ServiceManager()
     s1 = Service('S1')
     s2 = Service('S2')
     s3 = Service('S3')
     s4 = Service('S4')
     s1.add_action(Action('start', command='/bin/true'))
     s2.add_action(Action('start', command='/bin/true'))
     s3.add_action(Action('start', command='/bin/true'))
     s4.add_action(Action('start', command='/bin/true'))
     s1.add_dep(target=s2)
     s2.add_dep(target=s3)
     s2.add_dep(target=s4)
     for svc in (s1, s2, s3, s4):
         manager.add_service(svc)
     manager.call_services([], 'start')
     self.assertTrue(manager.status not in (WARNING, ERROR, DEP_ERROR))
コード例 #39
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
    def test_filter_mixed(self):
        """test filter and regular deps works fine together"""
        svc1 = Service('top1')
        tgt = '%s,fakenode' % HOSTNAME
        svc1.add_action(Action('start', command='true', target=tgt))

        svc2 = Service('top2')
        svc2.add_action(Action('start', command='true', target=HOSTNAME))

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

        svc3.run('start')

        self.assertEqual(svc1.status, ERROR)
        self.assertEqual(svc2.status, DONE)
        self.assertEqual(svc3.status, DEP_ERROR)
コード例 #40
0
    def test_filter_mixed(self):
        """test filter and regular deps works fine together"""
        svc1 = Service('top1')
        tgt = '%s,fakenode' % HOSTNAME
        svc1.add_action(Action('start', command='true', target=tgt))

        svc2 = Service('top2')
        svc2.add_action(Action('start', command='true', target=HOSTNAME))

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

        svc3.run('start')

        self.assertEqual(svc1.status, ERROR)
        self.assertEqual(svc2.status, DONE)
        self.assertEqual(svc3.status, DEP_ERROR)
コード例 #41
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
    def test_prepare_multiple_errors(self):
        """Test prepare with check and require deps with errors."""
        serv_a = Service('BASE')
        serv_b = Service('DEP_B')
        serv_c = Service('DEP_C')
        serv_d = Service('DEP_D')
        serv_x = Service('DEP_VX')
        serv_k = Service('DEP_K')

        act_suc = Action(name='start', command='/bin/true')
        act_suc2 = Action(name='start', command='/bin/true')
        act_suc3 = Action(name='start', command='/bin/true')
        act_suc4 = Action(name='start', command='/bin/true')
        act_suc5 = Action(name='start', command='/bin/true')
        act_status_failed = Action(name='status', command='/bin/false')
        act_status = Action(name='status', command='/bin/true')

        serv_a.add_action(act_suc)
        serv_b.add_action(act_suc2)
        serv_c.add_action(act_suc3)
        serv_d.add_action(act_suc4)
        serv_d.add_action(act_status)
        serv_x.add_action(act_suc5)
        serv_k.add_action(act_status_failed)

        serv_a.add_dep(serv_x)
        serv_a.add_dep(serv_b)
        serv_a.add_dep(serv_c, REQUIRE_WEAK)

        serv_b.add_dep(serv_d, CHECK)

        serv_c.add_dep(serv_d)
        serv_c.add_dep(serv_k, CHECK)

        serv_a.run('start')

        self.assertEqual(serv_d.status, DONE)
        self.assertEqual(serv_k.status, ERROR)
        self.assertEqual(serv_c.status, DEP_ERROR)
        self.assertEqual(serv_b.status, DONE)
        self.assertEqual(serv_x.status, DONE)
        self.assertEqual(serv_a.status, DONE)
コード例 #42
0
    def test_prepare_multiple_errors(self):
        """Test prepare with check and require deps with errors."""
        serv_a = Service('BASE')
        serv_b = Service('DEP_B')
        serv_c = Service('DEP_C')
        serv_d = Service('DEP_D')
        serv_x = Service('DEP_VX')
        serv_k = Service('DEP_K')

        act_suc = Action(name='start', command='/bin/true')
        act_suc2 = Action(name='start', command='/bin/true')
        act_suc3 = Action(name='start', command='/bin/true')
        act_suc4 = Action(name='start', command='/bin/true')
        act_suc5 = Action(name='start', command='/bin/true')
        act_status_failed = Action(name='status', command='/bin/false')
        act_status = Action(name='status', command='/bin/true')

        serv_a.add_action(act_suc)
        serv_b.add_action(act_suc2)
        serv_c.add_action(act_suc3)
        serv_d.add_action(act_suc4)
        serv_d.add_action(act_status)
        serv_x.add_action(act_suc5)
        serv_k.add_action(act_status_failed)

        serv_a.add_dep(serv_x)
        serv_a.add_dep(serv_b)
        serv_a.add_dep(serv_c, REQUIRE_WEAK)

        serv_b.add_dep(serv_d, CHECK)

        serv_c.add_dep(serv_d)
        serv_c.add_dep(serv_k, CHECK)

        serv_a.run('start')

        self.assertEqual(serv_d.status, DONE)
        self.assertEqual(serv_k.status, ERROR)
        self.assertEqual(serv_c.status, DEP_ERROR)
        self.assertEqual(serv_b.status, DONE)
        self.assertEqual(serv_x.status, DONE)
        self.assertEqual(serv_a.status, DONE)
コード例 #43
0
 def test_run_partial_deps(self):
     """Test stop algorithm as soon as the calling point is done."""
     serv = Service('NOT_CALLED')
     serv_a = Service('CALLING_POINT')
     serv_b = Service('SERV_1')
     serv_c = Service('SERV_2')
     act_suc = Action('start', command='/bin/true')
     act_suc2 = Action('start', command='/bin/true')
     act_suc3 = Action('start', command='/bin/true')
     serv_a.add_action(act_suc)
     serv_b.add_action(act_suc2)
     serv_c.add_action(act_suc3)
     serv.add_dep(serv_a)
     serv_a.add_dep(serv_b)
     serv_a.add_dep(serv_c)
     serv_a.run('start')
     self.assertEqual(serv.status, NO_STATUS)
     self.assertEqual(serv_a.status, DONE)
     self.assertEqual(serv_b.status, DONE)
     self.assertEqual(serv_c.status, DONE)
コード例 #44
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
 def test_run_partial_deps(self):
     """Test stop algorithm as soon as the calling point is done."""
     serv = Service('NOT_CALLED')
     serv_a = Service('CALLING_POINT')
     serv_b = Service('SERV_1')
     serv_c = Service('SERV_2')
     act_suc = Action('start', command='/bin/true')
     act_suc2 = Action('start', command='/bin/true')
     act_suc3 = Action('start', command='/bin/true')
     serv_a.add_action(act_suc)
     serv_b.add_action(act_suc2)
     serv_c.add_action(act_suc3)
     serv.add_dep(serv_a)
     serv_a.add_dep(serv_b)
     serv_a.add_dep(serv_c)
     serv_a.run('start')
     self.assertEqual(serv.status, NO_STATUS)
     self.assertEqual(serv_a.status, DONE)
     self.assertEqual(serv_b.status, DONE)
     self.assertEqual(serv_c.status, DONE)
コード例 #45
0
 def test_forget_service(self):
     '''The how the manager forgets a service properly'''
     manager = service_manager_self()
     s1 = Service('S1')
     s2 = Service('S2')
     s3 = Service('S3')
     s4 = Service('S4')
     s1.add_dep(target=s2)
     s2.add_dep(target=s3)
     s2.add_dep(target=s4)
     manager.register_services(s1, s2, s3, s4)
     manager.forget_service(s1)
     self.assertFalse(manager.has_service(s1))
     self.assertFalse(s1.has_parent_dep('S2'))
     self.assertFalse(s2.has_child_dep('S1'))
     manager.forget_services(s2, s4)
     self.assertFalse(manager.has_service(s2))
     self.assertFalse(manager.has_service(s4))
     self.assertFalse(s4.has_child_dep('S3'))
     self.assertFalse(s3.has_parent_dep('S4'))
コード例 #46
0
    def test_run_skipped_with_error_deps(self):
        """Test run with ERROR dependencies for a SKIPPED service"""

        # Distant service with empty target: should be skipped
        svc = Service('test_service', target="tempnode[1-2]")
        action = Action('start', command='/bin/true')
        action.inherits_from(svc)
        svc.add_action(action)
        svc.update_target("tempnode[1-2]", 'DIF')

        # A simple dep
        dep = Service('DEP_A')
        dep.add_action(Action('start', command='/bin/false'))

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

        self.assertEqual(svc.eval_deps_status(), DEP_ERROR)
        self.assertEqual(dep.status, ERROR)
        self.assertEqual(svc.status, SKIPPED)
コード例 #47
0
 def test_call_services_case_errors(self):
     '''Test errors generated by call_services'''
     manager = ServiceManager()
     s1 = Service('S1')
     s2 = Service('S2')
     s3 = Service('S3')
     s4 = Service('S4')
     s1.add_action(Action('start', command='%TARGET'))
     s2.add_action(Action('start', command='/bin/true'))
     s3.add_action(Action('start', command='/bin/true'))
     s4.add_action(Action('start', command='/bin/true'))
     s1.add_dep(target=s2)
     s2.add_dep(target=s3)
     s2.add_dep(target=s4)
     for svc in (s1, s2, s3, s4):
         manager.add_service(svc)
     self.assertRaises(ServiceNotFoundError,
                       manager.call_services, ['S8'], 'start')
     self.assertRaises(ServiceNotFoundError,
                       manager.call_services, ['S2', 'S8'], 'start')
コード例 #48
0
ファイル: ServiceTest.py プロジェクト: cea-hpc/milkcheck
    def test_run_skipped_with_error_deps(self):
        """Test run with ERROR dependencies for a SKIPPED service"""

        # Distant service with empty target: should be skipped
        svc = Service('test_service', target="tempnode[1-2]")
        action = Action('start', command='/bin/true')
        action.inherits_from(svc)
        svc.add_action(action)
        svc.update_target("tempnode[1-2]", 'DIF')

        # A simple dep
        dep = Service('DEP_A')
        dep.add_action(Action('start', command='/bin/false'))

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

        self.assertEqual(svc.eval_deps_status(), DEP_ERROR)
        self.assertEqual(dep.status, ERROR)
        self.assertEqual(svc.status, SKIPPED)
コード例 #49
0
ファイル: CliTest.py プロジェクト: cea-hpc/milkcheck
    def setUp(self):
        '''
        Set up the graph of services within the service manager

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

        self.backup_terminal = MilkCheck.UI.Cli.Terminal
        self.backup_interactivethr = MilkCheck.UI.Cli.InteractiveThread
        self.backup_confirm_actions = \
            ConfigParser.DEFAULT_FIELDS['confirm_actions']['value']
        MilkCheck.UI.Cli.Terminal = MockInterTerminal
        MilkCheck.UI.Cli.InteractiveThread = MockInteractiveThread
        MockInterTerminal.called = False
        CLICommon.setUp(self)

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

        service2.add_dep(target=service1)

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

        # Register services within the manager
        self.manager.add_service(service1)
        self.manager.add_service(service2)
コード例 #50
0
 def test_call_services_case_errors(self):
     '''Test errors generated by call_services'''
     manager = service_manager_self()
     s1 = Service('S1')
     s2 = Service('S2')
     s3 = Service('S3')
     s4 = Service('S4')
     s1.add_action(Action('start', command='%TARGET'))
     s2.add_action(Action('start', command='/bin/true'))
     s3.add_action(Action('start', command='/bin/true'))
     s4.add_action(Action('start', command='/bin/true'))
     s1.add_dep(target=s2)
     s2.add_dep(target=s3)
     s2.add_dep(target=s4)
     manager.register_services(s1, s2, s3, s4)
     self.assertRaises(AssertionError,
         manager.call_services, None, None)
     self.assertRaises(ServiceNotFoundError,
         manager.call_services, ['S8'], 'start')
     self.assertRaises(ServiceNotFoundError,
         manager.call_services, ['S2', 'S8'], 'start')
コード例 #51
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)
コード例 #52
0
 def test_call_services_case2(self):
     '''Test call of required services (start S3, S4)'''
     manager = service_manager_self()
     s1 = Service('S1')
     s2 = Service('S2')
     s3 = Service('S3')
     s4 = Service('S4')
     s1.add_action(Action('start', command='/bin/true'))
     s2.add_action(Action('start', command='/bin/true'))
     s3.add_action(Action('start', command='/bin/true'))
     s4.add_action(Action('start', command='/bin/true'))
     s1.add_dep(target=s2)
     s2.add_dep(target=s3)
     s2.add_dep(target=s4)
     manager.register_services(s1, s2, s3, s4)
     manager.call_services(['S3','S4'], 'start')
     self.assertTrue(manager.source.status not in (ERROR, DEP_ERROR,
                                                         WARNING))
     self.assertEqual(s1.status, NO_STATUS)
     self.assertEqual(s2.status, NO_STATUS)
     self.assertEqual(s3.status, DONE)
     self.assertEqual(s4.status, DONE)
コード例 #53
0
    def test_run_with_skipped_deps(self):
        """Test run with only SKIPPED dependencies"""

        # Define the main service
        serv_test = Service('test_service')
        start = Action(name='start', command='/bin/true')
        serv_test.add_action(start)

        serv_depa = Service('DEP_A')
        serv_depa.status = SKIPPED
        serv_depb = Service('DEP_B')
        serv_depb.status = SKIPPED

        serv_test.add_dep(serv_depa)
        serv_test.add_dep(serv_depb)

        self.assertEqual(serv_test.eval_deps_status(), SKIPPED)

        serv_test.run('start')
        self.assertEqual(serv_test.status, DONE)
        self.assertEqual(serv_depa.status, SKIPPED)
        self.assertEqual(serv_depb.status, SKIPPED)
コード例 #54
0
    def test_prepare_require_strong(self):
        """Test strong require dependency error."""
        serv = Service('BASE')
        serv_a = Service('DEP_A')
        serv_b = Service('DEP_B')

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

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

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

        serv.run('start')

        self.assertEqual(serv.status, DEP_ERROR)
        self.assertEqual(serv_a.status, ERROR)
        self.assertEqual(serv_b.status, DONE)
コード例 #55
0
    def test_prepare_several_dependencies(self):
        """Test prepare with several dependencies at the same level."""
        # Define the main service
        serv_test = Service('test_service')
        start = Action(name='start', command='/bin/true')
        start2 = Action(name='start', command='/bin/true')
        start3 = Action(name='start', command='/bin/true')
        serv_test.add_action(start)

        # Define the dependency DEP_A
        serv_depa = Service('DEP_A')
        serv_depa.add_action(start2)

        # Define the dependency DEP_B
        serv_depb = Service('DEP_B')
        serv_depb.add_action(start3)

        serv_test.add_dep(serv_depa)
        serv_test.add_dep(serv_depb)

        serv_test.run('start')
        self.assertEqual(serv_test.status, DONE)
        self.assertEqual(serv_depa.status, DONE)
        self.assertEqual(serv_depb.status, DONE)