def test_register_driver(self):
        ConsulServiceRegistry.register_driver(self.PA_NAME, self.PA_PORT)
        _, result = CONSUL.health.service(DRIVER_SERVICE_NAME, tag=self.PA_NAME)

        self.assertEqual(len(result), 1)
        result = result[0]

        self.assertIn('Service', result)
        service = result['Service']

        self.assertIn('Service', service)
        self.assertEqual(service['Service'], DRIVER_SERVICE_NAME)

        self.assertIn('Tags', service)
        self.assertEqual(service['Tags'], [self.PA_NAME])

        self.assertIn('Port', service)
        self.assertEqual(service['Port'], self.PA_PORT)

        self.assertIn('Checks', result)
        checks = result['Checks']

        self.assertEqual(len(checks), 2)
        driver_check = checks[1]

        self.assertIn('Status', driver_check)
        self.assertEqual(driver_check['Status'], 'critical')
Ejemplo n.º 2
0
    def test_register_driver(self):
        ConsulServiceRegistry.register_driver(self.PA_NAME, self.PA_PORT)
        _, result = CONSUL.health.service(DRIVER_SERVICE_NAME,
                                          tag=self.PA_NAME)

        self.assertEqual(len(result), 1)
        result = result[0]

        self.assertIn('Service', result)
        service = result['Service']

        self.assertIn('Service', service)
        self.assertEqual(service['Service'], DRIVER_SERVICE_NAME)

        self.assertIn('Tags', service)
        self.assertEqual(service['Tags'], [self.PA_NAME])

        self.assertIn('Port', service)
        self.assertEqual(service['Port'], self.PA_PORT)

        self.assertIn('Checks', result)
        checks = result['Checks']

        self.assertEqual(len(checks), 2)
        driver_check = checks[1]

        self.assertIn('Status', driver_check)
        self.assertEqual(driver_check['Status'], 'critical')
 def test_locate_port_agent(self):
     config = ConsulServiceRegistry.locate_port_agent(self.PA_NAME)
     self.assertIn('port', config)
     self.assertEqual(config['port'], self.PA_PORT)
     self.assertIn('cmd_port', config)
     self.assertEqual(config['cmd_port'], self.PA_COMMAND_PORT)
     self.assertIn('addr', config)
Ejemplo n.º 4
0
    def test_health_thread(self):
        real_sleep = time.sleep

        def sleep(*args):
            real_sleep(0.1)

        with mock.patch('mi.core.service_registry.time.sleep') as sleep_mock:
            sleep_mock.side_effect = sleep
            thread = ConsulServiceRegistry.create_health_thread(
                self.PA_NAME, self.PA_PORT)
            thread.start()

            self.assertIsInstance(thread, threading.Thread)
            self.assertTrue(thread.is_alive())
            # Sleep just long enough to send a passing check to consul
            sleep()

            thread.running = False
            thread.join()
            self.assertFalse(thread.is_alive())

            # verify we have registered our driver and we are in a passing state
            _, result = CONSUL.health.service(DRIVER_SERVICE_NAME,
                                              tag=self.PA_NAME,
                                              passing=True)
            self.assertEqual(len(result), 1)
Ejemplo n.º 5
0
 def test_locate_port_agent(self):
     config = ConsulServiceRegistry.locate_port_agent(self.PA_NAME)
     self.assertIn('port', config)
     self.assertEqual(config['port'], self.PA_PORT)
     self.assertIn('cmd_port', config)
     self.assertEqual(config['cmd_port'], self.PA_COMMAND_PORT)
     self.assertIn('addr', config)
Ejemplo n.º 6
0
    def start_threads(self):
        """
        Initialize and start messaging resources for the driver, blocking
        until messaging terminates. This ZMQ implementation starts and
        joins command and event threads, managing nonblocking send/recv calls
        on REP and PUB sockets, respectively. Terminate loops and close
        sockets when stop flag is set in driver process.
        """
        self.event_publisher.start()
        self.particle_publisher.start()

        self.load_balancer = LoadBalancer(self, self.num_workers)
        self.port = self.load_balancer.port

        # now that we have a port, start our status thread
        self.status_thread = ConsulServiceRegistry.create_health_thread(self.refdes, self.port)
        self.status_thread.setDaemon(True)
        self.status_thread.start()

        self.load_balancer.run()
Ejemplo n.º 7
0
    def start_threads(self):
        """
        Initialize and start messaging resources for the driver, blocking
        until messaging terminates. This ZMQ implementation starts and
        joins command and event threads, managing nonblocking send/recv calls
        on REP and PUB sockets, respectively. Terminate loops and close
        sockets when stop flag is set in driver process.
        """
        self.event_publisher.start()
        self.particle_publisher.start()

        self.load_balancer = LoadBalancer(self, self.num_workers)
        self.port = self.load_balancer.port

        # now that we have a port, start our status thread
        self.status_thread = ConsulServiceRegistry.create_health_thread(self.refdes, self.port)
        self.status_thread.setDaemon(True)
        self.status_thread.start()

        self.load_balancer.run()
    def test_health_thread(self):
        real_sleep = time.sleep

        def sleep(*args):
            real_sleep(0.1)

        with mock.patch('mi.core.service_registry.time.sleep') as sleep_mock:
            sleep_mock.side_effect = sleep
            thread = ConsulServiceRegistry.create_health_thread(self.PA_NAME, self.PA_PORT)
            thread.start()

            self.assertIsInstance(thread, threading.Thread)
            self.assertTrue(thread.is_alive())
            # Sleep just long enough to send a passing check to consul
            sleep()

            thread.running = False
            thread.join()
            self.assertFalse(thread.is_alive())

            # verify we have registered our driver and we are in a passing state
            _, result = CONSUL.health.service(DRIVER_SERVICE_NAME, tag=self.PA_NAME, passing=True)
            self.assertEqual(len(result), 1)