Exemplo n.º 1
0
 def setUp(self):
     TestStatsBaseClass.setUp(self)
     data_to_ignore = dict(exchange=["a.*", "b.*", "c.*"])
     conf = Config(self.auth, self.conn, data_to_ignore)
     self.stats = RabbitMQStats(conf)
     self.stats.get_vhost_names = Mock()
     self.stats.get_vhost_names.return_value = ['test_vhost']
Exemplo n.º 2
0
 def setUp(self):
     TestStatsBaseClass.setUp(self)
     data_to_ignore = dict(exchange=["a.*", "b.*", "c.*"])
     conf = Config(self.auth, self.conn, data_to_ignore)
     self.stats = RabbitMQStats(conf)
     self.stats.get_vhost_names = Mock()
     self.stats.get_vhost_names.return_value = ['test_vhost']
Exemplo n.º 3
0
    def setUp(self):
        self.conn = ConnectionInfo(host="example.com",
                                   port=15672,
                                   scheme="http")
        self.auth = Auth()
        self.conf = Config(self.auth, self.conn)
        self.stats = RabbitMQStats(self.conf)

        self.test_stats = dict(vhost="test_vhost",
                               message_stats=dict(
                                   publish_in=10,
                                   publish_in_details=dict(rate=0.0),
                                   publish_out=10,
                                   publish_out_details=dict(rate=0.0)))
Exemplo n.º 4
0
class TestIgnoredExchanges(TestStatsBaseClass):
    """
    Test the ignored exchanges.
    """
    def setUp(self):
        TestStatsBaseClass.setUp(self)
        data_to_ignore = dict(exchange=["a.*", "b.*", "c.*"])
        conf = Config(self.auth, self.conn, data_to_ignore)
        self.stats = RabbitMQStats(conf)
        self.stats.get_vhost_names = Mock()
        self.stats.get_vhost_names.return_value = ['test_vhost']

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_filterd_exchange_stats(self, mock_urlopen):
        """
        Asserts that exchange stats are filtered.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        self.stats.get_exchanges = Mock()
        self.stats.get_exchanges.return_value = [
            dict(name='a1'),
            dict(name='a2'),
            dict(name='a3'),
            dict(name='b1'),
            dict(name='b2'),
            dict(name='b3'),
            dict(name='c1'),
            dict(name='c2'),
            dict(name='c3'),
            dict(name='d1'),
            dict(name='d2'),
            dict(name='d3'),
            dict(name='e1'),
            dict(name='e2'),
            dict(name='e3'),
            dict(name='f1'),
            dict(name='f2'),
            dict(name='f3'),
        ]

        mock_urlopen.side_effect = create_mock_url_repsonse
        stats = self.stats.get_exchange_stats()
        self.assertNotIn('a1', stats.keys())
        self.assertNotIn('a2', stats.keys())
        self.assertNotIn('a3', stats.keys())

        self.assertNotIn('b1', stats.keys())
        self.assertNotIn('b2', stats.keys())
        self.assertNotIn('b3', stats.keys())

        self.assertNotIn('c1', stats.keys())
        self.assertNotIn('c2', stats.keys())
        self.assertNotIn('c3', stats.keys())

        self.assertIn('d1', stats.keys())
        self.assertIn('d2', stats.keys())
        self.assertIn('d3', stats.keys())

        self.assertIn('e1', stats.keys())
        self.assertIn('e2', stats.keys())
        self.assertIn('e3', stats.keys())

        self.assertIn('f1', stats.keys())
        self.assertIn('f2', stats.keys())
        self.assertIn('f3', stats.keys())

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_queue(self, mock_urlopen):
        """
        Asserts that get_queues returns the proper data.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        mock_urlopen.side_effect = create_mock_url_repsonse
        queues = self.stats.get_queues("test_vhost")
        self.assertIsNotNone(queues)
Exemplo n.º 5
0
 def setUp(self):
     self.stats = RabbitMQStats(Mock())
Exemplo n.º 6
0
class TestGetInfo(unittest.TestCase):
    """
    Test the get info method.
    """
    def setUp(self):
        self.stats = RabbitMQStats(Mock())

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_info(self, mock_urlopen):
        """
        Asserts that get_info returns the proper data from url.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        url = "http://test"
        test_value = ['test', 'json']
        mock_response = MockURLResponse(json.dumps(test_value))
        mock_urlopen.return_value = mock_response
        result = self.stats.get_info(url)
        self.assertIsNotNone(result)
        self.assertEqual(test_value, result)

    def test_get_info_bad_url(self):
        """
        Asserts that get_info returns None if url is incorrect.
        """
        url = "test"
        result = self.stats.get_info(url)
        self.assertIsNone(result)

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_info_httpd_exception(self, mock_urlopen):
        """
        Asserts that get_info returns None on HTTP Error.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        url = "http://test"
        mock_urlopen.side_effect = urllib2.HTTPError(url, 500,
                                                     'Internal Server Error',
                                                     None, None)
        result = self.stats.get_info(url)
        self.assertIsNone(result)

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_info_url_exception(self, mock_urlopen):
        """
        Asserts that get_info returns None on URLError.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        url = "http://test"
        mock_urlopen.side_effect = urllib2.URLError("URL Error ")
        result = self.stats.get_info(url)
        self.assertIsNone(result)

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_info_url_bad_json(self, mock_urlopen):
        """
        Asserts that get_info returns None on bad json.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        url = "http://test"
        mock_response = MockURLResponse('{"test":test}')
        mock_urlopen.return_value = mock_response
        result = self.stats.get_info(url)
        self.assertIsNone(result)
Exemplo n.º 7
0
 def setUp(self):
     self.stats = RabbitMQStats(Mock())
Exemplo n.º 8
0
class TestIgnoredExchanges(TestStatsBaseClass):
    """
    Test the ignored exchanges.
    """

    def setUp(self):
        TestStatsBaseClass.setUp(self)
        data_to_ignore = dict(exchange=["a.*", "b.*", "c.*"])
        conf = Config(self.auth, self.conn, data_to_ignore)
        self.stats = RabbitMQStats(conf)
        self.stats.get_vhost_names = Mock()
        self.stats.get_vhost_names.return_value = ['test_vhost']

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_filterd_exchange_stats(self, mock_urlopen):
        """
        Asserts that exchange stats are filtered.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        self.stats.get_exchanges = Mock()
        self.stats.get_exchanges.return_value = [
            dict(name='a1'), dict(name='a2'), dict(name='a3'),
            dict(name='b1'), dict(name='b2'), dict(name='b3'),
            dict(name='c1'), dict(name='c2'), dict(name='c3'),
            dict(name='d1'), dict(name='d2'), dict(name='d3'),
            dict(name='e1'), dict(name='e2'), dict(name='e3'),
            dict(name='f1'), dict(name='f2'), dict(name='f3'),
        ]

        mock_urlopen.side_effect = create_mock_url_repsonse
        stats = self.stats.get_exchange_stats()
        self.assertNotIn('a1', stats.keys())
        self.assertNotIn('a2', stats.keys())
        self.assertNotIn('a3', stats.keys())

        self.assertNotIn('b1', stats.keys())
        self.assertNotIn('b2', stats.keys())
        self.assertNotIn('b3', stats.keys())

        self.assertNotIn('c1', stats.keys())
        self.assertNotIn('c2', stats.keys())
        self.assertNotIn('c3', stats.keys())

        self.assertIn('d1', stats.keys())
        self.assertIn('d2', stats.keys())
        self.assertIn('d3', stats.keys())

        self.assertIn('e1', stats.keys())
        self.assertIn('e2', stats.keys())
        self.assertIn('e3', stats.keys())

        self.assertIn('f1', stats.keys())
        self.assertIn('f2', stats.keys())
        self.assertIn('f3', stats.keys())

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_queue(self, mock_urlopen):
        """
        Asserts that get_queues returns the proper data.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        mock_urlopen.side_effect = create_mock_url_repsonse
        queues = self.stats.get_queues("test_vhost")
        self.assertIsNotNone(queues)
Exemplo n.º 9
0
class TestGetInfo(unittest.TestCase):
    """
    Test the get info method.
    """

    def setUp(self):
        self.stats = RabbitMQStats(Mock())

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_info(self, mock_urlopen):
        """
        Asserts that get_info returns the proper data from url.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        url = "http://test"
        test_value = ['test', 'json']
        mock_response = MockURLResponse(json.dumps(test_value))
        mock_urlopen.return_value = mock_response
        result = self.stats.get_info(url)
        self.assertIsNotNone(result)
        self.assertEqual(test_value, result)

    def test_get_info_bad_url(self):
        """
        Asserts that get_info returns None if url is incorrect.
        """
        url = "test"
        result = self.stats.get_info(url)
        self.assertIsNone(result)

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_info_httpd_exception(self, mock_urlopen):
        """
        Asserts that get_info returns None on HTTP Error.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        url = "http://test"
        mock_urlopen.side_effect = urllib2.HTTPError(url,
                                                     500,
                                                     'Internal Server Error',
                                                     None, None)
        result = self.stats.get_info(url)
        self.assertIsNone(result)

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_info_url_exception(self, mock_urlopen):
        """
        Asserts that get_info returns None on URLError.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        url = "http://test"
        mock_urlopen.side_effect = urllib2.URLError("URL Error ")
        result = self.stats.get_info(url)
        self.assertIsNone(result)

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_info_url_bad_json(self, mock_urlopen):
        """
        Asserts that get_info returns None on bad json.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        url = "http://test"
        mock_response = MockURLResponse('{"test":test}')
        mock_urlopen.return_value = mock_response
        result = self.stats.get_info(url)
        self.assertIsNone(result)
Exemplo n.º 10
0
class TestIgnoredQueues(TestStatsBaseClass):
    """
    Test the ignored queues.
    """
    def setUp(self):
        TestStatsBaseClass.setUp(self)
        data_to_ignore = dict(queue=["a.*", "b.*", "c.*"])
        conf = Config(self.auth, self.conn, data_to_ignore)
        self.stats = RabbitMQStats(conf)
        self.stats.get_vhost_names = Mock()
        self.stats.get_vhost_names.return_value = ['test_vhost']

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_filterd_queue_stats(self, mock_urlopen):
        """
        Asserts that queue stats are filtered.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        self.stats.get_queues = Mock()
        self.stats.get_queues.return_value = [
            dict(name='a1'),
            dict(name='a2'),
            dict(name='a3'),
            dict(name='b1'),
            dict(name='b2'),
            dict(name='b3'),
            dict(name='c1'),
            dict(name='c2'),
            dict(name='c3'),
            dict(name='d1'),
            dict(name='d2'),
            dict(name='d3'),
            dict(name='e1'),
            dict(name='e2'),
            dict(name='e3'),
            dict(name='f1'),
            dict(name='f2'),
            dict(name='f3'),
        ]

        mock_urlopen.side_effect = create_mock_url_repsonse
        stats = self.stats.get_queue_stats()
        self.assertNotIn('a1', stats.keys())
        self.assertNotIn('a2', stats.keys())
        self.assertNotIn('a3', stats.keys())

        self.assertNotIn('b1', stats.keys())
        self.assertNotIn('b2', stats.keys())
        self.assertNotIn('b3', stats.keys())

        self.assertNotIn('c1', stats.keys())
        self.assertNotIn('c2', stats.keys())
        self.assertNotIn('c3', stats.keys())

        self.assertIn('d1', stats.keys())
        self.assertIn('d2', stats.keys())
        self.assertIn('d3', stats.keys())

        self.assertIn('e1', stats.keys())
        self.assertIn('e2', stats.keys())
        self.assertIn('e3', stats.keys())

        self.assertIn('f1', stats.keys())
        self.assertIn('f2', stats.keys())
        self.assertIn('f3', stats.keys())

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_exchanges(self, mock_urlopen):
        """
        Asserts that get_exchanges returns the proper data.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        mock_urlopen.side_effect = create_mock_url_repsonse
        exchanges = self.stats.get_exchanges("test_vhost")
        self.assertIsNotNone(exchanges)

    @patch('collectd_rabbitmq.rabbit.urllib2.urlopen')
    def test_get_exchanges_unavailable(self, mock_urlopen):
        """
        Asserts that get_exchanges returns an empty list if it can't access the
        data.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        mock_urlopen.side_effect = urllib2.HTTPError("testurl", 401,
                                                     "Forbidden", None, None)
        exchanges = self.stats.get_exchanges("test_vhost")
        self.assertEqual(exchanges, [])