def validate_config_spec(check_name, saved_errors): spec_file = get_default_config_spec(check_name) if not file_exists(spec_file): saved_errors[check_name].append( f"config spec does not exist: {spec_file}") return spec_files = yaml.safe_load(read_file(spec_file)).get('files') init_config_jmx = False instances_jmx = False for spec_file in spec_files: for base_option in spec_file.get('options', []): base_template = base_option.get('template') for option in base_option.get("options", []): template = option.get('template') if template == 'init_config/jmx' and base_template == 'init_config': init_config_jmx = True elif template == 'instances/jmx' and base_template == 'instances': instances_jmx = True if not init_config_jmx: saved_errors[check_name].append( "config spec: does not use `init_config/jmx` template") if not instances_jmx: saved_errors[check_name].append( "config spec: does not use `instances/jmx` template")
def validate_jmx_metrics(check_name, saved_errors, verbose): jmx_metrics_file, metrics_file_exists = get_jmx_metrics_file(check_name) if not metrics_file_exists: saved_errors[check_name].append(f'{jmx_metrics_file} does not exist') return jmx_metrics_data = yaml.safe_load( read_file(jmx_metrics_file)).get('jmx_metrics') if jmx_metrics_data is None: saved_errors[check_name].append( f'{jmx_metrics_file} does not have jmx_metrics definition') return for rule in jmx_metrics_data: include = rule.get('include') include_str = truncate_message(str(include), verbose) rule_str = truncate_message(str(rule), verbose) if not include: saved_errors[check_name].append(f"missing include: {rule_str}") return domain = include.get('domain') beans = include.get('bean') if (not domain) and (not beans): # Require `domain` or `bean` to be present, # that helps JMXFetch to better scope the beans to retrieve saved_errors[check_name].append( f"domain or bean attribute is missing for rule: {include_str}")
def read_fixture(name): return read_file(os.path.join(FIXTURES_DIR, name))
def mocked_perform_request(*args, **kwargs): """ A mocked version of _perform_request """ response = mock.MagicMock() url = args[1] if '/2/nginx' in url: file_contents = read_file( os.path.join(FIXTURES_PATH, 'plus_api_nginx.json')) response.json.return_value = json.loads(file_contents) elif '/2/processes' in url: file_contents = read_file( os.path.join(FIXTURES_PATH, 'plus_api_processes.json')) response.json.return_value = json.loads(file_contents) elif '/2/connections' in url: file_contents = read_file( os.path.join(FIXTURES_PATH, 'plus_api_connections.json')) response.json.return_value = json.loads(file_contents) elif '/2/ssl' in url: file_contents = read_file( os.path.join(FIXTURES_PATH, 'plus_api_ssl.json')) response.json.return_value = json.loads(file_contents) elif '/2/slabs' in url: file_contents = read_file( os.path.join(FIXTURES_PATH, 'plus_api_slabs.json')) response.json.return_value = json.loads(file_contents) elif '/2/http/requests' in url: file_contents = read_file( os.path.join(FIXTURES_PATH, 'plus_api_http_requests.json')) response.json.return_value = json.loads(file_contents) elif '/2/http/server_zones' in url: file_contents = read_file( os.path.join(FIXTURES_PATH, 'plus_api_http_server_zones.json')) response.json.return_value = json.loads(file_contents) elif '/2/http/caches' in url: file_contents = read_file( os.path.join(FIXTURES_PATH, 'plus_api_http_caches.json')) response.json.return_value = json.loads(file_contents) elif '/2/http/upstreams' in url: file_contents = read_file( os.path.join(FIXTURES_PATH, 'plus_api_http_upstreams.json')) response.json.return_value = json.loads(file_contents) elif '/2/stream/upstreams' in url: file_contents = read_file( os.path.join(FIXTURES_PATH, 'plus_api_stream_upstreams.json')) response.json.return_value = json.loads(file_contents) elif '/2/stream/server_zones' in url: file_contents = read_file( os.path.join(FIXTURES_PATH, 'plus_api_stream_server_zones.json')) response.json.return_value = json.loads(file_contents) else: response.json.return_value = '' return response
def read_fixture(name): return read_file(get_fixture_path(name))
def mocked_perform_request(*args, **kwargs): """ A mocked version of _perform_request """ response = mock.MagicMock() url = args[0] if re.search('/[234567]/nginx', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v1', 'plus_api_nginx.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[234567]/processes', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v1', 'plus_api_processes.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[234567]/connections', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v1', 'plus_api_connections.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[234567]/ssl', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v1', 'plus_api_ssl.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[234567]/slabs', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v1', 'plus_api_slabs.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[234567]/http/requests', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v1', 'plus_api_http_requests.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[23456]/http/server_zones', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v1/', 'plus_api_http_server_zones.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[234567]/http/caches', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v1', 'plus_api_http_caches.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[23456]/http/upstreams', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v1', 'plus_api_http_upstreams.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[234567]/stream/upstreams', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v1', 'plus_api_stream_upstreams.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[234567]/stream/server_zones', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v1', 'plus_api_stream_server_zones.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[34567]/stream/zone_sync', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v3', 'plus_api_stream_zone_sync.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[56]/http/location_zones', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v5', 'plus_api_http_location_zones.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[567]/resolvers', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v5', 'plus_api_resolvers.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[67]/http/limit_reqs', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v6', 'plus_api_http_limit_reqs.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[67]/http/limit_conns', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v6', 'plus_api_http_limit_conns.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[67]/stream/limit_conns', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v6', 'plus_api_stream_limit_conns.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[7]/http/upstreams', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v7', 'plus_api_http_upstreams.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[7]/http/server_zones', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v7', 'plus_api_http_server_zones.json')) response.json.return_value = json.loads(file_contents) elif re.search('/[7]/http/location_zones', url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v7', 'plus_api_http_location_zones.json')) response.json.return_value = json.loads(file_contents) elif re.match(".*/[23456]/http/?", url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v1', 'plus_api_http.json')) response.json.return_value = json.loads(file_contents) elif re.match(".*/[23456]/stream/?", url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v1', 'plus_api_stream.json')) response.json.return_value = json.loads(file_contents) elif re.match(".*/[23456]/?", url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v1', 'plus_api.json')) response.json.return_value = json.loads(file_contents) elif re.match(".*/[7]/http/?", url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v7', 'plus_api_http.json')) response.json.return_value = json.loads(file_contents) elif re.match(".*/[7]/stream/?", url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v7', 'plus_api_stream.json')) response.json.return_value = json.loads(file_contents) elif re.match(".*/[7]/?", url): file_contents = read_file( os.path.join(FIXTURES_PATH, 'v7', 'plus_api.json')) response.json.return_value = json.loads(file_contents) else: response.json.return_value = '' return response
def read_e2e_api_fixture(): return read_file(os.path.join(HERE, 'mock_boto3', 'boto3', 'list_nodes.json'))
def read_api_fixture(): return read_file(os.path.join(HERE, 'fixtures', 'list_nodes.json'))