当前位置: 首页>>代码示例>>Python>>正文


Python Importer.call方法代码示例

本文整理汇总了Python中importer.Importer.call方法的典型用法代码示例。如果您正苦于以下问题:Python Importer.call方法的具体用法?Python Importer.call怎么用?Python Importer.call使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在importer.Importer的用法示例。


在下文中一共展示了Importer.call方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ServiceTest

# 需要导入模块: from importer import Importer [as 别名]
# 或者: from importer.Importer import call [as 别名]
class ServiceTest(unittest.TestCase):

    def setUp(self):
        """ Initialize test environment. """
        # TODO: clean up spvd database beforehand
        self.imp = Importer()
        self.imp['distant_url'] = 'https://192.168.2.81/exporter/'
        self.groups = []
        self.checks = []
        self.objects = []

    def tearDown(self):
        """ Clean up test environment. """
        groups = [grp_id for list_id in self.groups for grp_id in list_id]
        checks = [chk_id for list_id in self.checks for chk_id in list_id]
        objects = [obj_id for list_id in self.objects for obj_id in list_id]

        if groups:
            self.imp.call('spv.services', 'delete_groups', groups)
        if checks:
            self.imp.call('spv.services', 'delete_checks', checks)
        if objects:
            self.imp.call('spv.services', 'delete_objects', objects)

    #
    # TEST FOR GET_STATUS
    #

    def _get_status_tests_create_data(self):
        """ Test create object,group,check for get_status tests """
        groups = self.imp.call('spv.services', 'create_groups', ['test_groups'])
        self.groups.append(groups.keys())
        objects = self.imp.call('spv.services', 'create_objects',
                [{'address': 'test_address', 'infos': {'key_toto': 'value_toto'}, 'group_id': groups.keys()[0]}])
        self.objects.append(objects.keys())
        checks = self.imp.call('spv.services', 'create_checks',
                [{'plugin': 'hey', 'plugin_check': 'salut', 'name': 'toi', 'repeat': 100,
                    'repeat_on_error': 100 , 'infos': {'key_toto': 'value_toto'}, 'group_id': groups.keys()[0]}])
        self.checks.append(checks.keys())
        return [groups, objects, checks]

    def _get_status_test_value(self, data, groups, objects, checks):
        keys = data.keys()
        keys.sort();
        self.assertTrue(keys == ['checks', 'groups', 'objects', 'status'])
        self.assertTrue(data['checks'][checks.keys()[0]]['name'] == 'toi')
        self.assertTrue(data['groups'][groups.keys()[0]]['name'] == 'test_groups')
        self.assertTrue(data['objects'][objects.keys()[0]]['address'] == 'test_address')
        self.assertTrue(data['status'][data['status'].keys()[0]]['grp_id'] == groups.keys()[0])
        self.assertTrue(data['status'][data['status'].keys()[0]]['chk_id'] == checks.keys()[0])
        self.assertTrue(data['status'][data['status'].keys()[0]]['obj_id'] == objects.keys()[0])

    def test_get_status_check_status(self):
        """ ['get_status'] Get every status with on specific status """
        self._get_status_tests_create_data()
        ret = self.imp.call('spv.services', 'get_status', {'status': ['FINISHED', 'ERROR']})
        for status in ret['status']:
            self.assertTrue(ret['status'][status]['check_status'] in ['FINISHED', 'ERROR'])
        ret_finish = self.imp.call('spv.services', 'get_status', {'status': 'FINISHED'})
        self.assertNotEqual(len(ret), 0)
        for status in ret_finish['status']:
            self.assertEqual(ret_finish['status'][status]['check_status'], 'FINISHED')
        len_error = len(self.imp.call('spv.services', 'get_status', {'status': 'ERROR'})['status'])
        self.assertEqual(len(ret['status']), len(ret_finish['status']) + len_error)

    def test_get_status_group_name(self):
        """ ['get_status'] Get every status with on specific group_name """
        groups, objects, checks = self._get_status_tests_create_data()
        ret = self.imp.call('spv.services', 'get_status', {'group_name': [groups.values()[0]['name']]})
        self._get_status_test_value(ret, groups, objects, checks)

    def test_get_status_object_address(self):
        """ ['get_status'] Get every status with on specific object address """
        groups, objects, checks = self._get_status_tests_create_data()
        ret = self.imp.call('spv.services', 'get_status', {'object_address': objects.values()[0]['address']})
        self._get_status_test_value(ret, groups, objects, checks)

    def test_get_status_plugin_name(self):
        """ ['get_status'] Get every status with on specific plugin name """
        groups, objects, checks = self._get_status_tests_create_data()
        ret = self.imp.call('spv.services', 'get_status', {'plugin_name': checks.values()[0]['plugin']})
        self._get_status_test_value(ret, groups, objects, checks)

    def test_get_status_plugin_check(self):
        """ ['get_status'] Get every status with on specific plugin check """
        groups, objects, checks = self._get_status_tests_create_data()
        ret = self.imp.call('spv.services', 'get_status', {'plugin_check': checks.values()[0]['plugin_check']})
        self._get_status_test_value(ret, groups, objects, checks)

    def test_get_status_group_id(self):
        """ ['get_status'] Get every status with on specific groups_id """
        groups, objects, checks = self._get_status_tests_create_data()
        ret = self.imp.call('spv.services', 'get_status', {'group_id': groups.keys()[0]})
        self._get_status_test_value(ret, groups, objects, checks)

    def test_get_status_check_id(self):
        """ ['get_status'] Get every status with on specific check_id """
        groups, objects, checks =  self._get_status_tests_create_data()
        checks_second = self.imp.call('spv.services', 'create_checks',
                [{'plugin': '1', 'plugin_check': '2', 'name': '3', 'repeat': 100,
#.........这里部分代码省略.........
开发者ID:PhilippeBridant,项目名称:webengine-spv,代码行数:103,代码来源:test_service_get_status.py

示例2: ServiceTest

# 需要导入模块: from importer import Importer [as 别名]
# 或者: from importer.Importer import call [as 别名]
class ServiceTest(unittest.TestCase):

    def setUp(self):
        """ Initialize test environment. """
        # TODO: clean up spvd database beforehand
        self.imp = Importer()
        self.imp['distant_url'] = 'https://192.168.2.81/exporter/'
        self.groups = []
        self.checks = []
        self.objects = []

    def tearDown(self):
        """ Clean up test environment. """
        groups = [grp_id for list_id in self.groups for grp_id in list_id]
        checks = [chk_id for list_id in self.checks for chk_id in list_id]
        objects = [obj_id for list_id in self.objects for obj_id in list_id]

        if groups:
            self.imp.call('spv.services', 'delete_groups', groups)
        if checks:
            self.imp.call('spv.services', 'delete_checks', checks)
        if objects:
            self.imp.call('spv.services', 'delete_objects', objects)

    #
    # TEST FOR GET_STATUS
    #

    def _get_status_tests_create_data(self):
        """ Test create object,group,check for get_status tests """
        groups = self.imp.call('spv.services', 'create_groups', ['test_groups'])
        self.groups.append(groups.keys())
        objects = self.imp.call('spv.services', 'create_objects',
                [{'address': 'test_address', 'infos': {'key_toto': 'value_toto'}, 'group_id': groups.keys()[0]}])
        self.objects.append(objects.keys())
        checks = self.imp.call('spv.services', 'create_checks',
                [{'plugin': 'hey', 'plugin_check': 'salut', 'name': 'toi', 'repeat': 100,
                    'repeat_on_error': 100 , 'infos': {'key_toto': 'value_toto'}, 'group_id': groups.keys()[0]}])
        self.checks.append(checks.keys())
        return [groups, objects, checks]

    def _get_status_test_value(self, data, groups, objects, checks):
        keys = data.keys()
        keys.sort();
        self.assertTrue(keys == ['checks', 'groups', 'objects', 'status'])
        self.assertTrue(data['checks'][checks.keys()[0]]['name'] == 'toi')
        self.assertTrue(data['groups'][groups.keys()[0]]['name'] == 'test_groups')
        self.assertTrue(data['objects'][objects.keys()[0]]['address'] == 'test_address')
        self.assertTrue(data['status'][0]['grp_id'] == groups.keys()[0])
        self.assertTrue(data['status'][0]['chk_id'] == checks.keys()[0])
        self.assertTrue(data['status'][0]['obj_id'] == objects.keys()[0])


    def _check_get_status_info(self, data, type, info, id_name):
        """ generic funtionc to test get_status with additional info"""
        id = data[type].keys()[0]
        self.assertTrue(info in data[type][id].keys())
        infos = data[type][id][info]
        self.assertTrue('key_toto' in infos.keys())
        self.assertEqual(infos['key_toto'][id_name], id)
        self.assertEqual(infos['key_toto']['key'], 'key_toto')
        self.assertEqual(infos['key_toto']['value'], 'value_toto')

    #
    # DELETION TEST
    #

    def test_delete_groups(self):
        """ Create a groups, check and try to delete it """
        groups = self.imp.call('spv.services', 'create_groups', 'toto')
        self.groups.append(groups.keys())
        self.assertEqual(len(self.imp.call('spv.services', 'get_groups', {'group_id': groups.keys()[0]})), 1)
        self.imp.call('spv.services', 'delete_groups', groups.keys())
        self.assertEqual(len(self.imp.call('spv.services', 'get_groups', {'group_id': groups.keys()[0]})), 0)

    def test_delete_checks(self):
        """ Create a checks, check and try to delete it """
        checks = self.imp.call('spv.services', 'create_checks',
            [{'plugin': 'a', 'plugin_check': 'b', 'name': 'c', 'repeat': 100, 'repeat_on_error': 100 }])
        self.checks.append(checks.keys())
        self.assertEqual(len(self.imp.call('spv.services', 'get_plugin_checks', {'check_id': checks.keys()[0]})), 1)
        self.imp.call('spv.services', 'delete_checks', checks.keys())
        self.assertEqual(len(self.imp.call('spv.services', 'get_plugin_checks', {'check_id': checks.keys()[0]})), 0)

    def test_delete_objects(self):
        """ Create a objects, check and try to delete it """
        objects = self.imp.call('spv.services', 'create_objects', [{'address': 'toto'}])
        self.objects.append(objects.keys())
        self.assertEqual(len(self.imp.call('spv.services', 'get_objects', {'obj_id': objects.keys()[0]})), 1)
        self.imp.call('spv.services', 'delete_objects', objects.keys())
        self.assertEqual(len(self.imp.call('spv.services', 'get_objects', {'obj_id': objects.keys()[0]})), 0)

    #
    # CREATE TEST
    #

    def test_create_group(self):
        """ Test multiple group creation and returned values. """
        # FIXME: group names are currently not unique but should probably be
        # create
#.........这里部分代码省略.........
开发者ID:PhilippeBridant,项目名称:webengine-spv,代码行数:103,代码来源:test_service.py

示例3: ServiceTest

# 需要导入模块: from importer import Importer [as 别名]
# 或者: from importer.Importer import call [as 别名]
class ServiceTest(unittest.TestCase):
    def setUp(self):
        """ Initialize test environment. """
        # TODO: clean up spvd database beforehand
        self.imp = Importer()
        self.imp["distant_url"] = "https://192.168.2.81/exporter/"
        self.groups = []
        self.checks = []
        self.objects = []

    def tearDown(self):
        """ Clean up test environment. """
        groups = [grp_id for list_id in self.groups for grp_id in list_id]
        checks = [chk_id for list_id in self.checks for chk_id in list_id]
        objects = [obj_id for list_id in self.objects for obj_id in list_id]

        if groups:
            self.imp.call("spv.services", "delete_groups", groups)
        if checks:
            self.imp.call("spv.services", "delete_checks", checks)
        if objects:
            self.imp.call("spv.services", "delete_objects", objects)

    #
    # TEST FOR GET_STATUS
    #

    def _get_status_tests_create_data(self):
        """ Test create object,group,check for get_status tests """
        groups = self.imp.call("spv.services", "create_groups", ["test_groups"])
        self.groups.append(groups.keys())
        objects = self.imp.call(
            "spv.services",
            "create_objects",
            [{"address": "test_address", "infos": {"key_toto": "value_toto"}, "group_id": groups.keys()[0]}],
        )
        self.objects.append(objects.keys())
        checks = self.imp.call(
            "spv.services",
            "create_checks",
            [
                {
                    "plugin": "hey",
                    "plugin_check": "salut",
                    "name": "toi",
                    "repeat": 100,
                    "repeat_on_error": 100,
                    "infos": {"key_toto": "value_toto"},
                    "group_id": groups.keys()[0],
                }
            ],
        )
        self.checks.append(checks.keys())
        return [groups, objects, checks]

    def _get_status_test_value(self, data, groups, objects, checks):
        keys = data.keys()
        keys.sort()
        self.assertTrue(keys == ["checks", "groups", "objects", "status"])
        self.assertTrue(data["checks"][checks.keys()[0]]["name"] == "toi")
        self.assertTrue(data["groups"][groups.keys()[0]]["name"] == "test_groups")
        self.assertTrue(data["objects"][objects.keys()[0]]["address"] == "test_address")
        self.assertTrue(data["status"][0]["grp_id"] == groups.keys()[0])
        self.assertTrue(data["status"][0]["chk_id"] == checks.keys()[0])
        self.assertTrue(data["status"][0]["obj_id"] == objects.keys()[0])

    def _check_get_status_info(self, data, type, info, id_name):
        """ generic funtionc to test get_status with additional info"""
        id = data[type].keys()[0]
        self.assertTrue(info in data[type][id].keys())
        infos = data[type][id][info]
        self.assertTrue("key_toto" in infos.keys())
        self.assertEqual(infos["key_toto"][id_name], id)
        self.assertEqual(infos["key_toto"]["key"], "key_toto")
        self.assertEqual(infos["key_toto"]["value"], "value_toto")

    #
    # DELETION TEST
    #

    def test_delete_groups(self):
        """ Create a groups, check and try to delete it """
        groups = self.imp.call("spv.services", "create_groups", "toto")
        self.groups.append(groups.keys())
        self.assertEqual(len(self.imp.call("spv.services", "get_groups", {"group_id": groups.keys()[0]})), 1)
        self.imp.call("spv.services", "delete_groups", groups.keys())
        self.assertEqual(len(self.imp.call("spv.services", "get_groups", {"group_id": groups.keys()[0]})), 0)

    def test_delete_checks(self):
        """ Create a checks, check and try to delete it """
        checks = self.imp.call(
            "spv.services",
            "create_checks",
            [{"plugin": "a", "plugin_check": "b", "name": "c", "repeat": 100, "repeat_on_error": 100}],
        )
        self.checks.append(checks.keys())
        self.assertEqual(len(self.imp.call("spv.services", "get_plugin_checks", {"check_id": checks.keys()[0]})), 1)
        self.imp.call("spv.services", "delete_checks", checks.keys())
        self.assertEqual(len(self.imp.call("spv.services", "get_plugin_checks", {"check_id": checks.keys()[0]})), 0)

#.........这里部分代码省略.........
开发者ID:EvaSDK,项目名称:webengine-spv,代码行数:103,代码来源:test_service.py

示例4: BasePlugin

# 需要导入模块: from importer import Importer [as 别名]
# 或者: from importer.Importer import call [as 别名]
class BasePlugin(threading.Thread):
    """ Base class for job implementation in spvd. """

    name = ''

    require = {
        'distant_url' : str,
    }

    optional = {
        'debug': bool,
        'ssl_cert' : str,
        'ssl_key' : str,
        'importer_retry_timeout' : int,
        'max_parallel_checks' : int,
        'max_checks_queue' : int,
        'check_poll' : int,
        'check_timeout' : int,
        'result_threshold' : int,
        'limit_group' : str,
        'limit_check' : str,
        'limit_commit' : int,
    }

    def __init__(self, options, event, url=None, params=None):
        """ Init method.

        @url: url pass to Importer.

        @params is a dictionary of optional parameters among:
        importer_retry_timeout: interval between successive importer calls if
                                importer failed.
        max_parallel_checks:    maximum number of threads for this plugin.
        max_checks_queue:       maximum number of checks to get from
                                the DB and queue for execution.
        check_poll:             interval between two get_checks call.
        check_timeout:          maximum wait time for get_checks calls.
        debug:                  enable debugging information.
        ssl_cert:               client X.509 public key.
        ssl_key:                client X.509 secret key.
        result_threshold:       number of results waiting for a commit that
                                will trigger a main-loop wake up.
        """

        threading.Thread.__init__(self)
        self.setDaemon(True)
        self.dismiss    = event
        self.resqueue   = {}
        self.checks     = {}
        self.rescommit  = threading.Event()

        self.params     = { 'importer_retry_timeout': 10,
                            'max_parallel_checks': 3,
                            'max_checks_queue': 9,
                            'check_poll': 60,
                            'check_timeout' : None,
                            'debug': False,
                            'ssl_cert': None,
                            'ssl_key': None,
                            'result_threshold': 5,
                            'limit_group': None,
                            'limit_check': None,
                            'limit_commit': 40,
                        }

        if params:
            self.params.update(params)

        # Set up the importer
        self.importer   = Importer()
        if url:
            self.importer['distant_url'] = url

        if self.params['ssl_cert'] and self.params['ssl_key']:
            self.importer['ssl_cert'] = self.params['ssl_cert']
            self.importer['ssl_key'] = self.params['ssl_key']

        if self.params['check_timeout']:
            self.importer['timeout'] = self.params['check_timeout']

        # Limiting groups
        self.limit_group = None
        if self.params['limit_group']:
            self.limit_group = [group.strip() for group in self.params['limit_group'].split(",") if group.strip()]
            if len(self.limit_group) == 1:
                self.limit_group = self.limit_group[0]

        # Limiting checks
        self.limit_check = None
        if self.params['limit_check']:
            self.limit_check = [check.strip() for check in self.params['limit_check'].split(",") if check.strip()]
            if len(self.limit_check) == 1:
                self.limit_check = self.limit_check[0]

        self.options = options

        self.log = logging.getLogger("spvd.plugins." + self.name)

        # Set up logging
        if not self.options.nodaemon:
#.........这里部分代码省略.........
开发者ID:PhilippeBridant,项目名称:spvd,代码行数:103,代码来源:baseplugin.py


注:本文中的importer.Importer.call方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。