#542 Bug fix: failure to fetch gating.yaml
Merged 4 years ago by gnaponie. Opened 4 years ago by gnaponie.
gnaponie/greenwave FACTORY-5877  into  master

file modified
+28 -10
@@ -28,16 +28,6 @@ 

      # instead

      DIST_GIT_URL_TEMPLATE = \

          'https://src.fedoraproject.org/{pkg_namespace}{pkg_name}/raw/{rev}/f/gating.yaml'

-     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'

-         }

-     }

      REMOTE_RULE_GIT_TIMEOUT = 30

      REMOTE_RULE_GIT_MAX_RETRY = 3

      KOJI_BASE_URL = 'https://koji.fedoraproject.org/kojihub'
@@ -68,6 +58,16 @@ 

      WAIVERDB_API_URL = 'http://localhost:5004/api/v1.0'

      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'

+         }

+     }

  

  

  class TestingConfig(Config):
@@ -76,3 +76,21 @@ 

      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):

+     RESULTSDB_API_URL = 'http://localhost:5001/api/v2.0'

+     WAIVERDB_API_URL = 'http://localhost:5004/api/v1.0'

+     GREENWAVE_API_URL = 'http://localhost:5005/api/v1.0'

+     KOJI_BASE_URL = 'http://localhost:5006/kojihub'

+     POLICIES_DIR = _local_conf_dir('policies')

file modified
+1 -1
@@ -458,7 +458,7 @@ 

          # remote rule file URL

          if pkg_namespace == 'containers':

              pkg_name = re.sub('-container$', '', pkg_name)

-         rr_policies_conf = current_app.config.get('REMOTE_RULE_POLICIES')

+         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']

@@ -339,6 +339,52 @@ 

                  assert isinstance(decision[0], TestResultFailed)

  

  

+ def test_remote_rule_policy_with_no_remote_rule_policies_param_defined(tmpdir):

+     """ Testing the RemoteRule with the koji interaction.

+     But this time let's assume that REMOTE_RULE_POLICIES is not defined. """

+ 

+     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)

+     app = create_app('greenwave.config.FedoraTestingConfig')

+ 

+     with app.app_context():

+         with mock.patch('greenwave.resources.retrieve_scm_from_koji') as scm:

+             scm.return_value = ('rpms', '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)

+ 

+ 

  @pytest.mark.parametrize('namespace', ["modules", ""])

  def test_remote_rule_policy_redhat_module(tmpdir, namespace):

      """ Testing the RemoteRule with the koji interaction.

New configuration variables were introduced, but REMOTE_RULE_POLICIES
was not always present. Trying to get this config param, without a
fallback will provoke this error:
TypeError: 'NoneType' object does not support item assignment
Changed the code to assume {} as default value.

Ref: FACTORY-5877

Signed-off-by: Giulia Naponiello gnaponie@redhat.com

This won't work for Fedora stage because ProductionConfig already defines REMOTE_RULE_POLICIES[*] it will override their DIST_GIT_URL_TEMPLATE (stage dist-git is src.stg.fedoraproject.org).

I think the quick fix is to include the REMOTE_RULE_POLICIES in TestingConfig only.

rebased onto 7568236

4 years ago

@lholecek could you please check once again?

Commit bf6557f fixes this pull-request

Pull-Request has been merged by gnaponie

4 years ago

Pull-Request has been merged by gnaponie

4 years ago