示例#1
0
    def setUp(self):
        """ Create a Supvisors-like structure and addresses. """
        self.supvisors = MockedSupvisors()
        # add addresses to context
        from supvisors.address import AddressStatus
        from supvisors.ttypes import AddressStates

        def create_status(name, address_state, loading):
            address_status = Mock(spec=AddressStatus,
                                  address_name=name,
                                  state=address_state)
            address_status.loading.return_value = loading
            return address_status

        addresses = self.supvisors.context.addresses
        addresses['10.0.0.0'] = create_status('10.0.0.0', AddressStates.SILENT,
                                              0)
        addresses['10.0.0.1'] = create_status('10.0.0.1',
                                              AddressStates.RUNNING, 50)
        addresses['10.0.0.2'] = create_status('10.0.0.2',
                                              AddressStates.ISOLATED, 0)
        addresses['10.0.0.3'] = create_status('10.0.0.3',
                                              AddressStates.RUNNING, 20)
        addresses['10.0.0.4'] = create_status('10.0.0.4',
                                              AddressStates.UNKNOWN, 0)
        addresses['10.0.0.5'] = create_status('10.0.0.5',
                                              AddressStates.RUNNING, 80)
        # initialize dummy address mapper with all address names (keep the alpha order)
        self.supvisors.address_mapper.addresses = sorted(addresses.keys())
示例#2
0
    def setUp(self):
        """ Create a Supvisors-like structure and conflicting processes. """
        from supvisors.process import ProcessStatus
        self.supvisors = MockedSupvisors()

        # create conflicting processes
        def create_process_status(name, timed_addresses):
            process_status = Mock(
                spec=ProcessStatus,
                process_name=name,
                addresses=set(timed_addresses.keys()),
                infos={
                    address_name: {
                        'uptime': time
                    }
                    for address_name, time in timed_addresses.items()
                })
            process_status.namespec.return_value = name
            return process_status

        self.conflicts = [
            create_process_status('conflict_1', {
                '10.0.0.1': 5,
                '10.0.0.2': 10,
                '10.0.0.3': 15
            }),
            create_process_status('conflict_2', {
                '10.0.0.4': 6,
                '10.0.0.2': 5,
                '10.0.0.0': 4
            })
        ]
示例#3
0
 def setUp(self):
     """ Create a dummy supvisors, ZMQ context and sockets. """
     from supvisors.supvisorszmq import RequestPusher, RequestPuller
     # the dummy Supvisors is used for addresses and ports
     self.supvisors = MockedSupvisors()
     # create pusher and puller
     self.pusher = RequestPusher(self.supvisors.logger)
     self.puller = RequestPuller()
     # socket configuration is meant to be blocking
     # however, a failure would block the unit test,
     # so a timeout is set for emission and reception
     self.puller.socket.setsockopt(zmq.SNDTIMEO, 1000)
     self.puller.socket.setsockopt(zmq.RCVTIMEO, 1000)
示例#4
0
 def setUp(self):
     """ Create a Supvisors-like structure. """
     from supvisors.address import AddressStatus
     from supvisors.ttypes import AddressStates
     self.supvisors = MockedSupvisors()
     # assign addresses in context
     addresses = self.supvisors.context.addresses
     for address_name in self.supvisors.address_mapper.addresses:
         addresses[address_name] = AddressStatus(address_name,
                                                 self.supvisors.logger)
     addresses['127.0.0.1']._state = AddressStates.RUNNING
     addresses['10.0.0.1']._state = AddressStates.SILENT
     addresses['10.0.0.2']._state = AddressStates.RUNNING
     addresses['10.0.0.3']._state = AddressStates.ISOLATING
     addresses['10.0.0.4']._state = AddressStates.RUNNING
     addresses['10.0.0.5']._state = AddressStates.ISOLATED
示例#5
0
 def setUp(self):
     """ Create a dummy supvisors and a ZMQ context. """
     from supvisors.supvisorszmq import EventPublisher, EventSubscriber
     # the dummy Supvisors is used for addresses and ports
     self.supvisors = MockedSupvisors()
     # create the ZeroMQ context
     # create publisher and subscriber
     self.publisher = EventPublisher(self.supvisors.options.event_port,
                                     self.supvisors.logger)
     self.subscriber = EventSubscriber(zmq.Context.instance(),
                                       self.supvisors.options.event_port,
                                       self.supvisors.logger)
     # WARN: this subscriber does not include a subscription
     # when using a subscription, use a time sleep to give time
     # to PyZMQ to handle it
     # WARN: socket configuration is meant to be blocking
     # however, a failure would block the unit test,
     # so a timeout is set for reception
     self.subscriber.socket.setsockopt(zmq.RCVTIMEO, 1000)
     # create test payloads
     self.supvisors_payload = Payload({
         'state': 'running',
         'version': '1.0'
     })
     self.address_payload = Payload({
         'state': 'silent',
         'name': 'cliche01',
         'date': 1234
     })
     self.application_payload = Payload({
         'state': 'starting',
         'name': 'supvisors'
     })
     self.process_payload = Payload({
         'state': 'running',
         'process_name': 'plugin',
         'application_name': 'supvisors',
         'date': 1230
     })
     self.event_payload = Payload({
         'state': 20,
         'name': 'plugin',
         'group': 'supvisors',
         'now': 1230
     })
示例#6
0
 def setUp(self):
     """ Create a dummy supvisors, ZMQ context and sockets. """
     from supvisors.supvisorszmq import (InternalEventPublisher,
                                         InternalEventSubscriber)
     # the dummy Supvisors is used for addresses and ports
     self.supvisors = MockedSupvisors()
     # create publisher and subscriber
     self.publisher = InternalEventPublisher(
         self.supvisors.address_mapper.local_address,
         self.supvisors.options.internal_port, self.supvisors.logger)
     self.subscriber = InternalEventSubscriber(
         self.supvisors.address_mapper.addresses,
         self.supvisors.options.internal_port)
     # socket configuration is meant to be blocking
     # however, a failure would block the unit test,
     # so a timeout is set for reception
     self.subscriber.socket.setsockopt(zmq.RCVTIMEO, 1000)
     # publisher does not wait for subscriber clients to work,
     # so give some time for connections
     time.sleep(1)
示例#7
0
 def setUp(self):
     """ Create a logger that stores log traces. """
     self.supvisors = MockedSupvisors()
示例#8
0
 def setUp(self):
     """ Create a dummy supvisors structure. """
     self.supvisors = MockedSupvisors()
示例#9
0
 def setUp(self):
     """ Create a logger that stores log traces. """
     self.supvisors = MockedSupvisors()
     from supvisors.ttypes import AddressStates
     self.all_states = AddressStates._values()
示例#10
0
 def setUp(self):
     """ Create a Supvisors-like structure. """
     self.supvisors = MockedSupvisors()
示例#11
0
 def setUp(self):
     """ Create a dummy supvisors and a ZMQ context. """
     # the dummy Supvisors is used for addresses and ports
     self.supvisors = MockedSupvisors()
     # create the ZeroMQ context
     self.zmq_context = zmq.Context.instance()
示例#12
0
 def setUp(self):
     """ Create a Supvisors-like structure and patch getRPCInterface. """
     self.supvisors = MockedSupvisors()
     self.rpc_patch = patch('supvisors.mainloop.getRPCInterface')
     self.mocked_rpc = self.rpc_patch.start()