summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py2
-rwxr-xr-xtests/py-test-snmptrap.sh26
-rw-r--r--tests/test_snmptrapd.py45
-rwxr-xr-xtests/test_snmptrapd_send_test_trap.py16
-rw-r--r--tests/test_trapd_exit.py16
-rw-r--r--tests/test_trapd_get_cbs_config.py116
-rw-r--r--tests/test_trapd_http_session.py31
-rw-r--r--tests/test_trapd_io.py295
-rw-r--r--tests/test_trapd_runtime_pid.py16
-rw-r--r--tests/test_trapd_settings.py16
-rw-r--r--tests/test_trapd_snmpv3.py16
-rw-r--r--tests/test_trapd_stormwatch.py54
-rw-r--r--tests/test_trapd_stormwatch_settings.py158
-rw-r--r--tests/test_trapd_vb_types.py116
14 files changed, 725 insertions, 198 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
index 1875bf6..af0fbb2 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,5 +1,5 @@
# ================================================================================
-# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
diff --git a/tests/py-test-snmptrap.sh b/tests/py-test-snmptrap.sh
new file mode 100755
index 0000000..b57eef6
--- /dev/null
+++ b/tests/py-test-snmptrap.sh
@@ -0,0 +1,26 @@
+#!/bin/env bash
+# ============LICENSE_START=======================================================
+# Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
+# export CBS_SIM_JSON=/opt/app/snmptrap/etc/snmptrapd.json
+export PYTHONPATH=/opt/app/snmptrap/bin:/opt/app/snmptrap/bin/mod:$PYTHONPATH
+
+# cd /opt/app/snmptrap
+cd /opt/app
+
+py.test --cov-config /opt/app/snmptrap/tests/.coveragerc --cov=snmptrap /opt/app/snmptrap/tests/
+# py.test --cov=snmptrap /opt/app/snmptrap/tests/
+coverage report -m
diff --git a/tests/test_snmptrapd.py b/tests/test_snmptrapd.py
index 9dc92c0..cdd19a4 100644
--- a/tests/test_snmptrapd.py
+++ b/tests/test_snmptrapd.py
@@ -1,3 +1,19 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
import os
import pytest
import unittest
@@ -5,6 +21,8 @@ import snmptrapd
import datetime
import trapd_settings as tds
+import trapd_stormwatch_settings as sws
+import trapd_stormwatch as sw
import trapd_http_session
import trapd_runtime_pid
import trapd_io
@@ -18,7 +36,7 @@ class test_snmptrapd(unittest.TestCase):
Test the save_pid mod
"""
- pytest_json_data = "{ \"snmptrapd\": { \"version\": \"1.4.0\", \"title\": \"ONAP SNMP Trap Receiver\" }, \"protocols\": { \"transport\": \"udp\", \"ipv4_interface\": \"0.0.0.0\", \"ipv4_port\": 6162, \"ipv6_interface\": \"::1\", \"ipv6_port\": 6162 }, \"cache\": { \"dns_cache_ttl_seconds\": 60 }, \"publisher\": { \"http_timeout_milliseconds\": 1500, \"http_retries\": 3, \"http_milliseconds_between_retries\": 750, \"http_primary_publisher\": \"true\", \"http_peer_publisher\": \"unavailable\", \"max_traps_between_publishes\": 10, \"max_milliseconds_between_publishes\": 10000 }, \"streams_publishes\": { \"sec_fault_unsecure\": { \"type\": \"message_router\", \"aaf_password\": null, \"dmaap_info\": { \"location\": \"mtl5\", \"client_id\": null, \"client_role\": null, \"topic_url\": \"http://uebsb91kcdc.it.att.com:3904/events/ONAP-COLLECTOR-SNMPTRAP\" }, \"aaf_username\": null } }, \"files\": { \"runtime_base_dir\": \"/tmp/opt/app/snmptrap\", \"log_dir\": \"logs\", \"data_dir\": \"data\", \"pid_dir\": \"tmp\", \"arriving_traps_log\": \"snmptrapd_arriving_traps.log\", \"snmptrapd_diag\": \"snmptrapd_prog_diag.log\", \"traps_stats_log\": \"snmptrapd_stats.csv\", \"perm_status_file\": \"snmptrapd_status.log\", \"eelf_base_dir\": \"/tmp/opt/app/snmptrap/logs\", \"eelf_error\": \"error.log\", \"eelf_debug\": \"debug.log\", \"eelf_audit\": \"audit.log\", \"eelf_metrics\": \"metrics.log\", \"roll_frequency\": \"day\", \"minimum_severity_to_log\": 2 }, \"trap_config\": { \"sw_interval_in_seconds\": 60, \"notify_oids\": { \".1.3.6.1.4.1.9.0.1\": { \"sw_high_water_in_interval\": 102, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.2\": { \"sw_high_water_in_interval\": 101, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.3\": { \"sw_high_water_in_interval\": 102, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.4\": { \"sw_high_water_in_interval\": 10, \"sw_low_water_in_interval\": 3, \"category\": \"logonly\" } } }, \"snmpv3_config\": { \"usm_users\": [ { \"user\": \"usr-sha-aes256\", \"engineId\": \"8000000001020304\", \"usmHMACSHAAuth\": \"authkey1\", \"usmAesCfb256\": \"privkey1\" }, { \"user\": \"user1\", \"engineId\": \"8000000000000001\", \"usmHMACMD5Auth\": \"authkey1\", \"usmDESPriv\": \"privkey1\" }, { \"user\": \"user2\", \"engineId\": \"8000000000000002\", \"usmHMACSHAAuth\": \"authkey2\", \"usmAesCfb128\": \"privkey2\" }, { \"user\": \"user3\", \"engineId\": \"8000000000000003\", \"usmHMACSHAAuth\": \"authkey3\", \"usmAesCfb256\": \"privkey3\" } ] } }"
+ pytest_json_data = "{ \"snmptrapd\": { \"version\": \"2.0.3\", \"title\": \"ONAP SNMP Trap Receiver\" }, \"protocols\": { \"transport\": \"udp\", \"ipv4_interface\": \"0.0.0.0\", \"ipv4_port\": 6162, \"ipv6_interface\": \"::1\", \"ipv6_port\": 6162 }, \"cache\": { \"dns_cache_ttl_seconds\": 60 }, \"publisher\": { \"http_timeout_milliseconds\": 1500, \"http_retries\": 3, \"http_milliseconds_between_retries\": 750, \"http_primary_publisher\": \"true\", \"http_peer_publisher\": \"unavailable\", \"max_traps_between_publishes\": 10, \"max_milliseconds_between_publishes\": 10000 }, \"streams_publishes\": { \"sec_fault_unsecure\": { \"type\": \"message_router\", \"aaf_password\": null, \"dmaap_info\": { \"location\": \"mtl5\", \"client_id\": null, \"client_role\": null, \"topic_url\": \"http://uebsb91kcdc.it.att.com:3904/events/ONAP-COLLECTOR-SNMPTRAP\" }, \"aaf_username\": null } }, \"files\": { \"runtime_base_dir\": \"/tmp/opt/app/snmptrap\", \"log_dir\": \"logs\", \"data_dir\": \"data\", \"pid_dir\": \"tmp\", \"arriving_traps_log\": \"snmptrapd_arriving_traps.log\", \"snmptrapd_diag\": \"snmptrapd_prog_diag.log\", \"traps_stats_log\": \"snmptrapd_stats.csv\", \"perm_status_file\": \"snmptrapd_status.log\", \"eelf_base_dir\": \"/tmp/opt/app/snmptrap/logs\", \"eelf_error\": \"error.log\", \"eelf_debug\": \"debug.log\", \"eelf_audit\": \"audit.log\", \"eelf_metrics\": \"metrics.log\", \"roll_frequency\": \"day\", \"minimum_severity_to_log\": 2 }, \"trap_config\": { \"sw_interval_in_seconds\": 60, \"notify_oids\": { \".1.3.6.1.4.1.9.0.1\": { \"sw_high_water_in_interval\": 102, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.2\": { \"sw_high_water_in_interval\": 101, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.3\": { \"sw_high_water_in_interval\": 102, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.4\": { \"sw_high_water_in_interval\": 10, \"sw_low_water_in_interval\": 3, \"category\": \"logonly\" } } }, \"snmpv3_config\": { \"usm_users\": [ { \"user\": \"usr-sha-aes256\", \"engineId\": \"8000000001020304\", \"usmHMACSHAAuth\": \"authkey1\", \"usmAesCfb256\": \"privkey1\" }, { \"user\": \"user1\", \"engineId\": \"8000000000000001\", \"usmHMACMD5Auth\": \"authkey1\", \"usmDESPriv\": \"privkey1\" }, { \"user\": \"user2\", \"engineId\": \"8000000000000002\", \"usmHMACSHAAuth\": \"authkey2\", \"usmAesCfb128\": \"privkey2\" }, { \"user\": \"user3\", \"engineId\": \"8000000000000003\", \"usmHMACSHAAuth\": \"authkey3\", \"usmAesCfb256\": \"privkey3\" } ] } }"
# create copy of snmptrapd.json for pytest
pytest_json_config = "/tmp/opt/app/snmptrap/etc/snmptrapd.json"
@@ -44,6 +62,7 @@ class test_snmptrapd(unittest.TestCase):
# init vars
tds.init()
+ sw.sw_init()
# request load of CBS data
os.environ.update(CBS_SIM_JSON='/tmp/opt/app/snmptrap/etc/snmptrapd.json')
@@ -150,29 +169,5 @@ class test_snmptrapd(unittest.TestCase):
result = errorIndication
self.assertEqual(result, None)
- def test_add_varbind_to_json(self):
-
- # init vars
- tds.init()
- tds.trap_dict["notify OID"] = ".1.2.3.4.5.6.7.8"
- tds.trap_dict["protocol version"] = "v2c"
-
- # varbinds=[(ObjectName('1.3.6.1.2.1.1.3.0'), TimeTicks(0)), (ObjectName('1.3.6.1.6.3.1.1.4.1.0'), ObjectIdentifier('1.3.6.1.4.1.74.2.46.12.1.1')), (ObjectName('1.3.6.1.4.1.74.2.46.12.1.1.1'), OctetString(b'ucsnmp heartbeat - ignore')), (ObjectName('1.3.6.1.4.1.74.2.46.12.1.1.2'), OctetString(b'Thu Mar 21 15:46:58 2019'))]
-
- # vb=(ObjectName('1.3.6.1.4.1.74.2.46.12.1.1.1'), OctetString(b'ucsnmp heartbeat - ignore'))
-
- self.assertEqual(snmptrapd.add_varbind_to_json(0,ObjectIdentifier('.1.2.3.4'), 'OctetString', OctetString(b'Thu Mar 21 15:46:58 2019')), 0)
- self.assertEqual(snmptrapd.add_varbind_to_json(1,ObjectIdentifier('.1.2.3.4'), 'OctetString', OctetString(b'Thu Mar 21 15:46:58 2019')), 0)
- self.assertEqual(snmptrapd.add_varbind_to_json(2,ObjectIdentifier('.1.2.3.4'), 'OctetString', OctetString(b'Thu Mar 21 15:46:58 2019')), 1)
- self.assertEqual(snmptrapd.add_varbind_to_json(3,ObjectIdentifier('.1.2.3.4'), 'OctetString', OctetString(b'Thu Mar 21 15:46:58 2019')), 1)
-
- # init vars
- tds.init()
- tds.trap_dict["notify OID"] = ".1.2.3.4.5.6.7.8"
- tds.trap_dict["protocol version"] = "v1"
-
- self.assertEqual(snmptrapd.add_varbind_to_json(0,ObjectIdentifier('.1.2.3.4'), 'OctetString', OctetString(b'Thu Mar 21 15:46:58 2019')), 0)
- self.assertEqual(snmptrapd.add_varbind_to_json(5,ObjectIdentifier('.1.2.3.4'), 'OctetString', OctetString(b'Thu Mar 21 15:46:58 2019')), 1)
-
if __name__ == '__main__':
unittest.main()
diff --git a/tests/test_snmptrapd_send_test_trap.py b/tests/test_snmptrapd_send_test_trap.py
index 54d522e..0e23def 100755
--- a/tests/test_snmptrapd_send_test_trap.py
+++ b/tests/test_snmptrapd_send_test_trap.py
@@ -1,3 +1,19 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
from pysnmp.hlapi import *
from pysnmp import debug
diff --git a/tests/test_trapd_exit.py b/tests/test_trapd_exit.py
index 594624f..3bbc386 100644
--- a/tests/test_trapd_exit.py
+++ b/tests/test_trapd_exit.py
@@ -1,3 +1,19 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
import pytest
import unittest
import trapd_exit
diff --git a/tests/test_trapd_get_cbs_config.py b/tests/test_trapd_get_cbs_config.py
index 44bf021..67bccfc 100644
--- a/tests/test_trapd_get_cbs_config.py
+++ b/tests/test_trapd_get_cbs_config.py
@@ -1,44 +1,77 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
import pytest
import unittest
import os
+import sys
from onap_dcae_cbs_docker_client.client import get_config
from trapd_exit import cleanup_and_exit
from trapd_io import stdout_logger, ecomp_logger
import trapd_settings as tds
import trapd_get_cbs_config
-
+
+from pathlib import Path
+
+# # # # # # # #
+# ENV setup
+# # # # # # # #
+
+# required directory tree
+try:
+ Path("/tmp/opt/app/snmptrap/logs").mkdir(parents=True, exist_ok=True)
+ Path("/tmp/opt/app/snmptrap/tmp").mkdir(parents=True, exist_ok=True)
+except Exception as e:
+ print("Error while running %s : %s" % (os.path.basename(__file__), str(e.strerror)))
+ sys.exit(1)
+
+# env var for CBS_SIM_JSON
+try:
+ os.environ['CBS_SIM_JSON'] = "/tmp/opt/app/snmptrap/etc/snmptrapd.json"
+except Exception as e:
+ print("Error while running %s : %s" % (os.path.basename(__file__), str(e.strerror)))
+ sys.exit(1)
+
+pytest_json_data = "{ \"snmptrapd\": { \"version\": \"1.4.0\", \"title\": \"ONAP SNMP Trap Receiver\" }, \"protocols\": { \"transport\": \"udp\", \"ipv4_interface\": \"0.0.0.0\", \"ipv4_port\": 6162, \"ipv6_interface\": \"::1\", \"ipv6_port\": 6162 }, \"cache\": { \"dns_cache_ttl_seconds\": 60 }, \"publisher\": { \"http_timeout_milliseconds\": 1500, \"http_retries\": 3, \"http_milliseconds_between_retries\": 750, \"http_primary_publisher\": \"true\", \"http_peer_publisher\": \"unavailable\", \"max_traps_between_publishes\": 10, \"max_milliseconds_between_publishes\": 10000 }, \"streams_publishes\": { \"sec_fault_unsecure\": { \"type\": \"message_router\", \"aaf_password\": null, \"dmaap_info\": { \"location\": \"mtl5\", \"client_id\": null, \"client_role\": null, \"topic_url\": \"http://localhost:3904/events/ONAP-COLLECTOR-SNMPTRAP\" }, \"aaf_username\": null } }, \"files\": { \"runtime_base_dir\": \"/tmp/opt/app/snmptrap\", \"log_dir\": \"logs\", \"data_dir\": \"data\", \"pid_dir\": \"tmp\", \"arriving_traps_log\": \"snmptrapd_arriving_traps.log\", \"snmptrapd_diag\": \"snmptrapd_prog_diag.log\", \"traps_stats_log\": \"snmptrapd_stats.csv\", \"perm_status_file\": \"snmptrapd_status.log\", \"eelf_base_dir\": \"/tmp/opt/app/snmptrap/logs\", \"eelf_error\": \"error.log\", \"eelf_debug\": \"debug.log\", \"eelf_audit\": \"audit.log\", \"eelf_metrics\": \"metrics.log\", \"roll_frequency\": \"day\", \"minimum_severity_to_log\": 2 }, \"trap_config\": { \"sw_interval_in_seconds\": 60, \"notify_oids\": { \".1.3.6.1.4.1.9.0.1\": { \"sw_high_water_in_interval\": 102, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.2\": { \"sw_high_water_in_interval\": 101, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.3\": { \"sw_high_water_in_interval\": 102, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.4\": { \"sw_high_water_in_interval\": 10, \"sw_low_water_in_interval\": 3, \"category\": \"logonly\" } } }, \"snmpv3_config\": { \"usm_users\": [ { \"user\": \"usr-sha-aes256\", \"engineId\": \"8000000001020304\", \"usmHMACSHAAuth\": \"authkey1\", \"usmAesCfb256\": \"privkey1\" }, { \"user\": \"user1\", \"engineId\": \"8000000000000001\", \"usmHMACMD5Auth\": \"authkey1\", \"usmDESPriv\": \"privkey1\" }, { \"user\": \"user2\", \"engineId\": \"8000000000000002\", \"usmHMACSHAAuth\": \"authkey2\", \"usmAesCfb128\": \"privkey2\" }, { \"user\": \"user3\", \"engineId\": \"8000000000000003\", \"usmHMACSHAAuth\": \"authkey3\", \"usmAesCfb256\": \"privkey3\" } ] } }"
+
+# create snmptrapd.json for pytest
+pytest_json_config = os.getenv('CBS_SIM_JSON')
+with open(pytest_json_config, 'w') as outfile:
+ outfile.write(pytest_json_data)
+outfile.close()
+
+# test class/methods
class test_get_cbs_config(unittest.TestCase):
"""
Test the trapd_get_cbs_config mod
"""
- pytest_json_data = "{ \"snmptrapd\": { \"version\": \"1.4.0\", \"title\": \"ONAP SNMP Trap Receiver\" }, \"protocols\": { \"transport\": \"udp\", \"ipv4_interface\": \"0.0.0.0\", \"ipv4_port\": 6162, \"ipv6_interface\": \"::1\", \"ipv6_port\": 6162 }, \"cache\": { \"dns_cache_ttl_seconds\": 60 }, \"publisher\": { \"http_timeout_milliseconds\": 1500, \"http_retries\": 3, \"http_milliseconds_between_retries\": 750, \"http_primary_publisher\": \"true\", \"http_peer_publisher\": \"unavailable\", \"max_traps_between_publishes\": 10, \"max_milliseconds_between_publishes\": 10000 }, \"streams_publishes\": { \"sec_fault_unsecure\": { \"type\": \"message_router\", \"aaf_password\": null, \"dmaap_info\": { \"location\": \"mtl5\", \"client_id\": null, \"client_role\": null, \"topic_url\": \"http://localhost:3904/events/ONAP-COLLECTOR-SNMPTRAP\" }, \"aaf_username\": null } }, \"files\": { \"runtime_base_dir\": \"/tmp/opt/app/snmptrap\", \"log_dir\": \"logs\", \"data_dir\": \"data\", \"pid_dir\": \"tmp\", \"arriving_traps_log\": \"snmptrapd_arriving_traps.log\", \"snmptrapd_diag\": \"snmptrapd_prog_diag.log\", \"traps_stats_log\": \"snmptrapd_stats.csv\", \"perm_status_file\": \"snmptrapd_status.log\", \"eelf_base_dir\": \"/tmp/opt/app/snmptrap/logs\", \"eelf_error\": \"error.log\", \"eelf_debug\": \"debug.log\", \"eelf_audit\": \"audit.log\", \"eelf_metrics\": \"metrics.log\", \"roll_frequency\": \"day\", \"minimum_severity_to_log\": 2 }, \"trap_config\": { \"sw_interval_in_seconds\": 60, \"notify_oids\": { \".1.3.6.1.4.1.9.0.1\": { \"sw_high_water_in_interval\": 102, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.2\": { \"sw_high_water_in_interval\": 101, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.3\": { \"sw_high_water_in_interval\": 102, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.4\": { \"sw_high_water_in_interval\": 10, \"sw_low_water_in_interval\": 3, \"category\": \"logonly\" } } }, \"snmpv3_config\": { \"usm_users\": [ { \"user\": \"usr-sha-aes256\", \"engineId\": \"8000000001020304\", \"usmHMACSHAAuth\": \"authkey1\", \"usmAesCfb256\": \"privkey1\" }, { \"user\": \"user1\", \"engineId\": \"8000000000000001\", \"usmHMACMD5Auth\": \"authkey1\", \"usmDESPriv\": \"privkey1\" }, { \"user\": \"user2\", \"engineId\": \"8000000000000002\", \"usmHMACSHAAuth\": \"authkey2\", \"usmAesCfb128\": \"privkey2\" }, { \"user\": \"user3\", \"engineId\": \"8000000000000003\", \"usmHMACSHAAuth\": \"authkey3\", \"usmAesCfb256\": \"privkey3\" } ] } }"
-
- # create copy of snmptrapd.json for pytest
- pytest_json_config = "/tmp/opt/app/snmptrap/etc/snmptrapd.json"
- with open(pytest_json_config, 'w') as outfile:
- outfile.write(pytest_json_data)
-
-
- def test_cbs_env_present(self):
+ def test_cbs_fallback_env_present(self):
"""
- Test that CONSUL_HOST env variable exists but fails to
- respond
+ Test that CBS fallback env variable exists and we can get config
+ from fallback env var
"""
- os.environ.update(CONSUL_HOST='nosuchhost')
- # del os.environ['CBS_SIM_JSON']
- # result = trapd_get_cbs_config.get_cbs_config()
- # print("result: %s" % result)
+ os.environ.update(CBS_SIM_JSON='/tmp/opt/app/snmptrap/etc/snmptrapd.json')
+ result = trapd_get_cbs_config.get_cbs_config()
+ print("result: %s" % result)
# compare = str(result).startswith("{'snmptrap': ")
- # self.assertEqual(compare, False)
-
- with pytest.raises(Exception) as pytest_wrapped_sys_exit:
- result = trapd_get_cbs_config.get_cbs_config()
- assert pytest_wrapped_sys_exit.type == SystemExit
- # assert pytest_wrapped_sys_exit.value.code == 1
+ # self.assertEqual(compare, True)
+ self.assertEqual(result, True)
-
def test_cbs_override_env_invalid(self):
"""
"""
@@ -51,35 +84,32 @@ class test_get_cbs_config(unittest.TestCase):
with pytest.raises(SystemExit) as pytest_wrapped_sys_exit:
result = trapd_get_cbs_config.get_cbs_config()
assert pytest_wrapped_sys_exit.type == SystemExit
- assert pytest_wrapped_sys_exit.value.code == 1
-
+ # assert pytest_wrapped_sys_exit.value.code == 1
- def test_cbs_override_env_unset(self):
+ def test_cbs_env_present(self):
"""
+ Test that CONSUL_HOST env variable exists but fails to
+ respond
"""
- os.environ.update(CBS_SIM_JSON='')
- #result = trapd_get_cbs_config.get_cbs_config()
- #print("result: %s" % result)
+ os.environ.update(CONSUL_HOST='localhost')
+ del os.environ['CBS_SIM_JSON']
+ # result = trapd_get_cbs_config.get_cbs_config()
+ # print("result: %s" % result)
# compare = str(result).startswith("{'snmptrap': ")
# self.assertEqual(compare, False)
- with pytest.raises(SystemExit) as pytest_wrapped_sys_exit:
- result = trapd_get_cbs_config.get_cbs_config()
- assert pytest_wrapped_sys_exit.type == SystemExit
- assert pytest_wrapped_sys_exit.value.code == 1
-
+ with pytest.raises(SystemExit) as sys_exit:
+ trapd_get_cbs_config.get_cbs_config()
+ assert sys_exit.value.errno == errno.ECONNREFUSED
- def test_cbs_fallback_env_present(self):
+ def test_cbs_override_env_undefined(self):
"""
- Test that CBS fallback env variable exists and we can get config
- from fallback env var
"""
- os.environ.update(CBS_SIM_JSON='/tmp/opt/app/snmptrap/etc/snmptrapd.json')
- result = trapd_get_cbs_config.get_cbs_config()
- print("result: %s" % result)
- # compare = str(result).startswith("{'snmptrap': ")
- # self.assertEqual(compare, True)
- self.assertEqual(result, True)
+ print("------>>> RUNNING test_no_cbs_override_env_var:")
+ del os.environ['CBS_SIM_JSON']
+
+ with pytest.raises(SystemExit) as pytest_wrapped_sys_exit:
+ assert trapd_get_cbs_config.get_cbs_config() == SystemExit
if __name__ == '__main__':
unittest.main()
diff --git a/tests/test_trapd_http_session.py b/tests/test_trapd_http_session.py
index a423be6..478b29d 100644
--- a/tests/test_trapd_http_session.py
+++ b/tests/test_trapd_http_session.py
@@ -1,3 +1,19 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
import pytest
import unittest
import trapd_http_session
@@ -7,6 +23,14 @@ class test_init_session_obj(unittest.TestCase):
Test the init_session_obj mod
"""
+ def close_nonexisting_session(self):
+ """
+ test close of existing http session
+ """
+ sess="no session"
+ result = trapd_http_session.close_session_obj(sess)
+ self.assertEqual(result, True)
+
def init_session(self):
"""
test creation of http session
@@ -32,12 +56,5 @@ class test_init_session_obj(unittest.TestCase):
result = trapd_http_session.close_session_obj(sess)
self.assertEqual(result, True)
- def close_nonexistent_session(self):
- """
- test close of non-existent http session
- """
- result = trapd_http_session.close_session_obj(None)
- self.assertEqual(result, True)
-
if __name__ == '__main__':
unittest.main()
diff --git a/tests/test_trapd_io.py b/tests/test_trapd_io.py
index 0ec93d5..3e32493 100644
--- a/tests/test_trapd_io.py
+++ b/tests/test_trapd_io.py
@@ -1,3 +1,19 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
import os
import pytest
import unittest
@@ -7,127 +23,176 @@ import json
import trapd_settings as tds
import trapd_runtime_pid
import trapd_io
+import sys
+from pathlib import Path
+
class test_trapd_io(unittest.TestCase):
"""
Test the save_pid mod
"""
tds.c_config = json.loads("{ \"snmptrapd\": { \"version\": \"1.4.0\", \"title\": \"ONAP SNMP Trap Receiver\" }, \"protocols\": { \"transport\": \"udp\", \"ipv4_interface\": \"0.0.0.0\", \"ipv4_port\": 6162, \"ipv6_interface\": \"::1\", \"ipv6_port\": 6162 }, \"cache\": { \"dns_cache_ttl_seconds\": 60 }, \"publisher\": { \"http_timeout_milliseconds\": 1500, \"http_retries\": 3, \"http_milliseconds_between_retries\": 750, \"http_primary_publisher\": \"true\", \"http_peer_publisher\": \"unavailable\", \"max_traps_between_publishes\": 10, \"max_milliseconds_between_publishes\": 10000 }, \"streams_publishes\": { \"sec_fault_unsecure\": { \"type\": \"message_router\", \"aaf_password\": null, \"dmaap_info\": { \"location\": \"mtl5\", \"client_id\": null, \"client_role\": null, \"topic_url\": \"http://localhost:3904/events/ONAP-COLLECTOR-SNMPTRAP\" }, \"aaf_username\": null } }, \"files\": { \"runtime_base_dir\": \"/tmp/opt/app/snmptrap\", \"log_dir\": \"logs\", \"data_dir\": \"data\", \"pid_dir\": \"tmp\", \"arriving_traps_log\": \"snmptrapd_arriving_traps.log\", \"snmptrapd_diag\": \"snmptrapd_prog_diag.log\", \"traps_stats_log\": \"snmptrapd_stats.csv\", \"perm_status_file\": \"snmptrapd_status.log\", \"eelf_base_dir\": \"/tmp/opt/app/snmptrap/logs\", \"eelf_error\": \"error.log\", \"eelf_debug\": \"debug.log\", \"eelf_audit\": \"audit.log\", \"eelf_metrics\": \"metrics.log\", \"roll_frequency\": \"day\", \"minimum_severity_to_log\": 2 }, \"trap_config\": { \"sw_interval_in_seconds\": 60, \"notify_oids\": { \".1.3.6.1.4.1.9.0.1\": { \"sw_high_water_in_interval\": 102, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.2\": { \"sw_high_water_in_interval\": 101, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.3\": { \"sw_high_water_in_interval\": 102, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.4\": { \"sw_high_water_in_interval\": 10, \"sw_low_water_in_interval\": 3, \"category\": \"logonly\" } } }, \"snmpv3_config\": { \"usm_users\": [ { \"user\": \"usr-sha-aes256\", \"engineId\": \"8000000001020304\", \"usmHMACSHAAuth\": \"authkey1\", \"usmAesCfb256\": \"privkey1\" }, { \"user\": \"user1\", \"engineId\": \"8000000000000001\", \"usmHMACMD5Auth\": \"authkey1\", \"usmDESPriv\": \"privkey1\" }, { \"user\": \"user2\", \"engineId\": \"8000000000000002\", \"usmHMACSHAAuth\": \"authkey2\", \"usmAesCfb128\": \"privkey2\" }, { \"user\": \"user3\", \"engineId\": \"8000000000000003\", \"usmHMACSHAAuth\": \"authkey3\", \"usmAesCfb256\": \"privkey3\" } ] } }")
- post_data_enclosed=json.loads("[{\"epoch_serno\": 15488041460000, \"uuid\": \"bd3a87a0-241c-11e9-ac41-0242ac11000f\", \"agent address\": \"127.0.0.1\", \"agent name\": \"localhost\", \"cambria.partition\": \"localhost\", \"community\": \"\", \"community len\": 0, \"protocol version\": \"v2c\", \"time received\": 1548804146, \"trap category\": \"com.att.dcae.dmaap.FTL.24256-DCAE-COLLECTOR-UCSNMP-v1\", \"notify OID\": \".1.3.6.1.4.1.74.2.46.12.1.1\", \"notify OID len\": 12, \"varbinds\": [{\"varbind_oid\": \".1.3.6.1.4.1.74.2.46.12.1.1.1\", \"varbind_type\": \"octet\", \"varbind_value\": \"ucsnmp heartbeat - ignore\"} ,{\"varbind_oid\": \".1.3.6.1.4.1.74.2.46.12.1.1.2\", \"varbind_type\": \"octet\", \"varbind_value\": \"Tue Jan 29 23:22:26 2019\"}]}, {\"epoch_serno\": 15488041560000, \"uuid\": \"c338a4b6-241c-11e9-ac41-0242ac11000f\", \"agent address\": \"127.0.0.1\", \"agent name\": \"localhost\", \"cambria.partition\": \"localhost\", \"community\": \"\", \"community len\": 0, \"protocol version\": \"v2c\", \"time received\": 1548804156, \"trap category\": \"com.att.dcae.dmaap.FTL.24256-DCAE-COLLECTOR-UCSNMP-v1\", \"notify OID\": \".1.3.6.1.4.1.74.2.46.12.1.1\", \"notify OID len\": 12, \"varbinds\": [{\"varbind_oid\": \".1.3.6.1.4.1.74.2.46.12.1.1.1\", \"varbind_type\": \"octet\", \"varbind_value\": \"ucsnmp heartbeat - ignore\"} ,{\"varbind_oid\": \".1.3.6.1.4.1.74.2.46.12.1.1.2\", \"varbind_type\": \"octet\", \"varbind_value\": \"Tue Jan 29 23:22:36 2019\"}]}]")
-
-
-def test_open_eelf_error_file():
- """
- Test bad error file location
- """
-
- # open eelf error logs
- tds.c_config['files.eelf_error']="/bad_dir/error.log"
-
- # try to open file in non-existent dir
- with pytest.raises(SystemExit) as pytest_wrapped_exception:
- result = trapd_io.open_eelf_logs()
- assert pytest_wrapped_exception.type == SystemExit
-
-def test_open_eelf_debug_file():
- """
- Test bad debug file location
- """
-
- # open eelf debug logs
- tds.c_config['files.eelf_debug']="/bad_dir/debug.log"
-
- # try to open file in non-existent dir
- with pytest.raises(SystemExit) as pytest_wrapped_exception:
- result = trapd_io.open_eelf_logs()
- assert pytest_wrapped_exception.type == SystemExit
-def test_open_eelf_audit_file():
- """
- Test bad audit file location
- """
-
- # open eelf debug logs
- tds.c_config['files.eelf_audit']="/bad_dir/audit.log"
-
- # try to open file in non-existent dir
- with pytest.raises(SystemExit) as pytest_wrapped_exception:
- result = trapd_io.open_eelf_logs()
- assert pytest_wrapped_exception.type == SystemExit
-
-def test_open_eelf_metrics_file():
- """
- Test bad metrics file location
- """
-
- # open eelf debug logs
- tds.c_config['files.eelf_metrics']="/bad_dir/metrics.log"
-
- # try to open file in non-existent dir
- with pytest.raises(SystemExit) as pytest_wrapped_exception:
- result = trapd_io.open_eelf_logs()
- assert pytest_wrapped_exception.type == SystemExit
-
-def test_roll_all_logs():
- """
- Test roll of logs when not open
- """
- # try to roll logs when not open
- with pytest.raises(SystemExit) as pytest_wrapped_exception:
- result = trapd_io.roll_all_logs()
- assert pytest_wrapped_exception.type == SystemExit
-
-def test_roll_file():
- """
- Test roll of individual file when not present
- """
-
- # try to roll logs when not open
- assert trapd_io.roll_file("/file/not/present") == False
-
-def test_open_file_exists():
- """
- Test file open in directory present
- """
-
- # create copy of snmptrapd.json for pytest
- test_file = "/tmp/snmptrap_pytest"
-
- # try to roll logs when not open
- result = trapd_io.open_file(test_file)
- assert str(result).startswith("<_io.TextIOWrapper name=") == True
-
-
-def test_open_file_exists_does_not_exist():
- """
- Test file open in directory present
- """
-
- # create copy of snmptrapd.json for pytest
- test_file = "/tmp/no_such_dir/snmptrap_pytest"
-
- # try to open file when dir not present
- with pytest.raises(SystemExit) as pytest_wrapped_exception:
+ def test_roll_all_files_notopen(self):
+ """
+ Test rolling files that aren't open
+ """
+
+ # try to roll logs when not open
+ with pytest.raises(SystemExit) as pytest_wrapped_exception:
+ result = trapd_io.roll_all_logs()
+ assert pytest_wrapped_exception.type == SystemExit
+
+ def test_open_eelf_error_file(self):
+ """
+ Test bad error file location
+ """
+
+ # open eelf error logs
+ tds.c_config['files.eelf_error']="/bad_dir/error.log"
+
+ # try to open file in non-existent dir
+ with pytest.raises(SystemExit) as pytest_wrapped_exception:
+ result = trapd_io.open_eelf_logs()
+ assert pytest_wrapped_exception.type == SystemExit
+
+ def test_open_eelf_debug_file(self):
+ """
+ Test bad debug file location
+ """
+
+ # open eelf debug logs
+ tds.c_config['files.eelf_debug']="/bad_dir/debug.log"
+
+ # try to open file in non-existent dir
+ with pytest.raises(SystemExit) as pytest_wrapped_exception:
+ result = trapd_io.open_eelf_logs()
+ assert pytest_wrapped_exception.type == SystemExit
+
+ def test_open_eelf_audit_file(self):
+ """
+ Test bad audit file location
+ """
+
+ # open eelf debug logs
+ tds.c_config['files.eelf_audit']="/bad_dir/audit.log"
+
+ # try to open file in non-existent dir
+ with pytest.raises(SystemExit) as pytest_wrapped_exception:
+ result = trapd_io.open_eelf_logs()
+ assert pytest_wrapped_exception.type == SystemExit
+
+ def test_open_eelf_metrics_file(self):
+ """
+ Test bad metrics file location
+ """
+
+ # open eelf debug logs
+ tds.c_config['files.eelf_metrics']="/bad_dir/metrics.log"
+
+ # try to open file in non-existent dir
+ with pytest.raises(SystemExit) as pytest_wrapped_exception:
+ result = trapd_io.open_eelf_logs()
+ assert pytest_wrapped_exception.type == SystemExit
+
+ def test_roll_all_logs(self):
+ """
+ Test roll of logs when not open
+ """
+
+ # try to roll logs when not open
+ with pytest.raises(SystemExit) as pytest_wrapped_exception:
+ result = trapd_io.roll_all_logs()
+ assert pytest_wrapped_exception.type == SystemExit
+
+ def test_roll_file(self):
+ """
+ Test roll of individual file when not present
+ """
+
+ # try to roll logs when not open
+ result = trapd_io.roll_file("/file/not/present")
+ self.assertEqual(result, False)
+
+ def test_roll_file_no_write_perms(self):
+ """
+ try to roll logs when not enough perms
+ """
+
+ no_perms_dir="/tmp/opt/app/snmptrap/no_perms"
+ no_perms_file="test.dat"
+ no_perms_fp= no_perms_dir + "/" + no_perms_file
+
+ # required directory tree
+ try:
+ Path(no_perms_dir).mkdir(parents=True, exist_ok=True)
+ os.chmod(no_perms_dir,0o777)
+ except Exception as e:
+ print("Error while running %s : %s" % (os.path.basename(__file__), str(e.strerror)))
+ sys.exit(1)
+
+ # create empty file
+ open(no_perms_fp,'a').close()
+ os.chmod(no_perms_dir,0o444)
+
+ result = trapd_io.roll_file(no_perms_fp)
+ self.assertEqual(result, False)
+
+ # try to roll file in dir with no write perms
+ with pytest.raises(SystemExit) as pytest_wrapped_exception:
+ result = trapd_io.open_file(no_perms_fp)
+ assert pytest_wrapped_exception.type == SystemExit
+
+
+ def test_open_file_exists(self):
+ """
+ Test file open in directory present
+ """
+
+ # create copy of snmptrapd.json for pytest
+ test_file = "/tmp/snmptrap_pytest"
+
+ # try to roll logs when not open
result = trapd_io.open_file(test_file)
- assert pytest_wrapped_exception.type == SystemExit
-
-def test_close_file_exists():
- """
- Test closing a file that's present
- """
-
- # create copy of snmptrapd.json for pytest
- test_file_name = "/tmp/snmptrap_pytest"
- test_file = trapd_io.open_file(test_file_name)
-
- # close active file
- assert trapd_io.close_file(test_file, test_file_name) == True
-
-def test_close_file_does_not_exists():
- """
- Test closing non-existent file
- """
-
- # try to roll logs when not open
- assert trapd_io.close_file(None, None) == False
+ compare = str(result).startswith("<_io.TextIOWrapper name=")
+ self.assertEqual(compare, True)
+
+ def test_open_file_exists_does_not_exist(self):
+ """
+ Test file open in directory present
+ """
+
+ # create copy of snmptrapd.json for pytest
+ test_file = "/tmp/no_such_dir/snmptrap_pytest"
+
+ # try to open file when dir not present
+ with pytest.raises(SystemExit) as pytest_wrapped_exception:
+ result = trapd_io.open_file(test_file)
+ assert pytest_wrapped_exception.type == SystemExit
+
+ def test_close_file_exists(self):
+ """
+ Test closing a file that's present
+ """
+
+ # create copy of snmptrapd.json for pytest
+ test_file_name = "/tmp/snmptrap_pytest"
+ test_file = trapd_io.open_file(test_file_name)
+
+ # close active file
+ result = trapd_io.close_file(test_file, test_file_name)
+ self.assertEqual(result, True)
+
+ def test_close_file_does_not_exists(self):
+ """
+ Test closing non-existent file
+ """
+
+ # try to roll logs when not open
+ result = trapd_io.close_file(None, None)
+ self.assertEqual(result, False)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/test_trapd_runtime_pid.py b/tests/test_trapd_runtime_pid.py
index b9010e1..e22b6cb 100644
--- a/tests/test_trapd_runtime_pid.py
+++ b/tests/test_trapd_runtime_pid.py
@@ -1,3 +1,19 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
import pytest
import unittest
import trapd_runtime_pid
diff --git a/tests/test_trapd_settings.py b/tests/test_trapd_settings.py
index 17b20a8..9d5cee2 100644
--- a/tests/test_trapd_settings.py
+++ b/tests/test_trapd_settings.py
@@ -1,3 +1,19 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
import pytest
import unittest
import trapd_exit
diff --git a/tests/test_trapd_snmpv3.py b/tests/test_trapd_snmpv3.py
index 2a0ef12..478f479 100644
--- a/tests/test_trapd_snmpv3.py
+++ b/tests/test_trapd_snmpv3.py
@@ -1,3 +1,19 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
import pytest
import json
import unittest
diff --git a/tests/test_trapd_stormwatch.py b/tests/test_trapd_stormwatch.py
new file mode 100644
index 0000000..236157e
--- /dev/null
+++ b/tests/test_trapd_stormwatch.py
@@ -0,0 +1,54 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
+import pytest
+import unittest
+import trapd_exit
+
+import trapd_stormwatch as sw
+import trapd_stormwatch_settings as sws
+import trapd_stats_settings as stats
+
+class test_cleanup_and_exit(unittest.TestCase):
+ """
+ Test for presense of required vars
+ """
+
+
+ def test_increment_existing_counter(self):
+ """
+ Test increment counter
+ """
+ sw.sw_init()
+ stats.init()
+
+ oid=".1.2.3.4.5.6"
+ sws.sw_config_oid_dict[oid] = True
+ sws.sw_config_low_water_in_interval_dict[oid] = 1
+ sws.sw_config_high_water_in_interval_dict[oid] = 10
+
+ try:
+ sw.stats_increment_counters("192.168.1.1", ".1.2.3.4.5.6")
+ result = True
+ except:
+ result = False
+
+ self.assertEqual(result, True)
+
+
+if __name__ == '__main__':
+ # sws.init()
+ unittest.main()
diff --git a/tests/test_trapd_stormwatch_settings.py b/tests/test_trapd_stormwatch_settings.py
new file mode 100644
index 0000000..ba8ddb0
--- /dev/null
+++ b/tests/test_trapd_stormwatch_settings.py
@@ -0,0 +1,158 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
+import pytest
+import unittest
+import trapd_exit
+
+pid_file="/tmp/test_pid_file"
+pid_file_dne="/tmp/test_pid_file_NOT"
+
+import trapd_stormwatch_settings as sws
+
+class test_cleanup_and_exit(unittest.TestCase):
+ """
+ Test for presense of required vars
+ """
+
+
+ def test_nonexistent_dict(self):
+ """
+ Test nosuch var
+ """
+ sws.init()
+ try:
+ sws.no_such_var
+ result = True
+ except:
+ result = False
+
+ self.assertEqual(result, False)
+
+ def test_storm_counter_dict(self):
+ """
+ Test storm_counter_dict
+ """
+ sws.init()
+ try:
+ sws.sw_storm_counter_dict
+ result = True
+ except:
+ result = False
+
+ self.assertEqual(result, True)
+
+ def test_storm_active_dict(self):
+ """
+ Test storm_active_dict
+ """
+
+ sws.init()
+ try:
+ sws.sw_storm_active_dict
+ result = True
+ except:
+ result = False
+
+ self.assertEqual(result, True)
+
+ def test_sw_config_oid_dict(self):
+ """
+ Test sw_config_oid_dict
+ """
+
+ sws.init()
+ try:
+ sws.sw_config_oid_dict
+ result = True
+ except:
+ result = False
+
+ self.assertEqual(result, True)
+
+ def test_sw_config_low_water_in_interval_dict(self):
+ """
+ Test low_water
+ """
+
+ sws.init()
+ try:
+ sws.sw_config_low_water_in_interval_dict
+ result = True
+ except:
+ result = False
+
+ self.assertEqual(result, True)
+
+ def test_sw_config_high_water_in_interval_dict(self):
+ """
+ Test high water dict
+ """
+
+ sws.init()
+ try:
+ sws.sw_config_high_water_in_interval_dict
+ result = True
+ except:
+ result = False
+
+ self.assertEqual(result, True)
+
+ def test_sw_config_category(self):
+ """
+ Test category
+ """
+
+ sws.init()
+ try:
+ sws.sw_config_category
+ result = True
+ except:
+ result = False
+
+ self.assertEqual(result, True)
+
+ def test_sw_interval_in_seconds(self):
+ """
+ Test sw_interval
+ """
+
+ sws.init()
+ try:
+ str(sws.sw_interval_in_seconds).isnumeric()
+ result = True
+ except:
+ result = False
+
+ self.assertEqual(result, True)
+
+ def test_sw_last_stormwatch_dict_analysis(self):
+ """
+ Test last_stormwatch_dict_analysis
+ """
+
+ sws.init()
+ try:
+ str(sws.sw_last_stormwatch_dict_analysis).isnumeric()
+ result = True
+ except:
+ result = False
+
+ self.assertEqual(result, True)
+
+if __name__ == '__main__':
+ # sws.init()
+ unittest.main()
diff --git a/tests/test_trapd_vb_types.py b/tests/test_trapd_vb_types.py
index 67c9233..1cf75ab 100644
--- a/tests/test_trapd_vb_types.py
+++ b/tests/test_trapd_vb_types.py
@@ -1,3 +1,19 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+
import pytest
import json
import unittest
@@ -16,25 +32,111 @@ class test_trapd_vb_types(unittest.TestCase):
Test snmpv3 module
"""
- def trapd_vb_type_conversion_valid(self):
+ good_varbind_types = ["Integer", "Unsigned32", "Counter32", "OctetString", "ObjectIdentifier", "TimeTicks", "IpAddress"]
+
+ def trapd_vb_type_conversion_integer(self):
"""
- Test that pysnmp varbind types convert to netsnmp
+ Test that pysnmp varbind types Integer converts
"""
- tds.c_config = json.loads("{ \"snmptrapd\": { \"version\": \"1.4.0\", \"title\": \"ONAP SNMP Trap Receiver\" }, \"protocols\": { \"transport\": \"udp\", \"ipv4_interface\": \"0.0.0.0\", \"ipv4_port\": 6162, \"ipv6_interface\": \"::1\", \"ipv6_port\": 6162 }, \"cache\": { \"dns_cache_ttl_seconds\": 60 }, \"publisher\": { \"http_timeout_milliseconds\": 1500, \"http_retries\": 3, \"http_milliseconds_between_retries\": 750, \"http_primary_publisher\": \"true\", \"http_peer_publisher\": \"unavailable\", \"max_traps_between_publishes\": 10, \"max_milliseconds_between_publishes\": 10000 }, \"streams_publishes\": { \"sec_fault_unsecure\": { \"type\": \"message_router\", \"aaf_password\": null, \"dmaap_info\": { \"location\": \"mtl5\", \"client_id\": null, \"client_role\": null, \"topic_url\": \"http://localhost:3904/events/ONAP-COLLECTOR-SNMPTRAP\" }, \"aaf_username\": null } }, \"files\": { \"runtime_base_dir\": \"/tmp/opt/app/snmptrap\", \"log_dir\": \"logs\", \"data_dir\": \"data\", \"pid_dir\": \"tmp\", \"arriving_traps_log\": \"snmptrapd_arriving_traps.log\", \"snmptrapd_diag\": \"snmptrapd_prog_diag.log\", \"traps_stats_log\": \"snmptrapd_stats.csv\", \"perm_status_file\": \"snmptrapd_status.log\", \"eelf_base_dir\": \"/tmp/opt/app/snmptrap/logs\", \"eelf_error\": \"error.log\", \"eelf_debug\": \"debug.log\", \"eelf_audit\": \"audit.log\", \"eelf_metrics\": \"metrics.log\", \"roll_frequency\": \"day\", \"minimum_severity_to_log\": 2 }, \"trap_config\": { \"sw_interval_in_seconds\": 60, \"notify_oids\": { \".1.3.6.1.4.1.9.0.1\": { \"sw_high_water_in_interval\": 102, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.2\": { \"sw_high_water_in_interval\": 101, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.3\": { \"sw_high_water_in_interval\": 102, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.4\": { \"sw_high_water_in_interval\": 10, \"sw_low_water_in_interval\": 3, \"category\": \"logonly\" } } } }")
+ result = trapd_vb_types.pysnmp_to_netsnmp_varbind_convert("Integer32")
+ self.assertEqual(result, "integer")
+
+ def trapd_vb_type_conversion_integer(self):
+ """
+ Test that pysnmp varbind types Integer converts
+ """
- good_varbind_types = ["Integer", "Unsigned32", "Counter32", "OctetString", "ObjectIdentifier", "TimeTicks", "IpAddress"]
result = trapd_vb_types.pysnmp_to_netsnmp_varbind_convert("Integer")
self.assertEqual(result, "integer")
- def trapd_vb_type_conversion_invalid(self):
+ def trapd_vb_type_conversion_integer(self):
+ """
+ Test that pysnmp varbind types Integer converts
+ """
+
+ result = trapd_vb_types.pysnmp_to_netsnmp_varbind_convert("Gauge32")
+ self.assertEqual(result, "unsigned")
+
+ def trapd_vb_type_conversion_integer(self):
+ """
+ Test that pysnmp varbind types Integer converts
+ """
+
+ result = trapd_vb_types.pysnmp_to_netsnmp_varbind_convert("Counter32")
+ self.assertEqual(result, "counter32")
+
+ def trapd_vb_type_conversion_integer(self):
+ """
+ Test that pysnmp varbind types convert accurately
+ """
+
+ result = trapd_vb_types.pysnmp_to_netsnmp_varbind_convert("OctetString")
+ self.assertEqual(result, "octet")
+
+ def trapd_vb_type_conversion_integer(self):
+ """
+ Test that pysnmp varbind types convert accurately
+ """
+
+ result = trapd_vb_types.pysnmp_to_netsnmp_varbind_convert("py_type_5")
+ self.assertEqual(result, "hex")
+
+ def trapd_vb_type_conversion_integer(self):
"""
- Test that pysnmp varbind types convert to netsnmp
+ Test that pysnmp varbind types convert accurately
"""
- tds.c_config = json.loads("{ \"snmptrapd\": { \"version\": \"1.4.0\", \"title\": \"ONAP SNMP Trap Receiver\" }, \"protocols\": { \"transport\": \"udp\", \"ipv4_interface\": \"0.0.0.0\", \"ipv4_port\": 6162, \"ipv6_interface\": \"::1\", \"ipv6_port\": 6162 }, \"cache\": { \"dns_cache_ttl_seconds\": 60 }, \"publisher\": { \"http_timeout_milliseconds\": 1500, \"http_retries\": 3, \"http_milliseconds_between_retries\": 750, \"http_primary_publisher\": \"true\", \"http_peer_publisher\": \"unavailable\", \"max_traps_between_publishes\": 10, \"max_milliseconds_between_publishes\": 10000 }, \"streams_publishes\": { \"sec_fault_unsecure\": { \"type\": \"message_router\", \"aaf_password\": null, \"dmaap_info\": { \"location\": \"mtl5\", \"client_id\": null, \"client_role\": null, \"topic_url\": \"http://localhost:3904/events/ONAP-COLLECTOR-SNMPTRAP\" }, \"aaf_username\": null } }, \"files\": { \"runtime_base_dir\": \"/tmp/opt/app/snmptrap\", \"log_dir\": \"logs\", \"data_dir\": \"data\", \"pid_dir\": \"tmp\", \"arriving_traps_log\": \"snmptrapd_arriving_traps.log\", \"snmptrapd_diag\": \"snmptrapd_prog_diag.log\", \"traps_stats_log\": \"snmptrapd_stats.csv\", \"perm_status_file\": \"snmptrapd_status.log\", \"eelf_base_dir\": \"/tmp/opt/app/snmptrap/logs\", \"eelf_error\": \"error.log\", \"eelf_debug\": \"debug.log\", \"eelf_audit\": \"audit.log\", \"eelf_metrics\": \"metrics.log\", \"roll_frequency\": \"day\", \"minimum_severity_to_log\": 2 }, \"trap_config\": { \"sw_interval_in_seconds\": 60, \"notify_oids\": { \".1.3.6.1.4.1.9.0.1\": { \"sw_high_water_in_interval\": 102, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.2\": { \"sw_high_water_in_interval\": 101, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.3\": { \"sw_high_water_in_interval\": 102, \"sw_low_water_in_interval\": 7, \"category\": \"logonly\" }, \".1.3.6.1.4.1.9.0.4\": { \"sw_high_water_in_interval\": 10, \"sw_low_water_in_interval\": 3, \"category\": \"logonly\" } } } }")
+ result = trapd_vb_types.pysnmp_to_netsnmp_varbind_convert("py_type_6")
+ self.assertEqual(result, "decimal")
+
+ def trapd_vb_type_conversion_integer(self):
+ """
+ Test that pysnmp varbind types convert accurately
+ """
+
+ result = trapd_vb_types.pysnmp_to_netsnmp_varbind_convert("Null")
+ self.assertEqual(result, "null")
+
+ def trapd_vb_type_conversion_integer(self):
+ """
+ Test that pysnmp varbind types convert accurately
+ """
+
+ result = trapd_vb_types.pysnmp_to_netsnmp_varbind_convert("ObjectIdentifier")
+ self.assertEqual(result, "oid")
+
+ def trapd_vb_type_conversion_integer(self):
+ """
+ Test that pysnmp varbind types convert accurately
+ """
+
+ result = trapd_vb_types.pysnmp_to_netsnmp_varbind_convert("TimeTicks")
+ self.assertEqual(result, "timeticks")
+
+ def trapd_vb_type_conversion_integer(self):
+ """
+ Test that pysnmp varbind types convert accurately
+ """
+
+ result = trapd_vb_types.pysnmp_to_netsnmp_varbind_convert("IpAddress")
+ self.assertEqual(result, "ipaddress")
+
+ def trapd_vb_type_conversion_integer(self):
+ """
+ Test that pysnmp varbind types convert accurately
+ """
+
+ result = trapd_vb_types.pysnmp_to_netsnmp_varbind_convert("Bits")
+ self.assertEqual(result, "bits")
+
+ def trapd_vb_type_conversion_invalid(self):
+ """
+ Test that pysnmp varbind types convert accurately
+ """
result = trapd_vb_types.pysnmp_to_netsnmp_varbind_convert("noSuchVarbindType")
+ # should return default of octet if not defined
self.assertEqual(result, "octet")