示例#1
0
    def test_get_snmp_engine(self, mock_config, mock_engine, mock_transport,
                             mock_security):
        logger = Mock()
        pysnmp_params = Mock()
        snmp = Snmp()

        snmp._get_snmp_engine(logger=logger, pysnmp_params=pysnmp_params)

        mock_engine.SnmpEngine.assert_called_once_with()
        mock_config.addTargetParams.assert_called_once_with(
            mock_engine.SnmpEngine.return_value,
            "pms",
            pysnmp_params.user,
            pysnmp_params.security,
            pysnmp_params.version,
        )
        mock_transport.assert_called_once_with(
            snmp_parameters=pysnmp_params.snmp_parameters, logger=logger)
        mock_transport.return_value.add_udp_endpoint.assert_called_once_with(
            mock_engine.SnmpEngine.return_value,
            snmp._snmp_timeout,
            snmp._snmp_retry_count,
        )
        mock_security.assert_called_once_with(py_snmp_params=pysnmp_params,
                                              logger=logger)
        mock_security.return_value.add_security.assert_called_once_with(
            mock_engine.SnmpEngine.return_value)
    def get_sys_desc(self):
        """

        :return:
        """
        with Snmp().get_snmp_service(snmp_parameters=self._snmp_params, logger=self._logger) as snmp_service:
            return snmp_service.get_property(SnmpMibObject("SNMPv2-MIB", "sysDescr", "0")).safe_value
示例#3
0
    def test_snmp_init_without_params(self):
        # Act
        snmp = Snmp()

        # Assert
        self.assertEqual(snmp._snmp_timeout, SNMP_TIMEOUT)
        self.assertEqual(snmp._snmp_retry_count, SNMP_RETRIES_COUNT)
示例#4
0
    def test_snmp_init_with_params(self):
        # Assign
        timeout = 1
        retries = 2

        # Act
        snmp = Snmp(timeout=timeout, retry_count=retries)

        # Assert
        self.assertEqual(snmp._snmp_timeout, timeout)
        self.assertEqual(snmp._snmp_retry_count, retries)
    def __init__(self, resource_config, logger, snmp=None):
        """Create snmp service, according to resource config values.

        :param cloudshell.shell.standards.resource_config_generic_models.GenericSnmpConfig resource_config:  # noqa: E501
        :param logging.Logger logger:
        :param snmp:
        """
        self.resource_config = resource_config
        self._logger = logger
        # use like a container
        self._snmp = snmp or Snmp()
        self._snmp_parameters_helper = SnmpParametersHelper(resource_config)
示例#6
0
    def test_get_snmp_service(self, mock_get_engine, mock_params_converter,
                              mock_context, mock_context_manager):
        logger = Mock()
        snmp_params = Mock()
        snmp = Snmp()
        mock_params_converter.return_value.version = 0

        snmp.get_snmp_service(snmp_parameters=snmp_params, logger=logger)

        mock_params_converter.assert_called_once_with(snmp_params)
        mock_get_engine.assert_called_once_with(
            mock_params_converter.return_value, logger)
        mock_context.assert_called_once_with(snmp_params.context_engine_id,
                                             snmp_params.context_name)
        mock_context_manager.assert_called_once_with(
            snmp_engine=mock_get_engine.return_value,
            v3_context_engine_id=mock_context.return_value.context_engine_id,
            v3_context_name=mock_context.return_value.context_name,
            logger=logger,
            get_bulk_flag=False,
            is_snmp_read_only=mock_params_converter.return_value.is_read_only,
        )