當前位置: 首頁>>代碼示例>>Python>>正文


Python NginxManager._discover_objects方法代碼示例

本文整理匯總了Python中amplify.agent.managers.nginx.NginxManager._discover_objects方法的典型用法代碼示例。如果您正苦於以下問題:Python NginxManager._discover_objects方法的具體用法?Python NginxManager._discover_objects怎麽用?Python NginxManager._discover_objects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在amplify.agent.managers.nginx.NginxManager的用法示例。


在下文中一共展示了NginxManager._discover_objects方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_bad_plus_status_discovery_with_config

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_bad_plus_status_discovery_with_config(self):
        amplify.agent.common.context.context.app_config['nginx']['plus_status'] = '/foo_plus'
        amplify.agent.common.context.context.app_config['nginx']['stub_status'] = '/foo_basic'

        self.stop_first_nginx()
        self.start_second_nginx(conf='nginx_bad_status.conf')
        container = NginxManager()
        container._discover_objects()
        assert_that(container.objects.objects_by_type[container.type], has_length(1))

        # self.http_request should look like this
        # [
        # first - internal plus statuses
        # 'http://127.0.0.1:82/plus_status', 'https://127.0.0.1:82/plus_status',
        # 'http://127.0.0.1/foo_plus', 'https://127.0.0.1/foo_plus',
        #
        # then external plus statuses
        # 'http://bad.status.naas.nginx.com:82/plus_status', 'https://bad.status.naas.nginx.com:82/plus_status',
        #
        # finally - stub statuses
        # 'http://127.0.0.1:82/basic_status', 'https://127.0.0.1:82/basic_status',
        # 'http://127.0.0.1/foo_basic', 'https://127.0.0.1/foo_basic'
        # ]

        assert_that(self.http_requests[2], equal_to('http://127.0.0.1/foo_plus'))
        assert_that(self.http_requests[-2], equal_to('http://127.0.0.1/foo_basic'))
開發者ID:Ferrisbane,項目名稱:nginx-amplify-agent,代碼行數:28,代碼來源:object.py

示例2: test_plus_status

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_plus_status(self):
        time.sleep(1)  # Give N+ some time to start
        container = NginxManager()
        container._discover_objects()
        assert_that(container.objects.objects_by_type[container.type], has_length(1))

        # get nginx object
        nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]

        # get metrics collector - the second from the list
        collectors = nginx_obj.collectors
        metrics_collector = collectors[1]

        # run plus status - twice, because counters will appear only on the second run
        metrics_collector.plus_status()
        time.sleep(1)
        metrics_collector.plus_status()

        # check counters
        metrics = nginx_obj.statsd.current
        assert_that(metrics, has_item('counter'))
        counters = metrics['counter']
        assert_that(counters, has_item('nginx.http.conn.accepted'))
        assert_that(counters, has_item('nginx.http.request.count'))
        assert_that(counters, has_item('nginx.http.conn.dropped'))

        # check gauges
        assert_that(metrics, has_item('gauge'))
        gauges = metrics['gauge']
        assert_that(gauges, has_item('nginx.http.conn.active'))
        assert_that(gauges, has_item('nginx.http.conn.current'))
        assert_that(gauges, has_item('nginx.http.conn.idle'))
        assert_that(gauges, has_item('nginx.http.request.current'))
開發者ID:Ferrisbane,項目名稱:nginx-amplify-agent,代碼行數:35,代碼來源:metrics.py

示例3: test_test_run_time

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_test_run_time(self):
        container = NginxManager()
        container._discover_objects()

        nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]
        cfg_collector = nginx_obj.collectors[0]
        assert_that(nginx_obj.run_config_test, equal_to(True))

        # set maximum run time for test to 0.0
        context.app_config['containers']['nginx']['max_test_duration'] = 0.0

        # running collect won't do anything until the config changes
        cfg_collector.collect(no_delay=True)
        assert_that(nginx_obj.run_config_test, equal_to(True))

        # change the collector's previous files record so that it will call full_parse
        cfg_collector.previous['files'] = {}

        # avoid restarting the object for testing
        cfg_collector.previous['checksum'] = None

        # running collect should now cause the run_time to exceed 0.0, rendering run_config_test False
        cfg_collector.collect(no_delay=True)
        assert_that(nginx_obj.run_config_test, equal_to(False))

        events = nginx_obj.eventd.current.values()
        messages = []
        for event in events:
            messages.append(event.message)

        assert_that(messages, has_item(starts_with('/usr/sbin/nginx -t -c /etc/nginx/nginx.conf took')))
開發者ID:nginxinc,項目名稱:nginx-amplify-agent,代碼行數:33,代碼來源:config.py

示例4: test_plus_status_priority

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_plus_status_priority(self):
        """
        Checks that if we can reach plus status then we don't use stub_status
        """
        time.sleep(1)  # Give N+ some time to start
        container = NginxManager()
        container._discover_objects()
        assert_that(container.objects.objects_by_type[container.type], has_length(1))

        # get nginx object
        nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]

        # check that it has n+ status and stub_status enabled
        assert_that(nginx_obj.plus_status_enabled, equal_to(True))
        assert_that(nginx_obj.stub_status_enabled, equal_to(True))

        # get metrics collector - the second from the list
        collectors = nginx_obj.collectors
        metrics_collector = collectors[1]

        # run status twice
        metrics_collector.status()
        time.sleep(1)
        metrics_collector.status()

        # check gauges - we should't see request.writing/reading here, because n+ status doesn't have those
        metrics = nginx_obj.statsd.current
        assert_that(metrics, has_item('gauge'))
        gauges = metrics['gauge']
        assert_that(gauges, not_(has_item('nginx.http.request.writing')))
        assert_that(gauges, not_(has_item('nginx.http.request.reading')))
開發者ID:Ferrisbane,項目名稱:nginx-amplify-agent,代碼行數:33,代碼來源:metrics.py

示例5: test_collect

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_collect(self):
        container = NginxManager()
        container._discover_objects()

        nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]
        cfg_collector = nginx_obj.collectors[0]

        # run collect
        cfg_collector.collect()
        assert_that(nginx_obj.configd.current, not_(empty()))
開發者ID:nginxinc,項目名稱:nginx-amplify-agent,代碼行數:12,代碼來源:config.py

示例6: test_bad_stub_status_discovery_with_config

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_bad_stub_status_discovery_with_config(self):
        amplify.agent.common.context.context.app_config['nginx']['stub_status'] = '/foo_basic'

        self.stop_first_nginx()
        self.start_second_nginx(conf='nginx_bad_status.conf')
        container = NginxManager()
        container._discover_objects()
        assert_that(container.objects.objects_by_type[container.type], has_length(1))

        assert_that(self.http_requests[-1], equal_to('https://127.0.0.1/foo_basic'))
        assert_that(self.http_requests[-2], equal_to('http://127.0.0.1/foo_basic'))
開發者ID:Ferrisbane,項目名稱:nginx-amplify-agent,代碼行數:13,代碼來源:object.py

示例7: test_two_instances

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_two_instances(self):
        container = NginxManager()
        container._discover_objects()
        obj = container.objects.find_all(types=container.types)[0]

        self.start_second_nginx()

        container._discover_objects()
        assert_that(container.objects.find_all(types=container.types), has_length(2))

        local_ids = map(lambda x: x.local_id, container.objects.find_all(types=container.types))
        assert_that(local_ids, has_item(obj.local_id))
開發者ID:MSmmer,項目名稱:nginx-amplify-agent,代碼行數:14,代碼來源:nginx.py

示例8: test_collect_meta

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_collect_meta(self):
        container = NginxManager()
        container._discover_objects()
        nginx_obj = container.objects.find_all(types=container.types)[0]

        collector = NginxMetaCollector(object=nginx_obj, interval=nginx_obj.intervals['meta'])
        assert_that(not_(collector.in_container))
        collector.collect()

        assert_that(nginx_obj.metad.current, contains_inanyorder(
            'type', 'local_id', 'root_uuid', 'running', 'stub_status_enabled', 'status_module_enabled', 'ssl',
            'stub_status_url', 'plus_status_url', 'version', 'plus', 'configure', 'packages', 'path',
            'built_from_source', 'parent_hostname', 'start_time', 'pid'
        ))
開發者ID:nginxinc,項目名稱:nginx-amplify-agent,代碼行數:16,代碼來源:meta.py

示例9: test_ssl_config_doesnt_work_if_ssl_disabled

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_ssl_config_doesnt_work_if_ssl_disabled(self):
        # set upload_ssl to True
        context.app_config['containers']['nginx']['upload_ssl'] = False

        container = NginxManager()
        container._discover_objects()
        assert_that(container.objects.objects_by_type[container.type], has_length(1))

        # get nginx object
        nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]
        cfg_collector = nginx_obj.collectors[0]
        cfg_collector.collect()

        config = nginx_obj.configd.current
        assert_that(config['data']['ssl_certificates'], has_length(0))
開發者ID:nginxinc,項目名稱:nginx-amplify-agent,代碼行數:17,代碼來源:config.py

示例10: test_bad_plus_status_discovery

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_bad_plus_status_discovery(self):
        self.stop_first_nginx()
        self.start_second_nginx(conf='nginx_bad_status.conf')
        container = NginxManager()
        container._discover_objects()

        assert_that(container.objects.objects_by_type[container.type], has_length(1))

        # get nginx object
        nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]

        # check all plus status urls
        assert_that(nginx_obj.plus_status_enabled, equal_to(True))
        assert_that(nginx_obj.plus_status_internal_url, equal_to(None))
        assert_that(nginx_obj.plus_status_external_url, equal_to('http://bad.status.naas.nginx.com:82/plus_status'))
開發者ID:Ferrisbane,項目名稱:nginx-amplify-agent,代碼行數:17,代碼來源:object.py

示例11: test_plus_status_discovery

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_plus_status_discovery(self):
        """
        Checks that for plus nginx we collect two status urls:
        - one for web link (with server name)
        - one for agent purposes (local url)
        """
        container = NginxManager()
        container._discover_objects()
        assert_that(container.objects.objects_by_type[container.type], has_length(1))

        # get nginx object
        nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]

        # check all plus status urls
        assert_that(nginx_obj.plus_status_enabled, equal_to(True))
        assert_that(nginx_obj.plus_status_internal_url, equal_to('https://127.0.0.1:443/plus_status'))
        assert_that(nginx_obj.plus_status_external_url, equal_to('http://status.naas.nginx.com:443/plus_status_bad'))
開發者ID:Ferrisbane,項目名稱:nginx-amplify-agent,代碼行數:19,代碼來源:object.py

示例12: test_plus_status_cache_limit

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_plus_status_cache_limit(self):
        time.sleep(1)  # Give N+ some time to start
        container = NginxManager()
        container._discover_objects()
        assert_that(container.objects.objects_by_type[container.type], has_length(1))

        # get nginx object
        nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]

        # get metrics collector - the third in the list
        metrics_collector = nginx_obj.collectors[2]

        # run plus status - 4 times
        for x in xrange(4):
            metrics_collector.plus_status()
            time.sleep(1)

        assert_that(context.plus_cache['https://127.0.0.1:443/plus_status'], has_length(3))
開發者ID:nginxinc,項目名稱:nginx-amplify-agent,代碼行數:20,代碼來源:plus_cache.py

示例13: test_plus_status_cache

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_plus_status_cache(self):
        time.sleep(1)  # Give N+ some time to start
        container = NginxManager()
        container._discover_objects()
        assert_that(container.objects.objects_by_type[container.type], has_length(1))

        # get nginx object
        nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]

        # get metrics collector - the third in the list
        metrics_collector = nginx_obj.collectors[2]

        # run plus status - twice, because counters will appear only on the second run
        metrics_collector.plus_status()
        time.sleep(1)
        metrics_collector.plus_status()

        assert_that(context.plus_cache['https://127.0.0.1:443/plus_status'], not_(has_length(0)))
開發者ID:nginxinc,項目名稱:nginx-amplify-agent,代碼行數:20,代碼來源:plus_cache.py

示例14: test_discover

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_discover(self):
        nginx_manager = NginxManager()
        nginx_manager._discover_objects()
        assert_that(nginx_manager.objects.objects_by_type[nginx_manager.type], has_length(1))

        # get nginx object
        nginx_obj = nginx_manager.objects.objects[nginx_manager.objects.objects_by_type[nginx_manager.type][0]]

        # get metrics collector - the third in the list
        metrics_collector = nginx_obj.collectors[2]

        # run plus status - twice, because counters will appear only on the second run
        metrics_collector.plus_status()
        time.sleep(1)
        metrics_collector.plus_status()

        plus_manager = PlusManager()
        plus_manager._discover_objects()
        assert_that(plus_manager.objects.find_all(types=plus_manager.types), has_length(2))
開發者ID:nginxinc,項目名稱:nginx-amplify-agent,代碼行數:21,代碼來源:plus.py

示例15: test_reload

# 需要導入模塊: from amplify.agent.managers.nginx import NginxManager [as 別名]
# 或者: from amplify.agent.managers.nginx.NginxManager import _discover_objects [as 別名]
    def test_reload(self):
        old_master, old_workers = self.get_master_workers()

        container = NginxManager()
        container._discover_objects()
        assert_that(container.objects.find_all(types=container.types), has_length(1))
        obj = container.objects.find_all(types=container.types)[0]
        # The following assertion is unreliable for some reason.
        assert_that(obj.pid, equal_to(old_master))
        assert_that(obj.workers, equal_to(old_workers))

        self.reload_nginx()
        new_master, new_workers = self.get_master_workers()
        assert_that(new_master, equal_to(old_master))

        container._discover_objects()
        obj = container.objects.find_all(types=container.types)[0]
        assert_that(obj.pid, equal_to(old_master))
        assert_that(obj.workers, not_(equal_to(old_workers)))
        assert_that(obj.workers, equal_to(new_workers))
開發者ID:MSmmer,項目名稱:nginx-amplify-agent,代碼行數:22,代碼來源:nginx.py


注:本文中的amplify.agent.managers.nginx.NginxManager._discover_objects方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。