Ejemplo n.º 1
0
 def test_group_config(self):
     """ Test the access of a group configuration. """
     from supvisors.infosource import SupervisordSource
     source = SupervisordSource(self.supervisor)
     # test unknown application
     with self.assertRaises(KeyError):
         source.get_group_config('unknown_application')
     # test normal behaviour
     self.assertEqual('dummy_application_config', source.get_group_config('dummy_application'))
Ejemplo n.º 2
0
 def test_disable_autorestart(self):
     """ Test the disable of the autostart of a process configuration. """
     from supvisors.infosource import SupervisordSource
     source = SupervisordSource(self.supervisor)
     # test unknown application and process
     with self.assertRaises(KeyError):
         source.disable_autorestart('unknown_application:unknown_process')
     with self.assertRaises(KeyError):
         source.disable_autorestart('dummy_application:unknown_process')
     # test normal behaviour
     self.assertTrue(source.autorestart('dummy_application:dummy_process_1'))
     source.disable_autorestart('dummy_application:dummy_process_1')
     self.assertFalse(source.autorestart('dummy_application:dummy_process_1'))
Ejemplo n.º 3
0
 def test_close_server(self):
     """ Test the closing of supervisord HTTP servers. """
     from supvisors.infosource import SupervisordSource
     source = SupervisordSource(self.supervisor)
     # keep reference to http servers
     http_servers = self.supervisor.options.httpservers
     self.assertIsNone(self.supervisor.options.storage)
     # call the method
     source.close_httpservers()
     # test the result
     self.assertIsNotNone(self.supervisor.options.storage)
     self.assertIs(http_servers, self.supervisor.options.storage)
     self.assertTupleEqual((), self.supervisor.options.httpservers)
     # restore old value for tests
     self.supervisor.options.httpservers = http_servers
Ejemplo n.º 4
0
 def test_creation(self):
     """ Test the values set at construction. """
     from supvisors.infosource import SupervisordSource
     source = SupervisordSource(self.supervisor)
     self.assertIs(self.supervisor, source.supervisord)
     self.assertIs(source.supervisord.options.server_configs[0], source.server_config)
     self.assertIsNone(source._supervisor_rpc_interface)
     self.assertIsNone(source._supvisors_rpc_interface)
Ejemplo n.º 5
0
 def test_process(self):
     """ Test the access of a supervisord process. """
     from supvisors.infosource import SupervisordSource
     source = SupervisordSource(self.supervisor)
     # test unknown application and process
     with self.assertRaises(KeyError):
         source.get_process('unknown_application:unknown_process')
     with self.assertRaises(KeyError):
         source.get_process('dummy_application:unknown_process')
     # test normal behaviour
     self.assertIs(self.supervisor.process_groups['dummy_application'].processes['dummy_process_1'],
         source.get_process('dummy_application:dummy_process_1'))
     self.assertIs(self.supervisor.process_groups['dummy_application'].processes['dummy_process_2'],
         source.get_process('dummy_application:dummy_process_2'))
Ejemplo n.º 6
0
 def test_accessors(self):
     """ Test the accessors. """
     from supvisors.infosource import SupervisordSource
     source = SupervisordSource(self.supervisor)
     # test consistence with DummySupervisor configuration
     self.assertIs(self.supervisor.options.httpserver, source.httpserver)
     self.assertEqual('supervisor_RPC', source.supervisor_rpc_interface)
     self.assertEqual('supvisors_RPC', source.supvisors_rpc_interface)
     self.assertEqual('url', source.serverurl)
     self.assertEqual(1234, source.serverport)
     self.assertEqual('user', source.username)
     self.assertEqual('p@$$w0rd', source.password)
     self.assertEqual('mood', source.supervisor_state)
Ejemplo n.º 7
0
 def test_force_unknown(self):
     """ Test the way to force a process in UNKNOWN state. """
     from supvisors.infosource import SupervisordSource
     source = SupervisordSource(self.supervisor)
     # test unknown application and process
     with self.assertRaises(KeyError):
         source.force_process_unknown('unknown_application:unknown_process', 'mystery')
     with self.assertRaises(KeyError):
         source.force_process_unknown('dummy_application:unknown_process', 'mystery')
     # test normal behaviour
     process_1 = source.get_process('dummy_application:dummy_process_1')
     self.assertEqual('STOPPED', process_1.state)
     self.assertEqual('', process_1.spawnerr)
     source.force_process_unknown('dummy_application:dummy_process_1', 'mystery')
     self.assertEqual(1000, process_1.state)
     self.assertEqual('mystery', process_1.spawnerr)
     # restore configuration
     process_1.state = 'STOPPED'
     process_1.spawnerr = ''
Ejemplo n.º 8
0
 def test_process_config(self):
     """ Test the access of a group configuration. """
     from supvisors.infosource import SupervisordSource
     source = SupervisordSource(self.supervisor)
     # test unknown application and process
     with self.assertRaises(KeyError):
         source.get_process_config('unknown_application:unknown_process')
     with self.assertRaises(KeyError):
         source.get_process_config('dummy_application:unknown_process')
     # test normal behaviour
     config = source.get_process_config('dummy_application:dummy_process_1')
     self.assertTrue(config.autorestart)
     self.assertEqual('ls', config.command)
     config = source.get_process_config('dummy_application:dummy_process_2')
     self.assertFalse(config.autorestart)
     self.assertEqual('cat', config.command)
Ejemplo n.º 9
0
 def __init__(self, supervisord):
     """ Initialization of the attributes. """
     # store this instance in supervisord to ensure persistence
     supervisord.supvisors = self
     # get options from config file
     server_options = SupvisorsServerOptions()
     server_options.realize()
     self.options = server_options.supvisors_options
     # create logger
     stdout = supervisord.options.nodaemon
     self.logger = getLogger(self.options.logfile, self.options.loglevel,
                             Supvisors.LOGGER_FORMAT, True,
                             self.options.logfile_maxbytes,
                             self.options.logfile_backups, stdout)
     # configure supervisor info source
     self.info_source = SupervisordSource(supervisord)
     # set addresses and check local address
     self.address_mapper = AddressMapper(self.logger)
     self.address_mapper.addresses = self.options.address_list
     if not self.address_mapper.local_address:
         raise RPCError(
             Faults.SUPVISORS_CONF_ERROR,
             'local host unexpected in address list: {}'.format(
                 self.options.address_list))
     # create context data
     self.context = Context(self)
     # create application starter and stopper
     self.starter = Starter(self)
     self.stopper = Stopper(self)
     # create statistics handler
     self.statistician = StatisticsCompiler(self)
     # create the failure handler of crashing processes
     self.failure_handler = RunningFailureHandler(self)
     # create state machine
     self.fsm = FiniteStateMachine(self)
     # check parsing
     try:
         self.parser = Parser(self)
     except:
         self.logger.warn('cannot parse rules file: {}'.format(
             self.options.rules_file))
         self.parser = None
     # create event subscriber
     self.listener = SupervisorListener(self)
Ejemplo n.º 10
0
 def test_replace_handler(self):
     """ Test the autostart value of a process configuration. """
     from supvisors.infosource import SupervisordSource
     source = SupervisordSource(self.supervisor)
     # keep reference to handler
     self.assertIsInstance(self.supervisor.options.httpserver.handlers[1], Mock)
     # check method behaviour with authentication server
     source.replace_default_handler()
     # keep reference to handler
     self.assertIsInstance(self.supervisor.options.httpserver.handlers[1], supervisor_auth_handler)
     # check method behaviour with authentication server
     with patch.dict(source.server_config, {'username': None}):
         source.replace_default_handler()
     # keep reference to handler
     self.assertIsInstance(self.supervisor.options.httpserver.handlers[1], default_handler.default_handler)
Ejemplo n.º 11
0
 def test_TODO(self):
     """ Test the values set at construction. """
     from supvisors.infosource import SupervisordSource
     source = SupervisordSource(self.supervisor)
     self.assertIsNotNone(source)
Ejemplo n.º 12
0
 def test_env(self):
     """ Test the environment build. """
     from supvisors.infosource import SupervisordSource
     source = SupervisordSource(self.supervisor)
     self.assertDictEqual({'SUPERVISOR_SERVER_URL': 'url', 'SUPERVISOR_USERNAME': '******',
         'SUPERVISOR_PASSWORD': '******'}, source.get_env())
Ejemplo n.º 13
0
 def test_unix_server(self):
     """ Test the values set at construction. """
     from supvisors.infosource import SupervisordSource
     with patch.dict(self.supervisor.options.server_configs[0], {'section': 'unix_http_server'}):
         with self.assertRaises(ValueError):
             SupervisordSource(self.supervisor)
Ejemplo n.º 14
0
 def test_extra_args(self):
     """ Test the possibility to add extra arguments to default command line. """
     from supvisors.infosource import SupervisordSource
     source = SupervisordSource(self.supervisor)
     # test unknown application and process
     with self.assertRaises(KeyError):
         source.update_extra_args('unknown_application:unknown_process', '-la')
     with self.assertRaises(KeyError):
         source.update_extra_args('dummy_application:unknown_process', '-la')
     # test normal behaviour
     config_1 = source.get_process_config('dummy_application:dummy_process_1')
     # check that there is no save of the initial command
     self.assertFalse(hasattr(config_1, 'config_ref'))
     # add extra arguments
     source.update_extra_args('dummy_application:dummy_process_1', '-la')
     self.assertEqual('ls -la', config_1.command)
     self.assertEqual('ls', config_1.config_ref)
     # remove them
     source.update_extra_args('dummy_application:dummy_process_1', None)
     self.assertEqual('ls', config_1.command)
     self.assertEqual('ls', config_1.config_ref)
     # restore initial config
     delattr(config_1, 'config_ref')