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 """ if not configuration_type: configuration_type = 'running' if not restore_method: restore_method = 'override' if not vrf_management_name: vrf_management_name = get_attribute_by_name( context=context, attribute_name='VRF Management Name') logger = get_logger_with_thread_id(context) api = get_api(context) configuration_operations = ConfigurationRunner(logger=logger, api=api, cli=self._cli, context=context) logger.info('Restore started') configuration_operations.restore( path=path, restore_method=restore_method, configuration_type=configuration_type, vrf_management_name=vrf_management_name) logger.info('Restore completed')
class TestCiscoConfigurationRunner(TestCase): TEST_NAME = "resource_name" def setUp(self): self._logger = MagicMock() self._cli_handler = MagicMock() self._resource_config = MagicMock() self._resource_config.name = self.TEST_NAME self._handler = CiscoConfigurationRunner( logger=self._logger, cli_handler=self._cli_handler, resource_config=self._resource_config, api=MagicMock()) def test_save(self): with patch( "cloudshell.networking.cisco.runners.cisco_configuration_runner.CiscoSaveFlow" ) as save_mock: config_type = "running" result = self._handler.save("tftp://10.10.10.10", "running", "") self.assertEqual( "{}-{}-{}".format( self.TEST_NAME, config_type, time.strftime("%d%m%y-%H%M%S", time.localtime())), result) save_mock.assert_called_once_with(cli_handler=self._cli_handler, logger=self._logger) def test_restore(self): with patch( "cloudshell.networking.cisco.runners.cisco_configuration_runner.CiscoRestoreFlow" ) as restore_mock: self._handler.restore("tftp://10.10.10.10", "running", "", "") restore_mock.assert_called_once_with(cli_handler=self._cli_handler, logger=self._logger)
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 = get_logger_with_thread_id(context) api = get_api(context) resource_config = create_networking_resource_from_context( shell_name=self.SHELL_NAME, supported_os=self.SUPPORTED_OS, context=context) 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 = CliHandler(self._cli, resource_config, logger, api) configuration_operations = ConfigurationRunner( cli_handler=cli_handler, logger=logger, resource_config=resource_config, api=api) logger.info('Restore started') configuration_operations.restore( path=path, restore_method=restore_method, configuration_type=configuration_type, vrf_management_name=vrf_management_name) logger.info('Restore completed')