diff options
author | Justin Cook <justin.cook@linaro.org> | 2020-10-28 14:17:16 -0500 |
---|---|---|
committer | Justin Cook <justin.cook@linaro.org> | 2020-10-28 14:17:16 -0500 |
commit | 1661c325f747aaf75fa15c75e4742dde9bf4c8a1 (patch) | |
tree | 874bfd13c8100e459a1aa1bef9e19d4b9dc79de6 | |
parent | 1b58899222d2984daae8275d15a6f3c624d4699c (diff) |
Add an option to the submit command that allows the submission of tuxbuild json result files
-rw-r--r-- | squad_client/commands/submit.py | 44 | ||||
-rw-r--r-- | tests/data/submit/tuxbuild/build.json | 55 | ||||
-rw-r--r-- | tests/data/submit/tuxbuild/malformed.json | 55 | ||||
-rw-r--r-- | tests/test_submit.py | 39 |
4 files changed, 190 insertions, 3 deletions
diff --git a/squad_client/commands/submit.py b/squad_client/commands/submit.py index d43d24a..bbf93b8 100644 --- a/squad_client/commands/submit.py +++ b/squad_client/commands/submit.py @@ -1,3 +1,4 @@ +import hashlib import json import logging import os @@ -30,6 +31,11 @@ class SubmitCommand(SquadClientCommand): choices=["pass", "fail", "skip"], ) parser.add_argument( + "--results-layout", + help="Layout of the results file, if any", + choices=["tuxbuild_json"], + ) + parser.add_argument( "--metrics", help="File with metrics(benchmarsk) to submit. Max 5MB. JSON and YAML formats are supported", ) @@ -89,6 +95,38 @@ class SubmitCommand(SquadClientCommand): return output_dict + def _load_tuxbuild_json(self, path): + if not self.__check_file(path): + return None + + data = None + try: + with open(path) as f: + tb = {} + builds = json.load(f) + + for b in builds: + name = self._get_tuxbuild_test_name(b) + tb[name] = b["build_status"] + + data = tb + + except json.JSONDecodeError as jde: + logger.error("Failed to load json: %s", jde) + + except OSError as ose: + logger.error("Failed to open file: %s", ose) + + return data + + def _get_tuxbuild_test_name(self, build): + suite = "build" + kconfig_hash = hashlib.sha1(json.dumps(build["kconfig"][1:]).encode()).hexdigest()[0:8] + + return "%s/%s-%s-%s-%s" % ( + suite, build["target_arch"], build["toolchain"], build["kconfig"][0], kconfig_hash, + ) + def run(self, args): results_dict = {} metrics_dict = {} @@ -101,7 +139,11 @@ class SubmitCommand(SquadClientCommand): results_dict = {args.result_name: args.result_value} if args.results: - results_dict = self.__read_input_file(args.results) + if args.results_layout == 'tuxbuild_json': + results_dict = self._load_tuxbuild_json(args.results) + else: + results_dict = self.__read_input_file(args.results) + if results_dict is None: return False diff --git a/tests/data/submit/tuxbuild/build.json b/tests/data/submit/tuxbuild/build.json new file mode 100644 index 0000000..bdefd53 --- /dev/null +++ b/tests/data/submit/tuxbuild/build.json @@ -0,0 +1,55 @@ +[ + { + "build_key": "t8NSUfTBZiSPbBVaXLH7kw", + "build_status": "pass", + "client_token": "3cffcab5-aaf8-446d-8dec-861da6814788", + "download_url": "https://builds.tuxbuild.com/t8NSUfTBZiSPbBVaXLH7kw/", + "errors_count": 0, + "git_describe": "next-20201021", + "git_repo": "https://gitlab.com/Linaro/lkft/mirrors/next/linux-next", + "git_sha": "5302568121ba345f5c22528aefd72d775f25221e", + "git_short_log": "5302568121ba (\"Add linux-next specific files for 20201021\")", + "kconfig": [ + "defconfig", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/lkft.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/lkft-crypto.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/distro-overrides.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/systemd.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/virtio.config", + "CONFIG_IGB=y", + "CONFIG_UNWINDER_FRAME_POINTER=y" + ], + "kernel_version": "5.9.0", + "status_message": "build completed", + "target_arch": "x86", + "toolchain": "gcc-9", + "tuxbuild_status": "complete", + "warnings_count": 1 + }, + { + "build_key": "B3TECkH4_1X9yKoWOPIhew", + "build_status": "fail", + "client_token": "32b482ac-2cc1-4f68-bf73-cc9f780b72cf", + "download_url": "https://builds.tuxbuild.com/B3TECkH4_1X9yKoWOPIhew/", + "errors_count": 2, + "git_describe": "next-20201021", + "git_repo": "https://gitlab.com/Linaro/lkft/mirrors/next/linux-next", + "git_sha": "5302568121ba345f5c22528aefd72d775f25221e", + "git_short_log": "5302568121ba (\"Add linux-next specific files for 20201021\")", + "kconfig": [ + "defconfig", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/lkft.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/lkft-crypto.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/distro-overrides.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/systemd.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/virtio.config", + "CONFIG_ARM64_MODULE_PLTS=y" + ], + "kernel_version": "5.9.0", + "status_message": "build failed due to compilation error(s)", + "target_arch": "arm64", + "toolchain": "gcc-9", + "tuxbuild_status": "complete", + "warnings_count": 2 + } +] diff --git a/tests/data/submit/tuxbuild/malformed.json b/tests/data/submit/tuxbuild/malformed.json new file mode 100644 index 0000000..f404a9d --- /dev/null +++ b/tests/data/submit/tuxbuild/malformed.json @@ -0,0 +1,55 @@ +[ + { + "build_key": "t8NSUfTBZiSPbBVaXLH7kw", + "build_status": "pass", + "client_token": "3cffcab5-aaf8-446d-8dec-861da6814788", + "download_url": "https://builds.tuxbuild.com/t8NSUfTBZiSPbBVaXLH7kw/", + "errors_count": 0, + "git_describe": "next-20201021", + "git_repo": "https://gitlab.com/Linaro/lkft/mirrors/next/linux-next", + "git_sha": "5302568121ba345f5c22528aefd72d775f25221e", + "git_short_log": "5302568121ba (\"Add linux-next specific files for 20201021\")", + "kconfig": [ + "defconfig", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/lkft.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/lkft-crypto.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/distro-overrides.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/systemd.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/virtio.config", + "CONFIG_IGB=y", + "CONFIG_UNWINDER_FRAME_POINTER=y" + ], + "kernel_version": "5.9.0", + "status_message": "build completed", + "target_arch": "x86", + "toolchain": "gcc-9", + "tuxbuild_status": "complete", + "warnings_count": 1 + } + { + "build_key": "B3TECkH4_1X9yKoWOPIhew", + "build_status": "fail", + "client_token": "32b482ac-2cc1-4f68-bf73-cc9f780b72cf", + "download_url": "https://builds.tuxbuild.com/B3TECkH4_1X9yKoWOPIhew/", + "errors_count": 2, + "git_describe": "next-20201021", + "git_repo": "https://gitlab.com/Linaro/lkft/mirrors/next/linux-next", + "git_sha": "5302568121ba345f5c22528aefd72d775f25221e", + "git_short_log": "5302568121ba (\"Add linux-next specific files for 20201021\")", + "kconfig": [ + "defconfig", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/lkft.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/lkft-crypto.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/distro-overrides.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/systemd.config", + "https://raw.githubusercontent.com/Linaro/meta-lkft/sumo/recipes-kernel/linux/files/virtio.config", + "CONFIG_ARM64_MODULE_PLTS=y" + ], + "kernel_version": "5.9.0", + "status_message": "build failed due to compilation error(s)", + "target_arch": "arm64", + "toolchain": "gcc-9", + "tuxbuild_status": "complete", + "warnings_count": 2 + } +] diff --git a/tests/test_submit.py b/tests/test_submit.py index 7539ced..151be44 100644 --- a/tests/test_submit.py +++ b/tests/test_submit.py @@ -71,7 +71,7 @@ class SubmitCommandTest(unittest.TestCase): self.squad = Squad() SquadApi.configure(url=self.testing_server, token=self.testing_token) - def manage_submit(self, results=None, result_name=None, result_value=None, metrics=None, + def manage_submit(self, results=None, results_layout=None, result_name=None, result_value=None, metrics=None, metadata=None, attachments=None, logs=None, environment=None): argv = ['./manage.py', '--squad-host', self.testing_server, '--squad-token', self.testing_token, 'submit', '--group', 'my_group', '--project', 'my_project', '--build', 'my_build6', '--environment', 'test_submit_env'] @@ -80,6 +80,8 @@ class SubmitCommandTest(unittest.TestCase): argv += ['--logs', logs] if results: argv += ['--results', results] + if results_layout: + argv += ['--results-layout', results_layout] if metrics: argv += ['--metrics', metrics] if metadata: @@ -144,6 +146,39 @@ class SubmitCommandTest(unittest.TestCase): self.assertFalse(proc.ok) self.assertIn('Failed parsing file', proc.err) + def test_submit_results_tuxbuild_json(self): + proc = self.manage_submit(results='tests/data/submit/tuxbuild/build.json', results_layout='tuxbuild_json') + self.assertTrue(proc.ok, msg=proc.err) + self.assertIn("Submitting 2 tests", proc.err) + + test = first(self.squad.tests(name="x86-gcc-9-defconfig-b9979cfa")) + self.assertEqual("build/x86-gcc-9-defconfig-b9979cfa", test.name) + self.assertEqual("pass", test.status) + + test = first(self.squad.tests(name="arm64-gcc-9-defconfig-5b09568e")) + self.assertEqual("build/arm64-gcc-9-defconfig-5b09568e", test.name) + self.assertEqual("fail", test.status) + + def test_submit_results_tuxbuild_json_malformed(self): + proc = self.manage_submit(results='tests/data/submit/tuxbuild/malformed.json', results_layout='tuxbuild_json') + self.assertFalse(proc.ok, msg=proc.err) + self.assertIn("Failed to load json", proc.err) + + def test_submit_results_tuxbuild_json_missing(self): + proc = self.manage_submit(results="tests/data/submit/tuxbuild/missing.json", results_layout="tuxbuild_json") + self.assertFalse(proc.ok) + self.assertIn("Requested file tests/data/submit/tuxbuild/missing.json doesn't exist", proc.err) + + def test_submit_results_tuxbuild_json_results_opt_missing(self): + proc = self.manage_submit(results_layout="tuxbuild_json") + self.assertFalse(proc.ok) + self.assertIn("At least one of --result-name, --results, --metrics is required", proc.err) + + def test_submit_results_tuxbuild_json_layout_arg_bad(self): + proc = self.manage_submit(results="tests/data/submit/tuxbuild/build.json", results_layout="bad_layout") + self.assertFalse(proc.ok) + self.assertIn("argument --results-layout: invalid choice: 'bad_layout'", proc.err) + def test_submit_results_yaml(self): proc = self.manage_submit(results='tests/submit_results/sample_results.yaml') self.assertTrue(proc.ok) @@ -179,7 +214,7 @@ class SubmitCommandTest(unittest.TestCase): metrics='tests/submit_results/sample_metrics.json', metadata='tests/submit_results/sample_metadata.json', logs='tests/submit_results/sample_log.log') - self.assertTrue(proc.ok) + self.assertTrue(proc.ok, msg=proc.err) self.assertIn('2 tests, 1 metrics', proc.err) testrun = first(self.squad.testruns(job_id='jsonmetadatajobid1')) |