def test_accept_extra_arguments(self): """ Test the possibility to add extra arguments when starting the process, iaw the process rules. """ from supvisors.process import ProcessStatus info = any_process_info() process = ProcessStatus(info['group'], info['name'], self.supvisors) self.supvisors.info_source.autorestart.return_value = False self.assertTrue(process.accept_extra_arguments()) self.supvisors.info_source.autorestart.return_value = True self.assertFalse(process.accept_extra_arguments())
def test_add_process(self): """ Test the add_process method. """ from supvisors.address import AddressStatus from supvisors.process import ProcessStatus status = AddressStatus('10.0.0.1', self.supvisors.logger) info = any_process_info() process = ProcessStatus(info['group'], info['name'], self.supvisors) status.add_process(process) # check that process is stored self.assertIn(process.namespec(), status.processes.keys()) self.assertIs(process, status.processes[process.namespec()])
def test_load_processes(self): """ Test the storage of processes handled by Supervisor on a given address. """ from supvisors.context import Context context = Context(self.supvisors) # check application list self.assertDictEqual({}, context.applications) self.assertDictEqual({}, context.processes) for address in context.addresses.values(): self.assertDictEqual({}, address.processes) # load ProcessInfoDatabase in unknown address with self.assertRaises(KeyError): context.load_processes('10.0.0.0', database_copy()) # load ProcessInfoDatabase in known address context.load_processes('10.0.0.1', database_copy()) # check context contents self.assertItemsEqual(['sample_test_1', 'sample_test_2', 'firefox', 'crash'], context.applications.keys()) self.assertItemsEqual(['sample_test_1:xclock', 'sample_test_1:xfontsel', 'sample_test_1:xlogo', 'sample_test_2:sleep', 'sample_test_2:yeux_00', 'sample_test_2:yeux_01', 'crash:late_segv', 'crash:segv', 'firefox'], context.processes.keys()) self.assertDictEqual(context.addresses['10.0.0.1'].processes, context.processes) # load ProcessInfoDatabase in other known address context.load_processes('10.0.0.2', database_copy()) # check context contents self.assertItemsEqual(['sample_test_1', 'sample_test_2', 'firefox', 'crash'], context.applications.keys()) self.assertItemsEqual(['sample_test_1:xclock', 'sample_test_1:xfontsel', 'sample_test_1:xlogo', 'sample_test_2:sleep', 'sample_test_2:yeux_00', 'sample_test_2:yeux_01', 'crash:late_segv', 'crash:segv', 'firefox'], context.processes.keys()) self.assertDictEqual(context.addresses['10.0.0.2'].processes, context.processes) # load different database in other known address info = any_process_info() info.update({'group': 'dummy_application', 'name': 'dummy_process'}) database = [info] context.load_processes('10.0.0.4', database) # check context contents self.assertItemsEqual(['sample_test_1', 'sample_test_2', 'firefox', 'crash', 'dummy_application'], context.applications.keys()) self.assertItemsEqual(['sample_test_1:xclock', 'sample_test_1:xfontsel', 'sample_test_1:xlogo', 'sample_test_2:sleep', 'sample_test_2:yeux_00', 'sample_test_2:yeux_01', 'crash:late_segv', 'crash:segv', 'firefox', 'dummy_application:dummy_process'], context.processes.keys()) self.assertListEqual(['dummy_application:dummy_process'], context.addresses['10.0.0.4'].processes.keys()) # equality lost between processes in addresses and processes in context self.assertNotIn(context.processes.keys(), context.addresses['10.0.0.1'].processes.keys()) self.assertNotIn(context.processes.keys(), context.addresses['10.0.0.2'].processes.keys()) self.assertNotIn(context.processes.keys(), context.addresses['10.0.0.4'].processes.keys()) self.assertDictContainsSubset(context.addresses['10.0.0.1'].processes, context.processes) self.assertDictContainsSubset(context.addresses['10.0.0.2'].processes, context.processes) self.assertDictContainsSubset(context.addresses['10.0.0.4'].processes, context.processes)
def test_add_process(self): """ Test the add_process method. """ from supvisors.application import ApplicationStatus from supvisors.process import ProcessStatus application = ApplicationStatus('ApplicationTest', self.supvisors.logger) # add a process to the application info = any_process_info() process = ProcessStatus(info['group'], info['name'], self.supvisors) process.add_info('10.0.0.1', info) application.add_process(process) # check that process is stored self.assertIn(process.process_name, application.processes.keys()) self.assertIs(process, application.processes[process.process_name])
def test_filter(self): """ Test the filtering of unused entries into process info dictionary. """ from supvisors.process import ProcessStatus info = any_process_info() all_keys = info.keys() removed_keys = ['statename', 'description', 'stderr_logfile', 'stdout_logfile', 'logfile', 'exitstatus'] kept_keys = filter(lambda x: x not in removed_keys, all_keys) # check that keys to be filtered are there for key in removed_keys: self.assertIn(key, all_keys) # check filtering ProcessStatus.filter(info) info_keys = info.keys() # check that keys to be filtered have been removed for key in removed_keys: self.assertNotIn(key, info_keys) for key in kept_keys: self.assertIn(key, info_keys)
def test_load_processes(self): """ Test the storage of processes handled by Supervisor on a given address. """ from supvisors.context import Context context = Context(self.supvisors) # check application list self.assertDictEqual({}, context.applications) self.assertDictEqual({}, context.processes) for address in context.addresses.values(): self.assertDictEqual({}, address.processes) # load ProcessInfoDatabase in unknown address with self.assertRaises(KeyError): context.load_processes('10.0.0.0', database_copy()) # load ProcessInfoDatabase in known address context.load_processes('10.0.0.1', database_copy()) # check context contents self.assertItemsEqual( ['sample_test_1', 'sample_test_2', 'firefox', 'crash'], context.applications.keys()) self.assertItemsEqual([ 'sample_test_1:xclock', 'sample_test_1:xfontsel', 'sample_test_1:xlogo', 'sample_test_2:sleep', 'sample_test_2:yeux_00', 'sample_test_2:yeux_01', 'crash:late_segv', 'crash:segv', 'firefox' ], context.processes.keys()) self.assertDictEqual(context.addresses['10.0.0.1'].processes, context.processes) # load ProcessInfoDatabase in other known address context.load_processes('10.0.0.2', database_copy()) # check context contents self.assertItemsEqual( ['sample_test_1', 'sample_test_2', 'firefox', 'crash'], context.applications.keys()) self.assertItemsEqual([ 'sample_test_1:xclock', 'sample_test_1:xfontsel', 'sample_test_1:xlogo', 'sample_test_2:sleep', 'sample_test_2:yeux_00', 'sample_test_2:yeux_01', 'crash:late_segv', 'crash:segv', 'firefox' ], context.processes.keys()) self.assertDictEqual(context.addresses['10.0.0.2'].processes, context.processes) # load different database in other known address info = any_process_info() info.update({'group': 'dummy_application', 'name': 'dummy_process'}) database = [info] context.load_processes('10.0.0.4', database) # check context contents self.assertItemsEqual([ 'sample_test_1', 'sample_test_2', 'firefox', 'crash', 'dummy_application' ], context.applications.keys()) self.assertItemsEqual([ 'sample_test_1:xclock', 'sample_test_1:xfontsel', 'sample_test_1:xlogo', 'sample_test_2:sleep', 'sample_test_2:yeux_00', 'sample_test_2:yeux_01', 'crash:late_segv', 'crash:segv', 'firefox', 'dummy_application:dummy_process' ], context.processes.keys()) self.assertListEqual(['dummy_application:dummy_process'], context.addresses['10.0.0.4'].processes.keys()) # equality lost between processes in addresses and processes in context self.assertNotIn(context.processes.keys(), context.addresses['10.0.0.1'].processes.keys()) self.assertNotIn(context.processes.keys(), context.addresses['10.0.0.2'].processes.keys()) self.assertNotIn(context.processes.keys(), context.addresses['10.0.0.4'].processes.keys()) self.assertDictContainsSubset(context.addresses['10.0.0.1'].processes, context.processes) self.assertDictContainsSubset(context.addresses['10.0.0.2'].processes, context.processes) self.assertDictContainsSubset(context.addresses['10.0.0.4'].processes, context.processes)