From 872037dd695ddb60d1205536e3e92359e0dc10cd Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Aug 21 2018 09:07:24 +0000 Subject: [PATCH 1/2] Refine error message for failure gating.yaml validation Instead of printing message in a single long line, the message is splitted into multiple lines for better readability. Signed-off-by: Chenxiong Qi --- diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index abd7c6a..707807e 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1536,19 +1536,25 @@ see API KEY section of copr-cli(1) man page. # read content from gating.yaml and validate it from greenwave endpoint with open(filename, 'rb') as gating_file: - response = self.greenwave_validation_gating(greenwave_url, gating_file.read()) + response = self.greenwave_validation_gating( + greenwave_url, gating_file.read()) + resp_msg = response.json()['message'] + if response.status_code == 400: - raise rpkgError(('Found a gating.yaml file in your repo with additional ' - 'Greenwave policies, but it is not valid. Please fix the file' - ' or skip this check using the parameter' - ' --skip-remote-rules-validation. Error response from ' - 'Greenwave: %s') % (response.json()['message'])) + raise rpkgError( + 'Found a gating.yaml file in your repo with additional ' + 'Greenwave policies, but it is not valid.\n' + 'Please fix the file or skip this check using the ' + 'option --skip-remote-rules-validation.\n' + 'Error response from Greenwave: %s' % resp_msg) elif response.status_code != 200: - raise rpkgError(('Found a gating.yaml file in your repo with additional ' - 'Greenwave policies, but it was not possible to validate it for ' - 'an unknown problem. It is possible to skip this check using the ' - 'parameter --skip-remote-rules-validation. Error response from ' - 'Greenwave: %s') % (response.json()['message'])) + raise rpkgError( + 'Found a gating.yaml file in your repo with additional ' + 'Greenwave policies, but it was not possible to validate ' + 'it for an unknown problem.\n' + 'It is possible to skip this check using the option ' + '--skip-remote-rules-validation.\n' + 'Error response from Greenwave: %s' % resp_msg) else: self.log.info(("Found a gating.yaml file in the repo and it is properly " "configured")) From 182d794f617ef7ff61e97b3ac10055dbb5e9482e Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Aug 21 2018 09:08:25 +0000 Subject: [PATCH 2/2] Validate greenwave policy early in Commands.build Original method call to validate greenwave policy is too late and it is difficult to reuse _build in downstream tools. For example of fedpkg, _build is overridden to submit multiple builds in some case, which causes greenwave policy defined in gating.yaml will be validated multiple times accordingly. This change ensures the validation happens only once, whatever how _build is reused. Signed-off-by: Chenxiong Qi --- diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 707807e..44beb9c 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1561,6 +1561,8 @@ see API KEY section of copr-cli(1) man page. def build(self, sets=None): """Implement build command""" + self.check_remote_rules_gating() + try: task_id = self._build(sets=sets) finally: @@ -1610,8 +1612,6 @@ see API KEY section of copr-cli(1) man page. # handle uploading the srpm if we got one url = self._handle_srpm_option() - self.check_remote_rules_gating() - return self.cmd.build( skip_tag=self.args.skip_tag, scratch=self.args.scratch,