def get_inventory(self, context): """Return device structure with all standard attributes :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside :return: response :rtype: str """ 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) cli_handler = CliHandler(self._cli, resource_config, logger, api) snmp_handler = SNMPHandler(resource_config, logger, api, cli_handler) autoload_operations = AutoloadRunner(logger=logger, resource_config=resource_config, snmp_handler=snmp_handler) logger.info('Autoload started') response = autoload_operations.discover() logger.info('Autoload completed') return response
def setUp(self): self._logger = MagicMock() self._snmp_handler = MagicMock() resource_config = MagicMock() self._handler = CiscoAutoloadRunner(logger=self._logger, snmp_handler=self._snmp_handler, resource_config=resource_config)
def get_inventory(self, context): """Return device structure with all standard attributes :param ResourceCommandContext context: ResourceCommandContext object with all Resource Attributes inside :return: response :rtype: str """ 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 "true" in resource_config.enable_snmp.lower() and "3" in resource_config.snmp_version: raise Exception("Enabling of snmp v3 is not supported") cli_handler = CliHandler(self._cli, resource_config, logger, api) snmp_handler = SNMPHandler(resource_config, logger, api, cli_handler) autoload_operations = AutoloadRunner(logger=logger, resource_config=resource_config, snmp_handler=snmp_handler) logger.info('Autoload started') response = autoload_operations.discover() logger.info('Autoload completed') return response
class TestCiscoAutoloadRunner(TestCase): def setUp(self): self._logger = MagicMock() self._snmp_handler = MagicMock() resource_config = MagicMock() self._handler = CiscoAutoloadRunner(logger=self._logger, snmp_handler=self._snmp_handler, resource_config=resource_config) def test_discover(self): with patch( "cloudshell.networking.cisco.runners.cisco_autoload_runner.CiscoSnmpAutoloadFlow" ) as flow_mock: self._handler.discover() flow_mock.assert_called_once_with(self._snmp_handler, self._logger)