예제 #1
0
    def test_plugin_info_configMtime(self):
        panoptes_plugin_info = PanoptesPluginInfo("plugin_name", "path/to/plugin")
        panoptes_plugin_info.config_filename = self.my_dir
        self.assertEqual(panoptes_plugin_info.configMtime, int(os.path.getmtime(self.my_dir)))

        panoptes_plugin_info.config_filename = "/non/existent/file"
        with self.assertRaises(PanoptesPluginConfigurationError):
            panoptes_plugin_info.configMtime
예제 #2
0
    def test_plugin_info_moduleMtime(self):
        panoptes_plugin_info = PanoptesPluginInfo("plugin_name", "path/to/plugin")
        panoptes_plugin_info.path = self.my_dir

        self.assertEqual(panoptes_plugin_info.moduleMtime, get_module_mtime(self.my_dir))

        panoptes_plugin_info.path = 0
        with self.assertRaises(PanoptesPluginConfigurationError):
            panoptes_plugin_info.moduleMtime
예제 #3
0
    def test_plugin_info_last_executed(self):
        panoptes_plugin_info = PanoptesPluginInfo("plugin_name", "path/to/plugin")
        panoptes_plugin_info.panoptes_context = self._panoptes_context
        panoptes_plugin_info.kv_store_class = PanoptesTestKeyValueStore

        #  Test last_executed setter handles exception.
        with patch('yahoo_panoptes.framework.plugins.panoptes_base_plugin.PanoptesPluginInfo.metadata_kv_store',
                   mock_metadata_kv_store):
            panoptes_plugin_info.last_executed = 1
            self.assertNotEqual(panoptes_plugin_info.last_executed, 1)
            self.assertEqual(panoptes_plugin_info.last_executed, 0)
예제 #4
0
    def test_plugin_info_moduleMtime(self):
        panoptes_plugin_info = PanoptesPluginInfo(u"plugin_name",
                                                  u"path/to/plugin")
        panoptes_plugin_info.path = self.my_dir

        self.assertEqual(panoptes_plugin_info.moduleMtime,
                         get_module_mtime(self.my_dir))

        with self.assertRaises(Exception):
            panoptes_plugin_info.path = 0
            panoptes_plugin_info.moduleMtime
예제 #5
0
    def test_plugin_info_last_properties(self):
        panoptes_plugin_info = PanoptesPluginInfo("Test Polling Plugin",
                                                  "tests/plugins/polling/test")

        #  Test last_results and last_executed return 0 on exception.
        with self.assertRaises(AssertionError):
            panoptes_plugin_info.last_executed = "test"
        self.assertEqual(panoptes_plugin_info.last_executed, 0)

        with self.assertRaises(AssertionError):
            panoptes_plugin_info.last_results = "test"
        self.assertEqual(panoptes_plugin_info.last_results, 0)
예제 #6
0
    def test_plugin_info_properties(self):
        panoptes_plugin_info = PanoptesPluginInfo("Test Polling Plugin",
                                                  "tests/plugins/polling/test")

        with self.assertRaises(PanoptesPluginConfigurationError):
            panoptes_plugin_info.panoptes_context

        panoptes_plugin_info.panoptes_context = self._panoptes_context
        panoptes_plugin_info.kv_store_class = PanoptesTestKeyValueStore
        panoptes_plugin_info.last_executed = _LAST_EXECUTED_TEST_VALUE
        panoptes_plugin_info.config_filename = "tests/plugins/polling/test/plugin_polling_test.panoptes-plugin"

        #  Test results_cache_age, execute_frequency, last_executed return 0 on exception.
        self.assertEqual(panoptes_plugin_info.results_cache_age, 0)
        self.assertEqual(panoptes_plugin_info.execute_frequency, 0)

        panoptes_plugin_info.details.read(panoptes_plugin_info.config_filename)

        self.assertEqual(panoptes_plugin_info.results_cache_age, 100)
        self.assertEqual(panoptes_plugin_info.execute_frequency, 60)

        #  Test last_executed setter cannot be reset after being read
        self.assertEqual(panoptes_plugin_info.last_executed, _LAST_EXECUTED_TEST_VALUE)
        panoptes_plugin_info.last_executed = 1
        self.assertNotEqual(panoptes_plugin_info.last_executed, 1)
        self.assertEqual(panoptes_plugin_info.last_executed, _LAST_EXECUTED_TEST_VALUE)

        with patch("yahoo_panoptes.framework.plugins.panoptes_base_plugin.time.time", mock_time):
            self.assertEqual(panoptes_plugin_info.last_executed_age, int(_TIMESTAMP - _LAST_EXECUTED_TEST_VALUE))
예제 #7
0
    def test_plugin_info_last_results(self):
        panoptes_plugin_info = PanoptesPluginInfo(u"plugin_name",
                                                  u"path/to/plugin")
        panoptes_plugin_info.panoptes_context = self._panoptes_context
        panoptes_plugin_info.kv_store_class = PanoptesTestKeyValueStore

        panoptes_plugin_info.last_results = _LAST_RESULTS_TEST_VALUE
        self.assertEqual(panoptes_plugin_info.last_results,
                         _LAST_RESULTS_TEST_VALUE)

        # Test value is cached.
        self.assertEqual(panoptes_plugin_info.last_results,
                         _LAST_RESULTS_TEST_VALUE)

        #  Test last_results setter handles exception.
        with patch(
                u'yahoo_panoptes.framework.plugins.panoptes_base_plugin.PanoptesPluginInfo.metadata_kv_store',
                mock_metadata_kv_store):
            panoptes_plugin_info.last_results = 1
            self.assertNotEqual(panoptes_plugin_info.last_results, 1)
            self.assertEqual(panoptes_plugin_info.last_results,
                             _LAST_RESULTS_TEST_VALUE)

        #  Test last results age.
        with patch(
                u"yahoo_panoptes.framework.plugins.panoptes_base_plugin.time.time",
                mock_time):
            self.assertEqual(panoptes_plugin_info.last_results_age,
                             int(_TIMESTAMP - _LAST_RESULTS_TEST_VALUE))
예제 #8
0
    def test_plugin_info_repr(self):
        panoptes_plugin_info = PanoptesPluginInfo("plugin_name",
                                                  "path/to/plugin")
        panoptes_plugin_info.panoptes_context = self._panoptes_context
        panoptes_plugin_info.data = self._panoptes_resource
        panoptes_plugin_info.kv_store_class = PanoptesTestKeyValueStore
        panoptes_plugin_info.last_executed = _LAST_EXECUTED_TEST_VALUE
        panoptes_plugin_info.last_results = _LAST_RESULTS_TEST_VALUE

        repr_string = "PanoptesPluginInfo: Normalized name: plugin__name, Config file: None, " \
                      "Panoptes context: [PanoptesContext: KV Stores: [PanoptesTestKeyValueStore], " \
                      "Config: ConfigObj({'main': {'sites': ['local'], " \
                      "'plugins_extension': 'panoptes-plugin', 'plugins_skew': 1}, " \
                      "'log': {'config_file': 'tests/config_files/test_panoptes_logging.ini', 'rate': 1000, " \
                      "'per': 1, 'burst': 10000, " \
                      "'formatters': {'keys': ['root_log_format', 'log_file_format', 'discovery_plugins_format']}}, " \
                      "'redis': {'default': {'namespace': 'panoptes', 'shards': {'shard1': " \
                      "{'host': 'localhost', 'port': 6379, 'db': 0, 'password': '******'}}}}, " \
                      "'kafka': {'topic_key_delimiter': ':', 'topic_name_delimiter': '-', " \
                      "'brokers': {'broker1': {'host': 'localhost', 'port': 9092}}, " \
                      "'topics': {'metrics': {'raw_topic_name_suffix': 'metrics', " \
                      "'transformed_topic_name_suffix': 'processed'}}}, " \
                      "'zookeeper': {'connection_timeout': 30, 'servers': {'server1': " \
                      "{'host': 'localhost', 'port': 2181}}}, 'discovery': {" \
                      "'plugins_paths': ['tests/plugins/discovery'], 'plugin_scan_interval': 60, " \
                      "'celerybeat_max_loop_interval': 5}, " \
                      "'polling': {'plugins_paths': ['tests/plugins/polling'], 'plugin_scan_interval': 60, " \
                      "'celerybeat_max_loop_interval': 5}, " \
                      "'enrichment': {'plugins_paths': ['tests/plugins/enrichment'], " \
                      "'plugin_scan_interval': 60, 'celerybeat_max_loop_interval': 5}, " \
                      "'snmp': {'port': 10161, 'connection_factory_module': " \
                      "'yahoo_panoptes.framework.utilities.snmp.connection', 'connection_factory_class': " \
                      "'PanoptesSNMPConnectionFactory', 'community': '**', 'timeout': 5, 'retries': 1, " \
                      "'non_repeaters': 0, 'max_repetitions': 25, 'proxy_port': 10161, " \
                      "'community_string_key': 'snmp_community_string'}}), Redis pool set: False, " \
                      "Message producer set: False, Kafka client set: False, Zookeeper client set: False], " \
                      "KV store class: PanoptesTestKeyValueStore, Last executed timestamp: 1458947997, " \
                      "Last executed key: plugin_metadata:plugin__name:" \
                      "61547fbb304169f2a076016678bc9cca:last_executed, " \
                      "Last results timestamp: 1458948005, " \
                      "Last results key: plugin_metadata:plugin__name:" \
                      "61547fbb304169f2a076016678bc9cca:last_results, " \
                      "Data: Data object passed, " \
                      "Lock: Lock is set"
        self.assertEqual(repr(panoptes_plugin_info), repr_string)
예제 #9
0
    def test_plugin_info_lock(self):
        panoptes_plugin_info = PanoptesPluginInfo("plugin_name", "path/to/plugin")
        panoptes_plugin_info.panoptes_context = self._panoptes_context
        self.assertIsNotNone(panoptes_plugin_info.lock)
        self.assertTrue(panoptes_plugin_info.lock.locked)

        #  Assert lock is cached
        self.assertIsNotNone(panoptes_plugin_info.lock)
        self.assertTrue(panoptes_plugin_info.lock.locked)

        panoptes_plugin_info_2 = PanoptesPluginInfo("plugin_name", "path/to/plugin")
        panoptes_plugin_info_2.panoptes_context = self._panoptes_context

        #  Patch timeout to speed up test
        with patch('yahoo_panoptes.framework.plugins.panoptes_base_plugin.const.PLUGIN_AGENT_LOCK_ACQUIRE_TIMEOUT', 1):
            self.assertFalse(panoptes_plugin_info_2.lock.locked)
예제 #10
0
    def test_plugininfo_repr(self):
        panoptes_context = PanoptesContext(self.panoptes_test_conf_file,
                                           key_value_store_class_list=[PanoptesTestKeyValueStore],
                                           create_message_producer=False, async_message_producer=False,
                                           create_zookeeper_client=True)

        panoptes_resource = PanoptesResource(resource_site='test', resource_class='test',
                                             resource_subclass='test',
                                             resource_type='test', resource_id='test', resource_endpoint='test',
                                             resource_plugin='test')

        panoptes_plugininfo = PanoptesPluginInfo("plugin_name", "plugin_path")
        panoptes_plugininfo.panoptes_context = panoptes_context
        panoptes_plugininfo.data = panoptes_resource
        panoptes_plugininfo.kv_store_class = PanoptesTestKeyValueStore
        panoptes_plugininfo.last_executed = "1458947997"
        panoptes_plugininfo.last_results = "1458948005"

        repr_string = "PanoptesPluginInfo: Normalized name: plugin__name, Config file: None, "\
                      "Panoptes context: " \
                      "[PanoptesContext: KV Stores: [PanoptesTestKeyValueStore], "\
                      "Config: ConfigObj({'main': {'sites': " \
                      "['local'], 'plugins_extension': 'panoptes-plugin', 'plugins_skew': 1}, " \
                      "'log': " \
                      "{'config_file': 'tests/config_files/test_panoptes_logging.ini', " \
                      "'rate': 1000, " \
                      "'per': 1, " \
                      "'burst': 10000, " \
                      "'formatters': {'keys': ['root_log_format', 'log_file_format', 'discovery_plugins_format']}}, " \
                      "'redis': {'default': {'namespace': 'panoptes', "\
                      "'shards': {'shard1': {'host': 'localhost', 'port': 6379, 'db': 0, 'password': '******'}}}}, "\
                      "'kafka': {'topic_key_delimiter': ':', 'topic_name_delimiter': '-', " \
                      "'brokers': {'broker1': {'host': 'localhost', 'port': 9092}}, " \
                      "'topics': " \
                      "{'metrics': {'raw_topic_name_suffix': 'metrics', " \
                      "'transformed_topic_name_suffix': 'processed'}}}, " \
                      "'zookeeper': {'connection_timeout': 30, 'servers': {'server1': {'host': " \
                      "'localhost', 'port': 2181}}}, " \
                      "'discovery': " \
                      "{'plugins_path': 'tests/plugins/discovery', " \
                      "'plugin_scan_interval': 60, " \
                      "'celerybeat_max_loop_interval': 5}, " \
                      "'polling': " \
                      "{'plugins_path': 'tests/plugins/polling', " \
                      "'plugin_scan_interval': 60, " \
                      "'celerybeat_max_loop_interval': 5}, " \
                      "'enrichment': " \
                      "{'plugins_path': 'tests/plugins/enrichment', " \
                      "'plugin_scan_interval': 60, " \
                      "'celerybeat_max_loop_interval': 5}, " \
                      "'snmp': " \
                      "{'port': 10161, " \
                      "'connection_factory_module': 'yahoo_panoptes.framework.utilities.snmp.connection', " \
                      "'connection_factory_class': 'PanoptesSNMPConnectionFactory', " \
                      "'community': '**', 'timeout': 5, 'retries': 1, 'non_repeaters': 0, 'max_repetitions': 25, " \
                      "'proxy_port': 10161, 'community_string_key': 'snmp_community_string'}}), "\
                      "Redis pool set: False, " \
                      "Message producer set: False, " \
                      "Kafka client set: False, " \
                      "Zookeeper client set: False], " \
                      "KV store class: PanoptesTestKeyValueStore, " \
                      "Last executed timestamp: 1458947997, " \
                      "Last executed key: " \
                      "plugin_metadata:plugin__name:be7eabbca3b05b9aaa8c81201aa0ca3e:last_executed, " \
                      "Last results timestamp: 1458948005, " \
                      "Last results key: plugin_metadata:plugin__name:be7eabbca3b05b9aaa8c81201aa0ca3e:last_results, " \
                      "Data: Data object passed, " \
                      "Lock: Lock is set"
        self.assertEqual(repr(panoptes_plugininfo), repr_string)
예제 #11
0
    def test_plugin_info_execute_now(self):
        with patch("yahoo_panoptes.framework.plugins.panoptes_base_plugin.time.time", mock_time):
            panoptes_plugin_info = PanoptesPluginInfo("plugin_name", "path/to/plugin")
            panoptes_plugin_info.panoptes_context = self._panoptes_context
            panoptes_plugin_info.kv_store_class = PanoptesTestKeyValueStore
            panoptes_plugin_info.config_filename = "tests/plugins/polling/test/plugin_polling_test.panoptes-plugin"
            panoptes_plugin_info.details.read(panoptes_plugin_info.config_filename)

            mock_moduleMtime = _TIMESTAMP - 1
            mock_configMtime = _TIMESTAMP - 2
            with patch('yahoo_panoptes.framework.plugins.panoptes_base_plugin.PanoptesPluginInfo.configMtime',
                       mock_configMtime):
                with patch('yahoo_panoptes.framework.plugins.panoptes_base_plugin.PanoptesPluginInfo.moduleMtime',
                           mock_moduleMtime):
                    # Ensure first if-block in execute_now returns False
                    panoptes_plugin_info.last_results = int(_TIMESTAMP)
                    panoptes_plugin_info.last_executed = int(_TIMESTAMP)
                    self.assertFalse(panoptes_plugin_info.execute_now)

                    # Ensure second if-block in execute_now returns False
                    panoptes_plugin_info._last_results = None
                    panoptes_plugin_info._last_executed = None

                    panoptes_plugin_info.last_results = int(_TIMESTAMP)
                    panoptes_plugin_info.last_executed = (int(_TIMESTAMP) - panoptes_plugin_info.execute_frequency)
                    self.assertFalse(panoptes_plugin_info.execute_now)

                    # Ensure returns True
                    panoptes_plugin_info._last_results = None
                    panoptes_plugin_info._last_executed = None

                    panoptes_plugin_info.last_results = (int(_TIMESTAMP) - panoptes_plugin_info.execute_frequency)
                    self.assertTrue(panoptes_plugin_info.execute_now)