def test_publish_error(self): with mock.patch('socket.socket', self._make_broken_socket): publisher = udp.UDPPublisher( network_utils.urlsplit('udp://localhost')) publisher.publish_samples(None, self.test_data)
def test_published(self): self.data_sent = [] with mock.patch('socket.socket', self._make_fake_socket(self.data_sent)): publisher = udp.UDPPublisher(self.CONF, netutils.urlsplit('udp://somehost')) publisher.publish_samples(self.test_data) self.assertEqual(5, len(self.data_sent)) sent_counters = [] for data, dest in self.data_sent: counter = msgpack.loads(data, encoding="utf-8") sent_counters.append(counter) # Check destination self.assertEqual(('somehost', 4952), dest) # Check that counters are equal def sort_func(counter): return counter['counter_name'] counters = [ utils.meter_message_from_counter(d, "not-so-secret") for d in self.test_data ] counters.sort(key=sort_func) sent_counters.sort(key=sort_func) self.assertEqual(counters, sent_counters)
def test_published(self): self.data_sent = [] with mock.patch('socket.socket', self._make_fake_socket(self.data_sent)): publisher = udp.UDPPublisher( network_utils.urlsplit('udp://somehost')) publisher.publish_samples(None, self.test_data) self.assertEqual(5, len(self.data_sent)) sent_counters = [] for data, dest in self.data_sent: counter = msgpack.loads(data) sent_counters.append(counter) # Check destination self.assertEqual(('somehost', self.CONF.collector.udp_port), dest) # Check that counters are equal self.assertEqual(sorted( [utils.meter_message_from_counter(d, "not-so-secret") for d in self.test_data]), sorted(sent_counters))
def test_published(self): self.data_sent = [] with mock.patch('socket.socket', self._make_fake_socket(self.data_sent)): publisher = udp.UDPPublisher(urlparse.urlparse('udp://somehost')) publisher.publish_counters(None, self.test_data, self.COUNTER_SOURCE) self.assertEqual(len(self.data_sent), 5) sent_counters = [] for data, dest in self.data_sent: counter = msgpack.loads(data) self.assertEqual(counter['source'], self.COUNTER_SOURCE) # Remove source because our test Counters don't have it, so the # comparison would fail later del counter['source'] sent_counters.append(counter) # Check destination self.assertEqual(dest, ('somehost', cfg.CONF.collector.udp_port)) # Check that counters are equal self.assertEqual(sorted(sent_counters), sorted([dict(d._asdict()) for d in self.test_data]))
def test_published(self): self.data_sent = [] with mock.patch('socket.socket', self._make_fake_socket(self.data_sent)): publisher = udp.UDPPublisher( network_utils.urlsplit('udp://somehost')) publisher.publish_samples(None, self.test_data) self.assertEqual(len(self.data_sent), 5) sent_counters = [] for data, dest in self.data_sent: counter = msgpack.loads(data) sent_counters.append(counter) # Check destination self.assertEqual(dest, ('somehost', self.CONF.collector.udp_port)) # Check that counters are equal self.assertEqual(sorted(sent_counters), sorted([dict(d.as_dict()) for d in self.test_data]))
def _check_udp_socket(self, url, expected_addr_family): with mock.patch.object(socket, 'socket') as mock_socket: udp.UDPPublisher(self.CONF, netutils.urlsplit(url)) mock_socket.assert_called_with(expected_addr_family, socket.SOCK_DGRAM)
def test_publish_error(self): with mock.patch('socket.socket', self._make_broken_socket): publisher = udp.UDPPublisher(urlparse.urlparse('udp://localhost')) publisher.publish_counters(None, self.test_data, self.COUNTER_SOURCE)
def test_publish_error(self): with mock.patch('socket.socket', self._make_broken_socket): publisher = udp.UDPPublisher() publisher.publish_counters(None, self.test_data, self.COUNTER_SOURCE)