def test_port_state(self): """ Check the update method of the GaugePortStateInfluxDBLogger class""" conf = self.create_config_obj(create_mock_datapath(3)) db_logger = gauge_influx.GaugePortStateInfluxDBLogger( conf, '__name__', mock.Mock()) db_logger._running = True reasons = [ ofproto.OFPPR_ADD, ofproto.OFPPR_DELETE, ofproto.OFPPR_MODIFY ] for i in range(1, len(conf.dp.ports) + 1): msg = port_state_msg(conf.dp, i, reasons[i - 1]) 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.read() influx_data = self.parse_influx_output(output)[1] data = { conf.dp.name, conf.dp.ports[i].name, rcv_time, reasons[i - 1] } self.assertEqual(data, set(influx_data.values()))
def test_port_state(self): """ Check the update method of the GaugePortStateInfluxDBLogger class""" conf = self.create_config_obj(create_mock_datapath(3)) db_logger = gauge_influx.GaugePortStateInfluxDBLogger( conf, '__name__', mock.Mock()) statuses = [ ofproto.OFPPR_ADD, ofproto.OFPPR_DELETE, ofproto.OFPPR_MODIFY ] for i in range(1, len(conf.dp.ports) + 1): port = parser.OFPPort(i, '00:00:00:d0:00:0' + str(i), conf.dp.ports[i].name, 0, 0, i, i, i, i, i, i) message = parser.OFPPortStatus(conf.dp.id, statuses[i - 1], port) rcv_time = int(time.time()) db_logger.update(rcv_time, conf.dp.id, message) self.server.output_file.seek(0) output = self.server.output_file.readlines()[i - 1] influx_data = self.parse_influx_output(output)[1] data = { conf.dp.name, conf.dp.ports[i].name, rcv_time, statuses[i - 1] } self.assertEqual(data, set(influx_data.values()))