本文整理汇总了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'))
示例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'))
示例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')))
示例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')))
示例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()))
示例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'))
示例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))
示例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'
))
示例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))
示例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'))
示例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'))
示例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))
示例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)))
示例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))
示例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))