Ejemplo n.º 1
0
    def test_eval_sla(self):
        records = [{'type': 'agent', 'test': 'iperf_tcp',
                    'stats': {'bandwidth': {'avg': 700}}},
                   {'type': 'agent', 'test': 'iperf_udp',
                    'stats': {'bandwidth': {'avg': 1000}}},
                   {'type': 'node', 'test': 'iperf_tcp',
                    'stats': {'bandwidth': {'avg': 850}}}]

        expr = 'stats.bandwidth.avg > 800'
        sla_records = sla.eval_expr('[type == "agent"] >> (%s)' % expr,
                                    records)
        self.assertEqual([
            sla.SLAItem(record=records[0], state=sla.STATE_FALSE,
                        expression=expr),
            sla.SLAItem(record=records[1], state=sla.STATE_TRUE,
                        expression=expr)],
            sla_records)

        expr = 'stats.bandwidth.avg > 900'
        sla_records = sla.eval_expr('[test == "iperf_udp", type == "node"] >> '
                                    '(%s)' % expr, records)
        self.assertEqual([
            sla.SLAItem(record=records[1], state=sla.STATE_TRUE,
                        expression=expr),
            sla.SLAItem(record=records[2], state=sla.STATE_FALSE,
                        expression=expr)],
            sla_records)
Ejemplo n.º 2
0
    def test_eval_sla_undefined_ref(self):
        records = [{'type': 'agent', 'test': 'iperf_tcp',
                    'stats': {'bandwidth': {'avg': 850}}}]
        expr = 'stats.nonexistent.avg > 800'
        sla_records = sla.eval_expr('[type == "agent"] >> (%s)' % expr,
                                    records)

        self.assertEqual([
            sla.SLAItem(record=records[0],
                        state='Value "stats.nonexistent" is not found',
                        expression=expr)],
            sla_records)
Ejemplo n.º 3
0
    def test_verify_sla(self):
        records = {0: {'id': 0, 'type': 'agent', 'test': 'iperf_tcp',
                       'stats': {'bandwidth': {'avg': 700, 'min': 400}}},
                   1: {'id': 1, 'type': 'agent', 'test': 'iperf_udp',
                       'stats': {'bandwidth': {'avg': 1000, 'min': 800}}},
                   2: {'id': 2, 'type': 'agent', 'test': 'iperf_tcp',
                       'stats': {'bandwidth': {'avg': 850, 'min': 600}}}}

        tests = {
            'iperf_tcp': {
                'sla': [
                    '[type == "agent"] >> (stats.bandwidth.avg > 800)',
                    '[type == "agent"] >> (stats.bandwidth.min > 500)',
                ],
            },
            'iperf_udp': {
                'sla': [
                    '[type == "agent"] >> (stats.bandwidth.avg > 900)',
                ],
            }
        }

        sla_records = report.verify_sla(records, tests)

        self.assertIn(sla.SLAItem(records[0], sla.STATE_FALSE,
                                  'stats.bandwidth.avg > 800'), sla_records)
        self.assertIn(sla.SLAItem(records[0], sla.STATE_FALSE,
                                  'stats.bandwidth.min > 500'), sla_records)

        self.assertIn(sla.SLAItem(records[1], sla.STATE_TRUE,
                                  'stats.bandwidth.avg > 900'), sla_records)

        self.assertIn(sla.SLAItem(records[2], sla.STATE_TRUE,
                                  'stats.bandwidth.avg > 800'), sla_records)
        self.assertIn(sla.SLAItem(records[2], sla.STATE_TRUE,
                                  'stats.bandwidth.min > 500'), sla_records)
Ejemplo n.º 4
0
    def test_verify_sla(self):
        records = [{
            'type': 'agent',
            'test': 'iperf_tcp',
            'stats': {
                'bandwidth': {
                    'mean': 700,
                    'min': 400
                }
            }
        }, {
            'type': 'agent',
            'test': 'iperf_udp',
            'stats': {
                'bandwidth': {
                    'mean': 1000,
                    'min': 800
                }
            }
        }, {
            'type': 'agent',
            'test': 'iperf_tcp',
            'stats': {
                'bandwidth': {
                    'mean': 850,
                    'min': 600
                }
            }
        }]

        tests = {
            'iperf_tcp': {
                'sla': [
                    '[type == "agent"] >> (stats.bandwidth.mean > 800)',
                    '[type == "agent"] >> (stats.bandwidth.min > 500)',
                ],
            },
            'iperf_udp': {
                'sla': [
                    '[type == "agent"] >> (stats.bandwidth.mean > 900)',
                ],
            }
        }

        sla_records = report.verify_sla(records, tests)

        self.assertIn(
            sla.SLAItem(records[0], False, 'stats.bandwidth.mean > 800'),
            sla_records)
        self.assertIn(
            sla.SLAItem(records[0], False, 'stats.bandwidth.min > 500'),
            sla_records)

        self.assertIn(
            sla.SLAItem(records[1], True, 'stats.bandwidth.mean > 900'),
            sla_records)

        self.assertIn(
            sla.SLAItem(records[2], True, 'stats.bandwidth.mean > 800'),
            sla_records)
        self.assertIn(
            sla.SLAItem(records[2], True, 'stats.bandwidth.min > 500'),
            sla_records)