def _post_send_config( self, config: str, multi_response: MultiResponse, ) -> Response: """ Handle post "send_config" tasks for consistency between sync/async versions Args: config: string configuration to send to the device, supports sending multi-line strings multi_response: multi_response object send_config got from calling self.send_configs; we need this to parse out the multi_response back into a single Response object Returns: Response: Unified response object Raises: N/A """ # capture failed_when_contains and host from zeroith multi_response element (there should # always be at least a zeroith element here!); getting host just lets us keep the mixin # class a little cleaner without having to deal with sync vs async transport classes from # a typing perspective failed_when_contains = multi_response[0].failed_when_contains host = multi_response[0].host # create a new unified response object response = Response( host=host, channel_input=config, failed_when_contains=failed_when_contains, ) response.start_time = multi_response[0].start_time response.finish_time = datetime.now() response.elapsed_time = (response.finish_time - response.start_time).total_seconds() # join all the results together into a single final result response.result = "\n".join(response.result for response in multi_response) response.failed = False if any(r.failed for r in multi_response): response.failed = True self._update_response(response=response) return response
def test_pre_and_post_clear_config_sessions(eos_base_cfg_object, dummy_logger): eos_base_cfg_object.logger = dummy_logger eos_base_cfg_object.conn = Scrapli(host="localhost", platform="arista_eos") pre_response = eos_base_cfg_object._pre_clear_config_sessions() assert isinstance(pre_response, ScrapliCfgResponse) scrapli_response = Response(host="localhost", channel_input="diff a config") post_response = eos_base_cfg_object._post_clear_config_sessions( response=pre_response, scrapli_responses=[scrapli_response]) assert post_response.result == "failed to clear device configuration session(s)" scrapli_response.failed = False post_response = eos_base_cfg_object._post_clear_config_sessions( response=pre_response, scrapli_responses=[scrapli_response]) assert post_response.result == "configuration session(s) cleared"