Example #1
0
class TestBaseSnmpMacPlugin(unittest2.TestCase):
    """teset base snmp plugin class."""

    def setUp(self):
        super(TestBaseSnmpMacPlugin, self).setUp()
        logsetting.init()
        self.test_plugin = BaseSnmpMacPlugin('127.0.0.1',
                                             {'version': '2c',
                                              'community': 'public'})

    def tearDown(self):
        del self.test_plugin
        super(TestBaseSnmpMacPlugin, self).tearDown()

    @patch('compass.hdsdiscovery.utils.snmpget_by_cl')
    def test_get_port(self, mock_snmpget):
        """test snmp get port."""
        # Successfully get port number
        mock_snmpget.return_value = 'IF-MIB::ifName.4 = STRING: ge-1/1/4'
        result = self.test_plugin.get_port('4')
        self.assertEqual('4', result)

        # Failed to get port number, switch is timeout
        mock_snmpget.side_effect = TimeoutError("Timeout")
        result = self.test_plugin.get_port('4')
        self.assertIsNone(result)

    @patch('compass.hdsdiscovery.utils.snmpget_by_cl')
    def test_get_vlan_id(self, mock_snmpget):
        """test snmp get vlan."""
        # Port is None
        self.assertIsNone(self.test_plugin.get_vlan_id(None))

        # Port is not None
        mock_snmpget.return_value = 'Q-BRIDGE-MIB::dot1qPvid.4 = Gauge32: 100'
        result = self.test_plugin.get_vlan_id('4')
        self.assertEqual('100', result)

        # Faild to query switch due to timeout
        mock_snmpget.side_effect = TimeoutError("Timeout")
        result = self.test_plugin.get_vlan_id('4')
        self.assertIsNone(result)

    def test_get_mac_address(self):
        """tet snmp get mac address."""
        # Correct input for mac numbers
        mac_numbers = '0.224.129.230.57.173'.split('.')
        mac = self.test_plugin.get_mac_address(mac_numbers)
        self.assertEqual('00:e0:81:e6:39:ad', mac)

        # Incorrct input for mac numbers
        mac_numbers = '0.224.129.230.57'.split('.')
        mac = self.test_plugin.get_mac_address(mac_numbers)
        self.assertIsNone(mac)
Example #2
0
class TestBaseSnmpMacPlugin(unittest2.TestCase):
    """teset base snmp plugin class."""
    def setUp(self):
        super(TestBaseSnmpMacPlugin, self).setUp()
        logsetting.init()
        self.test_plugin = BaseSnmpMacPlugin('127.0.0.1', {
            'version': '2c',
            'community': 'public'
        })

    def tearDown(self):
        del self.test_plugin
        super(TestBaseSnmpMacPlugin, self).tearDown()

    @patch('compass.hdsdiscovery.utils.snmpget_by_cl')
    def test_get_port(self, mock_snmpget):
        """test snmp get port."""
        # Successfully get port number
        mock_snmpget.return_value = 'IF-MIB::ifName.4 = STRING: ge-1/1/4'
        result = self.test_plugin.get_port('4')
        self.assertEqual('4', result)

        # Failed to get port number, switch is timeout
        mock_snmpget.side_effect = TimeoutError("Timeout")
        result = self.test_plugin.get_port('4')
        self.assertIsNone(result)

    @patch('compass.hdsdiscovery.utils.snmpget_by_cl')
    def test_get_vlan_id(self, mock_snmpget):
        """test snmp get vlan."""
        # Port is None
        self.assertIsNone(self.test_plugin.get_vlan_id(None))

        # Port is not None
        mock_snmpget.return_value = 'Q-BRIDGE-MIB::dot1qPvid.4 = Gauge32: 100'
        result = self.test_plugin.get_vlan_id('4')
        self.assertEqual('100', result)

        # Faild to query switch due to timeout
        mock_snmpget.side_effect = TimeoutError("Timeout")
        result = self.test_plugin.get_vlan_id('4')
        self.assertIsNone(result)

    def test_get_mac_address(self):
        """tet snmp get mac address."""
        # Correct input for mac numbers
        mac_numbers = '0.224.129.230.57.173'.split('.')
        mac = self.test_plugin.get_mac_address(mac_numbers)
        self.assertEqual('00:e0:81:e6:39:ad', mac)

        # Incorrct input for mac numbers
        mac_numbers = '0.224.129.230.57'.split('.')
        mac = self.test_plugin.get_mac_address(mac_numbers)
        self.assertIsNone(mac)
Example #3
0
class TestBaseSnmpMacPlugin(unittest2.TestCase):

    def setUp(self):
        self.test_plugin = BaseSnmpMacPlugin('12.0.0.1',
                                             {'version': '2c',
                                              'community': 'public'})

    def tearDown(self):
        del self.test_plugin

    @patch('compass.hdsdiscovery.utils.snmpget_by_cl')
    def test_get_port(self, mock_snmpget):
        mock_snmpget.return_value = 'IF-MIB::ifName.4 = STRING: ge-1/1/4'
        result = self.test_plugin.get_port('4')
        self.assertEqual('4', result)

    @patch('compass.hdsdiscovery.utils.snmpget_by_cl')
    def test_get_vlan_id(self, mock_snmpget):
        # Port is None
        self.assertIsNone(self.test_plugin.get_vlan_id(None))

        # Port is not None
        mock_snmpget.return_value = 'Q-BRIDGE-MIB::dot1qPvid.4 = Gauge32: 100'
        result = self.test_plugin.get_vlan_id('4')
        self.assertEqual('100', result)

    def test_get_mac_address(self):
        # Correct input for mac numbers
        mac_numbers = '0.224.129.230.57.173'.split('.')
        mac = self.test_plugin.get_mac_address(mac_numbers)
        self.assertEqual('00:e0:81:e6:39:ad', mac)

        # Incorrct input for mac numbers
        mac_numbers = '0.224.129.230.57'.split('.')
        mac = self.test_plugin.get_mac_address(mac_numbers)
        self.assertIsNone(mac)