Skip to content

Commit

Permalink
Create bot friendly sanity output. (ansible#22381)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclay authored Mar 7, 2017
1 parent 3c69cf6 commit 8f463fc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ packaging/release/ansible_release
/test/results/coverage/coverage*
/test/results/reports/coverage.xml
/test/results/reports/coverage/
/test/results/bot/*.json
/test/results/junit/*.xml
/test/results/logs/*.log
/test/integration/inventory.remote
Expand Down
Empty file added test/results/bot/.keep
Empty file.
60 changes: 51 additions & 9 deletions test/runner/lib/sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ def write(self, args):
:type args: SanityConfig
"""
self.write_console()
self.write_bot(args)

if args.lint:
self.write_lint()
Expand All @@ -582,25 +583,41 @@ def write_lint(self):
"""Write lint results to stdout."""
pass

def write_bot(self, args):
"""
:type args: SanityConfig
"""
pass

def write_junit(self, args):
"""
:type args: SanityConfig
"""
pass

def create_path(self, directory, extension):
"""
:type directory: str
:type extension: str
:rtype: str
"""
path = 'test/results/%s/ansible-test-%s' % (directory, self.test)

if self.python_version:
path += '-python-%s' % self.python_version

path += extension

return path

def save_junit(self, args, test_case, properties=None):
"""
:type args: SanityConfig
:type test_case: junit_xml.TestCase
:type properties: dict[str, str] | None
:rtype: str | None
"""
path = 'test/results/junit/ansible-test-%s' % self.test

if self.python_version:
path += '-python-%s' % self.python_version

path += '.xml'
path = self.create_path('junit', '.xml')

test_suites = [
self.junit.TestSuite(
Expand Down Expand Up @@ -704,9 +721,6 @@ def write_junit(self, args):
title = self.format_title()
output = self.format_block()

# Hack to remove ANSI color reset code from SubprocessError messages.
output = output.replace(display.clear, '')

test_case = self.junit.TestCase(classname='sanity', name=self.test)

# Include a leading newline to improve readability on Shippable "Tests" tab.
Expand All @@ -715,6 +729,31 @@ def write_junit(self, args):

self.save_junit(args, test_case)

def write_bot(self, args):
"""
:type args: SanityConfig
"""
message = self.format_title()
output = self.format_block()

bot_data = dict(
results=[
dict(
message=message,
output=output,
),
],
)

path = self.create_path('bot', '.json')

if args.explain:
return

with open(path, 'wb') as bot_fd:
json.dump(bot_data, bot_fd, indent=4, sort_keys=True)
bot_fd.write('\n')

def format_command(self):
"""
:rtype: str
Expand Down Expand Up @@ -752,6 +791,9 @@ def format_block(self):

message = block.strip()

# Hack to remove ANSI color reset code from SubprocessError messages.
message = message.replace(display.clear, '')

return message


Expand Down
1 change: 1 addition & 0 deletions test/utils/shippable/shippable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function cleanup

rmdir shippable/testresults/
cp -a test/results/junit/ shippable/testresults/
cp -aT test/results/bot/ shippable/testresults/
}

trap cleanup EXIT
Expand Down

0 comments on commit 8f463fc

Please sign in to comment.