def test_port_stats(self): """Check the update method of the GaugePortStatsInfluxDBLogger class""" conf = self.create_config_obj(create_mock_datapath(2)) db_logger = gauge_influx.GaugePortStatsInfluxDBLogger( conf, '__name__', mock.Mock()) db_logger._running = True msg = port_stats_msg(conf.dp) rcv_time = int(time.time()) db_logger.update(rcv_time, msg) with open(self.server.output_file, 'r', encoding='utf-8') as log: output = log.readlines() for line in output: measurement, influx_data = self.parse_influx_output(line) # get the number at the end of the port_name port_num = influx_data['port_name'] # pytype: disable=unsupported-operands # get the original port stat value port_stat_val = logger_to_ofp(msg.body[port_num - 1])[measurement] # pytype: disable=unsupported-operands self.assertEqual(port_stat_val, influx_data['value']) self.assertEqual(conf.dp.name, influx_data['dp_name']) self.assertEqual(rcv_time, influx_data['timestamp'])
def test_port_stats(self): """Check the update method of the GaugePortStatsInfluxDBLogger class""" conf = self.create_config_obj(create_mock_datapath(2)) db_logger = gauge_influx.GaugePortStatsInfluxDBLogger( conf, '__name__', mock.Mock()) port_stats = [ parser.OFPPortStats(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 100, 50), parser.OFPPortStats(2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 100, 50) ] message = parser.OFPPortStatsReply(conf.dp, body=port_stats) rcv_time = int(time.time()) db_logger.update(rcv_time, conf.dp.id, message) self.server.output_file.seek(0) for line in self.server.output_file.readlines(): measurement, influx_data = self.parse_influx_output(line) #get the number at the end of the port_name port_num = int(influx_data['port_name'][-1]) #get the original port stat value port_stat_val = self.get_stats(measurement, port_stats[port_num - 1]) self.assertEqual(port_stat_val, influx_data['value']) self.assertEqual(conf.dp.name, influx_data['dp_name']) self.assertEqual(rcv_time, influx_data['timestamp'])