本文整理汇总了Python中amplify.agent.objects.nginx.config.config.NginxConfig类的典型用法代码示例。如果您正苦于以下问题:Python NginxConfig类的具体用法?Python NginxConfig怎么用?Python NginxConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NginxConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_regex_status_url
def test_regex_status_url(self):
"""
Check that we could handle regex urls like
location ~ /(nginx_status|status)
location ~ ^/nginx_status$
"""
config = NginxConfig(regex_status_config)
config.full_parse()
# check total amount of status urls
assert_that(config.stub_status_urls, has_length(4)) # we have 4 valid locations in the regex_status/status.conf
# check each location
valid_urls_dict = {
'1.1.1.1:80': [
'1.1.1.1:80/nginx_status',
'1.1.1.1:80/status',
],
'1.1.1.1:81': ['1.1.1.1:81/nginx_status'],
'1.1.1.1:82': [
'1.1.1.1:82/status_weird_thing', '1.1.1.1:82/nginx_status_weird_thing',
'1.1.1.1:82/status_weird_some', '1.1.1.1:82/nginx_status_weird_some'
],
'1.1.1.1:84': ['1.1.1.1:84/valid_location'],
}
for url in config.stub_status_urls:
address = url.split('/')[0]
valid_urls = valid_urls_dict[address]
assert_that(valid_urls, has_item(url))
示例2: test_parse_huge
def test_parse_huge(self):
config = NginxConfig(huge_config)
config.full_parse()
# error logs
assert_that(config.error_logs, has_length(1))
assert_that(config.error_logs, has_key('/var/log/nginx-error.log'))
# access logs
assert_that(config.access_logs, has_length(2))
assert_that(config.access_logs, has_item('/var/log/default.log'))
assert_that(config.access_logs, has_item('/var/log/pp.log'))
assert_that(config.access_logs['/var/log/pp.log'], equal_to('main'))
# log formats
assert_that(config.log_formats, has_length(1))
assert_that(config.log_formats, has_item('main'))
assert_that(
config.log_formats['main'],
equal_to(
'$remote_addr - $remote_user [$time_local] "$request" ' +
'$status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"'
)
)
# stub status url
assert_that(config.stub_status_urls, has_length(2))
assert_that(config.stub_status_urls[0], equal_to('127.0.0.1:80/nginx_status'))
示例3: test_json
def test_json(self):
config = NginxConfig(json_config)
config.full_parse()
assert_that(config.log_formats, has_key('json'))
assert_that(
config.log_formats['json'],
equal_to('{ "time_iso8601": "$time_iso8601", "browser": [{"modern_browser": "$modern_browser", '
'"ancient_browser": "$ancient_browser", "msie": "$msie"}], "core": [{"args": "$args", "arg": '
'{ "arg_example": "$arg_example"}, "body_bytes_sent": "$body_bytes_sent", "bytes_sent": '
'"$bytes_sent", "cookie": { "cookie_example": "$cookie_example" }, "connection": "$connection", '
'"connection_requests": "$connection_requests", "content_length": "$content_length", '
'"content_type": "$content_type", "document_root": "$document_root", "document_uri": '
'"$document_uri","host": "$host", "hostname": "$hostname", "http": { "http_example": '
'"$http_example" }, "https": "$https", "is_args": "$is_args", "limit_rate": "$limit_rate", '
'"msec": "$msec", "nginx_version": "$nginx_version", "pid": "$pid", "pipe": "$pipe", '
'"proxy_protocol_addr": "$proxy_protocol_addr", "query_string": "$query_string", "realpath_root": '
'"$realpath_root", "remote_addr": "$remote_addr", "remote_port": "$remote_port", "remote_user": '
'"$remote_user", "request": "$request", "request_body": "$request_body", "request_body_file": '
'"$request_body_file", "request_completion": "$request_completion", "request_filename": '
'"$request_filename", "request_length": "$request_length", "request_method": "$request_method", '
'"request_time": "$request_time", "request_uri": "$request_uri", "scheme": "$scheme", '
'"sent_http_": { "sent_http_example": "$sent_http_example" }, "server_addr": "$server_addr", '
'"server_name": "$server_name", "server_port": "$server_port", "server_protocol": '
'"$server_protocol", "status": "$status", "tcpinfo_rtt": "$tcpinfo_rtt", "tcpinfo_rttvar": '
'"$tcpinfo_rttvar", "tcpinfo_snd_cwnd": "$tcpinfo_snd_cwnd", "tcpinfo_rcv_space": '
'"$tcpinfo_rcv_space", "uri": "$uri" }]}')
)
示例4: test_parse_tabbed_config
def test_parse_tabbed_config(self):
config = NginxConfig(tabs_config)
config.full_parse()
assert_that(config.log_formats, has_key('main'))
assert_that(
config.log_formats['main'],
equal_to('"$time_local"\t"$remote_addr"\t"$http_host"\t"$request"\t'
'"$status"\t"$body_bytes_sent\t"$http_referer"\t'
'"$http_user_agent"\t"$http_x_forwarded_for"')
)
示例5: test_ssl
def test_ssl(self):
config = NginxConfig(ssl_simple_config)
config.full_parse()
config.run_ssl_analysis()
ssl_certificates = config.ssl_certificates
assert_that(ssl_certificates, has_length(1))
# check contents
assert_that(ssl_certificates.keys()[0], ends_with('certs.d/example.com.crt'))
assert_that(ssl_certificates.values()[0], has_item('names'))
示例6: test_proxy_buffers_simple
def test_proxy_buffers_simple(self):
config = NginxConfig(proxy_buffers_simple_config)
config.full_parse()
assert_that(config.tree, has_key('http'))
http_bucket = config.tree['http'][0]
assert_that(http_bucket, has_key('proxy_buffering'))
assert_that(http_bucket, has_key('proxy_buffers'))
assert_that(config.parser_errors, has_length(0))
assert_that(config.test_errors, has_length(0))
示例7: test_fastcgi
def test_fastcgi(self):
config = NginxConfig(fastcgi_config)
config.full_parse()
assert_that(config.tree, has_key('http'))
http_bucket = config.tree['http'][0]
server_bucket = http_bucket['server'][0][0] # fastcgi server tree
location = server_bucket['location']['~ \\.php$'][0] # fastcgi pass location tree
assert_that(location, has_key('fastcgi_pass'))
assert_that(location, has_key('fastcgi_param'))
assert_that(location['fastcgi_param'], has_length(17))
示例8: test_proxy_buffers_complex
def test_proxy_buffers_complex(self):
config = NginxConfig(proxy_buffers_complex_config)
config.full_parse()
assert_that(config.tree, has_key('http'))
http_bucket = config.tree['http'][0]
assert_that(http_bucket, has_key('proxy_buffering'))
assert_that(http_bucket, has_key('proxy_buffers'))
location_bucket = config.tree['http'][0]['server'][0][0]['location']['/'][0]
assert_that(location_bucket, has_key('proxy_buffering'))
assert_that(location_bucket, has_key('proxy_buffers'))
assert_that(config.parser_errors, has_length(0))
assert_that(config.test_errors, has_length(0))
示例9: test_parse_wildcard_dir
def test_parse_wildcard_dir(self):
"""
Tests wild card directory handling.
"""
config = NginxConfig(wildcard_directory_config)
config.full_parse()
assert_that(
config.directory_map,
has_key(
'/amplify/test/fixtures/nginx/wildcard_directory/data/www/test.domain.info/config/nginx/'
)
)
files = config.directory_map[
'/amplify/test/fixtures/nginx/wildcard_directory/data/www/test.domain.info/config/nginx/'
]['files']
assert_that(
files,
has_key('/amplify/test/fixtures/nginx/wildcard_directory/data/www/test.domain.info/config/nginx/test.conf')
)
示例10: test_parse_complex
def test_parse_complex(self):
config = NginxConfig(complex_config)
config.full_parse()
context.log.info(config.index)
context.log.info(config.tree)
context.log.info(config.files)
context.log.info(config.checksum())
# error logs
assert_that(config.error_logs, has_length(0))
# access logs
assert_that(config.access_logs, has_length(0))
# log formats
assert_that(config.log_formats, has_length(0))
# stub status url
assert_that(config.stub_status_urls, has_length(0))
示例11: test_parse_simple_exclude_multiple
def test_parse_simple_exclude_multiple(self):
"""Check that config.full_parse() obeys exclude_logs from app_config with multiple ignores"""
context.app_config['nginx']['exclude_logs'] = '/var/log/nginx/super*.log,error*'
config = NginxConfig(simple_config)
config.full_parse()
del context.app_config['nginx']['exclude_logs']
# error logs
assert_that(config.error_logs, has_length(0))
# access logs
assert_that(config.access_logs, has_length(1))
assert_that(config.access_logs, has_item('/var/log/nginx/access.log'))
assert_that(config.access_logs['/var/log/nginx/access.log'], equal_to('super_log_format'))
# log formats
assert_that(config.log_formats, has_length(1))
assert_that(config.log_formats, has_item('super_log_format'))
assert_that(
config.log_formats['super_log_format'],
equal_to(
'$remote_addr - $remote_user [$time_local] "$request" $status ' +
'$body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" ' +
'rt="$request_time" ua="$upstream_addr" us="$upstream_status" ' +
'ut="$upstream_response_time" "$gzip_ratio"'
)
)
# stub status urls
assert_that(config.stub_status_urls, has_length(1))
assert_that(config.stub_status_urls[0], equal_to('127.0.0.1:81/basic_status'))
# status urls
assert_that(config.plus_status_external_urls, has_length(1))
assert_that(config.plus_status_external_urls[0], equal_to('127.0.0.1:81/plus_status'))
assert_that(config.plus_status_internal_urls, has_length(1))
assert_that(config.plus_status_internal_urls[0], equal_to('127.0.0.1:81/plus_status'))
示例12: test_permissions_and_mtime_affect_checksum
def test_permissions_and_mtime_affect_checksum(self):
"""
Check that changing permissions or mtime affect checksum
"""
config = NginxConfig(simple_config)
config.full_parse()
old_checksum = config.checksum()
os.system('touch %s' % (os.getcwd() + '/test/fixtures/nginx/simple/conf.d/'))
config.full_parse()
new_checksum = config.checksum()
assert_that(new_checksum, not_(equal_to(old_checksum)))
示例13: test_parse_simple
def test_parse_simple(self):
config = NginxConfig(simple_config)
config.full_parse()
# error logs
assert_that(config.error_logs, has_length(1))
assert_that(config.error_logs, has_key('/var/log/nginx/error.log'))
# access logs
assert_that(config.access_logs, has_length(2))
assert_that(config.access_logs, has_item('/var/log/nginx/access.log'))
assert_that(config.access_logs, has_item('/var/log/nginx/superaccess.log'))
assert_that(config.access_logs['/var/log/nginx/access.log'], equal_to('super_log_format'))
# log formats
assert_that(config.log_formats, has_length(1))
assert_that(config.log_formats, has_item('super_log_format'))
assert_that(
config.log_formats['super_log_format'],
equal_to(
'$remote_addr - $remote_user [$time_local] "$request" $status ' +
'$body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" ' +
'rt="$request_time" ua="$upstream_addr" us="$upstream_status" ' +
'ut="$upstream_response_time" "$gzip_ratio"'
)
)
# stub status urls
assert_that(config.stub_status_urls, has_length(1))
assert_that(config.stub_status_urls[0], equal_to('127.0.0.1:81/basic_status'))
# status urls
assert_that(config.plus_status_external_urls, has_length(1))
assert_that(config.plus_status_external_urls[0], equal_to('127.0.0.1:81/plus_status'))
assert_that(config.plus_status_internal_urls, has_length(1))
assert_that(config.plus_status_internal_urls[0], equal_to('127.0.0.1:81/plus_status'))
示例14: __init__
def __init__(self, **kwargs):
super(CommonNginxObject, self).__init__(**kwargs)
# Have to override intervals here because new container sub objects.
self.intervals = context.app_config['containers'].get('nginx', {}).get('poll_intervals', {'default': 10})
self.root_uuid = self.data.get(
'root_uuid') or context.objects.root_object.uuid if context.objects.root_object else None
self.local_id_cache = self.data['local_id'] # Assigned by manager
self.pid = self.data['pid']
self.version = self.data['version']
self.workers = self.data['workers']
self.prefix = self.data['prefix']
self.bin_path = self.data['bin_path']
self.conf_path = self.data['conf_path']
default_config = context.app_config['containers']['nginx']
self.upload_config = self.data.get('upload_config') or default_config.get('upload_config', False)
self.run_config_test = self.data.get('run_test') or default_config.get('run_test', False)
self.upload_ssl = self.data.get('upload_ssl') or default_config.get('upload_ssl', False)
self.filters = []
# filters
for raw_filter in self.data.get('filters') or []:
self.filters.append(Filter(**raw_filter))
self.config = NginxConfig(self.conf_path, prefix=self.prefix)
self.config.full_parse()
self.plus_status_external_url, self.plus_status_internal_url = self.get_alive_plus_status_urls()
self.plus_status_enabled = True if (self.plus_status_external_url or self.plus_status_internal_url) else False
self.stub_status_url = self.get_alive_stub_status_url()
self.stub_status_enabled = True if self.stub_status_url else False
self.processes = []
示例15: __init__
def __init__(self, **kwargs):
super(NginxObject, self).__init__(**kwargs)
self.root_uuid = self.data.get('root_uuid') or context.objects.root_object.uuid if context.objects.root_object else None
self.local_id_cache = self.data['local_id'] # Assigned by manager
self.pid = self.data['pid']
self.version = self.data['version']
self.workers = self.data['workers']
self.prefix = self.data['prefix']
self.bin_path = self.data['bin_path']
self.conf_path = self.data['conf_path']
default_config = context.app_config['containers'][self.type]
self.upload_config = self.data.get('upload_config') or default_config.get('upload_config', False)
self.run_config_test = self.data.get('run_test') or default_config.get('run_test', False)
self.upload_ssl = self.data.get('upload_ssl') or default_config.get('upload_ssl', False)
self.config = NginxConfig(self.conf_path, prefix=self.prefix)
self.config.full_parse()
self.plus_status_external_url, self.plus_status_internal_url = self.get_alive_plus_status_urls()
self.plus_status_enabled = True if (self.plus_status_external_url or self.plus_status_internal_url) else False
self.stub_status_url = self.get_alive_stub_status_url()
self.stub_status_enabled = True if self.stub_status_url else False
self.processes = []
self.filters = []
# filters
for raw_filter in self.data.get('filters') or []:
self.filters.append(Filter(**raw_filter))
# meta
meta_collector_class = NginxCommonMetaCollector
if host.os_name() == 'linux':
if host.linux_name() in ('ubuntu', 'debian'):
meta_collector_class = NginxDebianMetaCollector
elif host.linux_name() in ('centos',):
meta_collector_class = NginxCentosMetaCollector
self.collectors = [
meta_collector_class(
object=self, interval=self.intervals['meta']
),
NginxMetricsCollector(
object=self, interval=self.intervals['metrics']
),
NginxConfigCollector(
object=self, interval=self.intervals['configs'],
)
]
# access logs
for log_filename, format_name in self.config.access_logs.iteritems():
log_format = self.config.log_formats.get(format_name)
try:
self.collectors.append(
NginxAccessLogsCollector(
object=self,
interval=self.intervals['logs'],
filename=log_filename,
log_format=log_format,
)
)
# Send access log discovery event.
self.eventd.event(level=INFO, message='nginx access log %s found' % log_filename)
except IOError as e:
exception_name = e.__class__.__name__
context.log.error(
'failed to start reading log %s due to %s (maybe has no rights?)' %
(log_filename, exception_name)
)
context.log.debug('additional info:', exc_info=True)
# error logs
for log_filename, log_level in self.config.error_logs.iteritems():
try:
self.collectors.append(
NginxErrorLogsCollector(
object=self,
interval=self.intervals['logs'],
filename=log_filename,
level=log_level
)
)
# Send error log discovery event.
self.eventd.event(level=INFO, message='nginx error log %s found' % log_filename)
except IOError as e:
exception_name = e.__class__.__name__
context.log.error(
'failed to start reading log %s due to %s (maybe has no rights?)' %
(log_filename, exception_name)
)
context.log.debug('additional info:', exc_info=True)