Skip to content

Commit

Permalink
fix: Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Nov 11, 2019
1 parent a27974b commit 348e14b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 52 deletions.
54 changes: 33 additions & 21 deletions tests/load-tests/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


from yaml import load

try:
from yaml import CLoader as Loader, CDumper as Dumper, CFullLoader as FullLoader
except ImportError:
Expand Down Expand Up @@ -40,14 +41,16 @@ def load_events(cls):
event_dir = cls._get_event_directory()
events_file = os.path.join(event_dir, "event_index.yml")
try:
with open(events_file, 'r') as file:
with open(events_file, "r") as file:
file_names = load(file, Loader=FullLoader)

except Exception as err:
raise ValueError("Invalid event index file, event_index.yml", events_file)
raise ValueError(
"Invalid event index file, event_index.yml", events_file
)

for file_name in file_names:
file_path = os.path.join(event_dir, file_name + '.json')
file_path = os.path.join(event_dir, file_name + ".json")
with open(file_path, "r") as file:
content = file.read()
event_list.append(content)
Expand Down Expand Up @@ -82,19 +85,22 @@ def _get_event_directory(cls):


def small_event_task(task_set: TaskSet):
msg_body = EventsCache.get_event_by_name('small_event')
msg_body = EventsCache.get_event_by_name("small_event")
send_message(task_set, msg_body)


def medium_event_task(task_set: TaskSet):
msg_body = EventsCache.get_event_by_name('medium_event')
msg_body = EventsCache.get_event_by_name("medium_event")
send_message(task_set, msg_body)


def large_event_task(task_set: TaskSet):
msg_body = EventsCache.get_event_by_name('large_event')
msg_body = EventsCache.get_event_by_name("large_event")
send_message(task_set, msg_body)


def bad_event_task(task_set: TaskSet):
msg_body = EventsCache.get_event_by_name('bad_event')
msg_body = EventsCache.get_event_by_name("bad_event")
send_message(task_set, msg_body)


Expand All @@ -103,10 +109,10 @@ def send_message(task_set, msg_body):
num_projects = task_set.num_projects
config = task_set.locust.config

use_fake_projects = config['use_fake_projects']
use_fake_projects = config["use_fake_projects"]

if not use_fake_projects:
projects = config['projects']
projects = config["projects"]
num_available_projects = len(projects)
if num_projects > num_available_projects:
num_projects = num_available_projects
Expand All @@ -115,29 +121,33 @@ def send_message(task_set, msg_body):
project_idx = floor(random() * num_projects)
if use_fake_projects:
project_id = project_idx
project_key = config["fake_projects"]['key']
project_key = config["fake_projects"]["key"]
else:
project_cfg = config['projects'][project_idx]
project_id = project_cfg['id']
project_key = project_cfg['key']
project_cfg = config["projects"][project_idx]
project_id = project_cfg["id"]
project_key = project_cfg["key"]

url = "/api/{}/store/".format(project_id)
headers = {
"X-Sentry-Auth": "Sentry sentry_key={},sentry_version=7".format(project_key),
"Content-Type": "application/json; charset=UTF-8"
"Content-Type": "application/json; charset=UTF-8",
}
return client.post(url, headers=headers, data=msg_body)


def _get_semaphore_address(config):
semaphore_settings = config.get('semaphore', {})
host = semaphore_settings.get('host')
port = semaphore_settings.get('port')
semaphore_settings = config.get("semaphore", {})
host = semaphore_settings.get("host")
port = semaphore_settings.get("port")

if host is None:
raise "Missing semaphore.host settings from config file:{}".format(_get_config_file_path())
raise "Missing semaphore.host settings from config file:{}".format(
_get_config_file_path()
)
if port is None:
raise "Missing semaphore.port settings from config file:{}".format(_get_config_file_path())
raise "Missing semaphore.port settings from config file:{}".format(
_get_config_file_path()
)

return "{}:{}".format(host, port)

Expand All @@ -149,10 +159,12 @@ def _get_config():
"""
file_name = _get_config_file_path()
try:
with open(file_name, 'r') as file:
with open(file_name, "r") as file:
return load(file, Loader=FullLoader)
except Exception as err:
print("Error while getting the configuration file:{}\n {}".format(file_name, err))
print(
"Error while getting the configuration file:{}\n {}".format(file_name, err)
)
raise ValueError("Invalid configuration")


Expand Down
65 changes: 34 additions & 31 deletions tests/load-tests/semaphore_load_tests/fake_sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import os

from yaml import load, dump

try:
from yaml import CLoader as Loader, CDumper as Dumper, CFullLoader as FullLoader
except ImportError:
from yaml import Loader, Dumper, FullLoader


class Sentry(object):
_healthcheck_passed = False

Expand Down Expand Up @@ -71,7 +73,14 @@ def iter_public_keys(self):

def basic_project_config(self):
return {
"publicKeys": [{"publicKey": self.dsn_public_key, "isEnabled": True, "numericId": 123, "quotas": []}],
"publicKeys": [
{
"publicKey": self.dsn_public_key,
"isEnabled": True,
"numericId": 123,
"quotas": [],
}
],
"rev": "5ceaea8c919811e8ae7daae9fe877901",
"disabled": False,
"lastFetch": datetime.datetime.utcnow().isoformat() + "Z",
Expand All @@ -97,41 +106,28 @@ def full_project_config(self):
"config": {
"excludeFields": [],
"filterSettings": {
"browser-extensions": {
"isEnabled": True
},
"web-crawlers": {
"isEnabled": True
},
"localhost": {
"isEnabled": False
},
"legacy-browsers": {
"isEnabled": True,
"options": ["ie_pre_9"]
}
"browser-extensions": {"isEnabled": True},
"web-crawlers": {"isEnabled": True},
"localhost": {"isEnabled": False},
"legacy-browsers": {"isEnabled": True, "options": ["ie_pre_9"]},
},
"scrubIpAddresses": False,
"sensitiveFields": [],
"scrubDefaults": True,
"scrubData": True,
"groupingConfig": {
"id": "legacy:2019-03-12",
"enhancements": "eJybzDhxY05qemJypZWRgaGlroGxrqHRBABbEwcC"
"enhancements": "eJybzDhxY05qemJypZWRgaGlroGxrqHRBABbEwcC",
},
"blacklistedIps": [
"127.43.33.22"
],
"trustedRelays": []
"blacklistedIps": ["127.43.33.22"],
"trustedRelays": [],
},
}

return {
**basic,
**full,
'config': {
**basic['config'],
**full['config']},
"config": {**basic["config"], **full["config"]},
}

@property
Expand Down Expand Up @@ -165,7 +161,7 @@ def _fake_sentry_thread(config):
# sentry = None
host = config.get("host")
port = config.get("port")
dns_public_key = config.get('key')
dns_public_key = config.get("key")
sentry = Sentry((host, port), dns_public_key, app)

authenticated_relays = {}
Expand Down Expand Up @@ -204,18 +200,22 @@ def public_keys():

return jsonify(public_keys=rv)

@app.route('/api/<project_id>/store', methods=["POST", "GET"])
@app.route("/api/<project_id>/store", methods=["POST", "GET"])
def store_all(project_id):
print("FAKE sentry store called for project:{}".format(repr(project_id)))
return ""

@app.route('/<path:u_path>', methods=["POST", "GET"])
@app.route("/<path:u_path>", methods=["POST", "GET"])
def catch_all(u_path):
print("fake sentry called on:'{}'".format(repr(u_path)))
return ("<h1>Fake Sentry</h1>" +
"<div>You have called fake-sentry on: <nbsp/>" +
"<span style='font-family:monospace; background-color:#e8e8e8;'>{}</span></div>".format(u_path) +
"<h3><b>Note:</b> This is probably the wrong url to call !!!<h3/>")
return (
"<h1>Fake Sentry</h1>"
+ "<div>You have called fake-sentry on: <nbsp/>"
+ "<span style='font-family:monospace; background-color:#e8e8e8;'>{}</span></div>".format(
u_path
)
+ "<h3><b>Note:</b> This is probably the wrong url to call !!!<h3/>"
)

@app.route("/", methods=["GET"])
def root():
Expand All @@ -229,14 +229,17 @@ def fail(e):

app.run(host=host, port=port)


def _get_config():
"""
Returns the program settings located in the main directory (just above this file's directory)
with the name config.yml
"""
file_name = os.path.realpath(os.path.join(__file__, "../..", "fake_sentry.config.yml"))
file_name = os.path.realpath(
os.path.join(__file__, "../..", "fake_sentry.config.yml")
)
try:
with open(file_name, 'r') as file:
with open(file_name, "r") as file:
return load(file, Loader=FullLoader)
except Exception as err:
print("Error while getting the configuration file:\n {}".format(err))
Expand Down

0 comments on commit 348e14b

Please sign in to comment.