def default_meta(self): meta = { 'type': self.object.type, 'uuid': self.uuid, 'os-type': os_name(), 'display_name': self.object.display_name, 'tags': context.tags, 'network': { 'interfaces': [], 'default': None }, 'disk_partitions': [], 'release': { 'name': None, 'version_id': None, 'version': None }, 'processor': { 'cache': {} } } if not self.in_container: meta['hostname'] = self.object.hostname meta['boot'] = int(psutil.boot_time()) * 1000 meta['ec2'] = self.ec2_metadata or None else: meta['imagename'] = self.object.imagename meta['container_type'] = context.container_type or 'None' return meta
def collect(self): meta = { 'type': self.object.type, 'uuid': self.uuid, 'os-type': os_name(), 'network': { 'interfaces': [], 'default': None }, 'disk_partitions': [], 'release': { 'name': None, 'version_id': None, 'version': None }, 'processor': { 'cache': {} }, 'warnings': [] } for method in ( self.disk_partitions, self.etc_release, self.proc_cpuinfo, self.lscpu ): try: method(meta) except Exception as e: exception_name = e.__class__.__name__ context.log.error('failed to collect meta %s due to %s' % (method.__name__, exception_name)) context.log.debug('additional info:', exc_info=True) return meta # Top level returns a dictionary so additional processing can be done by specific objects.
def collect(self): meta = { 'type': self.object.type, 'uuid': self.uuid, 'uname': None, 'boot': int(psutil.boot_time()) * 1000, 'os-type': os_name(), 'hostname': self.hostname, 'network': { 'interfaces': [], 'default': None }, 'disk_partitions': [], 'release': { 'name': None, 'version_id': None, 'version': None }, 'processor': { 'cache': {} }, 'warnings': [] } for method in (self.uname, self.disk_partitions, self.etc_release, self.proc_cpuinfo, self.lscpu, self.network, self.ec2): try: method(meta) except Exception as e: exception_name = e.__class__.__name__ context.log.error('failed to collect meta %s due to %s' % (method.__name__, exception_name)) context.log.debug('additional info:', exc_info=True) self.object.metad.meta(meta)
def test_hostname_uuid_os(self): hostname = host.hostname() assert_that(hostname, is_not(None)) uuid = host.uuid() assert_that(uuid, is_not(None)) os_name = host.os_name() assert_that(os_name, is_not(None))
def test_hostname_uuid_os(self): hostname = host.hostname() assert_that(hostname, is_not(None)) uuid = host.uuid() assert_that(uuid, is_not(None)) os_name = host.os_name() assert_that(os_name, is_not(None))
def __init__(self, **kwargs): super(ContainerSystemObject, self).__init__(**kwargs) self.imagename = self.data['imagename'] meta_collector_class = ContainerMetaCollector if host.os_name() == 'linux' and host.linux_name() in ('centos',): meta_collector_class = DockerCentosMetaCollector self.collectors = [ meta_collector_class(object=self, interval=self.intervals['meta']), SystemMetricsCollector(object=self, interval=self.intervals['metrics']) ]
def container_test(f): """ Decorator that makes collectors think they're running inside docker """ if host.os_name() == 'freebsd': return pytest.mark.skip( reason='FreeBSD cannot run in linux containers') def wrapper(*args, **kwargs): context.app_config['credentials']['imagename'] = 'DockerTest' f(*args, **kwargs) context.app_config['credentials']['imagename'] = None return wrapper
def __init__(self, **kwargs): super(SystemObject, self).__init__(**kwargs) self.uuid = self.data['uuid'] self.hostname = self.data['hostname'] meta_collector_class = SystemCommonMetaCollector if host.os_name() == 'linux' and host.linux_name() in ('centos',): meta_collector_class = SystemCentosMetaCollector self.collectors = [ meta_collector_class(object=self, interval=self.intervals['meta']), SystemMetricsCollector(object=self, interval=self.intervals['metrics']) ]
def default_meta(self): meta = { 'type': self.object.type, 'uuid': self.uuid, 'os-type': os_name(), 'network': {'interfaces': [], 'default': None}, 'disk_partitions': [], 'release': {'name': None, 'version_id': None, 'version': None}, 'processor': {'cache': {}} } if not self.in_container: meta['hostname'] = self.object.hostname meta['boot'] = int(psutil.boot_time()) * 1000 meta['ec2'] = self.ec2_metadata or None else: meta['imagename'] = self.object.imagename meta['container_type'] = context.container_type or 'None' return meta
def collect(self): meta = { 'type': self.object.type, 'uuid': self.uuid, 'uname': None, 'boot': int(psutil.boot_time()) * 1000, 'os-type': os_name(), 'hostname': self.hostname, 'network': { 'interfaces': [], 'default': None }, 'disk_partitions': [], 'release': { 'name': None, 'version_id': None, 'version': None }, 'processor': { 'cache': {} }, 'warnings': [] } for method in ( self.uname, self.disk_partitions, self.etc_release, self.proc_cpuinfo, self.lscpu, self.network, self.ec2 ): try: method(meta) except Exception as e: exception_name = e.__class__.__name__ context.log.error('failed to collect meta %s due to %s' % (method.__name__, exception_name)) context.log.debug('additional info:', exc_info=True) self.object.metad.meta(meta)
def __init__(self, **kwargs): super(NginxObject, self).__init__(**kwargs) meta_collector_class = NginxMetaCollector 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 # Collector setup... self.collectors = [ meta_collector_class( object=self, interval=self.intervals['meta'] ), NginxMetricsCollector( object=self, interval=self.intervals['metrics'] ) ] self._setup_config_collector() self._setup_access_logs() self._setup_error_logs()
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)
super(RealNginxTestCase, self).teardown_method(method) def reload_nginx(self): subp.call('service nginx reload') def start_second_nginx(self, conf='nginx2.conf'): subp.call('/usr/sbin/nginx2 -c /etc/nginx/%s' % conf) self.second_started = True def stop_first_nginx(self): subp.call('service nginx stop') def restart_nginx(self): subp.call('service nginx restart') def nginx_plus_installed(): out, err = subp.call('/usr/sbin/nginx -V') first_line = err[0] return True if 'nginx-plus' in first_line else False nginx_plus_test = pytest.mark.skipif(not nginx_plus_installed(), reason='This is a test for nginx+') nginx_oss_test = pytest.mark.skipif(nginx_plus_installed(), reason='This is a test for OSS nginx') future_test = pytest.mark.skipif(1 > 0, reason='This test will be written in future') disabled_test = pytest.mark.skipif(1 > 0, reason='This test has unexpected behavior') if host.os_name() == 'freebsd': container_test = pytest.mark.skip(reason='FreeBSD cannot run in linux containers') else: container_test = pytest.mark.usefixtures('docker')