Пример #1
0
    def test_nested_wire_format(self):
        """make sure nested format round trips correctly."""

        data_flow = dict(name="traffic",
                         columns=["time", "direction"],
                         points=[[1400425947000, {
                             'in': 1,
                             'out': 2
                         }], [1400425948000, {
                             'in': 3,
                             'out': 4
                         }], [1400425949000, {
                             'in': 5,
                             'out': 6
                         }], [1400425950000, {
                             'in': 7,
                             'out': 8
                         }]])

        series = TimeSeries(data_flow)

        wire = self._call_interop_script('event', series.to_string())

        new_series = TimeSeries(wire)

        self.assertEqual(new_series.at(0).value('direction').get('in'), 1)
        self.assertEqual(new_series.at(0).value('direction').get('out'), 2)
        self.assertEqual(new_series.at(1).value('direction').get('in'), 3)
        self.assertEqual(new_series.at(1).value('direction').get('out'), 4)
Пример #2
0
    def test_series_creation(self):
        """test timeseries creation.

        Calls to to_json() are to trigger coverage for different variants.
        """

        # from a wire format event list
        ts1 = TimeSeries(DATA)
        self.assertEqual(ts1.size(), len(DATA.get('points')))

        # from a wire format index
        ts2 = TimeSeries(AVAILABILITY_DATA)
        self.assertEqual(ts2.size(), len(AVAILABILITY_DATA.get('points')))
        self.assertEqual(ts2.to_json().get('name'), 'availability')

        # from a list of events
        ts3 = TimeSeries(dict(name='events', events=EVENT_LIST))
        self.assertEqual(ts3.size(), len(EVENT_LIST))

        # from a collection
        ts4 = TimeSeries(
            dict(name='collection', collection=self._canned_collection))
        self.assertEqual(ts4.size(), self._canned_collection.size())

        # copy constructor
        ts5 = TimeSeries(ts4)
        self.assertEqual(ts4.size(), ts5.size())

        # from a wire format time range
        ts6 = TimeSeries(TICKET_RANGE)
        self.assertEqual(ts6.size(), len(TICKET_RANGE.get('points')))
        self.assertEqual(ts6.to_json().get('name'), 'outages')

        # non-utc indexed data variant mostly for coverage
        idxd = copy.deepcopy(INDEXED_DATA)
        idxd['utc'] = False
        ts7 = TimeSeries(idxd)
        self.assertFalse(ts7.is_utc())
        self.assertFalse(ts7.to_json().get('utc'))

        # indexed data variant using Index object - for coverage as well
        idxd2 = copy.deepcopy(INDEXED_DATA)
        idxd2['index'] = Index(idxd2.get('index'))
        ts8 = TimeSeries(idxd2)
        self.assertEqual(ts8.to_json().get('index'), '1d-625')

        # make sure complex/deep/nested wire format is being handled correctly.
        ts7 = TimeSeries(DATA_FLOW)
        self.assertEqual(ts7.at(0).value('direction').get('in'), 1)
        self.assertEqual(ts7.at(0).value('direction').get('out'), 2)
        self.assertEqual(ts7.at(1).value('direction').get('in'), 3)
        self.assertEqual(ts7.at(1).value('direction').get('out'), 4)
Пример #3
0
    def test_series_creation(self):
        """test timeseries creation.

        Calls to to_json() are to trigger coverage for different variants.
        """

        # from a wire format event list
        ts1 = TimeSeries(DATA)
        self.assertEqual(ts1.size(), len(DATA.get('points')))

        # from a wire format index
        ts2 = TimeSeries(AVAILABILITY_DATA)
        self.assertEqual(ts2.size(), len(AVAILABILITY_DATA.get('points')))
        self.assertEqual(ts2.to_json().get('name'), 'availability')

        # from a list of events
        ts3 = TimeSeries(dict(name='events', events=EVENT_LIST))
        self.assertEqual(ts3.size(), len(EVENT_LIST))

        # from a collection
        ts4 = TimeSeries(dict(name='collection', collection=self._canned_collection))
        self.assertEqual(ts4.size(), self._canned_collection.size())

        # copy constructor
        ts5 = TimeSeries(ts4)
        self.assertEqual(ts4.size(), ts5.size())

        # from a wire format time range
        ts6 = TimeSeries(TICKET_RANGE)
        self.assertEqual(ts6.size(), len(TICKET_RANGE.get('points')))
        self.assertEqual(ts6.to_json().get('name'), 'outages')

        # non-utc indexed data variant mostly for coverage
        idxd = copy.deepcopy(INDEXED_DATA)
        idxd['utc'] = False
        ts7 = TimeSeries(idxd)
        self.assertFalse(ts7.is_utc())
        self.assertFalse(ts7.to_json().get('utc'))

        # indexed data variant using Index object - for coverage as well
        idxd2 = copy.deepcopy(INDEXED_DATA)
        idxd2['index'] = Index(idxd2.get('index'))
        ts8 = TimeSeries(idxd2)
        self.assertEqual(ts8.to_json().get('index'), '1d-625')

        # make sure complex/deep/nested wire format is being handled correctly.
        ts7 = TimeSeries(DATA_FLOW)
        self.assertEqual(ts7.at(0).value('direction').get('in'), 1)
        self.assertEqual(ts7.at(0).value('direction').get('out'), 2)
        self.assertEqual(ts7.at(1).value('direction').get('in'), 3)
        self.assertEqual(ts7.at(1).value('direction').get('out'), 4)
Пример #4
0
    def test_nested_wire_format(self):
        """make sure nested format round trips correctly."""

        data_flow = dict(
            name="traffic",
            columns=["time", "direction"],
            points=[
                [1400425947000, {'in': 1, 'out': 2}],
                [1400425948000, {'in': 3, 'out': 4}],
                [1400425949000, {'in': 5, 'out': 6}],
                [1400425950000, {'in': 7, 'out': 8}]
            ]
        )

        series = TimeSeries(data_flow)

        wire = self._call_interop_script('event', series.to_string())

        new_series = TimeSeries(wire)

        self.assertEqual(new_series.at(0).value('direction').get('in'), 1)
        self.assertEqual(new_series.at(0).value('direction').get('out'), 2)
        self.assertEqual(new_series.at(1).value('direction').get('in'), 3)
        self.assertEqual(new_series.at(1).value('direction').get('out'), 4)
Пример #5
0
    def test_event_series(self):
        """test a series that contains basic event objects."""
        event_series = dict(
            name="traffic",
            columns=["time", "value", "status"],
            points=[
                [1400425947000, 52, "ok"],
                [1400425948000, 18, "ok"],
                [1400425949000, 26, "fail"],
                [1400425950000, 93, "offline"]
            ]
        )

        series = TimeSeries(event_series)

        wire = self._call_interop_script('event', series.to_string())

        new_series = TimeSeries(wire)
        new_json = new_series.to_json()

        self._validate_wire_points(event_series, new_json)
        self.assertTrue(new_json.get('utc'))

        # try something a bit fancier with different types
        interface_series = dict(
            name="star-cr5:to_anl_ip-a_v4",
            description="star-cr5->anl(as683):100ge:site-ex:show:intercloud",
            device="star-cr5",
            id=169,
            interface="to_anl_ip-a_v4",
            is_ipv6=False,
            is_oscars=False,
            oscars_id=None,
            resource_uri="",
            site="anl",
            site_device="noni",
            site_interface="et-1/0/0",
            stats_type="Standard",
            title=None,
            columns=["time", "in", "out"],
            points=[
                [1400425947000, 52, 34],
                [1400425948000, 18, 13],
                [1400425949000, 26, 67],
                [1400425950000, 93, 91]
            ]
        )

        series = TimeSeries(interface_series)

        wire = self._call_interop_script('event', series.to_string())

        new_series = TimeSeries(wire)
        new_json = new_series.to_json()

        self._validate_wire_points(interface_series, new_json)

        # Now with a list of events

        event_objects = [
            Event(1429673400000, {'in': 1, 'out': 2}),
            Event(1429673460000, {'in': 3, 'out': 4}),
            Event(1429673520000, {'in': 5, 'out': 6}),
        ]

        series = TimeSeries(dict(name='events', events=event_objects))

        wire = self._call_interop_script('event', series.to_string())

        new_series = TimeSeries(wire)

        for i in enumerate(event_objects):
            self.assertTrue(Event.same(i[1], new_series.at(i[0])))
Пример #6
0
    def test_rename(self):
        """Test the renamer facility."""

        # rename an Event series

        ts = copy.deepcopy(self._canned_event_series)

        renamed = ts.rename_columns({'in': 'new_in', 'out': 'new_out'})

        self.assertEqual(
            renamed.at(0).get('new_in'),
            self._canned_event_series.at(0).get('in')
        )
        self.assertEqual(
            renamed.at(0).get('new_out'),
            self._canned_event_series.at(0).get('out')
        )

        self.assertEqual(
            renamed.at(1).get('new_in'),
            self._canned_event_series.at(1).get('in')
        )
        self.assertEqual(
            renamed.at(1).get('new_out'),
            self._canned_event_series.at(1).get('out')
        )

        self.assertEqual(
            renamed.at(2).get('new_in'),
            self._canned_event_series.at(2).get('in')
        )

        self.assertEqual(
            renamed.at(2).get('new_out'),
            self._canned_event_series.at(2).get('out')
        )

        # rename a TimeRangeEvent series

        ts = TimeSeries(TICKET_RANGE)

        renamed = ts.rename_columns({'title': 'event', 'esnet_ticket': 'ticket'})

        self.assertEqual(renamed.at(0).get('event'), ts.at(0).get('title'))
        self.assertEqual(renamed.at(0).get('ticket'), ts.at(0).get('esnet_ticket'))

        self.assertEqual(renamed.at(1).get('event'), ts.at(1).get('title'))
        self.assertEqual(renamed.at(1).get('ticket'), ts.at(1).get('esnet_ticket'))

        self.assertEqual(renamed.at(0).timestamp(), ts.at(0).timestamp())
        self.assertEqual(renamed.at(1).timestamp(), ts.at(1).timestamp())

        # rename and IndexedEvent series

        ts = TimeSeries(AVAILABILITY_DATA)

        renamed = ts.rename_columns(dict(uptime='available'))
        self.assertEqual(renamed.at(0).get('available'), ts.at(0).get('uptime'))
        self.assertEqual(renamed.at(2).get('available'), ts.at(2).get('uptime'))
        self.assertEqual(renamed.at(4).get('available'), ts.at(4).get('uptime'))
        self.assertEqual(renamed.at(6).get('available'), ts.at(6).get('uptime'))

        self.assertEqual(renamed.at(0).timestamp(), ts.at(0).timestamp())
        self.assertEqual(renamed.at(1).timestamp(), ts.at(1).timestamp())
        self.assertEqual(renamed.at(2).timestamp(), ts.at(2).timestamp())
Пример #7
0
    def test_event_series(self):
        """test a series that contains basic event objects."""
        event_series = dict(name="traffic",
                            columns=["time", "value", "status"],
                            points=[[1400425947000, 52, "ok"],
                                    [1400425948000, 18, "ok"],
                                    [1400425949000, 26, "fail"],
                                    [1400425950000, 93, "offline"]])

        series = TimeSeries(event_series)

        wire = self._call_interop_script('event', series.to_string())

        new_series = TimeSeries(wire)
        new_json = new_series.to_json()

        self._validate_wire_points(event_series, new_json)
        self.assertTrue(new_json.get('utc'))

        # try something a bit fancier with different types
        interface_series = dict(
            name="star-cr5:to_anl_ip-a_v4",
            description="star-cr5->anl(as683):100ge:site-ex:show:intercloud",
            device="star-cr5",
            id=169,
            interface="to_anl_ip-a_v4",
            is_ipv6=False,
            is_oscars=False,
            oscars_id=None,
            resource_uri="",
            site="anl",
            site_device="noni",
            site_interface="et-1/0/0",
            stats_type="Standard",
            title=None,
            columns=["time", "in", "out"],
            points=[[1400425947000, 52, 34], [1400425948000, 18, 13],
                    [1400425949000, 26, 67], [1400425950000, 93, 91]])

        series = TimeSeries(interface_series)

        wire = self._call_interop_script('event', series.to_string())

        new_series = TimeSeries(wire)
        new_json = new_series.to_json()

        self._validate_wire_points(interface_series, new_json)

        # Now with a list of events

        event_objects = [
            Event(1429673400000, {
                'in': 1,
                'out': 2
            }),
            Event(1429673460000, {
                'in': 3,
                'out': 4
            }),
            Event(1429673520000, {
                'in': 5,
                'out': 6
            }),
        ]

        series = TimeSeries(dict(name='events', events=event_objects))

        wire = self._call_interop_script('event', series.to_string())

        new_series = TimeSeries(wire)

        for i in enumerate(event_objects):
            self.assertTrue(Event.same(i[1], new_series.at(i[0])))
Пример #8
0
    def test_rename(self):
        """Test the renamer facility."""

        # rename an Event series

        ts = copy.deepcopy(self._canned_event_series)

        renamed = ts.rename_columns({'in': 'new_in', 'out': 'new_out'})

        self.assertEqual(
            renamed.at(0).get('new_in'),
            self._canned_event_series.at(0).get('in'))
        self.assertEqual(
            renamed.at(0).get('new_out'),
            self._canned_event_series.at(0).get('out'))

        self.assertEqual(
            renamed.at(1).get('new_in'),
            self._canned_event_series.at(1).get('in'))
        self.assertEqual(
            renamed.at(1).get('new_out'),
            self._canned_event_series.at(1).get('out'))

        self.assertEqual(
            renamed.at(2).get('new_in'),
            self._canned_event_series.at(2).get('in'))

        self.assertEqual(
            renamed.at(2).get('new_out'),
            self._canned_event_series.at(2).get('out'))

        # rename a TimeRangeEvent series

        ts = TimeSeries(TICKET_RANGE)

        renamed = ts.rename_columns({
            'title': 'event',
            'esnet_ticket': 'ticket'
        })

        self.assertEqual(renamed.at(0).get('event'), ts.at(0).get('title'))
        self.assertEqual(
            renamed.at(0).get('ticket'),
            ts.at(0).get('esnet_ticket'))

        self.assertEqual(renamed.at(1).get('event'), ts.at(1).get('title'))
        self.assertEqual(
            renamed.at(1).get('ticket'),
            ts.at(1).get('esnet_ticket'))

        self.assertEqual(renamed.at(0).timestamp(), ts.at(0).timestamp())
        self.assertEqual(renamed.at(1).timestamp(), ts.at(1).timestamp())

        # rename and IndexedEvent series

        ts = TimeSeries(AVAILABILITY_DATA)

        renamed = ts.rename_columns(dict(uptime='available'))
        self.assertEqual(
            renamed.at(0).get('available'),
            ts.at(0).get('uptime'))
        self.assertEqual(
            renamed.at(2).get('available'),
            ts.at(2).get('uptime'))
        self.assertEqual(
            renamed.at(4).get('available'),
            ts.at(4).get('uptime'))
        self.assertEqual(
            renamed.at(6).get('available'),
            ts.at(6).get('uptime'))

        self.assertEqual(renamed.at(0).timestamp(), ts.at(0).timestamp())
        self.assertEqual(renamed.at(1).timestamp(), ts.at(1).timestamp())
        self.assertEqual(renamed.at(2).timestamp(), ts.at(2).timestamp())