Esempio n. 1
0
    def _post_clear_config_sessions(
        self,
        response: ScrapliCfgResponse,
        scrapli_responses: Iterable[Response],
    ) -> ScrapliCfgResponse:
        """
        Handle post "clear_config_sessions" operations for parity between sync and async

        Args:
            response: response object to update
            scrapli_responses: list of scrapli response objects from fetching the version

        Returns:
            ScrapliCfgResponse: response object containing string of the version as the `result`
                attribute

        Raises:
            N/A

        """
        response.record_response(scrapli_responses=scrapli_responses)

        if response.failed:
            msg = "failed to clear device configuration session(s)"
            self.logger.critical(msg)
            response.result = msg
        else:
            response.result = "configuration session(s) cleared"

        return response
Esempio n. 2
0
    def _post_commit_config(
        self,
        response: ScrapliCfgResponse,
        scrapli_responses: List[Union[Response, MultiResponse]],
    ) -> ScrapliCfgResponse:
        """
        Handle post "commit_config" operations for parity between sync and async

        Args:
            response: response object to update
            scrapli_responses: list of scrapli response objects from committing the config

        Returns:
            ScrapliCfgResponse: response object

        Raises:
            N/A

        """
        response.record_response(scrapli_responses=scrapli_responses)

        if response.failed:
            msg = "failed to commit config"
            self.logger.critical(msg)

        return response
Esempio n. 3
0
    def _post_get_config(
        self,
        response: ScrapliCfgResponse,
        source: str,
        scrapli_responses: List[Union[Response, MultiResponse]],
        result: str,
    ) -> ScrapliCfgResponse:
        """
        Handle post "get_config" operations for parity between sync and async

        Args:
            response: response object to update
            source: name of the config source, generally running|startup
            scrapli_responses: list of scrapli response objects from fetching the config
            result: final string of the "get_config" result

        Returns:
            ScrapliCfgResponse: response object containing string of the target config source as the
                `result` attribute

        Raises:
            N/A

        """
        response.record_response(scrapli_responses=scrapli_responses,
                                 result=result)

        if response.failed:
            msg = f"failed to get {source} config"
            self.logger.critical(msg)

        return response
Esempio n. 4
0
    def _post_get_version(
        self,
        response: ScrapliCfgResponse,
        scrapli_responses: List[Response],
        result: str,
    ) -> ScrapliCfgResponse:
        """
        Handle post "get_version" operations for parity between sync and async

        Args:
            response: response object to update
            scrapli_responses: list of scrapli response objects from fetching the version
            result: final version string of the device

        Returns:
            ScrapliCfgResponse: response object containing string of the version as the `result`
                attribute

        Raises:
            N/A

        """
        response.record_response(scrapli_responses=scrapli_responses,
                                 result=result)

        if response.failed:
            msg = "failed to get version from device"
            self.logger.critical(msg)

        return response
Esempio n. 5
0
def test_validate_and_set_version_failed_to_parse(base_cfg_object):
    failed_to_parse_version_response = ScrapliCfgResponse(host="localhost")
    failed_to_parse_version_response.record_response(scrapli_responses=[],
                                                     result="")
    with pytest.raises(VersionError):
        base_cfg_object._validate_and_set_version(
            version_response=failed_to_parse_version_response)
Esempio n. 6
0
def test_validate_and_set_version(base_cfg_object):
    assert base_cfg_object._version_string == ""
    version_response = ScrapliCfgResponse(host="localhost")
    version_response.record_response(scrapli_responses=[], result="1.2.3")
    base_cfg_object._validate_and_set_version(
        version_response=version_response)
    assert base_cfg_object._version_string == "1.2.3"