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


Python nginx.NginxManager类代码示例

本文整理汇总了Python中amplify.agent.managers.nginx.NginxManager的典型用法代码示例。如果您正苦于以下问题:Python NginxManager类的具体用法?Python NginxManager怎么用?Python NginxManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_test_run_time

    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,代码行数:31,代码来源:config.py

示例2: test_plus_status

    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,代码行数:33,代码来源:metrics.py

示例3: test_find_all

    def test_find_all(self):
        out = subp.call('ps xao pid,ppid,command | grep "supervisor[d]" | tr -s " "')[0]
        supervisors = [map(int, line.strip().split()[:2]) for line in out if 'supervisord' in line]
        assert_that(supervisors, has_length(1))
        supervisor_pid, supervisor_ppid = supervisors[0]
        assert_that(supervisor_ppid, equal_to(1))

        time.sleep(2)

        out = subp.call('ps xao pid,ppid,command | grep "nginx[:]" | tr -s " "')[0]
        masters = [map(int, line.strip().split()[:2]) for line in out if 'nginx: master process' in line]
        assert_that(masters, has_length(1))
        master_pid, master_ppid = masters[0]
        assert_that(master_ppid, equal_to(supervisor_pid))

        worker_pids = []

        workers = [map(int, line.strip().split()[:2]) for line in out if 'nginx: worker process' in line]
        for worker_pid, worker_ppid in workers:
            worker_pids.append(worker_pid)
            assert_that(worker_ppid, equal_to(master_pid))

        container = NginxManager()
        nginxes = container._find_all()
        assert_that(nginxes, has_length(1))

        definition, data = nginxes.pop(0)
        assert_that(data, has_key('pid'))
        assert_that(data, has_key('workers'))

        assert_that(master_pid, equal_to(data['pid']))
        assert_that(worker_pids, equal_to(data['workers']))
开发者ID:nginxinc,项目名称:nginx-amplify-agent,代码行数:32,代码来源:nginx.py

示例4: test_bad_plus_status_discovery_with_config

    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,代码行数:26,代码来源:object.py

示例5: test_plus_status_priority

    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,代码行数:31,代码来源:metrics.py

示例6: test_collect

    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,代码行数:10,代码来源:config.py

示例7: test_bad_stub_status_discovery_with_config

    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,代码行数:11,代码来源:object.py

示例8: test_two_instances

    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,代码行数:12,代码来源:nginx.py

示例9: test_collect_meta

    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,代码行数:14,代码来源:meta.py

示例10: test_find_all

    def test_find_all(self):
        container = NginxManager()
        nginxes = container._find_all()
        assert_that(nginxes, has_length(1))

        definition, data = nginxes.pop(0)
        assert_that(data, has_key('pid'))
        assert_that(data, has_key('workers'))

        # get ps info
        master, workers = self.get_master_workers()

        assert_that(master, equal_to(data['pid']))
        assert_that(workers, equal_to(data['workers']))
开发者ID:MSmmer,项目名称:nginx-amplify-agent,代码行数:14,代码来源:nginx.py

示例11: test_ssl_config_doesnt_work_if_ssl_disabled

    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,代码行数:15,代码来源:config.py

示例12: test_bad_plus_status_discovery

    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,代码行数:15,代码来源:object.py

示例13: test_plus_status_discovery

    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,代码行数:17,代码来源:object.py

示例14: test_plus_status_cache

    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,代码行数:18,代码来源:plus_cache.py

示例15: test_plus_status_cache_limit

    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,代码行数:18,代码来源:plus_cache.py


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