Skip to content

Commit

Permalink
Fix Fake API responses for .../status/<period>
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Maretskiy committed Dec 6, 2016
1 parent 3d403d5 commit 56ee63e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 70 deletions.
39 changes: 31 additions & 8 deletions ceagle/api_fake_data/fake_status.py
Expand Up @@ -126,19 +126,15 @@ def generate_region_data(region, period, service=None):
return ({"period": period, "status": {region: result}}, 200)


def generate_status_data(period, service=None):
def generate_status_data(period, service):
if not period_is_valid(period):
return flask.jsonify({"error": "Not Found"}), 404

data = {}
for region in fake_regions.regions():
result, code = generate_region_data(region, period, service)
if code == 200:
if service:
data.update(result[service])
else:
data.update(result["status"])
service = service or "status"
data.update(result[service])
return flask.jsonify({"period": period, service: data})


Expand All @@ -152,7 +148,18 @@ def generate_region_data_response(region, period, service=None):

@base.api_handler
def get_status(period):
return generate_status_data(period)
if not period_is_valid(period):
flask.abort(404)
status = {}
rand = random.random
for region in fake_regions.regions():
status[region] = {
"sla": rand() if rand() > 0.4 else None,
"performance": random.randint(1, 10),
"availability": rand() if rand() > 0.4 else None,
"health": rand() if rand() > 0.4 else None
}
return flask.jsonify({"status": status, "period": period})


@base.api_handler
Expand All @@ -172,7 +179,23 @@ def get_status_availability(period):

@base.api_handler
def get_region_status(region, period):
return generate_region_data_response(region, period)
if not period_is_valid(period):
flask.abort(404)

data = fake_regions.regions(detailed=True).get(region)
if not data:
return ({"error": "Region '%s' not found" % region}, 404)

status = {}
rand = random.random
for service in ("keystone", "nova", "cinder"):
status[service] = {
"sla": rand() if rand() > 0.4 else None,
"performance": random.randint(1, 10),
"availability": rand() if rand() > 0.4 else None,
"health": rand() if rand() > 0.4 else None
}
return flask.jsonify({"status": status, "period": period})


@base.api_handler
Expand Down
2 changes: 1 addition & 1 deletion raml/api.raml
Expand Up @@ -142,7 +142,7 @@ mediaType: application/json
body:
application/json:
schema: schemas/200.json
example: !include response_examples/200/status_region.json
example: !include response_examples/200/status.json

/status/health/{period}:
uriParametrs:
Expand Down
11 changes: 5 additions & 6 deletions raml/response_examples/200/status.json
@@ -1,18 +1,17 @@
{
"period": "week",

"regions": {
"status": {
"west-1.hooli.net": {
"sla": 0.9,
"sla": null,
"availability": 0.9,
"health": 0.9,
"performance": 100
"performance": 7
},
"west-2.hooli.net": {
"sla": 0.9,
"sla":null,
"availability": 0.9,
"health": 0.9,
"performance": 200
"performance": 10
}
}
}
72 changes: 17 additions & 55 deletions raml/response_examples/200/status_region.json
@@ -1,61 +1,23 @@
{
"period": "week",
"status": {
"west-1.hooli.net": {
"sla": 0.8,
"availability": {
"score": 0.8,
"data": [
["2016-11-16T00:00", 0.95],
["2016-11-16T01:00", 1.0],
["2016-11-16T02:00", 1.0],
["2016-11-16T03:00", 0.5]
]
"period": "week",
"status": {
"keystone": {
"availability": 0.973,
"health": 0.95,
"performance": null,
"sla": null
},
"health": {
"west-1.hooli.net": {
"fci": 0.9,
"response_time": 100.43,
"response_size": 234343,
"api_calls_count": 100,
"fci_data": [
["2016-09-16T01:00", 0.9],
["2016-09-16T01:00", 0.7],
["2016-09-16T02:00", 1.0],
["2016-09-16T03:00", 0.95],
["2016-09-16T04:00", 1.0],
],
"response_time_data": [
["2016-09-16T01:00", 0.9],
["2016-09-16T02:00", 0.8],
["2016-09-16T03:00", 1.0],
["2016-09-16T04:00", 0.95],
["2016-09-16T05:00", 1.0],
],
"repsonse_size_data": [
["2016-09-16T01:00", 100],
["2016-09-16T02:00", 250],
["2016-09-16T03:00", 300],
["2016-09-16T04:00", 400],
["2016-09-16T05:00", 500],
]
}
"nova": {
"availability": 0.94,
"health": 0.995,
"performance": null,
"sla": null
},
"performance": {
"score": 5,
"data": [
["2016-11-16T00:00", 0.95],
["2016-11-16T01:00", 1.0],
["2016-11-16T02:00", 1.0],
["2016-11-16T03:00", 0.5]
]
"cinder": {
"availability": 0.984,
"health": 0.87,
"performance": null,
"sla": null
}
},
"east-2.piedpiper.net": {
"sla": 1.0,
"availability": {},
"health": {},
"performance": {}
}
}
}

0 comments on commit 56ee63e

Please sign in to comment.