def test_getRPCInterface(self): """ Test the values set at construction. """ from supvisors.rpcrequests import getRPCInterface address = '10.0.0.1' # test with empty environment env = {} with self.assertRaises(KeyError): proxy = getRPCInterface(address, env) # test with incorrect environment env = {'SUPERVISOR_SERVER_URL': 'unix://*****:*****@$$w0rd', proxy._ServerProxy__transport.password)
def check_address(self, address_name): """ Check isolation and get all process info asynchronously. """ try: remote_proxy = getRPCInterface(address_name, self.env) # check authorization status = remote_proxy.supvisors.get_address_info(address_name) authorized = status['statecode'] not in [AddressStates.ISOLATING, AddressStates.ISOLATED] # get process info if authorized if authorized: # get information about all processes handled by Supervisor all_info = remote_proxy.supervisor.getAllProcessInfo() # create a payload from Supervisor process info payload = [extract_process_info(info) for info in all_info] # post the payload internally self.send_remote_comm_event(RemoteCommEvents.SUPVISORS_INFO, json.dumps((address_name, payload))) # inform local Supvisors that authorization is available self.send_remote_comm_event( RemoteCommEvents.SUPVISORS_AUTH, 'address_name:{} authorized:{}'.format( address_name, authorized)) except: print >> stderr, '[ERROR] failed to check address {}'.format( address_name)
def setUp(self): """ Check that 3 running addresses are available. """ # get a reference to the local RPC proxy self.local_proxy = childutils.getRPCInterface(os.environ) self.local_supervisor = self.local_proxy.supervisor self.local_supvisors = self.local_proxy.supvisors # check the number of running addresses addresses_info = self.local_supvisors.get_all_addresses_info() self.running_addresses = [ info['address_name'] for info in addresses_info if info['statecode'] == AddressStates.RUNNING ] self.assertEqual(3, len(self.running_addresses)) # assumption is made that this test is run on Supvisors Master address self.assertEqual(gethostname(), self.local_supvisors.get_master_address()) # keep a reference to all RPC proxies self.proxies = { address: rpcrequests.getRPCInterface(address, os.environ) for address in self.running_addresses } # create the thread of event subscriber self.evloop = SupvisorsEventQueues() # start the thread self.evloop.start()
def shutdown(self, address_name): """ Stop process asynchronously. """ try: proxy = getRPCInterface(address_name, self.env) proxy.supervisor.shutdown() except: self.logger.error( 'failed to shutdown address {}'.format(address_name))
def restart(self, address_name): """ Restart a Supervisor instance asynchronously. """ try: proxy = getRPCInterface(address_name, self.env) proxy.supervisor.restart() except: self.logger.error( 'failed to restart address {}'.format(address_name))
def stop_process(self, address_name, namespec): """ Stop process asynchronously. """ try: proxy = getRPCInterface(address_name, self.env) proxy.supervisor.stopProcess(namespec, False) except: self.logger.error('failed to stop process {} on {}'.format( namespec, address_name))
def shutdown(self, address_name): """ Stop process asynchronously. """ try: proxy = getRPCInterface(address_name, self.env) proxy.supervisor.shutdown() except: print >> stderr, '[ERROR] failed to shutdown address {}'.format( address_name)
def restart(self, address_name): """ Restart a Supervisor instance asynchronously. """ try: proxy = getRPCInterface(address_name, self.env) proxy.supervisor.restart() except: print >> stderr, '[ERROR] failed to restart address {}'.format( address_name)
def stop_process(self, address_name, namespec): """ Stop process asynchronously. """ try: proxy = getRPCInterface(address_name, self.env) proxy.supervisor.stopProcess(namespec, False) except: print >> stderr, '[ERROR] failed to stop process {} on {}'.format( namespec, address_name)
def start_process(self, address_name, namespec, extra_args): """ Start process asynchronously. """ try: proxy = getRPCInterface(address_name, self.env) proxy.supvisors.start_args(namespec, extra_args, False) except: print >> stderr, '[ERROR] failed to start process {} on {} with {}'.format( namespec, address_name, extra_args)
def __init__(self, supvisors): """ Initialization of the attributes. """ # thread attributes Thread.__init__(self) # create stop event self.stop_event = Event() # keep a reference to the Supvisors instance and to the environment self.supvisors = supvisors self.env = supvisors.info_source.get_env() # create a XML-RPC client to the local Supervisor instance self.proxy = getRPCInterface('localhost', self.env)
def __init__(self, supvisors): """ Initialization of the attributes. """ # thread attributes Thread.__init__(self) # shortcuts self.supvisors = supvisors supvisors_short_cuts(self, ['info_source', 'logger']) # keep a reference of zmq sockets self.subscriber = supvisors.zmq.internal_subscriber self.puller = supvisors.zmq.puller # keep a reference to the environment self.env = self.info_source.get_env() # create a xml-rpc client to the local Supervisor instance self.proxy = getRPCInterface('localhost', self.env)
def setUp(self): """ Check that 3 running addresses are available. """ # get a reference to the local RPC proxy self.local_proxy = childutils.getRPCInterface(os.environ) self.local_supervisor = self.local_proxy.supervisor self.local_supvisors = self.local_proxy.supvisors # check the number of running addresses addresses_info = self.local_supvisors.get_all_addresses_info() self.running_addresses = [info['address_name'] for info in addresses_info if info['statecode'] == AddressStates.RUNNING] self.assertEqual(3, len(self.running_addresses)) # assumption is made that this test is run on Supvisors Master address self.assertEqual(gethostname(), self.local_supvisors.get_master_address()) # keep a reference to all RPC proxies self.proxies = {address: rpcrequests.getRPCInterface(address, os.environ) for address in self.running_addresses} # create the thread of event subscriber self.evloop = SupvisorsEventQueues() # start the thread self.evloop.start()
def check_address(self, address_name): """ Check isolation and get all process info asynchronously. """ try: remote_proxy = getRPCInterface(address_name, self.env) # check authorization status = remote_proxy.supvisors.get_address_info(address_name) authorized = status['statecode'] not in [ AddressStates.ISOLATING, AddressStates.ISOLATED ] # get process info if authorized if authorized: all_info = remote_proxy.supervisor.getAllProcessInfo() self.send_remote_comm_event( RemoteCommEvents.SUPVISORS_INFO, json.dumps((address_name, all_info))) # inform local Supvisors that authorization is available self.send_remote_comm_event( RemoteCommEvents.SUPVISORS_AUTH, 'address_name:{} authorized:{}'.format(address_name, authorized)) except: self.logger.error( 'failed to check address {}'.format(address_name))