Beispiel #1
0
    def test_sample_type_invalid(self, collectd, LOGGER):
        collectd.get_dataset.side_effect = Exception("Boom!")
        meter = Meter(collectd)

        actual = meter.sample_type(Values())

        collectd.get_dataset.assert_called_once()
        LOGGER.warning.assert_called_once()
        self.assertEqual("gauge", actual)
Beispiel #2
0
    def test_sample_type_counter(self, collectd):
        # sample_type uses get_dataset()[0][1]
        collectd.get_dataset.return_value = [('value', 'counter', )]
        meter = Meter(collectd)

        actual = meter.sample_type(Values())

        collectd.get_dataset.assert_called_once()
        self.assertEqual("cumulative", actual)
Beispiel #3
0
    def test_sample_type_derive(self, collectd):
        # sample_type uses get_dataset()[0][1]
        collectd.get_dataset.return_value = [('value', 'derive', )]
        meter = Meter(collectd)

        actual = meter.sample_type(Values())

        collectd.get_dataset.assert_called_once()
        self.assertEqual("delta", actual)
class MetersTest(TestCase):
    """Test the meters/base.py class"""

    @mock.patch(collectd_class, spec=True)
    def setUp(self, collectd):
        super(MetersTest, self).setUp()
        self._collectd = collectd
        # need this as a parameter for sample_type()
        self.vl = Values()
        self.meter = Meter(self._collectd)

    def test_sample_type_gauge(self):
        # sample_type uses get_dataset()[0][1]
        self._collectd.get_dataset.return_value = [('value', 'gauge', )]

        actual = self.meter.sample_type(self.vl)

        self._collectd.get_dataset.assert_called_once()
        self.assertEqual("gauge", actual)

    def test_sample_type_derive(self):
        # sample_type uses get_dataset()[0][1]
        self._collectd.get_dataset.return_value = [('value', 'derive', )]

        actual = self.meter.sample_type(self.vl)

        self._collectd.get_dataset.assert_called_once()
        self.assertEqual("delta", actual)

    def test_sample_type_absolute(self):
        # sample_type uses get_dataset()[0][1]
        self._collectd.get_dataset.return_value = [('value', 'absolute', )]

        actual = self.meter.sample_type(self.vl)

        self._collectd.get_dataset.assert_called_once()
        self.assertEqual("cumulative", actual)

    def test_sample_type_counter(self):
        # sample_type uses get_dataset()[0][1]
        self._collectd.get_dataset.return_value = [('value', 'counter', )]

        actual = self.meter.sample_type(self.vl)

        self._collectd.get_dataset.assert_called_once()
        self.assertEqual("cumulative", actual)

    @mock.patch('collectd_ceilometer.common.meters.base.LOGGER')
    def test_sample_type_invalid(self, LOGGER):
        self._collectd.get_dataset.side_effect = Exception("Boom!")

        actual = self.meter.sample_type(self.vl)

        self._collectd.get_dataset.assert_called_once()
        LOGGER.warning.assert_called_once()
        self.assertEqual("gauge", actual)
class MetersTest(TestCase):
    """Test the meters/base.py class"""

    @mock.patch(collectd_class, spec=True)
    def setUp(self, collectd):
        super(MetersTest, self).setUp()
        self._collectd = collectd
        # need this as a parameter for sample_type()
        self.vl = Values()
        self.meter = Meter(self._collectd)

    def test_sample_type_gauge(self):
        # sample_type uses get_dataset()[0][1]
        self._collectd.get_dataset.return_value = [("value", "gauge")]

        actual = self.meter.sample_type(self.vl)

        self._collectd.get_dataset.assert_called_once()
        self.assertEqual("gauge", actual)

    def test_sample_type_derive(self):
        # sample_type uses get_dataset()[0][1]
        self._collectd.get_dataset.return_value = [("value", "derive")]

        actual = self.meter.sample_type(self.vl)

        self._collectd.get_dataset.assert_called_once()
        self.assertEqual("delta", actual)

    def test_sample_type_absolute(self):
        # sample_type uses get_dataset()[0][1]
        self._collectd.get_dataset.return_value = [("value", "absolute")]

        actual = self.meter.sample_type(self.vl)

        self._collectd.get_dataset.assert_called_once()
        self.assertEqual("cumulative", actual)

    def test_sample_type_counter(self):
        # sample_type uses get_dataset()[0][1]
        self._collectd.get_dataset.return_value = [("value", "counter")]

        actual = self.meter.sample_type(self.vl)

        self._collectd.get_dataset.assert_called_once()
        self.assertEqual("cumulative", actual)

    @mock.patch("collectd_ceilometer.common.meters.base.LOGGER")
    def test_sample_type_invalid(self, LOGGER):
        self._collectd.get_dataset.side_effect = Exception("Boom!")

        actual = self.meter.sample_type(self.vl)

        self._collectd.get_dataset.assert_called_once()
        LOGGER.warning.assert_called_once()
        self.assertEqual("gauge", actual)
Beispiel #6
0
    def __init__(self, collectd):
        self._meters = {}
        self._default = Meter(collectd=collectd)

        # fill dict with specialized meters classes
        self._meters = {key: meter_class(collectd=collectd)
                        for key, meter_class in six.iteritems(self._classes)}
 def setUp(self, collectd):
     super(MetersTest, self).setUp()
     self._collectd = collectd
     # need this as a parameter for sample_type()
     self.vl = Values()
     self.meter = Meter(self._collectd)
 def setUp(self, collectd):
     super(MetersTest, self).setUp()
     self._collectd = collectd
     # need this as a parameter for sample_type()
     self.vl = Values()
     self.meter = Meter(self._collectd)