def test_result_answer(self, count): fetcher_payload = AgentResultMessage(AgentRawData(69 * b"\xff")) fetcher_stats = ResultStats(Snapshot.null()) fetcher_message = FetcherMessage( FetcherHeader( FetcherType.TCP, PayloadType.AGENT, status=42, payload_length=len(fetcher_payload), stats_length=len(fetcher_stats), ), fetcher_payload, fetcher_stats, ) fetcher_messages = list(repeat(fetcher_message, count)) timeout = 7 message = CMCMessage.result_answer(fetcher_messages, timeout, Snapshot.null()) assert isinstance(repr(message), str) assert CMCMessage.from_bytes(bytes(message)) == message assert message.header.name == "fetch" assert message.header.state == CMCHeader.State.RESULT assert message.header.log_level.strip() == "" assert message.header.payload_length == len(message) - len( message.header) assert message.header.payload_length == len(message.payload)
def test_log_answer(self): log_message = "the log message" level = logging.WARN message = CMCMessage.log_answer(log_message, level) assert CMCMessage.from_bytes(bytes(message)) == message assert message.header.name == "fetch" assert message.header.state == CMCHeader.State.LOG assert message.header.log_level.strip() == "warning" assert message.header.payload_length == len(message) - len( message.header) assert message.header.payload_length == len(log_message)
def test_result_answer(self, fetcher_message, count): fetcher_messages = list(repeat(fetcher_message, count)) message = CMCMessage.result_answer(*fetcher_messages) assert CMCMessage.from_bytes(bytes(message)) == message assert len(fetcher_messages) == count assert message.header.name == "fetch" assert message.header.state == CMCHeader.State.RESULT assert message.header.log_level.strip() == "" assert message.header.payload_length == len(message) - len( message.header) assert message.header.payload_length == count * len(fetcher_message) assert not set(message.payload) ^ set(fetcher_messages)
def test_serialization(self, count): fetcher_payload = AgentResultMessage(AgentRawData(69 * b"\xff")) fetcher_stats = ResultStats(Snapshot.null()) fetcher_message = FetcherMessage( FetcherHeader( FetcherType.TCP, PayloadType.AGENT, status=42, payload_length=len(fetcher_payload), stats_length=len(fetcher_stats), ), fetcher_payload, fetcher_stats, ) fetcher_messages = list(repeat(fetcher_message, count)) serial = 1337 host_name = "my_host_name" timeout = 7 message = CMCMessage.result_answer( fetcher_messages, serial=serial, host_name=host_name, timeout=timeout, duration=Snapshot.null(), ) other = CMCMessage.from_bytes(bytes(message)) assert other == message assert isinstance(repr(other), str) assert other.header.name == "fetch" assert other.header.state == CMCHeader.State.RESULT assert other.header.log_level.strip() == "" assert other.header.payload_length == len(message) - len( message.header) assert other.header.payload_length == len(message.payload) assert isinstance(other.payload, CMCResults) assert other.payload.id_.serial == serial assert other.payload.id_.host_name == host_name assert other.payload.stats.timeout == timeout assert other.payload.stats.duration == Snapshot.null()
def test_from_bytes(self, eor): assert CMCMessage.from_bytes(bytes(eor)) is eor
def eor(self): return CMCMessage.end_of_reply()
def test_end_of_reply(self): message = CMCMessage.end_of_reply() assert isinstance(repr(message), str) assert CMCMessage.from_bytes(bytes(message)) is message
def test_controller_end_of_reply(self): assert CMCMessage.end_of_reply() == b"fetch:ENDREPL: :0 :"
def test_controller_log(self): assert CMCMessage.log_answer( "payload", logging.WARNING, ) == b"fetch:LOG :warning :7 :payload"
def test_end_of_reply(self): assert CMCMessage.end_of_reply() is CMCMessage.end_of_reply()
def test_from_bytes(self, message): assert CMCMessage.from_bytes(bytes(message)) == message
def message(self, header, fetcher_message): return CMCMessage(header, fetcher_message)