Beispiel #1
0
    def test_do_spawn_and_publish_publish_error(self, mc_spawn_instance,
                                                mc_grc):
        mc_spawn_instance.return_value = {"result": "foobar"}
        mc_grc.side_effect = ConnectionError()

        do_spawn_and_publish(self.opts, self.spawn_pb_path, self.group)
        assert mc_grc.called
Beispiel #2
0
    def get_connection(self, command_name, *keys, **options):
        """Get a connection, blocking for ``self.timeout`` until a connection
        is available from the pool.

        If the connection returned is ``None`` then creates a new connection.
        Because we use a last-in first-out queue, the existing connections
        (having been returned to the pool after the initial ``None`` values
        were added) will be returned before ``None`` values. This means we only
        create new connections when we need to, i.e.: the actual number of
        connections will only increase in response to demand.
        """
        self._checkpid()

        # Try and get a connection from the pool. If one isn't available within
        # self.timeout then raise a `ConnectionError`.
        connection = None
        try:
            connection = self._master_pool.get(block=True,
                                               timeout=self.timeout)
            logging.debug("Using connection from pool: %r", connection)
        except Empty:
            if self._current_master:
                raise ConnectionError("No connection available")

        # If the ``connection`` is actually ``None`` then that's a cue to make
        # a new connection to add to the pool.
        if connection is None:
            logging.debug("Create new connection")
            connection = self.make_connection()

        return connection
Beispiel #3
0
 def make_connection(self):
     """Create a new connection"""
     if self._created_connections[self._pattern_idx] >= self.max_connections_per_pattern:
         raise ConnectionError("Too many connections")
     self._created_connections[self._pattern_idx] += 1
     conn = self.connection_class(**self.patterns[self._pattern_idx])
     conn._pattern_idx = self._pattern_idx
     return conn
Beispiel #4
0
    def test_do_spawn_and_publish_error(self, mc_run_ans, mc_grc):
        mc_grc.side_effect = ConnectionError()

        terminate_vm(self.opts, self.terminate_pb_path, 0, self.vm_name, self.vm_ip)

        assert mc_run_ans.called
        expected_cmd = '-c ssh {} --extra-vars=\'{{"copr_task": {{"vm_name": "{}", "ip": "{}"}}}}\''.format(
            self.terminate_pb_path, self.vm_name, self.vm_ip)

        assert expected_cmd == mc_run_ans.call_args[:-1][0][0]
        assert mc_grc.called
Beispiel #5
0
    def test_check_health_pubsub_publish_error(self, mc_ans_runner, mc_grc):
        mc_conn = MagicMock()
        mc_ans_runner.return_value = mc_conn
        mc_conn.run.return_value = {"contacted": [self.vm_ip]}

        mc_grc.side_effect = ConnectionError()

        # didn't raise exception
        check_health(self.opts, self.vm_name, self.vm_ip)

        assert mc_conn.run.called
        assert mc_grc.called
Beispiel #6
0
 def __init__(
     self,
     default_name: str,
     cache_url: str,
     **kwargs,
 ):
     kwargs.setdefault('decode_responses', True)
     super().__init__(
         connection_pool=from_url(url=cache_url, **kwargs).connection_pool)
     self.default_name = default_name
     try:
         self.ping()
     except ConnectionError as exc:
         raise ConnectionError(
             f'Could not connect to Redis with URL: {cache_url}') from exc
Beispiel #7
0
    def make_connection(self):
        "Create a new connection"
        if self._created_connections >= self.max_connections:
            raise ConnectionError("Too many connections")

        self._created_connections += 1

        if self._current_master == None:
            logger.debug("No master set - reconfiguratin")
            self._configure()

        host = self._current_master[0]
        port = self._current_master[1]

        logger.debug("Creating new connection to {}:{}".format(host, port))
        return self.connection_class(host=host, port=port, **self.connection_kwargs)
Beispiel #8
0
    def make_connection(self):
        """Create a new connection"""
        if self._current_master is None:
            logging.warning("No master set - reconfiguration")
            self._reconfigure()

        if not self._current_master:
            raise ConnectionError("Can't connect to a master")

        host = self._current_master[0]
        port = self._current_master[1]

        logging.info("Creating new connection to {0}:{1}".format(host, port))
        connection = self.connection_class(host=host,
                                           port=port,
                                           **self.connection_kwargs)
        self._connections.append(connection)
        return connection
Beispiel #9
0
 def get_redis_link(host, port, decode_responses=False):
     if port == 7000:
         raise ConnectionError('mock connection error for 7000')
     return Redis(host=host, port=port, decode_responses=decode_responses)
Beispiel #10
0
 def test_redis_connection_error(self, ping_error_mock):
     """ Test a Bad Redis connection """
     ping_error_mock.side_effect = ConnectionError()
     self.assertRaises(ConnectionError, Pet.init_db)
     self.assertIsNone(Pet.redis)
Beispiel #11
0
 def get_redis_connection(self) -> Redis:
     try:
         self._conn = Redis(connection_pool=self.pool, socket_connect_timeout=1000)
     except ConnectionError:
         raise ConnectionError()