From 81b58203644ed7f7cb8b43b75e7c9df7cbcce1aa Mon Sep 17 00:00:00 2001 From: Giulia Naponiello Date: Jun 12 2018 14:29:25 +0000 Subject: Renamed RemoteOriginalSpecNvrRule to RemoteRule The RemoteOriginalSpecNvrRule rule type originally only worked against decisions for original_spec_nvr. Now this changed, so also the name should change, otherwise it is confusing. --- diff --git a/conf/policies/fedora.yaml b/conf/policies/fedora.yaml index a0d68fe..98cf691 100644 --- a/conf/policies/fedora.yaml +++ b/conf/policies/fedora.yaml @@ -60,7 +60,7 @@ decision_context: bodhi_update_push_stable_with_remoterule subject_type: bodhi_update blacklist: [] rules: - - !RemoteOriginalSpecNvrRule {} + - !RemoteRule {} # No Fedora product has *actually* used an empty policy like this, # but we cover it in our tests for completeness. diff --git a/docs/policies.rst b/docs/policies.rst index 0bd234c..dd031c0 100644 --- a/docs/policies.rst +++ b/docs/policies.rst @@ -164,17 +164,16 @@ PackageSpecificBuild ``FedoraAtomicCi`` is a backwards compatibility alias for this rule type. -.. _remote-original-spec-nvr-rule: +.. _remote-rule: -RemoteOriginalSpecNvrRule -------------------------- +RemoteRule +---------- This rule allows the packager to configure some additional policies in a gating.yaml file configured in the repo. Greenwave checks if the file exists, and, if it does it pulls it down, loads it, and uses it to additionally evaluate the subject of the decision. - This feature is available for an `nvr` that is ``original_spec_nvr``. To use this feature it is required to configure ``KOJI_BASE_URL``, ``DIST_GIT_BASE_URL`` and ``DIST_GIT_URL_TEMPLATE``. diff --git a/greenwave/api_v1.py b/greenwave/api_v1.py index f5b1ad4..bb727cc 100644 --- a/greenwave/api_v1.py +++ b/greenwave/api_v1.py @@ -3,7 +3,7 @@ from flask import Blueprint, request, current_app, jsonify, url_for, redirect from werkzeug.exceptions import BadRequest, NotFound, UnsupportedMediaType, InternalServerError from greenwave import __version__ -from greenwave.policies import summarize_answers, RemoteOriginalSpecNvrRule +from greenwave.policies import summarize_answers, RemoteRule from greenwave.resources import retrieve_results, retrieve_waivers, retrieve_builds_in_update from greenwave.utils import insert_headers, jsonp @@ -302,11 +302,11 @@ def make_decision(): for policy in current_app.config['policies']: for rule in policy.rules: - if isinstance(rule, RemoteOriginalSpecNvrRule): + if isinstance(rule, RemoteRule): if ('DIST_GIT_BASE_URL' not in current_app.config or 'DIST_GIT_URL_TEMPLATE' not in current_app.config or 'KOJI_BASE_URL' not in current_app.config): - raise InternalServerError("If you want to apply a RemoteOriginalSpecNvrRule" + raise InternalServerError("If you want to apply a RemoteRule" " you need to configure 'DIST_GIT_BASE_URL'," "'DIST_GIT_URL_TEMPLATE' and KOJI_BASE_URL in " "your configuration.") diff --git a/greenwave/policies.py b/greenwave/policies.py index 657165f..014dfed 100644 --- a/greenwave/policies.py +++ b/greenwave/policies.py @@ -261,8 +261,8 @@ class Rule(yaml.YAMLObject): raise NotImplementedError() -class RemoteOriginalSpecNvrRule(Rule): - yaml_tag = '!RemoteOriginalSpecNvrRule' +class RemoteRule(Rule): + yaml_tag = '!RemoteRule' yaml_loader = yaml.SafeLoader def check(self, subject_type, subject_identifier, results, waivers): @@ -271,7 +271,7 @@ class RemoteOriginalSpecNvrRule(Rule): pkg_name = subject_identifier.rsplit('-', 2)[0] rev = greenwave.resources.retrieve_rev_from_koji(subject_identifier) - response = greenwave.resources.retrieve_yaml_remote_original_spec_nvr_rule(rev, pkg_name) + response = greenwave.resources.retrieve_yaml_remote_rule(rev, pkg_name) if response is None: # greenwave extension file not found @@ -283,7 +283,7 @@ class RemoteOriginalSpecNvrRule(Rule): # policies in dist-git are always about a package for policy in policies: policy.subject_type = 'koji_build' - validate_policies(policies, [RemoteOriginalSpecNvrRule]) + validate_policies(policies, [RemoteRule]) answers = [] for policy in policies: response = policy.check(subject_identifier, results, waivers) diff --git a/greenwave/resources.py b/greenwave/resources.py index d8b8a8d..d38f186 100644 --- a/greenwave/resources.py +++ b/greenwave/resources.py @@ -45,7 +45,7 @@ def retrieve_rev_from_koji(nvr): @cached -def retrieve_yaml_remote_original_spec_nvr_rule(rev, pkg_name): +def retrieve_yaml_remote_rule(rev, pkg_name): """ Retrieve cached gating.yaml content for a given rev. """ data = { "DIST_GIT_BASE_URL": current_app.config['DIST_GIT_BASE_URL'], diff --git a/greenwave/tests/test_policies.py b/greenwave/tests/test_policies.py index 6d86cc3..b299896 100644 --- a/greenwave/tests/test_policies.py +++ b/greenwave/tests/test_policies.py @@ -238,8 +238,8 @@ rules: [] assert not policy.applies_to('dummy_context', 'epel-7', 'bodhi_update') -def test_remote_original_spec_nvr_rule_policy(tmpdir): - """ Testing the RemoteOriginalSpecNvrRule with the koji interaction. +def test_remote_rule_policy(tmpdir): + """ Testing the RemoteRule with the koji interaction. In this case we are just mocking koji """ nvr = 'nethack-1.2.3-1.el9000' @@ -253,7 +253,7 @@ decision_context: bodhi_update_push_stable_with_remoterule subject_type: koji_build blacklist: [] rules: - - !RemoteOriginalSpecNvrRule {} + - !RemoteRule {} """ remote_fragment = """ @@ -272,7 +272,7 @@ rules: app = create_app('greenwave.config.TestingConfig') with app.app_context(): with mock.patch('greenwave.resources.retrieve_rev_from_koji'): - with mock.patch('greenwave.resources.retrieve_yaml_remote_original_spec_nvr_rule') as f: + with mock.patch('greenwave.resources.retrieve_yaml_remote_rule') as f: f.return_value = remote_fragment policies = load_policies(tmpdir.strpath) policy = policies[0]