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 ] """)
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)
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.add_service(svc1) self.manager.add_service(svc2) self.manager.add_service(svc3) self.manager.add_service(group1)
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)
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)
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")
def test_prepare_multilevel_dependencies(self): """Test prepare with multiple dependencies at different levels.""" #Service Arthemis is delcared here arth = Service('arthemis') arth.desc = 'Sleep five seconds' start = Action(name='start', command='/bin/true') start2 = Action(name='start', command='/bin/true') start3 = Action(name='start', command='/bin/true') start4 = Action(name='start', command='/bin/true') arth.add_action(start) # Service Chiva is declared here chiva = Service('chiva') chiva.desc = 'List all processes in details' chiva.add_action(start2) chiva.add_dep(arth) # Service Dyonisos is declared here dion = Service('dionysos') dion.desc = 'Perform tree on directory specified' dion.add_action(start3) dion.add_dep(arth) # Service Brutus is declared here brut = Service('brutus') brut.desc = 'Wanna sleep all the time' brut.add_action(start4) brut.add_dep(chiva) brut.add_dep(dion) brut.run('start') self.assertEqual(arth.status, DONE) self.assertEqual(chiva.status, DONE) self.assertEqual(dion.status, DONE) self.assertEqual(brut.status, DONE)
def test_command_output_interactive_delayed(self): '''Test command line output in interactive mode with delayed actions''' action = Action('start', command='/bin/sleep 0.1', delay=0.3) srv = Service('service') srv.desc = 'I am the service' action.inherits_from(srv) srv.add_action(action) self.manager.register_services(srv) self._output_check(['service', 'start'], RC_OK, ''' Actions in progress > service.start (delayed for 0.3s) on localhost service - I am the service [ OK ] ''')
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 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' service2 = Service('service2') service2.desc = 'I am the service 2' # 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.register_services(service1, service2)
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.register_services(svc_warn, 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 ] """)
def test_command_output_dist_report_full_error_and_ok(self): """ Test command line output with full report, FAILED actions and OK actions on distant nodes. """ # Service svc = Service('service_ok') svc.desc = 'I am the ok service' svc2 = Service('service_fail') svc2.desc = 'I am the fail service' svc.add_dep(svc2, sgth=REQUIRE_WEAK) # Actions false_action = Action('stop', command='/bin/false', target=NodeSet(HOSTNAME)) false_action.inherits_from(svc) svc.add_action(false_action) true_action = Action('stop', command='/bin/true', target=NodeSet(HOSTNAME)) true_action.inherits_from(svc2) svc2.add_action(true_action) # Register services within the manager self.manager.add_service(svc) self.manager.add_service(svc2) # FIXME: must return RC_OK self._output_check(['service_fail', 'stop', '--report=full'], RC_OK, """stop service_ok ran in 0.00 s > HOSTNAME exited with 1 service_ok - I am the ok service [ ERROR ] service_fail - I am the fail service [ OK ] SUMMARY - 2 actions (1 failed) + service_ok.stop - I am the ok service Target: HOSTNAME Command: /bin/false """)