def load_firmware(self, context, path, vrf_management_name):
        """Upload and updates firmware on the resource

        :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside
        :param path: full path to firmware file, i.e. tftp://10.10.10.1/firmware.tar
        :param vrf_management_name: VRF management Name
        """

        logger = LoggingSessionContext.get_logger_with_thread_id(context)
        api = CloudShellSessionContext(context).get_api()

        resource_config = NetworkingResourceConfig.from_context(shell_name=self.SHELL_NAME,
                                                                supported_os=self.SUPPORTED_OS,
                                                                context=context, api=api)

        if not vrf_management_name:
            vrf_management_name = resource_config.vrf_management_name

        cli_handler = self._cli.get_cli_handler(resource_config, logger)

        logger.info('Start Load Firmware')
        firmware_operations = FirmwareFlow(cli_handler=cli_handler,
                                           logger=logger)
        response = firmware_operations.load_firmware(path=path,
                                                     vrf_management_name=vrf_management_name)
        logger.info('Finish Load Firmware: {}'.format(response))
Exemplo n.º 2
0
    def load_firmware(
        self, context: ResourceCommandContext, path: str, vrf_management_name: str
    ):
        """Upload and updates firmware on the resource."""
        with LoggingSessionContext(context) as logger:
            logger.info("Starting 'Load Firmware' command ...")
            api = CloudShellSessionContext(context).get_api()

            resource_config = NetworkingResourceConfig.from_context(
                shell_name=self.SHELL_NAME,
                supported_os=self.SUPPORTED_OS,
                context=context,
                api=api,
            )

            vrf_management_name = (
                vrf_management_name or resource_config.vrf_management_name
            )
            cli_handler = self._cli.get_cli_handler(resource_config, logger)

            firmware_operations = CiscoLoadFirmwareFlow(
                cli_handler=cli_handler, logger=logger
            )
            firmware_operations.load_firmware(
                path=path, vrf_management_name=vrf_management_name
            )
            logger.info("'Load Firmware' command completed")
Exemplo n.º 3
0
class TestCiscoLoadFirmwareFlow(TestCase):
    def setUp(self):
        self.firmware_flow = CiscoLoadFirmwareFlow(MagicMock(), MagicMock())

    @patch(
        "cloudshell.networking.cisco.flows.cisco_load_firmware_flow.SystemActions"
    )
    def test_execute_flow(self, sys_actions_mock):
        sys_actions_mock.return_value.get_current_boot_config.side_effect = [
            "filename.bin", "filename.bin"
        ]
        self.firmware_flow.execute_flow("filename.bin", "", "")

        sys_actions_mock.return_value.get_flash_folders_list.assert_called_once(
        )
        sys_actions_mock.return_value.get_current_boot_image.assert_called()
        sys_actions_mock.return_value.copy.assert_called_once()
        sys_actions_mock.return_value.get_current_boot_config.assert_called_once(
        )

    @patch(
        "cloudshell.networking.cisco.flows.cisco_load_firmware_flow.FirmwareActions"
    )
    def test_apply_firmware(self, fw_actions_mock):
        old_firmware = "flash:/oldfirmware.bin"
        new_firmware = "flash:/filename.bin"
        self.firmware_flow._apply_firmware(enable_session=MagicMock(),
                                           current_boot=[old_firmware],
                                           firmware_dst_path=new_firmware)

        fw_actions_mock.return_value.clean_boot_config.assert_called_once()
        fw_actions_mock.return_value.add_boot_config_file.assert_called_once_with(
            new_firmware)
        fw_actions_mock.return_value.add_boot_config.assert_called_once_with(
            old_firmware)
 def load_firmware_flow(self):
     return CiscoLoadFirmwareFlow(self.cli_handler, self._logger)
Exemplo n.º 5
0
 def setUp(self):
     self.firmware_flow = CiscoLoadFirmwareFlow(MagicMock(), MagicMock())