Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #203 from imduffy15/master
Browse files Browse the repository at this point in the history
Fixes #173 - Add senza version to /api/status endpoint
  • Loading branch information
jmcs authored Jun 9, 2017
2 parents b1b4b72 + e79f84b commit 779d113
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lizzy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from lizzy.security import bouncer
from lizzy.util import filter_empty_values
from lizzy.version import VERSION
from senza import __version__ as SENZA_VERSION

logger = logging.getLogger('lizzy.api') # pylint: disable=invalid-name

Expand All @@ -24,6 +25,7 @@ def _make_headers(**kwargs: Dict[str, str]) -> dict:
headers = {'x-Lizzy-{key}'.format(key=k.title()): v.replace('\n', '\\n')
for k, v in kwargs.items()}
headers['X-Lizzy-Version'] = VERSION
headers['X-Senza-Version'] = SENZA_VERSION
return headers


Expand Down Expand Up @@ -293,6 +295,7 @@ def get_app_status():

status_info = {
'version': os.environ.get("APPLICATION_VERSION", ""),
'senza_version': SENZA_VERSION,
'status': status,
'config': {
name: getattr(config, name)
Expand Down
45 changes: 45 additions & 0 deletions lizzy/swagger/lizzy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ paths:
X-Lizzy-Version:
description: Lizzy Version
type: string
X-Senza-Version:
description: Senza Version
type: string
schema:
type: array
items:
Expand All @@ -69,6 +72,9 @@ paths:
X-Lizzy-Version:
description: Lizzy Version
type: string
X-Senza-Version:
description: Senza Version
type: string
schema:
$ref: '#/definitions/problem'
post:
Expand All @@ -86,6 +92,9 @@ paths:
X-Lizzy-Version:
description: Lizzy Version
type: string
X-Senza-Version:
description: Senza Version
type: string
X-Lizzy-Output:
description: Senza Output
type: string
Expand All @@ -95,6 +104,9 @@ paths:
X-Lizzy-Version:
description: Lizzy Version
type: string
X-Senza-Version:
description: Senza Version
type: string
schema:
$ref: '#/definitions/problem'
401:
Expand All @@ -104,6 +116,9 @@ paths:
X-Lizzy-Version:
description: Lizzy Version
type: string
X-Senza-Version:
description: Senza Version
type: string
schema:
$ref: '#/definitions/problem'
security:
Expand Down Expand Up @@ -142,6 +157,9 @@ paths:
X-Lizzy-Version:
description: Lizzy Version
type: string
X-Senza-Version:
description: Senza Version
type: string
schema:
$ref: '#/definitions/stack'
401:
Expand All @@ -168,6 +186,9 @@ paths:
X-Lizzy-Version:
description: Lizzy Version
type: string
X-Senza-Version:
description: Senza Version
type: string
schema:
$ref: '#/definitions/problem'
500:
Expand All @@ -177,6 +198,9 @@ paths:
X-Lizzy-Version:
description: Lizzy Version
type: string
X-Senza-Version:
description: Senza Version
type: string
X-Lizzy-Output:
description: Senza Output
type: string
Expand Down Expand Up @@ -207,6 +231,9 @@ paths:
X-Lizzy-Version:
description: Lizzy Version
type: string
X-Senza-Version:
description: Senza Version
type: string
schema:
type: object
$ref: '#/definitions/stack'
Expand All @@ -217,6 +244,9 @@ paths:
X-Lizzy-Version:
description: Lizzy Version
type: string
X-Senza-Version:
description: Senza Version
type: string
schema:
$ref: '#/definitions/problem'
404:
Expand All @@ -226,6 +256,9 @@ paths:
X-Lizzy-Version:
description: Lizzy Version
type: string
X-Senza-Version:
description: Senza Version
type: string
schema:
$ref: '#/definitions/problem'
security:
Expand Down Expand Up @@ -270,6 +303,9 @@ paths:
X-Lizzy-Version:
description: Lizzy Version
type: string
X-Senza-Version:
description: Senza Version
type: string
schema:
type: object
properties:
Expand All @@ -284,6 +320,9 @@ paths:
X-Lizzy-Version:
description: Lizzy Version
type: string
X-Senza-Version:
description: Senza Version
type: string
schema:
$ref: '#/definitions/problem'

Expand All @@ -302,12 +341,18 @@ paths:
X-Lizzy-Version:
description: Lizzy Version
type: string
X-Senza-Version:
description: Senza Version
type: string
schema:
type: object
properties:
version:
type: string
description: Lizzy version running
senza_version:
type: string
description: Senza version running
status:
type: string
config:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from lizzy.models.stack import Stack
from lizzy.service import setup_webapp
from lizzy.version import VERSION
from senza import __version__ as SENZA_VERSION

CURRENT_VERSION = VERSION

Expand Down Expand Up @@ -117,6 +118,7 @@ def test_security(app, mock_senza):
get_stacks = app.get('/api/stacks', headers=GOOD_HEADERS)
assert get_stacks.status_code == 200
assert get_stacks.headers['X-Lizzy-Version'] == CURRENT_VERSION
assert get_stacks.headers['X-Senza-Version'] == SENZA_VERSION

inexistent_url = app.get('/api/does-not-exist', headers=GOOD_HEADERS)
assert inexistent_url.status_code == 404
Expand Down Expand Up @@ -198,6 +200,7 @@ def test_bad_senza_yaml(app, monkeypatch, mock_senza):
response = json.loads(request.data.decode())
assert response['title'] == 'Invalid senza yaml'
assert request.headers['X-Lizzy-Version'] == CURRENT_VERSION
assert request.headers['X-Senza-Version'] == SENZA_VERSION

mock_senza = MagicMock()
mock_senza.return_value = mock_senza
Expand Down Expand Up @@ -255,6 +258,7 @@ def test_new_stack(app, mock_senza,
expected_tags)
assert request.status_code == 201
assert request.headers['X-Lizzy-Version'] == CURRENT_VERSION
assert request.headers['X-Senza-Version'] == SENZA_VERSION
response = json.loads(request.get_data().decode())
assert len(response) == 5
assert response['stack_name'] == 'abc'
Expand Down Expand Up @@ -295,6 +299,7 @@ def test_get_stack(app, mock_senza):

response = app.get('/api/stacks/stack-1', headers=GOOD_HEADERS)
assert response.headers['X-Lizzy-Version'] == CURRENT_VERSION
assert response.headers['X-Senza-Version'] == SENZA_VERSION
payload = json.loads(response.data.decode()) # type: dict
assert parameters == payload.keys()

Expand Down Expand Up @@ -341,6 +346,7 @@ def test_get_stack_404(app, mock_senza):
request = app.get('/api/stacks/stack-404', headers=GOOD_HEADERS)
assert request.status_code == 404
assert request.headers['X-Lizzy-Version'] == CURRENT_VERSION
assert request.headers['X-Senza-Version'] == SENZA_VERSION


@pytest.mark.parametrize(
Expand All @@ -366,6 +372,7 @@ def test_delete(app, mock_senza, stack_id, region, dry_run, force):
request = app.delete(url, data=json.dumps(data), headers=GOOD_HEADERS)
assert request.status_code == 204
assert request.headers['X-Lizzy-Version'] == CURRENT_VERSION
assert request.headers['X-Senza-Version'] == SENZA_VERSION
mock_senza.assert_called_once_with(region)
mock_senza.remove.assert_called_once_with(stack_id,
dry_run=dry_run, force=force)
Expand All @@ -374,6 +381,7 @@ def test_delete(app, mock_senza, stack_id, region, dry_run, force):
request = app.delete(url, data=json.dumps(data), headers=GOOD_HEADERS)
assert request.status_code == 204
assert request.headers['X-Lizzy-Version'] == CURRENT_VERSION
assert request.headers['X-Senza-Version'] == SENZA_VERSION


@pytest.mark.parametrize(
Expand Down Expand Up @@ -407,6 +415,7 @@ def test_patch(monkeypatch, app, mock_senza):
stack_name='stack',
stack_version='1')
assert request.headers['X-Lizzy-Version'] == CURRENT_VERSION
assert request.headers['X-Senza-Version'] == SENZA_VERSION

# Should return 500 when not possible to change the traffic
# while running the one of the senza commands an error occurs
Expand All @@ -422,6 +431,7 @@ def test_patch(monkeypatch, app, mock_senza):
data=json.dumps({}))
assert request.status_code == 202
assert request.headers['X-Lizzy-Version'] == CURRENT_VERSION
assert request.headers['X-Senza-Version'] == SENZA_VERSION

# Run in a different region
mock_senza.traffic.reset()
Expand All @@ -439,6 +449,7 @@ def test_patch(monkeypatch, app, mock_senza):
data=json.dumps(update_image))
assert request.status_code == 202
assert request.headers['X-Lizzy-Version'] == CURRENT_VERSION
assert request.headers['X-Senza-Version'] == SENZA_VERSION
mock_senza.patch.assert_called_once_with('stack', '1', 'ami-2323')
mock_senza.respawn_instances.assert_called_once_with('stack', '1')

Expand Down Expand Up @@ -496,6 +507,7 @@ def test_patch404(app, mock_senza):
data=json.dumps(data))
assert response.status_code == 404
assert response.headers['X-Lizzy-Version'] == CURRENT_VERSION
assert response.headers['X-Senza-Version'] == SENZA_VERSION


def test_api_discovery_endpoint(app):
Expand Down

0 comments on commit 779d113

Please sign in to comment.