def orchestration_restore(self, context, saved_artifact_info, custom_params): """ :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside :param saved_artifact_info: OrchestrationSavedArtifactInfo json :param custom_params: json with custom restore parameters """ 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) cli_handler = self._cli.get_cli_handler(resource_config, logger) configuration_flow = ConfigurationFlow(cli_handler=cli_handler, logger=logger, resource_config=resource_config) logger.info('Orchestration restore started') restore_params = OrchestrationSaveRestore(logger, resource_config.name).parse_orchestration_save_result( saved_artifact_info) configuration_flow.restore(**restore_params) logger.info('Orchestration restore completed')
def orchestration_save(self, context, mode, custom_params): """ :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside :param mode: mode :param custom_params: json with custom save parameters :return str response: response json """ if not mode: mode = 'shallow' 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) cli_handler = self._cli.get_cli_handler(resource_config, logger) configuration_flow = ConfigurationFlow(cli_handler=cli_handler, logger=logger, resource_config=resource_config) logger.info('Orchestration save started') response = configuration_flow.orchestration_save(mode=mode, custom_params=custom_params) response_json = OrchestrationSaveRestore(logger, resource_config.name).prepare_orchestration_save_result( response) logger.info('Orchestration save completed') return response_json
def restore(self, context, path, configuration_type, restore_method, vrf_management_name): """Restore selected file to the provided destination :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside :param path: source config file :param configuration_type: running or startup configs :param restore_method: append or override methods :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 configuration_type: configuration_type = 'running' if not restore_method: restore_method = 'override' if not vrf_management_name: vrf_management_name = resource_config.vrf_management_name cli_handler = self._cli.get_cli_handler(resource_config, logger) configuration_flow = ConfigurationFlow(cli_handler=cli_handler, logger=logger, resource_config=resource_config) logger.info('Restore started') configuration_flow.restore(path=path, restore_method=restore_method, configuration_type=configuration_type, vrf_management_name=vrf_management_name) logger.info('Restore completed')
def save(self, context, folder_path, configuration_type, vrf_management_name): """Save selected file to the provided destination :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside :param configuration_type: source file, which will be saved :param folder_path: destination path where file will be saved :param vrf_management_name: VRF management Name :return str saved configuration file 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 configuration_type: configuration_type = 'running' if not vrf_management_name: vrf_management_name = resource_config.vrf_management_name cli_handler = self._cli.get_cli_handler(resource_config, logger) configuration_flow = ConfigurationFlow(cli_handler=cli_handler, logger=logger, resource_config=resource_config) logger.info('Save started') response = configuration_flow.save(folder_path=folder_path, configuration_type=configuration_type, vrf_management_name=vrf_management_name) logger.info('Save completed') return response
class TestCiscoSaveConfigurationFlow(TestCase): PATH = "ftp://*****:*****@10.10.10.10/CloudShell/config" def setUp(self): cli = MagicMock() logger = MagicMock() self.handler = CiscoConfigurationFlow(cli, MagicMock(), logger) @patch("cloudshell.networking.cisco.flows.cisco_configuration_flow.SystemActions") def test_restore_append_startup(self, sys_actions_mock): copy_mock = MagicMock() sys_actions_mock.return_value.copy = copy_mock configuration_type = "startup" restore_method = "append" vrf_management_name = MagicMock() self.handler._restore_flow( self.PATH, configuration_type, restore_method, vrf_management_name ) copy_mock.assert_called_once() @patch("cloudshell.networking.cisco.flows.cisco_configuration_flow.SystemActions") def test_restore_append_running(self, sys_actions_mock): copy_mock = MagicMock() sys_actions_mock.return_value.copy = copy_mock configuration_type = "running" restore_method = "append" vrf_management_name = MagicMock() self.handler._restore_flow( self.PATH, configuration_type, restore_method, vrf_management_name ) copy_mock.assert_called_once() @patch("cloudshell.networking.cisco.flows.cisco_configuration_flow.SystemActions") def test_restore_override_startup(self, sys_actions_mock): delete_mock = MagicMock() copy_mock = MagicMock() sys_actions_mock.return_value.delete_file = delete_mock sys_actions_mock.return_value.copy = copy_mock configuration_type = "startup" restore_method = "override" vrf_management_name = MagicMock() self.handler._restore_flow( self.PATH, configuration_type, restore_method, vrf_management_name ) delete_mock.assert_called_once() copy_mock.assert_called_once() @patch("cloudshell.networking.cisco.flows.cisco_configuration_flow.SystemActions") def test_restore_override_running(self, sys_actions_mock): override_running_mock = MagicMock() sys_actions_mock.return_value.override_running = override_running_mock configuration_type = "running" restore_method = "override" vrf_management_name = MagicMock() self.handler._restore_flow( self.PATH, configuration_type, restore_method, vrf_management_name ) override_running_mock.assert_called_once()
def _get_handler(self, output): cli = MagicMock() self.session = MagicMock() self.session.send_command.return_value = output cliservice = MagicMock() cliservice.__enter__.return_value = self.session cli.get_cli_service.return_value = cliservice logger = MagicMock() return CiscoConfigurationFlow(cli, MagicMock(), logger)
def setUp(self): cli = MagicMock() logger = MagicMock() self.handler = CiscoConfigurationFlow(cli, MagicMock(), logger)