def test_indexed_event_series(self): """test a series of IndexedEvent objects.""" indexed_event_series = dict( name="availability", columns=["index", "uptime"], points=[ ["2014-07", "100%"], ["2014-08", "88%"], ["2014-09", "95%"], ["2014-10", "99%"], ["2014-11", "91%"], ["2014-12", "99%"], ["2015-01", "100%"], ["2015-02", "92%"], ["2015-03", "99%"], ["2015-04", "87%"], ["2015-05", "92%"], ["2015-06", "100%"], ] ) series = TimeSeries(indexed_event_series) wire = self._call_interop_script('indexed_event', series.to_string()) new_series = TimeSeries(wire) new_json = new_series.to_json() self._validate_wire_points(indexed_event_series, new_json) self.assertTrue(new_json.get('utc')) # again with more involved data availability_series = dict( name="availability", columns=["index", "uptime", "notes", "outages"], points=[ ["2014-08", 88, "", 17], ["2014-09", 100, "", 2], ["2014-09", 95, "", 6], ["2014-10", 99, "", 3], ["2014-11", 91, "", 14], ["2014-12", 99, "", 3], ["2015-01", 100, "", 0], ["2015-02", 92, "", 12], ["2015-03", 99, "Minor outage March 2", 4], ["2015-04", 87, "Planned downtime in April", 82], ["2015-05", 92, "Router failure June 12", 26], ["2015-06", 100, "", 0], ] ) series = TimeSeries(availability_series) wire = self._call_interop_script('indexed_event', series.to_string()) new_series = TimeSeries(wire) new_json = new_series.to_json() self._validate_wire_points(availability_series, new_json)
def test_indexed_event_series(self): """test a series of IndexedEvent objects.""" indexed_event_series = dict(name="availability", columns=["index", "uptime"], points=[ ["2014-07", "100%"], ["2014-08", "88%"], ["2014-09", "95%"], ["2014-10", "99%"], ["2014-11", "91%"], ["2014-12", "99%"], ["2015-01", "100%"], ["2015-02", "92%"], ["2015-03", "99%"], ["2015-04", "87%"], ["2015-05", "92%"], ["2015-06", "100%"], ]) series = TimeSeries(indexed_event_series) wire = self._call_interop_script('indexed_event', series.to_string()) new_series = TimeSeries(wire) new_json = new_series.to_json() self._validate_wire_points(indexed_event_series, new_json) self.assertTrue(new_json.get('utc')) # again with more involved data availability_series = dict( name="availability", columns=["index", "uptime", "notes", "outages"], points=[ ["2014-08", 88, "", 17], ["2014-09", 100, "", 2], ["2014-09", 95, "", 6], ["2014-10", 99, "", 3], ["2014-11", 91, "", 14], ["2014-12", 99, "", 3], ["2015-01", 100, "", 0], ["2015-02", 92, "", 12], ["2015-03", 99, "Minor outage March 2", 4], ["2015-04", 87, "Planned downtime in April", 82], ["2015-05", 92, "Router failure June 12", 26], ["2015-06", 100, "", 0], ]) series = TimeSeries(availability_series) wire = self._call_interop_script('indexed_event', series.to_string()) new_series = TimeSeries(wire) new_json = new_series.to_json() self._validate_wire_points(availability_series, new_json)
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)
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)
def test_timerange_event_series(self): """test a series with a TimerangeEvent objects.""" timerange_event_series = dict( name="outages", columns=["timerange", "title", "esnet_ticket"], points=[ [[1429673400000, 1429707600000], "BOOM", "ESNET-20080101-001"], [[1429673400000, 1429707600000], "BAM!", "ESNET-20080101-002"], ], ) series = TimeSeries(timerange_event_series) wire = self._call_interop_script('time_range_event', series.to_string()) new_series = TimeSeries(wire) new_json = new_series.to_json() self._validate_wire_points(timerange_event_series, new_json) self.assertTrue(new_json.get('utc')) self.assertEqual(timerange_event_series.get('name'), new_json.get('name'))
def test_event_series_with_index(self): """test indexed data, not a series of IndexedEvent.""" event_series_with_index = dict(index="1d-625", name="traffic", columns=["time", "value", "status"], points=[[1400425947000, 522, "ok"], [1400425948000, 183, "ok"], [1400425949000, 264, "fail"], [1400425950000, 935, "offline"]]) series = TimeSeries(event_series_with_index) 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_with_index, new_json) self.assertTrue(new_json.get('utc')) self.assertEqual(event_series_with_index.get('index'), new_json.get('index'))
def test_timerange_event_series(self): """test a series with a TimerangeEvent objects.""" timerange_event_series = dict( name="outages", columns=["timerange", "title", "esnet_ticket"], points=[ [[1429673400000, 1429707600000], "BOOM", "ESNET-20080101-001"], [[1429673400000, 1429707600000], "BAM!", "ESNET-20080101-002"], ], ) series = TimeSeries(timerange_event_series) wire = self._call_interop_script('time_range_event', series.to_string()) new_series = TimeSeries(wire) new_json = new_series.to_json() self._validate_wire_points(timerange_event_series, new_json) self.assertTrue(new_json.get('utc')) self.assertEqual(timerange_event_series.get('name'), new_json.get('name'))
def test_event_series_with_index(self): """test indexed data, not a series of IndexedEvent.""" event_series_with_index = dict( index="1d-625", name="traffic", columns=["time", "value", "status"], points=[ [1400425947000, 522, "ok"], [1400425948000, 183, "ok"], [1400425949000, 264, "fail"], [1400425950000, 935, "offline"] ] ) series = TimeSeries(event_series_with_index) 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_with_index, new_json) self.assertTrue(new_json.get('utc')) self.assertEqual(event_series_with_index.get('index'), new_json.get('index'))
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])))
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])))