From c5b7abb6bc2d84b5da6eb567b322297a476d4342 Mon Sep 17 00:00:00 2001 From: Valerij Maljulin Date: Feb 18 2020 07:26:00 +0000 Subject: Remove GIT archive and some more tests for gating.yaml for new and old configurations Signed-off-by: Valerij Maljulin --- diff --git a/docs/policies.rst b/docs/policies.rst index f41c0f8..62ce7af 100644 --- a/docs/policies.rst +++ b/docs/policies.rst @@ -261,27 +261,21 @@ Greenwave requires these configuration parameters ``KOJI_BASE_URL`` and ``REMOTE_RULE_POLICIES`` is a map, where the key is the subject type. There could be a default pattern "*" used when no subject type matched. Old parameter ``DIST_GIT_URL_TEMPLATE`` -is used if there is no default subject type, but please note that it is obsolete -and should not be used in new configurations. Each subject should contain a map of parameters -depending on a retrieval mechanism. +if used will override the default subject type, but please note that it is obsolete +and should not be used in new configurations. Each subject should contain an URL template. -Greenwave has two mechanisms to retrieve the remote rule file: ``git archive`` is -using for side tags rules and using a git front-end. ``GIT_URL`` and ``GIT_PATH_TEMPLATE`` -should be set for ``git archive`` mechanism, ``HTTP_URL_TEMPLATE`` -should be set if you are going to use a git front-end. - -Below is an example configuration where ``git archive`` is being used for "brew-build-group" -subject type and HTTP is being used for other: +Below is an example configuration of remote rule URLs: .. code-block:: console REMOTE_RULE_POLICIES = { - 'brew-build-group': { - 'GIT_URL': 'git@gitlab.cee.redhat.com:devops/greenwave-policies/side-tags.git', - 'GIT_PATH_TEMPLATE': '{pkg_namespace}/{pkg_name}.yaml' - }, - '*': { - 'HTTP_URL_TEMPLATE': 'https://src.fedoraproject.org/{pkg_namespace}/{pkg_name}/raw/{rev}/f/gating.yaml' - } + 'brew-build-group': ( + 'https://git.example.com/devops/greenwave-policies/side-tags/raw/ + 'master/{pkg_namespace}{pkg_name}.yaml' + ), + '*': ( + 'https://src.fedoraproject.org/{pkg_namespace}' + '{pkg_name}/raw/{rev}/f/gating.yaml' + ) } KOJI_BASE_URL = 'https://koji.fedoraproject.org/kojihub' diff --git a/greenwave/app_factory.py b/greenwave/app_factory.py index d253689..22ae8f1 100644 --- a/greenwave/app_factory.py +++ b/greenwave/app_factory.py @@ -6,7 +6,7 @@ from flask import Flask from greenwave.api_v1 import api from greenwave.monitor import monitor_api from greenwave.utils import json_error, load_config, sha1_mangle_key -from greenwave.policies import load_policies, RemoteRule +from greenwave.policies import load_policies from greenwave.subjects.subject_type import load_subject_types from dogpile.cache import make_region @@ -16,31 +16,6 @@ from werkzeug.exceptions import default_exceptions log = logging.getLogger(__name__) -def _can_use_remote_rule(config): - if not config.get('KOJI_BASE_URL'): - return False - - if config.get('DIST_GIT_URL_TEMPLATE'): - return True - - if config.get('REMOTE_RULE_POLICIES'): - return all( - (conf_item.get('GIT_URL') and conf_item.get('GIT_PATH_TEMPLATE')) or - conf_item.get('HTTP_URL_TEMPLATE') - for conf_item in config.get('REMOTE_RULE_POLICIES').values() - ) - - return False - - -def _has_remote_rule(policies): - return any( - isinstance(rule, RemoteRule) - for policy in policies - for rule in policy.rules - ) - - # applicaiton factory http://flask.pocoo.org/docs/0.12/patterns/appfactories/ def create_app(config_obj=None): app = Flask(__name__) @@ -62,14 +37,6 @@ def create_app(config_obj=None): '{DIST_GIT_BASE_URL}', app.config['DIST_GIT_BASE_URL'] ) - if not _can_use_remote_rule(app.config) and _has_remote_rule(app.config['policies']): - raise RuntimeError( - 'If you want to apply a RemoteRule, you must have "KOJI_BASE_URL" and ' - '"DIST_GIT_URL_TEMPLATE" or "REMOTE_RULE_POLICIES" or both set in your configuration. ' - 'Each field in "REMOTE_RULE_POLICIES" map have to contain either ' - '"GIT_URL"/"GIT_PATH_TEMPLATE" or "HTTP_URL_TEMPLATE".' - ) - # register error handlers for code in default_exceptions.keys(): app.register_error_handler(code, json_error) diff --git a/greenwave/config.py b/greenwave/config.py index 207839c..9fad117 100644 --- a/greenwave/config.py +++ b/greenwave/config.py @@ -28,6 +28,13 @@ class Config(object): # instead DIST_GIT_URL_TEMPLATE = \ 'https://src.fedoraproject.org/{pkg_namespace}{pkg_name}/raw/{rev}/f/gating.yaml' + REMOTE_RULE_POLICIES = { + 'brew-build-group': ( + 'https://git.example.com/devops/greenwave-policies/side-tags/raw/master/{pkg_namespace}' + '{pkg_name}.yaml' + ), + '*': 'https://src.fedoraproject.org/{pkg_namespace}{pkg_name}/raw/{rev}/f/gating.yaml' + } REMOTE_RULE_GIT_TIMEOUT = 30 REMOTE_RULE_GIT_MAX_RETRY = 3 KOJI_BASE_URL = 'https://koji.fedoraproject.org/kojihub' @@ -59,14 +66,11 @@ class DevelopmentConfig(Config): GREENWAVE_API_URL = 'http://localhost:5005/api/v1.0' POLICIES_DIR = _local_conf_dir('policies') REMOTE_RULE_POLICIES = { - 'brew-build-group': { - 'GIT_URL': 'git@gitlab.cee.redhat.com:devops/greenwave-policies/side-tags.git', - 'GIT_PATH_TEMPLATE': '{pkg_namespace}/{pkg_name}.yaml' - }, - '*': { - 'HTTP_URL_TEMPLATE': - 'https://src.fedoraproject.org/{pkg_namespace}{pkg_name}/raw/{rev}/f/gating.yaml' - } + 'brew-build-group': ( + 'https://git.example.com/devops/greenwave-policies/side-tags/raw/master/{pkg_namespace}' + '{pkg_name}.yaml' + ), + '*': 'https://src.fedoraproject.org/{pkg_namespace}{pkg_name}/raw/{rev}/f/gating.yaml' } @@ -76,16 +80,6 @@ class TestingConfig(Config): GREENWAVE_API_URL = 'http://localhost:5005/api/v1.0' KOJI_BASE_URL = 'http://localhost:5006/kojihub' POLICIES_DIR = _local_conf_dir('policies') - REMOTE_RULE_POLICIES = { - 'brew-build-group': { - 'GIT_URL': 'git@gitlab.cee.redhat.com:devops/greenwave-policies/side-tags.git', - 'GIT_PATH_TEMPLATE': '{pkg_namespace}/{pkg_name}.yaml' - }, - '*': { - 'HTTP_URL_TEMPLATE': - 'https://src.fedoraproject.org/{pkg_namespace}{pkg_name}/raw/{rev}/f/gating.yaml' - } - } class FedoraTestingConfig(Config): diff --git a/greenwave/policies.py b/greenwave/policies.py index 5a85421..4304af3 100644 --- a/greenwave/policies.py +++ b/greenwave/policies.py @@ -433,14 +433,6 @@ class RemoteRule(Rule): 'required': SafeYAMLBool(optional=True, default=False), } - def _get_config_urls(self, rr_config, subject): - if subject in rr_config: - return rr_config[subject] - if '*' in rr_config: - return rr_config['*'] - raise RuntimeError(f'Cannot use a remote rule for {subject} subject ' - f'as it has not been configured') - def _get_sub_policies(self, policy, subject): if not subject.supports_remote_rule: return [] @@ -459,13 +451,16 @@ class RemoteRule(Rule): if pkg_namespace == 'containers': pkg_name = re.sub('-container$', '', pkg_name) rr_policies_conf = current_app.config.get('REMOTE_RULE_POLICIES', {}) - if not rr_policies_conf or '*' not in rr_policies_conf: - rr_policies_conf['*'] = { - 'HTTP_URL_TEMPLATE': current_app.config['DIST_GIT_URL_TEMPLATE'] - } - cur_subject_config = self._get_config_urls(rr_policies_conf, policy.subject_type) + cur_subject_url = rr_policies_conf.get( + policy.subject_type, current_app.config.get( + 'DIST_GIT_URL_TEMPLATE', rr_policies_conf.get('*') + ) + ) + if not cur_subject_url: + raise RuntimeError(f'Cannot use a remote rule for {subject} subject ' + f'as it has not been configured') response = greenwave.resources.retrieve_yaml_remote_rule( - rev, pkg_name, pkg_namespace, cur_subject_config + rev, pkg_name, pkg_namespace, cur_subject_url ) if response is None: diff --git a/greenwave/resources.py b/greenwave/resources.py index 1968122..1bccd6c 100644 --- a/greenwave/resources.py +++ b/greenwave/resources.py @@ -8,9 +8,6 @@ waiverdb, etc..). import logging import re -from io import BytesIO -import tarfile -import subprocess import socket from urllib.parse import urlparse @@ -167,22 +164,7 @@ def retrieve_scm_from_koji_build(nvr, build, koji_url): @cached -def retrieve_yaml_remote_rule(rev, pkg_name, pkg_namespace, rr_config): - """ Retrieve a remote rule file content from the given repo""" - if rr_config.get('GIT_URL') and rr_config.get('GIT_PATH_TEMPLATE'): - return _retrieve_yaml_remote_rule_git_archive( - pkg_name, pkg_namespace, rr_config['GIT_URL'], rr_config['GIT_PATH_TEMPLATE'] - ) - else: - return _retrieve_yaml_remote_rule_web( - rev, pkg_name, pkg_namespace, rr_config['HTTP_URL_TEMPLATE'] - ) - - -_retrieve_remote_rule_error = 'Error occurred while retrieving a remote rule file from the repo.' - - -def _retrieve_yaml_remote_rule_web(rev, pkg_name, pkg_namespace, url_template): +def retrieve_yaml_remote_rule(rev, pkg_name, pkg_namespace, url_template): """ Retrieve a remote rule file content from the git web UI. """ data = { "pkg_namespace": pkg_namespace + ('/' if pkg_namespace else ''), @@ -195,7 +177,7 @@ def _retrieve_yaml_remote_rule_web(rev, pkg_name, pkg_namespace, url_template): return None if response.status_code != 200: - raise BadGateway(_retrieve_remote_rule_error) + raise BadGateway('Error occurred while retrieving a remote rule file from the repo.') # remote rule file found... response = requests_session.request('GET', url) @@ -203,41 +185,6 @@ def _retrieve_yaml_remote_rule_web(rev, pkg_name, pkg_namespace, url_template): return response.content -def _retrieve_yaml_remote_rule_git_archive(pkg_name, pkg_namespace, git_url, path_template): - """ Retrieve a remote rule file content from a git repo using git archive. """ - git_path = path_template.format(pkg_name=pkg_name, pkg_namespace=pkg_namespace) - cmd = ['git', 'archive', f'--remote={git_url}', 'master', git_path] - # Retry thrice if TimeoutExpired exception is raised - MAX_RETRY = current_app.config.get('REMOTE_RULE_GIT_MAX_RETRY', 3) - git_archive = None - for _ in range(MAX_RETRY): - try: - git_archive = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - output, error_output = git_archive.communicate( - timeout=current_app.config.get('REMOTE_RULE_GIT_TIMEOUT', 30) - ) - break - except subprocess.TimeoutExpired: - if git_archive: - git_archive.kill() - continue - - if git_archive.returncode != 0: - error_output = error_output.decode('utf-8') - if 'path not found' in error_output: - return None - - cmd_str = ' '.join(cmd) - log.error('The following exception occurred while running "%s": %s', cmd_str, error_output) - raise BadGateway(_retrieve_remote_rule_error) - - # Convert the output to a file-like object with BytesIO, then tar can read it - # in memory rather than writing it to a file first - remote_rule_archive = tarfile.open(fileobj=BytesIO(output)) - remote_rule_content = remote_rule_archive.extractfile(git_path).read().decode('utf-8') - return remote_rule_content - - # NOTE - not cached. def retrieve_decision(greenwave_url, data): response = requests_session.post(greenwave_url, json=data) diff --git a/greenwave/tests/test_app_factory.py b/greenwave/tests/test_app_factory.py index 621cc1a..64bc65e 100644 --- a/greenwave/tests/test_app_factory.py +++ b/greenwave/tests/test_app_factory.py @@ -1,44 +1,14 @@ # SPDX-License-Identifier: GPL-2.0+ import mock -import pytest from textwrap import dedent - -from greenwave.app_factory import create_app, _can_use_remote_rule +from greenwave.app_factory import create_app from greenwave.policies import Policy from greenwave.config import TestingConfig @mock.patch('greenwave.policies.load_policies') -def test_remote_rules_misconfigured(mock_load_policies): - """ - The application shouldn't start if RemoteRule is in policy configuration - but if cannot be used because dist-git or koji URL is not configured. - """ - - policies = Policy.safe_load_all(dedent(""" - --- !Policy - id: test_policy - product_versions: [fedora-rawhide] - decision_context: another_test_context - subject_type: koji_build - rules: - - !RemoteRule {} - """)) - mock_load_policies.return_value = policies - - config = TestingConfig() - config.DIST_GIT_URL_TEMPLATE = '' - config.REMOTE_RULE_POLICIES = {} - - expected_error = 'If you want to apply a RemoteRule' - - with pytest.raises(RuntimeError, match=expected_error): - create_app(config) - - -@mock.patch('greenwave.policies.load_policies') def test_remote_rules_base_url(mock_load_policies): """ The application shouldn't start if RemoteRule is in policy configuration @@ -66,45 +36,3 @@ def test_remote_rules_base_url(mock_load_policies): assert app.config['DIST_GIT_URL_TEMPLATE'] == ( 'http://localhost.localdomain/{other_params}/blablabla/gating.yaml' ) - - -def test_can_use_remote_rule_http_fallback(): - """ Test that _can_use_remote_rule verifies the configuration properly if HTTP is used. """ - config = { - 'KOJI_BASE_URL': 'https://koji.domain.local/kojihub', - 'DIST_GIT_URL_TEMPLATE': - 'https://dist-git.domain.local/{pkg_namespace}{pkg_name}/raw/{rev}/f/gating.yaml' - } - assert _can_use_remote_rule(config) is True - - -def test_can_use_remote_rule_http(): - """ Test that _can_use_remote_rule verifies the configuration properly if HTTP is used. """ - config = { - 'KOJI_BASE_URL': 'https://koji.domain.local/kojihub', - 'REMOTE_RULE_POLICIES': { - '*': { - 'HTTP_URL_TEMPLATE': 'https://src.fedoraproject.org/{pkg_namespace}{pkg_name}/' - 'raw/{rev}/f/gating.yaml' - } - } - } - assert _can_use_remote_rule(config) is True - - -@pytest.mark.parametrize('config', ( - { - 'REMOTE_RULE_POLICIES': { - 'brew-build-group': { - 'GIT_URL': 'git@gitlab.cee.redhat.com:devops/greenwave-policies/side-tags.git', - 'GIT_PATH_TEMPLATE': '{pkg_namespace}/{pkg_name}.yaml' - } - }, - }, - { - 'KOJI_BASE_URL': 'https://koji.domain.local/kojihub' - } -)) -def test_can_use_remote_rule_missing_config(config): - """ Test that _can_use_remote_rule will return False if a configuration is missing. """ - assert _can_use_remote_rule(config) is False diff --git a/greenwave/tests/test_policies.py b/greenwave/tests/test_policies.py index 69d996c..004ae67 100644 --- a/greenwave/tests/test_policies.py +++ b/greenwave/tests/test_policies.py @@ -25,6 +25,7 @@ from greenwave.resources import ResultsRetriever from greenwave.safe_yaml import SafeYAMLError from greenwave.subjects.factory import create_subject from greenwave.waivers import waive_answers +from greenwave.config import TestingConfig, Config def create_test_subject(type_id, item): @@ -337,6 +338,146 @@ def test_remote_rule_policy(tmpdir, namespace): decision = policy.check('fedora-26', subject, results) assert len(decision) == 1 assert isinstance(decision[0], TestResultFailed) + f.assert_called_with( + 'c3c47a08a66451cb9686c49f040776ed35a0d1bb', + 'nethack', + namespace, + 'https://src.fedoraproject.org/{pkg_namespace}' + '{pkg_name}/raw/{rev}/f/gating.yaml' + ) + + +@pytest.mark.parametrize('namespace', ["rpms", ""]) +def test_remote_rule_policy_old_config(tmpdir, namespace): + """ Testing the RemoteRule with the koji interaction. + In this case we are just mocking koji """ + + subject = create_test_subject('koji_build', 'nethack-1.2.3-1.el9000') + + serverside_fragment = dedent(""" + --- !Policy + id: "taskotron_release_critical_tasks_with_remoterule" + product_versions: + - fedora-26 + decision_context: bodhi_update_push_stable_with_remoterule + subject_type: koji_build + rules: + - !RemoteRule {} + """) + + remote_fragment = dedent(""" + --- !Policy + id: "some-policy-from-a-random-packager" + product_versions: + - fedora-26 + decision_context: bodhi_update_push_stable_with_remoterule + rules: + - !PassingTestCaseRule {test_case_name: dist.upgradepath} + """) + + p = tmpdir.join('gating.yaml') + p.write(serverside_fragment) + + config_remote_rules_backup = Config.REMOTE_RULE_POLICIES + + try: + delattr(Config, 'REMOTE_RULE_POLICIES') + + config = TestingConfig() + config.DIST_GIT_BASE_URL = 'http://localhost.localdomain/' + config.DIST_GIT_URL_TEMPLATE = '{DIST_GIT_BASE_URL}{other_params}/blablabla/gating.yaml' + + app = create_app(config) + + with app.app_context(): + with mock.patch('greenwave.resources.retrieve_scm_from_koji') as scm: + scm.return_value = ( + namespace, 'nethack', 'c3c47a08a66451cb9686c49f040776ed35a0d1bb' + ) + with mock.patch('greenwave.resources.retrieve_yaml_remote_rule') as f: + f.return_value = remote_fragment + policies = load_policies(tmpdir.strpath) + policy = policies[0] + + # Ensure that presence of a result is success. + results = DummyResultsRetriever(subject, 'dist.upgradepath') + decision = policy.check('fedora-26', subject, results) + assert len(decision) == 1 + assert isinstance(decision[0], RuleSatisfied) + + f.assert_called_once_with( + 'c3c47a08a66451cb9686c49f040776ed35a0d1bb', + 'nethack', + namespace, + 'http://localhost.localdomain/{other_params}/blablabla/gating.yaml' + ) + finally: + Config.REMOTE_RULE_POLICIES = config_remote_rules_backup + + +@pytest.mark.parametrize('namespace', ["rpms", ""]) +def test_remote_rule_policy_brew_build_group(tmpdir, namespace): + """ Testing the RemoteRule with the koji interaction. + In this case we are just mocking koji """ + + subject = create_test_subject('koji_build', 'nethack-1.2.3-1.el9000') + + serverside_fragment = dedent(""" + --- !Policy + id: "taskotron_release_critical_tasks_with_remoterule" + product_versions: + - fedora-26 + decision_context: bodhi_update_push_stable_with_remoterule + subject_type: brew-build-group + rules: + - !RemoteRule {} + """) + + remote_fragment = dedent(""" + --- !Policy + id: "some-policy-from-a-random-packager" + product_versions: + - fedora-26 + decision_context: bodhi_update_push_stable_with_remoterule + rules: + - !PassingTestCaseRule {test_case_name: dist.upgradepath} + """) + + p = tmpdir.join('gating.yaml') + p.write(serverside_fragment) + app = create_app('greenwave.config.TestingConfig') + with app.app_context(): + with mock.patch('greenwave.resources.retrieve_scm_from_koji') as scm: + scm.return_value = (namespace, 'nethack', 'c3c47a08a66451cb9686c49f040776ed35a0d1bb') + with mock.patch('greenwave.resources.retrieve_yaml_remote_rule') as f: + f.return_value = remote_fragment + policies = load_policies(tmpdir.strpath) + policy = policies[0] + + # Ensure that presence of a result is success. + results = DummyResultsRetriever(subject, 'dist.upgradepath') + decision = policy.check('fedora-26', subject, results) + assert len(decision) == 1 + assert isinstance(decision[0], RuleSatisfied) + + # Ensure that absence of a result is failure. + results = DummyResultsRetriever() + decision = policy.check('fedora-26', subject, results) + assert len(decision) == 1 + assert isinstance(decision[0], TestResultMissing) + + # And that a result with a failure, is a failure. + results = DummyResultsRetriever(subject, 'dist.upgradepath', 'FAILED') + decision = policy.check('fedora-26', subject, results) + assert len(decision) == 1 + assert isinstance(decision[0], TestResultFailed) + f.assert_called_with( + 'c3c47a08a66451cb9686c49f040776ed35a0d1bb', + 'nethack', + namespace, + 'https://git.example.com/devops/greenwave-policies/side-tags/raw/' + 'master/{pkg_namespace}{pkg_name}.yaml' + ) def test_remote_rule_policy_with_no_remote_rule_policies_param_defined(tmpdir): @@ -383,6 +524,13 @@ def test_remote_rule_policy_with_no_remote_rule_policies_param_defined(tmpdir): decision = policy.check('fedora-26', subject, results) assert len(decision) == 1 assert isinstance(decision[0], RuleSatisfied) + f.assert_called_with( + 'c3c47a08a66451cb9686c49f040776ed35a0d1bb', + 'nethack', + 'rpms', + 'https://src.fedoraproject.org/{pkg_namespace}' + '{pkg_name}/raw/{rev}/f/gating.yaml' + ) @pytest.mark.parametrize('namespace', ["modules", ""]) diff --git a/greenwave/tests/test_retrieve_gating_yaml.py b/greenwave/tests/test_retrieve_gating_yaml.py index 75a68ea..349dc04 100644 --- a/greenwave/tests/test_retrieve_gating_yaml.py +++ b/greenwave/tests/test_retrieve_gating_yaml.py @@ -1,7 +1,5 @@ # SPDX-License-Identifier: GPL-2.0+ -import subprocess -import io import socket from requests.exceptions import ConnectionError, HTTPError @@ -11,7 +9,7 @@ from werkzeug.exceptions import BadGateway, NotFound import greenwave.app_factory from greenwave.resources import ( - retrieve_scm_from_koji_build, retrieve_yaml_remote_rule, retrieve_scm_from_koji, + retrieve_scm_from_koji_build, retrieve_scm_from_koji, retrieve_yaml_remote_rule, NoSourceException ) @@ -152,69 +150,6 @@ def test_retrieve_yaml_remote_rule_connection_error(): ) -@mock.patch('tarfile.open') -@mock.patch('subprocess.Popen') -def test_retrieve_yaml_remote_rule_git_archive(mock_subp, mock_tar): - # Make the git archive call return bytes - mock_subp.return_value.communicate.return_value = (b'tar file', '') - mock_subp.return_value.returncode = 0 - # Make the tar archive, based on the return value of git archive, return a file-like - # object representing the gating.yaml file - mock_tar.return_value.extractfile.return_value = io.BytesIO(b'some gating yaml file') - - app = greenwave.app_factory.create_app() - rr_config = { - 'GIT_URL': 'git://dist-git.domain.local/abc/abc.git', - 'GIT_PATH_TEMPLATE': '{pkg_namespace}/{pkg_name}.yaml' - } - with app.app_context(): - gating_yaml = retrieve_yaml_remote_rule('abcdef', 'python-requests', 'rpms', rr_config) - - assert gating_yaml == 'some gating yaml file' - expected_cmd = [ - 'git', 'archive', '--remote=git://dist-git.domain.local/abc/abc.git', - 'master', 'rpms/python-requests.yaml'] - mock_subp.assert_called_once_with(expected_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE) - tar_file = mock_tar.call_args[1]['fileobj'].read() - assert tar_file == b'tar file' - mock_tar.return_value.extractfile.assert_called_once_with('rpms/python-requests.yaml') - - -@mock.patch('subprocess.Popen') -def test_retrieve_yaml_remote_rule_git_archive_no_file(mock_subp): - # Make the git archive command return an error saying the file isn't in the repo - mock_subp.return_value.communicate.return_value = \ - (None, b'remote: fatal: path not found: xxx.yaml') - mock_subp.return_value.returncode = 1 - - app = greenwave.app_factory.create_app() - rr_config = { - 'GIT_URL': 'git://dist-git.domain.local/abc/abc.git', - 'GIT_PATH_TEMPLATE': '{pkg_namespace}/{pkg_name}.yaml' - } - with app.app_context(): - gating_yaml = retrieve_yaml_remote_rule('master', 'python-requests', 'rpms', rr_config) - - assert gating_yaml is None - - -@mock.patch('subprocess.Popen') -def test_retrieve_yaml_remote_rule_git_archive_error(mock_subp): - # Make the git archive command return an error - mock_subp.return_value.communicate.return_value = (None, b'remote: fatal: some error') - mock_subp.return_value.returncode = 1 - - app = greenwave.app_factory.create_app() - rr_config = { - 'GIT_URL': 'git://dist-git.domain.local/abc/abc.git', - 'GIT_PATH_TEMPLATE': '{pkg_namespace}/{pkg_name}.yaml' - } - expected_error = 'Error occurred while retrieving a remote rule file from the repo.' - with pytest.raises(BadGateway, match=expected_error): - with app.app_context(): - retrieve_yaml_remote_rule('master', 'python-requests', 'rpms', rr_config) - - @mock.patch('greenwave.resources.xmlrpc.client.ServerProxy') def test_retrieve_scm_from_koji_build_socket_error(mock_xmlrpc_client): mock_auth_server = mock_xmlrpc_client.return_value