]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Add regression tests for SNMP 6720/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 6 Jun 2018 15:15:51 +0000 (17:15 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 15 Jun 2018 12:29:03 +0000 (14:29 +0200)
build-scripts/travis.sh
regression-tests.recursor-dnssec/requirements.txt
regression-tests.recursor-dnssec/snmpd.conf [new file with mode: 0644]
regression-tests.recursor-dnssec/test_SNMP.py [new file with mode: 0644]

index 99efc4e0e6f055125ead81d0b9e7915db22d4898..ef4a0a6ce968fc2b33373e8a047efc375fd5f2cd 100755 (executable)
@@ -355,6 +355,12 @@ install_recursor() {
   run "sudo touch /etc/authbind/byport/53"
   run "sudo chmod 755 /etc/authbind/byport/53"
   run "cd ${TRAVIS_BUILD_DIR}"
+  # install SNMP
+  run "sudo sed -i \"s/agentxperms 0700 0755 recursor/agentxperms 0700 0755 ${USER}/g\" regression-tests.recursor-dnssec/snmpd.conf"
+  run "sudo cp -f regression-tests.recursor-dnssec/snmpd.conf /etc/snmp/snmpd.conf"
+  run "sudo service snmpd restart"
+  ## fun story, the directory perms are only applied if it doesn't exist yet, and it is created by the init script, so..
+  run "sudo chmod 0755 /var/agentx"
 }
 
 install_dnsdist() {
index 383124778a121e4b254ee593a8ebb3e9a52c7b44..18aa37e592302caca42b29184d237293587c62dc 100644 (file)
@@ -1,5 +1,5 @@
 dnspython>=1.11
 nose>=1.3.7
+pysnmp>=4.3.4
 requests>=2.1.0
 Twisted>0.15.0
-
diff --git a/regression-tests.recursor-dnssec/snmpd.conf b/regression-tests.recursor-dnssec/snmpd.conf
new file mode 100644 (file)
index 0000000..b881dd7
--- /dev/null
@@ -0,0 +1,13 @@
+
+# act as an Agent X master so that the recursor can export SNMP statistics
+master agentx
+
+# allow the recursor to connect to the Agent X master socket
+agentxperms 0700 0755 recursor
+
+# SNMPv2c community
+rocommunity secretcommunity
+
+# SNMPv3 user
+createUser secretuser SHA "mysecretauthkey" AES "mysecretenckey"
+rouser secretuser
diff --git a/regression-tests.recursor-dnssec/test_SNMP.py b/regression-tests.recursor-dnssec/test_SNMP.py
new file mode 100644 (file)
index 0000000..df68882
--- /dev/null
@@ -0,0 +1,78 @@
+import time
+
+from pysnmp.hlapi import *
+
+from recursortests import RecursorTest
+
+class TestSNMP(RecursorTest):
+
+    _snmpTimeout = 2.0
+    _snmpServer = '127.0.0.1'
+    _snmpPort = 161
+    _snmpV2Community = 'secretcommunity'
+    _snmpV3User = 'secretuser'
+    _snmpV3AuthKey = 'mysecretauthkey'
+    _snmpV3EncKey = 'mysecretenckey'
+    _snmpOID = '1.3.6.1.4.1.43315.2'
+    _queriesSent = 0
+    _confdir = 'SNMP'
+    _config_template = """
+    snmp-agent=yes
+    """
+
+    def _checkStatsValues(self, results):
+        for i in list(range(1, 93)):
+            oid = self._snmpOID + '.1.' + str(i) + '.0'
+            self.assertTrue(oid in results)
+            self.assertTrue(isinstance(results[oid], Counter64))
+
+        # check uptime > 0
+        self.assertGreater(results['1.3.6.1.4.1.43315.2.1.75.0'], 0)
+        # check memory usage > 0
+        self.assertGreater(results['1.3.6.1.4.1.43315.2.1.76.0'], 0)
+
+    def _getSNMPStats(self, auth):
+        results = {}
+        for (errorIndication, errorStatus, errorIndex, varBinds) in nextCmd(SnmpEngine(),
+                                                                            auth,
+                                                                            UdpTransportTarget((self._snmpServer, self._snmpPort), timeout=self._snmpTimeout),
+                                                                            ContextData(),
+                                                                            ObjectType(ObjectIdentity(self._snmpOID)),
+                                                                            lookupMib=False):
+            self.assertFalse(errorIndication)
+            self.assertFalse(errorStatus)
+            self.assertTrue(varBinds)
+            for key, value in varBinds:
+                keystr = key.prettyPrint()
+                if not keystr.startswith(self._snmpOID):
+                    continue
+                results[keystr] = value
+
+        return results
+
+    def _checkStats(self, auth):
+        # wait 1s so that the uptime is > 0
+        time.sleep(1)
+
+        results = self._getSNMPStats(auth)
+        self._checkStatsValues(results)
+
+    def testSNMPv2Stats(self):
+        """
+        SNMP: Retrieve statistics via SNMPv2c
+        """
+
+        auth = CommunityData(self._snmpV2Community, mpModel=1)
+        self._checkStats(auth)
+
+    def testSNMPv3Stats(self):
+        """
+        SNMP: Retrieve statistics via SNMPv3
+        """
+
+        auth = UsmUserData(self._snmpV3User,
+                               authKey=self._snmpV3AuthKey,
+                               privKey=self._snmpV3EncKey,
+                               authProtocol=usmHMACSHAAuthProtocol,
+                               privProtocol=usmAesCfb128Protocol)
+        self._checkStats(auth)