-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from gregoil/finish_signature_handler
Finish remote signature handler
- Loading branch information
Showing
28 changed files
with
356 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .get_or_create import GetOrCreate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# pylint: disable=unused-argument | ||
from __future__ import absolute_import | ||
|
||
import re | ||
|
||
from six.moves import http_client | ||
|
||
from swaggapi.api.builder.server.response import Response | ||
from swaggapi.api.builder.server.request import DjangoRequestView | ||
|
||
from rotest.core.models import SignatureData | ||
from rotest.api.common.responses import SignatureResponse | ||
from rotest.api.common.models import SignatureControlParamsModel | ||
|
||
|
||
class GetOrCreate(DjangoRequestView): | ||
"""Get or create error signature in the DB. | ||
Args: | ||
error (str): string of the error. | ||
""" | ||
URI = "signatures/get_or_create" | ||
DEFAULT_MODEL = SignatureControlParamsModel | ||
DEFAULT_RESPONSES = { | ||
http_client.OK: SignatureResponse, | ||
} | ||
TAGS = { | ||
"post": ["Signatures"] | ||
} | ||
|
||
@staticmethod | ||
def _match_signatures(error_str): | ||
"""Return the data of the matched signature. | ||
Args: | ||
error_str (str): exception traceback string. | ||
Returns: | ||
SignatureData. the signature of the given exception. | ||
""" | ||
for signature in SignatureData.objects.all(): | ||
signature_reg = re.compile(signature.pattern, | ||
re.MULTILINE) | ||
if signature_reg.match(error_str): | ||
return signature | ||
|
||
return None | ||
|
||
def post(self, request, *args, **kwargs): | ||
"""Get signature data for an error or create a new one.""" | ||
error_message = request.model.error | ||
# Normalize newline char | ||
error_message = error_message.replace("\r\n", "\n") | ||
|
||
match = self._match_signatures(error_message) | ||
|
||
is_new = False | ||
if match is None: | ||
is_new = True | ||
pattern = SignatureData.create_pattern(error_message) | ||
match = SignatureData.objects.create(link="", | ||
pattern=pattern) | ||
|
||
return Response({ | ||
"is_new": is_new, | ||
"id": match.id, | ||
"link": match.link | ||
}, status=http_client.OK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0003_rundata_config'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='signaturedata', | ||
name='name', | ||
), | ||
migrations.AlterField( | ||
model_name='signaturedata', | ||
name='link', | ||
field=models.CharField(max_length=200), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0004_auto_20181111_0319'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='signaturedata', | ||
name='pattern', | ||
field=models.TextField(max_length=1000), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.